@layer reset, base, layout, components, utilities;

/* Archivo carries every number and headline. Body copy stays on the system
   stack so the app feels native and loads instantly. */
@font-face {
  font-family: "Archivo";
  src: url("../fonts/archivo-variable.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}

@layer base {
  :root {
    /* Drawn from the ticket itself: thermal print, paper stock, latex silver,
       and the gold of a printed WINNER burst. */
    --ink: #1b1d22;
    --ink-raised: #24272e;
    --paper: #ede9e0;
    --paper-raised: #f7f4ee;
    --foil: #b4bac3;
    --foil-lit: #e3e7ec;
    --gold: #d89b1f;
    --gold-lit: #ffcb53;
    --gold-deep: #8f6408;
    --flag: #b8402a;

    --bg: light-dark(var(--paper), var(--ink));
    --surface: light-dark(var(--paper-raised), var(--ink-raised));
    --fg: light-dark(var(--ink), var(--paper));
    --fg-dim: light-dark(#5d6067, #99a0a9);
    --rule: light-dark(#d8d2c5, #343841);
    --accent: light-dark(var(--gold-deep), var(--gold-lit));
    --accent-solid: light-dark(var(--gold), var(--gold));

    --display: "Archivo", system-ui, sans-serif;
    --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

    --gap: 1.25rem;
    --radius: 1rem;
    --edge: max(1.25rem, env(safe-area-inset-left));

    color-scheme: light dark;
    accent-color: var(--accent-solid);
  }

  html { block-size: 100%; }

  body {
    margin: 0;
    min-block-size: 100dvh;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--body);
    font-size: 1rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
  }

  h1, h2, h3, p { margin: 0; }

  /* Numbers are the content of this app; never let them shift width. */
  :where(.hero-line, .verdict-amount, .chip, .cell, .tally-num, .summary-num, .work-status) {
    font-family: var(--display);
    font-variant-numeric: tabular-nums slashed-zero;
  }

  button, input { font: inherit; color: inherit; }

  :where(button, a, input, summary, label):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 4px;
  }

  svg {
    inline-size: 1.5rem;
    block-size: 1.5rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
}

@layer layout {
  .screen {
    display: flex;
    flex-direction: column;
    min-block-size: 100dvh;
    padding-block-end: env(safe-area-inset-bottom);
  }

  .screen-dark {
    color-scheme: dark;
    background: #0d0e11;
    color: var(--paper);
  }

  .screen-center { justify-content: center; align-items: center; }

  .topbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: max(0.75rem, env(safe-area-inset-top)) var(--edge) 0.75rem;
  }

  .topbar-title {
    flex: 1;
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.01em;
  }

  /* Keeps the centred title actually centred when only one side has a button. */
  .topbar > .icon-btn:only-of-type:first-child ~ .topbar-title { margin-inline-end: 2.75rem; }
}

@layer components {
  /* ── Wordmark ─────────────────────────────────────────────────────────
     The em is set in Archivo's condensed width, so the two halves of the
     name read as printed-then-scratched. */
  .wordmark {
    flex: 1;
    font-family: var(--display);
    font-size: 1.0625rem;
    font-weight: 700;
    letter-spacing: -0.015em;
  }

  .wordmark em {
    font-style: normal;
    font-stretch: 80%;
    font-weight: 500;
    color: var(--fg-dim);
  }

  .eyebrow {
    font-size: 0.75rem;
    font-weight: 650;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--fg-dim);
  }

  /* ── Home ─────────────────────────────────────────────────────────── */
  .home-hero {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.85rem;
    padding-inline: var(--edge);
    padding-block: 2rem;
  }

  .hero-line {
    font-size: clamp(3rem, 1.2rem + 14vw, 5.25rem);
    font-weight: 800;
    font-stretch: 88%;
    line-height: 0.92;
    letter-spacing: -0.035em;
    text-wrap: balance;
  }

  .home-actions {
    display: grid;
    gap: 0.6rem;
    padding-inline: var(--edge);
  }

  .tally { padding: 1.25rem var(--edge) 0; }

  .tally-body {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    padding-block: 0.9rem;
    border-block-start: 1px solid var(--rule);
    color: inherit;
    text-decoration: none;
  }

  .tally-num { font-size: 1.25rem; font-weight: 750; }
  .tally-won { color: var(--accent); }
  .tally-label { font-size: 0.8125rem; color: var(--fg-dim); }
  .tally-rule { flex: 1; }

  .disclaimer {
    padding: 1rem var(--edge) 1.5rem;
    font-size: 0.75rem;
    line-height: 1.45;
    color: var(--fg-dim);
    text-wrap: pretty;
  }

  /* ── Buttons ──────────────────────────────────────────────────────── */
  .btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    min-block-size: 3.5rem;
    padding-inline: 1.5rem;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 1.0625rem;
    font-weight: 620;
    cursor: pointer;
    transition: transform 0.12s ease, background-color 0.15s ease;
  }

  .btn:active:not(:disabled) { transform: scale(0.978); }
  .btn:disabled { opacity: 0.5; cursor: default; }
  .btn-icon { inline-size: 1.35rem; block-size: 1.35rem; }

  .btn-primary {
    background: var(--accent-solid);
    color: #17130a;
    box-shadow: 0 1px 0 var(--gold-lit) inset, 0 6px 18px -10px var(--gold);
  }

  .btn-quiet {
    background: transparent;
    border-color: var(--rule);
    color: var(--fg-dim);
    min-block-size: 3rem;
    font-size: 0.9375rem;
  }

  /* Destructive and rarely wanted: quiet, self-sized, and set apart from the
     list it would erase. */
  .btn-quiet.danger {
    justify-self: center;
    margin-block-start: 1.5rem;
    padding-inline: 2rem;
    color: var(--flag);
    border-color: color-mix(in oklab, var(--flag) 40%, transparent);
  }

  .icon-btn {
    display: grid;
    place-items: center;
    min-inline-size: 2.75rem;
    min-block-size: 2.75rem;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 50%;
    color: var(--fg);
    cursor: pointer;
  }

  .mini-btn {
    padding: 0.35rem 0.8rem;
    min-block-size: 2rem;
    background: transparent;
    border: 1px solid var(--rule);
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--fg-dim);
    cursor: pointer;
  }

  /* ── Camera ───────────────────────────────────────────────────────── */
  #cam-video {
    position: fixed;
    inset: 0;
    inline-size: 100%;
    block-size: 100%;
    object-fit: cover;
    background: #0d0e11;
  }

  .cam-overlay {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 4.5rem var(--edge) 1rem;
    pointer-events: none;
  }

  /* The cut-out is one huge spread shadow, so there is no second element to
     keep in sync with the frame. */
  .cam-window {
    inline-size: min(100%, 30rem);
    aspect-ratio: 4 / 3;
    border-radius: 0.75rem;
    box-shadow: 0 0 0 100vmax rgb(6 7 9 / 0.62);
    outline: 2px solid rgb(255 255 255 / 0.9);
    outline-offset: -1px;
  }

  .cam-hint {
    max-inline-size: 22rem;
    text-align: center;
    font-size: 0.875rem;
    color: rgb(255 255 255 / 0.86);
    text-shadow: 0 1px 6px rgb(0 0 0 / 0.6);
    text-wrap: pretty;
  }

  .cam-close {
    position: absolute;
    inset-block-start: max(0.75rem, env(safe-area-inset-top));
    inset-inline-end: var(--edge);
    display: grid;
    place-items: center;
    min-inline-size: 2.75rem;
    min-block-size: 2.75rem;
    background: rgb(0 0 0 / 0.45);
    border: 0;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
  }

  .cam-bar {
    position: relative;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    justify-items: center;
    gap: 1rem;
    padding: 1.25rem var(--edge) calc(1.5rem + env(safe-area-inset-bottom));
  }

  .cam-side {
    display: grid;
    justify-items: center;
    gap: 0.3rem;
    padding: 0.25rem;
    background: none;
    border: 0;
    color: rgb(255 255 255 / 0.88);
    font-size: 0.6875rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
  }

  .cam-side-face {
    display: grid;
    place-items: center;
    inline-size: 2.75rem;
    block-size: 2.75rem;
    border-radius: 50%;
    background: rgb(255 255 255 / 0.14);
  }

  .cam-side[aria-pressed="true"] .cam-side-face { background: var(--gold); color: #17130a; }

  .shutter {
    inline-size: 4.75rem;
    block-size: 4.75rem;
    padding: 0;
    background: none;
    border: 3px solid rgb(255 255 255 / 0.9);
    border-radius: 50%;
    cursor: pointer;
  }

  .shutter span {
    display: block;
    inline-size: 100%;
    block-size: 100%;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 3px #0d0e11 inset;
    transition: transform 0.12s ease;
  }

  .shutter:active span { transform: scale(0.86); }

  .cam-error {
    position: absolute;
    inset-block-end: 8rem;
    inset-inline: var(--edge);
    padding: 0.85rem 1rem;
    background: var(--flag);
    border-radius: 0.75rem;
    color: #fff;
    font-size: 0.875rem;
    text-wrap: pretty;
  }

  /* ── Working ──────────────────────────────────────────────────────── */
  .work {
    display: grid;
    justify-items: center;
    gap: 0.75rem;
    inline-size: min(100%, 22rem);
    padding-inline: var(--edge);
    text-align: center;
  }

  /* A silver panel being wiped clear: the same gesture as scratching. */
  .work-card {
    position: relative;
    inline-size: 100%;
    aspect-ratio: 16 / 9;
    margin-block-end: 1.25rem;
    border-radius: var(--radius);
    background: linear-gradient(148deg in oklab, #6e747d, #aeb5be 42%, #7b828b 60%, #9aa1aa);
    overflow: hidden;
  }

  .work-sweep {
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg, transparent 38%, rgb(255 255 255 / 0.55) 50%, transparent 62%);
    animation: sweep 1.7s ease-in-out infinite;
    --animation-reduced: none;
  }

  @keyframes sweep {
    from { translate: -110% 0; }
    to   { translate: 110% 0; }
  }

  .work-status { font-size: 1.5rem; font-weight: 720; letter-spacing: -0.02em; }
  .work-step { font-size: 0.875rem; color: var(--fg-dim); min-block-size: 1.4em; }

  .work-track {
    inline-size: 100%;
    block-size: 4px;
    margin-block: 0.4rem 1rem;
    border-radius: 999px;
    background: rgb(255 255 255 / 0.14);
    overflow: hidden;
  }

  .work-fill {
    block-size: 100%;
    inline-size: 0%;
    border-radius: inherit;
    background: var(--gold);
    transition: inline-size 0.35s ease;
  }

  /* ── Ticket read-back ─────────────────────────────────────────────────
     The signature of this app: your ticket redrawn in clean type, so you can
     hold the real one up beside it and confirm the reading in two seconds. */
  .ticket-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0.25rem var(--edge) 1.5rem;
    display: grid;
    gap: 1.75rem;
    align-content: start;
  }

  .band { display: grid; gap: 0.75rem; }

  .band-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }

  .band-empty {
    padding: 1rem;
    border: 1px dashed var(--rule);
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: var(--fg-dim);
    text-wrap: pretty;
  }

  .unsure-note {
    display: flex;
    gap: 0.6rem;
    padding: 0.85rem 1rem;
    margin-block-start: 0.75rem;
    border-radius: 0.75rem;
    background: color-mix(in oklab, var(--accent-solid) 16%, var(--bg));
    border: 1px solid color-mix(in oklab, var(--accent-solid) 40%, transparent);
    font-size: 0.875rem;
    text-wrap: pretty;
  }

  /* Says the reading came from the phone rather than the online reader —
     a caveat, so it is quieter than the gold "check this" note above it. */
  .fallback-note {
    padding: 0.85rem 1rem;
    margin-block-start: 0.75rem;
    border-radius: 0.75rem;
    border: 1px solid var(--rule);
    background: var(--surface);
    font-size: 0.8125rem;
    color: var(--fg-dim);
    text-wrap: pretty;
  }

  /* ── The game, as the ticket describes it ─────────────────────────── */
  .game-panel {
    display: grid;
    gap: 0.5rem;
    padding: 1rem;
    margin-block-start: 0.75rem;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
  }

  .game-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }

  .game-name {
    margin: 0;
    font-family: var(--display);
    font-size: 1.125rem;
    font-weight: 620;
    letter-spacing: -0.01em;
    text-wrap: balance;
  }

  .game-price {
    font-family: var(--display);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--fg-dim);
    flex: none;
  }

  .game-type {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
  }

  .game-rule { margin: 0; font-size: 0.875rem; text-wrap: pretty; }

  .game-rules-printed { font-size: 0.8125rem; color: var(--fg-dim); }
  .game-rules-printed summary { padding-block: 0.4rem; cursor: pointer; }
  .game-rules-text { margin: 0.25rem 0 0; white-space: pre-wrap; text-wrap: pretty; }

  /* One row per game printed on the ticket. */
  .games-list { display: grid; gap: 0.5rem; margin: 0.25rem 0 0; padding: 0; list-style: none; }

  .game-row {
    padding: 0.75rem 0.85rem;
    border: 1px solid var(--rule);
    border-radius: 0.75rem;
    background: var(--bg);
  }

  .game-row[data-won="true"] {
    border-color: color-mix(in oklab, var(--accent-solid) 55%, transparent);
    background: color-mix(in oklab, var(--accent-solid) 12%, var(--bg));
  }

  /* Same gold dashed outline the number cells use for "check this by eye". */
  .game-row[data-unsure="true"] { border-style: dashed; }

  .game-row-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; }

  .game-row-label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--fg-dim);
  }

  .game-row-prize { font-family: var(--display); font-weight: 640; }
  .game-row[data-won="true"] .game-row-prize { color: var(--accent); }

  .game-row-why { margin: 0.3rem 0 0; font-size: 0.8125rem; color: var(--fg-dim); text-wrap: pretty; }

  .chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }

  .chip, .cell {
    position: relative;
    border: 1px solid var(--rule);
    border-radius: 0.7rem;
    background: var(--surface);
  }

  /* Sized explicitly: a percentage-width input inside an auto-width flex item
     has nothing to resolve against and blows the chip out to full width. */
  .chip {
    display: flex;
    align-items: center;
    inline-size: 3.75rem;
    block-size: 3.75rem;
    flex: none;
  }

  .cells {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(4.5rem, 1fr));
    gap: 0.5rem;
  }

  .cell { display: grid; padding-block: 0.5rem 0.4rem; }

  /* Number and prize inputs are the ticket's own two-line cell, kept in the
     same stacked relationship so the redraw is directly comparable. */
  .num-input, .prize-input {
    inline-size: 100%;
    padding: 0;
    background: transparent;
    border: 0;
    text-align: center;
    font-family: var(--display);
    font-variant-numeric: tabular-nums slashed-zero;
  }

  .num-input {
    font-size: 1.375rem;
    font-weight: 750;
    letter-spacing: -0.02em;
    min-block-size: 1.9rem;
  }

  .chip .num-input { block-size: 100%; }

  .prize-input {
    font-size: 0.8125rem;
    font-weight: 560;
    color: var(--fg-dim);
    min-block-size: 1.2rem;
  }

  .num-input::placeholder, .prize-input::placeholder { color: var(--fg-dim); opacity: 0.5; }

  .cell-drop {
    position: absolute;
    inset-block-start: -0.3rem;
    inset-inline-end: -0.3rem;
    display: grid;
    place-items: center;
    inline-size: 1.6rem;
    block-size: 1.6rem;
    padding: 0;
    background: var(--bg);
    border: 1px solid var(--rule);
    border-radius: 50%;
    color: var(--fg-dim);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease;
  }

  .cell-drop svg { inline-size: 0.85rem; block-size: 0.85rem; stroke-width: 2.4; }

  /* The remove control appears once a cell is engaged — tapping into a cell to
     edit it is also how you reach its delete, so the grid stays calm at rest. */
  :where(.chip, .cell):is(:hover, :focus-within) .cell-drop { opacity: 1; }
  .cell-drop:focus-visible { opacity: 1; }

  [data-unsure="true"] {
    border-color: var(--accent-solid);
    border-style: dashed;
    background: color-mix(in oklab, var(--accent-solid) 10%, var(--surface));
  }

  /* Struck gold: the moment the app exists for. */
  [data-hit="true"] {
    border-color: transparent;
    background: linear-gradient(160deg in oklab, var(--gold-lit), var(--gold));
    color: #17130a;
    animation: ignite 0.42s cubic-bezier(0.2, 1.5, 0.4, 1) both;
    animation-delay: calc(var(--i, 0) * 55ms);
    --animation-reduced: none;
  }

  [data-hit="true"] :is(.num-input, .prize-input) { color: #17130a; }
  [data-hit="true"] .prize-input { font-weight: 700; }

  @keyframes ignite {
    from { scale: 0.9; filter: brightness(1.7); }
    60%  { scale: 1.04; }
    to   { scale: 1; filter: brightness(1); }
  }

  .shot-peek { font-size: 0.875rem; color: var(--fg-dim); }
  .shot-peek summary { padding-block: 0.5rem; cursor: pointer; }
  .shot-peek img { inline-size: 100%; border-radius: var(--radius); margin-block-start: 0.5rem; }

  /* ── Verdict ──────────────────────────────────────────────────────── */
  .verdict {
    display: grid;
    gap: 1rem;
    padding: 1.25rem var(--edge) calc(1.25rem + env(safe-area-inset-bottom));
    border-block-start: 1px solid var(--rule);
    background: var(--surface);
  }

  .verdict-label {
    font-size: 0.75rem;
    font-weight: 650;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--fg-dim);
  }

  .verdict-amount {
    font-size: clamp(2.75rem, 1rem + 12vw, 4rem);
    font-weight: 820;
    font-stretch: 90%;
    line-height: 1;
    letter-spacing: -0.04em;
  }

  .verdict-detail { font-size: 0.875rem; color: var(--fg-dim); text-wrap: pretty; }
  .verdict-actions { display: grid; }

  /* Specific things to check by eye. These must not be easy to skip past, so
     they carry the same gold as an unsure cell rather than sitting dim. */
  .verdict-cautions {
    display: grid;
    gap: 0.35rem;
    margin: 0.75rem 0 0;
    padding: 0.7rem 0.9rem 0.7rem 1.9rem;
    border-radius: 0.75rem;
    background: color-mix(in oklab, var(--accent-solid) 14%, var(--bg));
    border: 1px solid color-mix(in oklab, var(--accent-solid) 38%, transparent);
    font-size: 0.8125rem;
    text-wrap: pretty;
  }

  .verdict-cautions li { margin: 0; }

  .verdict[data-state="win"] .verdict-amount { color: var(--accent); }
  .verdict[data-state="win"] .verdict-label { color: var(--accent); }
  .verdict[data-state="none"] .verdict-amount { font-size: clamp(1.75rem, 1rem + 5vw, 2.25rem); }

  /* ── History ──────────────────────────────────────────────────────── */
  .history-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem var(--edge) 2rem;
    display: grid;
    gap: 1.25rem;
    align-content: start;
  }

  .summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    padding-block: 0.5rem 1.25rem;
    border-block-end: 1px solid var(--rule);
  }

  .summary div { display: grid; gap: 0.15rem; }
  .summary-num { font-size: 1.5rem; font-weight: 760; letter-spacing: -0.02em; }
  .summary-won { color: var(--accent); }
  .summary-label { font-size: 0.75rem; color: var(--fg-dim); }

  .history-list { display: grid; gap: 0.5rem; margin: 0; padding: 0; list-style: none; }

  .history-row {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    inline-size: 100%;
    padding: 0.9rem 1rem;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    text-align: start;
    cursor: pointer;
  }

  .history-amount {
    font-family: var(--display);
    font-variant-numeric: tabular-nums slashed-zero;
    font-size: 1.125rem;
    font-weight: 750;
    min-inline-size: 4rem;
  }

  .history-row[data-win="true"] .history-amount { color: var(--accent); }
  .history-row[data-win="false"] .history-amount { color: var(--fg-dim); }
  .history-meta { flex: 1; display: grid; gap: 0.1rem; }
  .history-when { font-size: 0.9375rem; }
  .history-sub { font-size: 0.8125rem; color: var(--fg-dim); }

  /* ── Settings sheet ───────────────────────────────────────────────── */
  .sheet {
    inline-size: min(100%, 32rem);
    max-block-size: 88dvh;
    margin: auto auto 0;
    padding: 0;
    border: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--surface);
    color: var(--fg);
    translate: 0 0;
    transition: translate 0.28s ease, display 0.28s allow-discrete, overlay 0.28s allow-discrete;
  }

  .sheet:not([open]) { translate: 0 100%; }
  @starting-style { .sheet[open] { translate: 0 100%; } }

  .sheet::backdrop {
    background: rgb(6 7 9 / 0.5);
    transition: background-color 0.28s ease, display 0.28s allow-discrete, overlay 0.28s allow-discrete;
  }

  .sheet:not([open])::backdrop { background: rgb(6 7 9 / 0); }
  @starting-style { .sheet[open]::backdrop { background: rgb(6 7 9 / 0); } }

  .sheet form {
    display: grid;
    gap: 1.25rem;
    padding: 1.5rem var(--edge) calc(1.5rem + env(safe-area-inset-bottom));
    overflow-y: auto;
  }

  .sheet h2 { font-family: var(--display); font-size: 1.375rem; font-weight: 740; letter-spacing: -0.02em; }

  .row-toggle { display: flex; gap: 0.85rem; align-items: start; cursor: pointer; }
  .row-toggle input { inline-size: 1.35rem; block-size: 1.35rem; margin-block-start: 0.15rem; flex: none; }
  .row-toggle span, .row-block { display: grid; gap: 0.2rem; }
  .row-toggle strong, .row-block strong { font-size: 0.9375rem; font-weight: 620; }
  .row-toggle small, .row-block small { font-size: 0.8125rem; color: var(--fg-dim); text-wrap: pretty; }
  .row-block .btn { margin-block-start: 0.6rem; justify-self: start; }

  .fine-print { font-size: 0.75rem; color: var(--fg-dim); text-wrap: pretty; }

  /* ── Toast ────────────────────────────────────────────────────────── */
  .toast {
    position: fixed;
    inset-inline: var(--edge);
    inset-block-end: calc(1.5rem + env(safe-area-inset-bottom));
    z-index: 20;
    padding: 0.85rem 1.1rem;
    background: var(--fg);
    color: var(--bg);
    border-radius: 0.75rem;
    font-size: 0.875rem;
    text-align: center;
    animation: rise 0.24s ease both;
    --animation-reduced: none;
  }

  @keyframes rise {
    from { opacity: 0; translate: 0 0.6rem; }
  }
}

