@layer reset, tokens, base, components, stage, phone;

@layer reset {
  *, ::before, ::after { box-sizing: border-box; margin: 0; padding: 0; border: 0 solid; }
  html { -webkit-text-size-adjust: 100%; }
  h1, h2, h3 { font: inherit; }
  ul { list-style: none; }
  img, svg, video, iframe { display: block; }
  img, video { max-width: 100%; height: auto; }
  button, input, select, textarea { font: inherit; color: inherit; background: transparent; }
  a { color: inherit; text-decoration: inherit; }
  table { border-collapse: collapse; }
  textarea { resize: vertical; }
  [hidden] { display: none !important; }
}

@layer tokens {
  @font-face { font-family: "Public Sans"; font-weight: 400; src: url(/game/fonts/PublicSans-Regular.ttf) format("truetype"); }
  @font-face { font-family: "Public Sans"; font-weight: 600; src: url(/game/fonts/PublicSans-SemiBold.ttf) format("truetype"); }
  @font-face { font-family: "Public Sans"; font-weight: 700; src: url(/game/fonts/PublicSans-Bold.ttf) format("truetype"); }
  @font-face { font-family: "Public Sans"; font-weight: 800; src: url(/game/fonts/PublicSans-ExtraBold.ttf) format("truetype"); }

  /* Values from the HUD v5 set A tokens (docs/reference/hud-v5-layout.md), so the page frames art in the game's own chrome. */
  :root {
    color-scheme: dark;
    --well: #0c141a;
    --slab: #121c24;
    --quiet: #16212a;
    --btn: #223241;
    --panel2: #26384a;
    --line: #2e3f4b;
    /* Softer than the HUD's #eef3f5 so page text never outshines the picture. */
    --text: #dfe7ec;
    --soft: #b9c6ce;
    --muted: #93a5b0;
    --sel: #60e5ed;
    --on-sel: #08131c;
    --amber: #f7c871;
    --on-amber: #1a1408;
    --error: #b3261e;
    --stage: #000;
    --scrim: rgb(0 0 0 / .88);
    --font: "Public Sans", Arial, sans-serif;
    --mono: ui-monospace, Menlo, monospace;
    --label: 12px;
    --row: 13px;
  }
}

