/* vallet: plain paper, ink, chunky borders. */
@layer reset, base, layout, parts, states;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, p, ul, ol, menu, figure { margin: 0; padding: 0; }
  ul, ol, menu { list-style: none; }
  button, input, select, textarea { font: inherit; color: inherit; }
  [hidden] { display: none !important; }
}

@layer base {
  :root {
    color-scheme: light dark;
    --paper: light-dark(#f3ead6, #1d1914);
    --paper-deep: light-dark(#e8dcc0, #2a241c);
    --ink: light-dark(#2b2118, #efe4cc);
    --ink-soft: light-dark(#6b5a45, #b8a88b);
    --fire: light-dark(#c4471d, #ff8a5c);
    --moss: light-dark(#3f6b2a, #9ccf7a);
    --border: 3px solid var(--ink);
    --shadow: 4px 4px 0 var(--ink);
    --radius: 14px;
    --radius-rough: 16px 12px 15px 11px / 12px 15px 11px 16px;
    --gap: 1rem;
    font-family: ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
    font-size: clamp(16px, 2.6vw + 10px, 19px);
    line-height: 1.45;
    accent-color: var(--fire);
  }
  body {
    background: var(--paper);
    color: var(--ink);
    min-height: 100dvh;
  }
  h1, h2 { text-wrap: balance; line-height: 1.15; }
  h1 { font-size: 2rem; letter-spacing: -0.02em; }
  h2 { font-size: 1.15rem; }
  p { text-wrap: pretty; }
  .mono, .address-big, .who { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
  ::selection { background: var(--fire); color: var(--paper); }
  :focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
}

@layer layout {
  #app {
    container: app / inline-size;
    max-width: 34rem;
    margin-inline: auto;
    padding: max(1.25rem, env(safe-area-inset-top)) 1.25rem 3rem;
  }
  .screen { display: grid; gap: var(--gap); view-transition-name: screen; }
  .hero { justify-items: center; text-align: center; padding-block-start: 12vh; }
  .actions { display: grid; gap: 0.75rem; width: 100%; }
  /* Action buttons stack: one full-width button per row, the main one first. */
  .top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
}

@layer parts {
  .card {
    background: var(--paper-deep);
    border: var(--border);
    border-radius: var(--radius-rough);
    box-shadow: var(--shadow);
    padding: 1rem 1.1rem;
    display: grid;
    gap: 0.6rem;
  }
  .lead { font-size: 1.15rem; }
  .money { container-type: inline-size; }
  .hint, .fine { color: var(--ink-soft); font-size: 0.9rem; }
  .mark { border-radius: 24px; }
  .brand { font-size: 1.4rem; }

  button {
    cursor: pointer;
    border: var(--border);
    border-radius: var(--radius-rough);
    background: var(--paper);
    box-shadow: var(--shadow);
    padding: 0.55rem 1rem;
    font-weight: 700;
    transition: translate 80ms, box-shadow 80ms;
    &:active { translate: 3px 3px; box-shadow: 1px 1px 0 var(--ink); }
    &:disabled { opacity: 0.5; cursor: progress; }
  }
  button.big {
    font-size: 1.2rem;
    padding: 0.85rem 1.2rem;
    background: var(--fire);
    color: var(--paper);
    min-height: 3.2rem;
  }
  button.quiet { background: var(--paper); color: var(--ink); }
  button.danger { background: var(--fire); color: var(--paper); }
  button.small { font-size: 0.85rem; padding: 0.3rem 0.6rem; box-shadow: 2px 2px 0 var(--ink); }
  button.link, button.back {
    border: 0; box-shadow: none; background: none; padding: 0.25rem 0;
    text-decoration: underline; text-underline-offset: 3px; font-weight: 600;
    justify-self: start;
  }
  .chip {
    font-family: ui-monospace, Menlo, monospace;
    font-size: 0.85rem;
    padding: 0.3rem 0.7rem;
    box-shadow: 2px 2px 0 var(--ink);
  }

  .form label { display: grid; gap: 0.25rem; font-weight: 700; }
  .threshold label { font-weight: 700; }
  .threshold .line { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
  .threshold .line input { width: auto; font-size: 1.3rem; font-weight: 800; text-align: center; }
  .threshold .line button { flex: 1 0 100%; }
  input, select, textarea {
    border: var(--border);
    border-radius: 10px;
    background: var(--paper);
    padding: 0.6rem 0.7rem;
    font-weight: 500;
    min-width: 0;
    width: 100%;
  }
  textarea { field-sizing: content; min-height: 3lh; max-height: 12lh; resize: vertical; }
  input[type="number"] { field-sizing: content; min-width: 4ch; }
  input:user-invalid, textarea:user-invalid { border-color: var(--fire); border-style: dashed; }
  label:has(:user-invalid)::after {
    content: "Check this.";
    color: var(--fire);
    font-size: 0.85rem;
    font-weight: 600;
  }
  .form:has(:user-invalid) button[type="submit"] { opacity: 0.6; }

  .balances li, .activity li, .keys li {
    padding-block: 0.45rem;
    border-block-end: 2px dotted var(--ink-soft);
    &:last-child { border-block-end: 0; }
  }
  .balances li { display: grid; gap: 0; }
  .balances .name { font-size: 0.95rem; color: var(--ink-soft); font-weight: 600; }
  .balances .amount {
    font-size: clamp(1.45rem, 6cqi, 1.9rem); font-weight: 800; letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
  }
  .activity li {
    display: grid; grid-template-columns: auto 1fr; column-gap: 0.6rem; align-items: baseline;
  }
  .activity .way { font-weight: 700; color: var(--ink-soft); }
  .activity .amount {
    justify-self: end; font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums;
  }
  .activity .who { grid-column: 1 / -1; justify-self: end; }
  .activity .who, .keys .who {
    color: var(--ink-soft); font-size: 0.8rem;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
  }
  .keys li {
    display: grid; grid-template-columns: 1fr auto; column-gap: 0.6rem; row-gap: 0.15rem;
    align-items: center;
  }
  .keys .name { font-weight: 800; font-size: 1.1rem; overflow-wrap: anywhere; }
  .keys .here:not(:empty) {
    grid-column: 1; justify-self: start; font-size: 0.75rem; font-weight: 700;
    border: 2px solid var(--ink); border-radius: 999px; padding: 0 0.5rem;
  }
  .keys .who { grid-column: 1; }
  .keys button { grid-column: 2; grid-row: 1 / span 3; }
  .keys li:only-child button { display: none; }
  .quickpay-text { white-space: pre-line; }
  .trouble {
    display: grid; gap: 0.6rem; font-weight: 700; color: var(--fire);
    border: 3px dashed var(--fire); border-radius: var(--radius-rough); padding: 0.7rem 0.9rem;
  }
  .summary { font-size: 1.3rem; font-weight: 700; }
  .address-big { font-size: 1.35rem; word-spacing: 0.3em; text-align: center; line-height: 1.7; }

  .status:not(:empty) {
    display: block;
    border: var(--border);
    border-style: dashed;
    border-radius: var(--radius-rough);
    padding: 0.7rem 0.9rem;
    font-weight: 700;
  }
  .share { display: grid; gap: 0.6rem; }

  dialog {
    border: var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: var(--paper);
    color: var(--ink);
    padding: 1.2rem;
    max-width: min(26rem, 92vw);
    &::backdrop { background: color-mix(in srgb, var(--ink) 40%, transparent); }
    form { display: grid; gap: 0.9rem; }
    menu { display: grid; gap: 0.6rem; }
  }

  #copied {
    position-area: top;
    margin: 0 0 0.5rem;
    inset: auto;
    border: var(--border);
    border-radius: 10px;
    background: var(--moss);
    color: var(--paper);
    padding: 0.3rem 0.8rem;
    font-weight: 800;
  }
}

@layer states {
  @scope ([data-state="busy"]) {
    button.big[type="submit"], button[data-ui="approve.confirm"] { cursor: progress; }
    .status { animation: thump 1.2s ease-in-out infinite; }
  }
  [data-state="good"] .status {
    border-color: var(--moss); color: var(--moss); border-style: solid;
  }
  [data-state="bad"] .status { border-color: var(--fire); color: var(--fire); }
  @keyframes thump { 50% { scale: 1.02; } }
  @media (prefers-reduced-motion: reduce) {
    [data-state="busy"] .status { animation: none; }
    ::view-transition-group(*) { animation-duration: 0s; }
  }
  ::view-transition { pointer-events: none; }
  ::view-transition-old(screen) { animation: 120ms ease-out both fade-out; }
  ::view-transition-new(screen) { animation: 160ms ease-in both fade-in; }
  @keyframes fade-out { to { opacity: 0; translate: 0 -6px; } }
  @keyframes fade-in { from { opacity: 0; translate: 0 6px; } }
}