@layer utilities {
  /* Components that set `display` would otherwise out-rank the UA's rule for
     `hidden`. Utilities is the last layer, so this wins without `!important`. */
  [hidden] { display: none; }

  .sr-only {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* ── Screen transitions ────────────────────────────────────────────────── */
::view-transition-group(root) { animation-duration: 0.28s; animation-timing-function: ease-in-out; }

@keyframes slide-to-left   { to   { translate: -22% 0; opacity: 0; } }
@keyframes slide-from-right{ from { translate: 22% 0;  opacity: 0; } }
@keyframes slide-to-right  { to   { translate: 22% 0;  opacity: 0; } }
@keyframes slide-from-left { from { translate: -22% 0; opacity: 0; } }

html:active-view-transition-type(forward)::view-transition-old(root)  { animation-name: slide-to-left; }
html:active-view-transition-type(forward)::view-transition-new(root)  { animation-name: slide-from-right; }
html:active-view-transition-type(backward)::view-transition-old(root) { animation-name: slide-to-right; }
html:active-view-transition-type(backward)::view-transition-new(root) { animation-name: slide-from-left; }

/* Reduced motion: keep state changes legible, drop the movement. */
@property --animation-reduced {
  syntax: "*";
  inherits: false;
  initial-value: none;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: var(--animation-reduced) !important; }
  ::view-transition-group(root) { animation: none !important; }
  .btn:active:not(:disabled) { transform: none; }
  .sheet, .sheet::backdrop { transition-duration: 0.01s; }
}

@media (forced-colors: active) {
  .chip, .cell, .history-row, .btn { border: 1px solid ButtonBorder; }
  [data-hit="true"] { outline: 3px solid Highlight; outline-offset: -3px; }
  [data-unsure="true"] { outline: 2px dashed CanvasText; outline-offset: -2px; }
  .cam-window { outline: 2px solid CanvasText; }
}