@layer base {
  body { background: var(--well); color: var(--text); font: 15px/1.45 var(--font); }
  textarea {
    display: block; width: 100%; padding: 8px 12px; font-size: 14px;
    background: var(--well); border: 1px solid var(--line);
    &:focus { outline: 2px solid var(--muted); outline-offset: 2px; }
  }
  kbd {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    min-width: 18px; height: 18px; padding: 0 4px; font: 700 var(--label)/1 var(--font);
    color: var(--muted); background: var(--well); border: 1px solid var(--line);
  }
  summary { cursor: pointer; }
  .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

@layer components {
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: nowrap;
    height: 40px; padding-inline: 16px; font-size: 14px; font-weight: 600; text-align: center; white-space: nowrap;
    color: var(--text); background: var(--quiet); border: 1px solid var(--quiet); cursor: pointer; user-select: none;
    &:hover { background: var(--btn); border-color: var(--btn); }
    /* A visible edge: --quiet on --well alone is 1.1:1. */
    &.neutral { border-color: var(--muted); }
    &:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
    &.sm { height: 32px; padding-inline: 12px; font-size: 12px; }
    &.lg { height: 48px; padding-inline: 20px; font-size: 18px; }
    &.xs { height: 24px; padding-inline: 8px; font-size: 11px; }
    &.on { color: var(--on-sel); background: var(--sel); border-color: var(--sel); }
    &.pick { color: var(--on-amber); background: var(--amber); border-color: var(--amber); font-weight: 800; }
    kbd { margin-inline: 4px; }
    &[aria-disabled=true] { color: var(--muted); background: transparent; border-color: var(--quiet); pointer-events: none; }
  }

  .tag {
    display: inline-flex; align-items: center; height: 20px; padding-inline: 6px; flex: none; white-space: nowrap;
    font-size: var(--label); font-weight: 700; vertical-align: middle; border: 1px solid transparent;
    /* Light badge: --well on --text is 14.8:1, and no amber, which marks where to act. */
    &.cp { color: var(--well); background: var(--text); }
    &.got { color: var(--on-sel); background: var(--sel); }
    &.rv { color: var(--text); border-color: currentColor; }
  }

  .w { font-weight: 700; color: var(--text); }
  .h, .step label.h, .cnt, figcaption { display: block; font-size: var(--label); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
  .cnt { display: inline; }
  .missing { color: var(--amber); font: 600 13px var(--mono); padding: 12px; display: block; }
  .localonly { color: var(--muted); font-size: 13px; padding: 12px; display: block; }

  #flash, #err { color: #fff; background: var(--error); padding: 12px 16px; font-size: 14px; white-space: pre-wrap; }
  #flash { position: fixed; inset: 0 0 auto; z-index: 99; max-height: 40vh; overflow: auto; }
  #err { font-family: var(--mono); }
  #toast { position: fixed; top: 56px; left: 50%; translate: -50% 0; z-index: 98; padding: 8px 14px; font-size: 14px; color: var(--text); background: var(--slab); border: 1px solid var(--line); }
  #readonly { padding: 6px 24px; font-size: var(--row); color: var(--muted); background: var(--slab); border-bottom: 1px solid var(--line); }

  .top { position: sticky; top: 0; z-index: 10; background: var(--well); border-bottom: 1px solid var(--line); }
  .chips { display: flex; gap: 6px; padding: 8px 24px; overflow-x: auto; scrollbar-width: thin; max-width: 1680px; margin: 0 auto; }
  .chip {
    flex: none; height: auto; padding: 4px 10px; font-size: var(--row);
    &.unsent { border: 1px dashed var(--amber); border-bottom: 3px dashed var(--amber); color: var(--amber); }
    &.er { margin-left: 12px; font-style: italic; }
  }

  .step { max-width: 1680px; margin: 0 auto; padding: 16px 24px 48px; display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); gap: 24px; align-items: start; }
  .step .left, .step .right { min-width: 0; display: flex; flex-direction: column; gap: 14px; }
  .step.v-side, .step.k-summary, .step.k-index, .step.k-missing { grid-template-columns: minmax(0, 1fr); }
  .step.v-side { display: flex; flex-direction: column; align-items: stretch; gap: 14px; }
  .step.v-side .left, .step.v-side .right { display: contents; }
  .v-side {
    :is(.intro, .head) { order: 1; } .why { order: 2; } .cue { order: 3; } .stagecol { order: 4; } .info { order: 5; } .notebox { order: 6; } .stepnav { order: 7; }
    :is(.why, .cue, .info, .notebox) { max-width: 1100px; }
  }
  .step .right:empty { display: none; }

  .head {
    .n { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
    h1 { margin: 2px 0 6px; font-size: 24px; font-weight: 800; line-height: 1.2; }
    p { margin: 0 0 4px; }
  }
  .rec {
    color: var(--muted); margin: 0;
    &:empty { display: none; }
    .fail { color: var(--amber); font-weight: 700; }
    button { margin-left: 6px; }
  }
  .cpline { color: var(--soft); font-size: 14px; }
  .intro {
    max-width: 1100px; padding: 10px 14px; background: var(--slab); border-left: 3px solid var(--line);
    p { margin: 0; color: var(--text); font-size: 14px; }
    summary { font-size: var(--label); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
    &[open] summary { margin-bottom: 4px; }
  }
  :is(.info, .cue, .why) p { margin: 0 0 10px; color: var(--soft); font-size: 14px; }
  .cue p.look { color: var(--amber); margin-bottom: 6px; }
  :is(.why, .ref) summary { font-size: var(--label); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
  .ref summary { text-transform: none; letter-spacing: 0; font-size: var(--row); font-weight: 600; }
  .fold {
    margin-top: 10px; border-top: 1px solid var(--line); padding-top: 6px;
    summary { color: var(--soft); font-weight: 700; font-size: 14px; }
    p { font-size: 14px; color: var(--soft); margin: .5em 0; }
  }
  :is(.uses, .check) ul { margin: 2px 0 10px; padding-left: 18px; font-size: 14px; color: var(--soft); list-style: disc; }
  .check ul { color: var(--text); }
  .notebox textarea { height: 72px; }
  .nhint { margin: 2px 0 0; color: var(--amber); font-size: var(--row); &:empty { display: none; } }
  .stepnav, .inav { display: flex; gap: 8px; align-items: center; }
  .stepnav [data-act=legend] { margin-left: auto; }

  .flipbar {
    display: flex; flex-wrap: wrap; gap: 6px; align-items: stretch;
    .ob { max-width: 320px; }
    .ob span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .fl { font-weight: 800; }
    .vt { margin-left: auto; }
  }
  .ctlbar {
    display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
    .btn span { color: var(--muted); font-weight: 700; }
  }
  .ctlsel {
    display: inline-flex; align-items: center; gap: 4px; font-size: var(--row); font-weight: 600; white-space: nowrap;
    span { color: var(--muted); font-weight: 700; }
    select { height: 32px; padding-inline: 8px; font-size: 12px; background: var(--well); border: 1px solid var(--line); }
  }
  .act, .tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
  .act {
    .pick { font-size: 16px; padding-inline: 22px; height: 44px; max-width: 100%; position: relative; }
    /* Above the button in the 16 px gap, 14 px tall so it never reaches the picture. */
    .ptab { position: absolute; left: -1px; bottom: calc(100% + 1px); height: 14px; font-size: var(--label); line-height: 1; }
    .pn { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 600; &:empty { display: none; } }
    &:empty { display: none; }
  }
  .tools {
    .scale { margin-left: auto; }
    .scale:empty + [data-act=large] { margin-left: auto; }
  }
  :is(.v-flip, .v-side) :is(.stage, .tiles) + .act, .v-flip .act + .tools { margin-top: 16px; }
  /* Out of flow so the buttons stay centred on one line. The row keeps room for it: the neutral button ends 2 px inside the 44 px row, then 4 px, the 16 px line and the 16 px gap. */
  .nwrap { position: relative; display: inline-flex; }
  .nexplain { position: absolute; left: 0; top: calc(100% + 4px); white-space: nowrap; color: var(--muted); font-size: var(--row); line-height: 16px; }
  .act:has(.nexplain) { margin-bottom: 34px; }
  .k-tune .act:has(.nexplain) { margin-bottom: 18px; }
  .tiles + .act { justify-content: center; }
  .scale { color: var(--muted); font-size: var(--row); &:empty { display: none; } }

  .ohd { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .let { font-size: 28px; font-weight: 800; line-height: 1; }
  .ohd h2 { margin: 0; font-size: 18px; font-weight: 700; flex: 1 1 200px; min-width: 0; }
  :is(.detail, .tile) p { margin: 8px 0 0; color: var(--soft); font-size: 14px; max-width: 1000px; }
  :is(.detail, .tile) p.sees { color: var(--text); }
  .chg { font-size: var(--row); }
  .extras { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; margin-top: 12px; }
  .extras figcaption { text-transform: none; letter-spacing: 0; font-size: var(--row); font-weight: 600; }

  .tiles { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 14px; align-items: stretch; }
  .tile {
    background: var(--slab); border: 2px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 10px;
    .ohd { min-height: 2.6em; flex-wrap: nowrap; }
    .ohd h2 { flex: 1 1 0; }
    &.done { border-color: var(--amber); }
    &.sel { border-color: var(--sel); .let { color: var(--sel); } }
    cursor: pointer;
    details summary { color: var(--muted); font-size: var(--row); }
    &.reft { border-style: dashed; }
    &.reft h2 { font-size: 15px; color: var(--soft); }
  }

  .gside {
    h2 { margin: 0 0 4px; font-size: 18px; font-weight: 700; }
    p { margin: 4px 0 10px; color: var(--soft); font-size: 14px; }
    textarea { height: 90px; }
    .inav { margin-top: 8px; }
  }
  .thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
  .th {
    border: 2px solid transparent; background: var(--slab); padding: 2px; display: block;
    &.on { border-color: var(--sel); }
    &.noted { border-bottom-color: var(--amber); }
    span { display: block; font-size: 12px; color: var(--muted); padding: 2px 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  }
  .verdict {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: stretch;
    .vb { font-weight: 800; padding-inline: 26px; white-space: normal; height: auto; min-height: 48px; }
    .vb.done { outline: 3px solid var(--sel); outline-offset: 3px; }
    textarea { flex: 1 1 100%; height: 72px; }
  }
  .k-verdict .right .verdict { margin-top: 40px; }

  .fields { display: flex; flex-direction: column; gap: 16px; }
  .field {
    textarea { height: 70px; font-size: 16px; }
    .was { margin: 4px 0 0; color: var(--muted); font-size: var(--row); }
  }

  .scroll { overflow-x: auto; }
  table.sum, .numbers table { width: 100%; text-align: left; }
  table.sum {
    font-size: var(--row);
    :is(th, td) { padding: 8px 12px; vertical-align: middle; }
    thead { color: var(--muted); font-size: 14px; font-weight: 600; white-space: nowrap; }
    :is(thead tr, tbody tr:not(:last-child)) > * { border-bottom: 1px solid var(--quiet); }
  }
  #sum {
    h2 { font-size: 18px; margin: 16px 0 0; font-weight: 700; }
    .cnt { margin-left: 8px; }
    .sum { max-width: 1200px; }
    p { margin: 1em 0; }
    .scroll { margin: 8px 0 20px; }
  }
  .sec { margin: 28px 0 0; font-size: 14px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
  .close { font-size: 20px; font-weight: 700; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; .btn { font-size: 15px; } }
  .opens { display: flex; flex-wrap: wrap; gap: 6px; }
  .copied { color: var(--muted); font-size: var(--row); }
  .rounds {
    width: fit-content; padding: 8px; font-size: 14px;
    a { display: flex; align-items: center; min-height: 48px; padding: 6px 12px; color: var(--text); border-bottom: 1px solid var(--line); }
    a:hover { background: var(--quiet); }
    .adv { margin-left: 12px; color: var(--muted); font-size: 13px; }
  }
  .lablink { font-size: 14px; color: inherit; text-decoration: underline; }

  .measure {
    &:empty { display: none; }
    table { font-size: 12px; }
    :is(th, td) { padding: 4px 8px; text-align: left; font-variant-numeric: tabular-nums; border-bottom: 1px solid var(--quiet); }
    th { color: var(--soft); font-weight: 600; }
    tr.off td { color: var(--muted); }
  }

  .numbers {
    table { font-size: 12px; }
    :is(th, td) { padding: 4px 8px; text-align: right; font-variant-numeric: tabular-nums; border-bottom: 1px solid var(--quiet); }
    thead th { color: var(--muted); font-weight: 600; }
    tr th:first-child { text-align: left; color: var(--soft); font-weight: 600; }
    th span { color: var(--muted); font: 11px var(--mono); }
    td.low { color: var(--amber); font-weight: 800; }
    p { font-size: 12px; color: var(--muted); margin: 4px 0 0; }
    .sw { display: inline-block; width: 10px; height: 10px; margin-right: 5px; vertical-align: -1px; border: 1px solid var(--line); }
  }

  #legend { cursor: default; }
  .keys {
    background: var(--slab); border: 1px solid var(--line); padding: 20px 24px; max-width: 640px; width: 100%; max-height: 92vh; overflow: auto;
    h2 { margin: 0 0 8px; font-size: 20px; font-weight: 800; }
    h3 { margin: 14px 0 4px; font-size: var(--row); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
    th { text-align: left; padding: 4px 16px 4px 0; font: 12px var(--mono); color: var(--text); white-space: nowrap; vertical-align: top; }
    td { padding: 4px 0; color: var(--soft); font-size: 14px; }
    p { color: var(--muted); font-size: var(--row); margin: 10px 0 0; }
    tr.off :is(th, td) { opacity: .5; }
  }

  wr-tune {
    display: block; max-width: 720px;
    --tp-base-background-color: var(--slab);
    --tp-base-shadow-color: transparent;
    --tp-base-border-radius: 0;
    --tp-blade-border-radius: 0;
    --tp-base-font-family: var(--font);
    --tp-container-unit-size: 34px;
    --tp-container-unit-spacing: 8px;
    --tp-blade-value-width: 55%;
    --tp-button-background-color: var(--line);
    --tp-button-background-color-hover: var(--panel2);
    --tp-button-background-color-focus: var(--panel2);
    --tp-button-background-color-active: var(--btn);
    --tp-button-foreground-color: var(--text);
    --tp-input-background-color: var(--well);
    --tp-input-background-color-hover: var(--quiet);
    --tp-input-background-color-focus: var(--quiet);
    --tp-input-background-color-active: var(--quiet);
    --tp-input-foreground-color: var(--text);
    --tp-groove-foreground-color: var(--line);
    --tp-label-foreground-color: var(--soft);
    .tp-rotv { font-size: 14px; }
    /* Knob only: the public --tp-button-* also fill the list, and Tweakpane resolves them once on .tp-rotv. */
    .tp-sldv_k { --btn-bg: var(--text); --btn-bg-h: var(--text); --btn-bg-f: var(--text); --btn-bg-a: var(--text); }
    /* Track only: the public --tp-input-* also fill every text field. */
    .tp-sldv_t { --in-bg: var(--muted); }
    /* The knob looks the same focused, so arrow keys need a ring, inside the track so it never touches a neighbour; !important beats Tweakpane's unlayered outline: none. */
    .tp-sldv_t:focus-visible { outline: 2px solid var(--text) !important; outline-offset: -2px; }
  }

  /* In flight: a page change dims the old page and shows a bar under the chips; note saves do not. */
  body:has(a.htmx-request, form.htmx-request, select.htmx-request) {
    #main { opacity: .55; }
    .top::after { content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 3px; background: var(--amber); }
  }
}

@layer stage {
  figure { margin: 0; }
  .stage { background: var(--stage); display: flex; justify-content: center; min-height: 120px; }
  .ostage { width: 100%; display: flex; justify-content: center; }
  .ref .pic { max-width: 420px; }

  .pic {
    position: relative; overflow: hidden; background: var(--stage); width: 100%;
    &[data-large] { cursor: zoom-in; }
    &[data-cw] { aspect-ratio: var(--ar); max-width: calc(var(--cw) * 1px); }
    .sc { position: absolute; left: 0; top: 0; overflow: hidden; transform-origin: 0 0; transform: scale(var(--s, 1)); }
    iframe { position: absolute; border: 0; pointer-events: none; }
    &.img img { display: block; width: 100%; height: auto; }
    &.none { min-height: 80px; }
    &.live { cursor: default; }
    &.live iframe { pointer-events: auto; }
    &.vid video { display: block; width: 100%; height: auto; background: var(--stage); }
    .hudlayer { position: absolute; border: 0; pointer-events: none; background: transparent; }
  }
  :is(.v-flip .stage, .k-gallery .gmain, .k-tune .stage) .pic[data-cw] { width: min(100%, calc((100vh - 280px) * var(--ar))); }
  :is(.v-flip .stage, .k-gallery .gmain) .pic.img img { width: auto; max-width: 100%; max-height: calc(100vh - 280px); margin: 0 auto; }
  .k-tune .stagecol { display: flex; flex-direction: column; gap: 14px; }

  .card {
    background: rgb(26 26 26 / .92); color: #dfdfdf; font-size: 15px; padding: 16px; display: flex; flex-direction: column; gap: 6px; width: min(100%, 560px); margin: 16px auto;
    .ct { font-weight: 700; color: #fff; margin-bottom: 4px; }
    .q { padding: 4px 8px; }
    .q.hl { background: var(--panel2); color: #fff; font-weight: 700; box-shadow: inset 3px 0 0 var(--sel); }
    .foot { color: #9a9a9a; font-size: 12px; }
  }
  .aud { display: flex; gap: 12px; align-items: center; padding: 28px; color: var(--text); .lv { font-size: var(--row); color: var(--muted); } }
  .lab {
    padding: 24px; color: var(--text); text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; width: 100%;
    &:has(.labframe) { padding: 0; }
  }
  .labframe { width: 100%; border: 0; display: block; background: var(--stage); }

  #over, #legend { position: fixed; inset: 0; z-index: 50; background: var(--scrim); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; cursor: zoom-out; padding: 16px; }
  #over {
    .cap { color: #c9d3d9; font-size: 14px; text-align: center; }
    .ov { width: min(96vw, calc((96vh - 48px) * var(--oar, 16 / 9))); }
    .pic { cursor: zoom-out; }
    .pic[data-cw] { max-width: none; }
    &.zoom, &.true100 { overflow: auto; justify-content: flex-start; align-items: flex-start; }
    &.zoom {
      .cap { position: sticky; top: 0; left: 0; z-index: 1; flex: none; max-width: calc(100vw - 32px); background: var(--scrim); padding: 4px 8px; text-align: left; }
      .ov, .pic { width: auto; flex: none; }
      :is(.pic.img, .pic.img img) { width: auto; max-width: none; max-height: none; }
    }
    &.true100 {
      .ov { width: calc(var(--ow, 1280) * 1px / var(--dpr, 1)); flex: none; }
      .pic.img img { width: calc(var(--nw, 1280) * 1px / var(--dpr, 1)); max-width: none; max-height: none; }
    }
  }

  .mark {
    position: absolute; border: 3px solid var(--amber); box-shadow: 0 0 0 2px rgb(0 0 0 / .65), inset 0 0 0 1px rgb(0 0 0 / .65); pointer-events: none;
    b { position: absolute; left: -3px; bottom: 100%; background: var(--amber); color: var(--on-amber); font: 800 12px/1.3 var(--font); padding: 1px 6px; white-space: nowrap; }
    b.u { bottom: auto; top: 100%; }
  }
  /* Undo the render's scale so a ring stays readable on a small phone picture. */
  .sc .mark {
    border-width: calc(3px / var(--s, 1)); box-shadow: 0 0 0 calc(2px / var(--s, 1)) rgb(0 0 0 / .65);
    b { font-size: calc(12px / var(--s, 1)); padding: calc(1px / var(--s, 1)) calc(6px / var(--s, 1)); left: calc(-3px / var(--s, 1)); }
  }
  .mark b.r, .sc .mark b.r { left: auto; right: calc(-3px / var(--s, 1)); }

  [data-cvd=deut] :is(.pic > .sc, .pic img, .pic video) { filter: url(#dp-deut); }
  [data-cvd=prot] :is(.pic > .sc, .pic img, .pic video) { filter: url(#dp-prot); }
  .true100 {
    :is(.v-flip .stage, .k-gallery .gmain) { overflow: auto; justify-content: flex-start; max-height: calc(100vh - 220px); }
    :is(.v-flip .stage, .k-gallery .gmain) .pic[data-cw] { width: calc(var(--cw) * 1px / var(--dpr, 1)); flex: none; }
    :is(.v-flip .stage, .k-gallery .gmain) .pic.img { width: auto; flex: none; }
    :is(.v-flip .stage, .k-gallery .gmain) .pic.img img { width: calc(var(--nw, 1280) * 1px / var(--dpr, 1)); max-width: none; max-height: none; }
  }

  body.shot { background: var(--stage); }
  .shot .pic { cursor: default; }
  .shot .pic[data-cw] { width: calc(var(--cw) * 1px); max-width: none; }
}

@layer phone {
  .phone, .sheet { display: none; }
  @media (max-width: 900px), (pointer: coarse) {
    /* In flow, so the page ends above the bar whatever its height; the column keeps it at the bottom on a short page. */
    #view:has(> .phone .row) { display: flex; flex-direction: column; min-height: 100dvh; }
    #readonly { padding: 4px 16px; }
    /* 16 px keeps iOS Safari from zooming the page when a note gets the focus. */
    textarea { font-size: 16px; }
    .chips { padding: 8px 16px; }
    .step { display: flex; flex-direction: column; align-items: stretch; width: 100%; padding: 12px 16px 24px; gap: 12px; }
    .step.v-side { gap: 14px; }
    .step .left, .step .right { display: contents; }
    .step {
      :is(.intro, .head) { order: 1; } .cue { order: 2; } .why { order: 3; } .stagecol { order: 4; }
      :is(.detail, .gside, .fields, #sum, .close, .rounds) { order: 5; }
      .verdict { order: 6; } .thumbs { order: 7; } .info { order: 8; } .notebox { order: 9; } .stepnav { order: 10; }
    }
    .head h1 { font-size: 20px; }
    .flipbar, .stepnav, .inav, .stagecol > .ctlbar, :is(.act, .tools) .btn { display: none; }
    :is(.act, .tools) { margin-top: 0; margin-bottom: 0; }
    .nexplain { display: none; }
    .tiles { grid-template-columns: minmax(0, 1fr); }
    :is(.v-flip .stage, .k-gallery .gmain, .k-tune .stage) .pic[data-cw] { width: 100%; }
    .ref .pic { max-width: none; }
    .extras { grid-template-columns: minmax(0, 1fr); }
    .verdict .vb { flex: 1 1 40%; padding-inline: 8px; }
    .opens { flex-basis: 100%; }
    .thumbs { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
    .true100 :is(.v-flip .stage, .k-gallery .gmain) { max-height: none; }
    .keys { padding: 14px; }
    .keys th { white-space: normal; width: 34%; padding-right: 10px; }
    wr-tune { max-width: none; }

    .phone {
      display: flex; flex-direction: column; gap: 6px; position: sticky; bottom: 0; margin-top: auto; z-index: 40;
      background: var(--slab); border-top: 1px solid var(--line); padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
      /* The round list has no bar; without this its padding and border leave a strip at the bottom. */
      &:empty { display: none; }
      .row { display: flex; gap: 6px; }
      .row .btn { flex: 1 1 0; min-width: 0; min-height: 48px; height: auto; padding: 4px; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
      .row .arrow { flex: 0 0 52px; font-size: 22px; }
      .row .pick { flex-grow: 2; }
      .row:last-child { flex-wrap: wrap; }
      .row:last-child .btn { flex: 1 1 auto; padding: 4px 10px; }
      .row.opts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
    }
    [data-sheet] {
      .sheet { display: flex; flex-direction: column; gap: 6px; max-height: 30vh; overflow: auto; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
      .phone [data-act=sheet] { color: var(--on-sel); background: var(--sel); border-color: var(--sel); }
    }
    .sheet {
      .ctlbar { gap: 6px; }
      :is(.btn, .ctlsel) { flex: 1 1 auto; min-height: 40px; padding: 4px 10px; font-size: 14px; }
      kbd { display: none; }
    }
  }
}
