/* responsive-mobile.css — PHONE MODE
   ============================================================
   The app's normal layout is a desktop two-column split that simply STACKS on a
   narrow screen: header, board, the whole right panel, footer. On a phone that
   left the board about a third of the screen — unreadable at arm's length, which
   is exactly when a phone gets used (walking the room, showing one kid a
   position).

   Phone Mode is the answer: board and arrows, nothing else, plus one button.

   Almost everything here hangs off `body.phone-mode`, which js/features/phone.js
   adds and removes. The one exception is the block for the FULL layout on a
   phone, and it sits inside `@media (max-width: 600px)` — so the desktop layout
   (and an iPad's) cannot be affected by anything below.

   The floating controls are NOT drawn over the board. A square board on a ~19.5:9
   phone leaves a deep empty band at the bottom; #board-cell reserves exactly that
   band as padding, fitBoard() sizes the board into what's left (it already reads
   the cell's padding), and the dock sits in the gap. Nothing overlaps, so nothing
   has to be translucent to stay usable.
   ============================================================ */

:root {
  /* 44px is the Apple/Android minimum tap target. Below this a coach taps twice. */
  --phone-tap: 2.85rem;
  /* How far the dock floats off the bottom edge. */
  --phone-dock-gap: 0.55rem;
  /* The band #board-cell reserves at the bottom. DERIVED, not hand-tuned: it has
     to cover the pill's real height (tap target + 0.3rem padding top and bottom +
     borders) plus the float gap, plus clearance. Two independently-tuned numbers
     drifted 1px apart during development and the pill sat on the file labels —
     deriving one from the other is what stops that recurring the next time a
     padding changes. */
  --phone-dock-h: calc(var(--phone-tap) + 0.6rem + 2px + var(--phone-dock-gap) + 0.55rem);
  /* Width of a button INSIDE the nav pill. Five of them (prev, next, Copy,
     Prompt, Annotate) have to clear the menu button on a 375px iPhone SE:
     5 x 44 + 4 gaps x 1.6 + 2 x 3.2 side padding + 2px border = 235px, centred
     at x 70-305, and the menu button starts at 316. At the old 45.6px + 0.4rem
     gaps the pill was 265px and sat 4px INTO the menu button. 44px is the
     Apple minimum, so only the gaps and side padding gave — height is
     untouched, so --phone-dock-h above stays exact. */
  --phone-nav-w: 2.75rem;
}

/* ---- chrome that phone mode removes ------------------------------------- */
body.phone-mode #main-footer,
body.phone-mode #right-panel {
  display: none !important;
}

/* The header is NOT simply removed any more (Jeff, 2026-09-05: "I want the
   timers and name selector to carry over to zen mode"). The shot clock and the
   drawn-student badge live in the header, and hiding the header took them with
   it — so on the zen board N picked a name and T started a clock that nobody
   could see. The header now collapses to a zero-height, click-through shell so
   its two classroom widgets can float over the board's top corners as fixed
   pills; everything else in it (the title input, fullscreen, camp banner) stays
   hidden. The badge and clock keep their own hidden/flex toggling untouched, so
   they only appear once N or T has actually been pressed. */
body.phone-mode #main-header {
  display: block !important;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 0 !important;
  min-height: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  overflow: visible;
  pointer-events: none;
  z-index: 75;             /* above the board (and the dock's 70), below modals */
}
body.phone-mode #main-header > * { display: none !important; }
body.phone-mode #header-left-slot,
body.phone-mode #header-right-slot {
  display: block !important;
  position: static;
  padding: 0 !important;
}
body.phone-mode #view-toggle-btn,
body.phone-mode #fullscreen-btn { display: none !important; }
/* The LIVE class chip (classroom.js _renderChip): with the header collapsed it
   would sit flush in the top-left corner; give it the same breathing room the
   board leaves above itself, and let it take taps through the dead header. */
body.phone-mode #class-chip:not(.hidden) {
  position: fixed;
  top: calc(0.5rem + env(safe-area-inset-top, 0px));
  left: 0.6rem;
  pointer-events: auto;
  z-index: 76;
}
/* The XP score. With the header collapsed it slid to the top-left corner,
   right on top of a8 (Jeff, 2026-10-14: "in scoresheet mode the xp should be
   on the other side. It's on the board"). On wide screens it sits bottom-right,
   beside the layout button, where the centred nav pill never reaches it (the
   pill ends at viewport-centre + ~118px; this spot starts at viewport-right
   minus ~195px, so anything over ~630px wide is clear). The "+XP" award still
   flies to wherever it is. */
/* Since 2026-11-19 the arrows sit at the right edge, so on a wide phone the
   score takes the empty middle of the dock band instead. */
body.phone-mode #xp-tally {
  position: fixed;
  left: 0;
  right: 0;
  margin-inline: auto;
  width: max-content;
  bottom: calc(0.9rem + env(safe-area-inset-bottom, 0px));
  pointer-events: auto;
  z-index: 76;
}
/* A portrait phone is not wide enough for that: the five-button pill reaches
   the same spot and the score painted over the next-move chevron, at z 76 over
   the dock's 70, taking its taps too (Jeff, 2026-10-19: "the xp bar counter is
   blocking"). So on a phone it goes top-centre, in the empty band a square
   board leaves above itself. NOT centred with translateX(-50%): XpTally.bump()
   animates `transform`, and a WAAPI transform replaces the CSS one while it
   plays, so the pill would jump half its width right on every award. The
   scoresheet layout has no band above the board (the board is height-limited
   by the 38vh sheet), so there it tucks in just above the menu button, in the
   sheet's bottom-right corner. */
@media (max-width: 640px) {
  body.phone-mode:not(.scoresheet-mode) #xp-tally {
    top: calc(0.6rem + env(safe-area-inset-top, 0px));
    bottom: auto;
    left: 0;
    right: 0;
    margin-inline: auto;
    width: max-content;
  }
  body.phone-mode.sc-strip:not(.scoresheet-mode) #xp-tally {
    top: calc(1.5rem + env(safe-area-inset-top, 0px));
  }
  /* Scoresheet under the board (a phone held upright): XP is parked in the
     sheet's title bar by Scoresheet._placeXp(). It used to sit "above the menu
     button", which was on the sheet's last rows. */
}
body.phone-mode #active-student-name,
body.phone-mode #shot-clock {
  position: fixed;
  top: calc(0.6rem + env(safe-area-inset-top, 0px));
  pointer-events: auto;
  z-index: 76;
}
body.phone-mode #active-student-name { left: 0.6rem; }
/* left:auto undoes the desktop placement rule (css/style.css "SHOT CLOCK
   PLACEMENT"), whose off-screen left would otherwise pair with this right and
   stretch the pill across the screen. */
body.phone-mode #shot-clock { right: 0.6rem; left: auto; }
/* A bar or fuse timer runs along the very top edge (body.sc-strip, set by
   js/features/shotclock.js). The top pills step down below it instead of
   sitting on it (Jeff, 2026-10-19: timer graphics never in the way). */
body.phone-mode.sc-strip #shot-clock,
body.phone-mode.sc-strip #active-student-name {
  top: calc(1.5rem + env(safe-area-inset-top, 0px));
}

/* Board fills what's left. The bottom padding is the dock's reserved band; the
   safe-area inset keeps it clear of the iPhone home indicator. */
body.phone-mode #main-area {
  padding: 0 !important;
  gap: 0 !important;
}
body.phone-mode #board-cell {
  padding: 0.35rem 0.35rem calc(var(--phone-dock-h) + env(safe-area-inset-bottom, 0px)) !important;
}

/* Thinner board frame — at phone size the desktop 5px ring eats a visible slice
   of every edge square. */
body.phone-mode #board-surface {
  border-width: 3px;
}

/* Coordinates are part of the minimum, not overhead to be trimmed. Board, arrows
   and coordinates is the whole screen — you cannot say "look at c4" to a room
   without them, and a coordinate too small to read at arm's length is the same as
   no coordinate.

   They were shrunk to 0.7rem here at first, to buy the board pixels. Wrong trade:
   the ~8px it bought is invisible on a 344px board, and it cost the one label the
   feature exists to keep. They now run LARGER than the desktop's phone-width size
   (0.875rem), and the column is sized so a digit never crowds the board edge. */
body.phone-mode #rank-labels,
body.phone-mode #rank-labels-right {
  width: 1.4rem;
}
body.phone-mode #file-labels,
body.phone-mode #file-labels-top,
body.phone-mode #rank-labels,
body.phone-mode #rank-labels-right {
  font-size: 1rem;
  letter-spacing: 0.02em;
}
/* Full-strength ink. The desktop uses slate-500 on a light panel; in phone mode
   these sit on the app's dark gradient with nothing else competing, so they can
   afford to be as legible as the pieces. */
body.phone-mode #file-labels,
body.phone-mode #file-labels-top,
body.phone-mode #rank-labels,
body.phone-mode #rank-labels-right {
  color: rgb(51 65 85);
}
.dark body.phone-mode #file-labels,
.dark body.phone-mode #file-labels-top,
.dark body.phone-mode #rank-labels,
.dark body.phone-mode #rank-labels-right {
  color: rgb(241 245 249);
}
/* Tap a coordinate to hide them all; tap the same spot to bring them back
   (PhoneMode.toggleCoords). style.css hides 'off' gutters with
   visibility:hidden, and a hidden element takes no taps — so the second tap
   would have nowhere to land. Here, in phone mode only and only for 'off'
   (body.coords-off, set by renderInsideCoords; 'inside' stays truly hidden),
   the gutters go invisible but stay hit-testable. 1 id + 3 classes outranks
   style.css's `body.coords-hidden #id`. The whiteboard shelf hides the whole
   board, gutters included (css/shelves.css), and keeps the last word. */
/* Since 2026-11-19 'off' collapses the gutters instead, so the board runs
   edge to edge like lichess (Jeff: "coordinates off by default on phone ...
   I want this proportions"). Bring them back from Settings or /coords. */
body.phone-mode.coords-off:not(.shelf-white) #rank-labels,
body.phone-mode.coords-off:not(.shelf-white) #rank-labels-right {
  width: 0 !important; min-width: 0 !important; padding: 0 !important; margin: 0 !important; border: 0 !important; overflow: hidden;
}
body.phone-mode.coords-off:not(.shelf-white) #file-labels,
body.phone-mode.coords-off:not(.shelf-white) #file-labels-top {
  height: 0 !important; min-height: 0 !important; overflow: hidden; margin: 0 !important;
}
body.phone-mode #rank-labels,
body.phone-mode #rank-labels-right,
body.phone-mode #file-labels,
body.phone-mode #file-labels-top {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s ease;
}

/* ---- the chalkboard --------------------------------------------------------
   The Golden-Rules chalkboard (/rgy, /rule 1-3) is `left-0 top-1/2 -translate-y-1/2
   w-64`: on a desktop that parks it in the empty margin beside the board. A phone
   has no margin, so it landed dead across the middle of the board — covering the
   very position the class is voting on, which defeats the whole point of this mode.

   Move it into the empty band ABOVE the board and let it span the width. Only
   `--tw-translate-y` is canceled, not `transform` itself, so the slide-in-from-
   the-left animation still plays; killing the transform outright would leave it
   fading in place. */
body.phone-mode #chalkboard-overlay {
  top: calc(0.6rem + env(safe-area-inset-top, 0px)) !important;
  bottom: auto !important;
  left: 0.6rem !important;
  right: 0.6rem !important;
  width: auto !important;
  --tw-translate-y: 0 !important;
  padding: 0.8rem 1rem !important;
  border-radius: 1rem;
}
body.phone-mode #chalkboard-text {
  font-size: 0.95rem;
  line-height: 1.4;
}

/* ---- the dock: nav pill + menu button ------------------------------------ */
/* Hidden unless phone mode is on; js/features/phone.js builds them once. */
#phone-dock { display: none; }
body.phone-mode #phone-dock {
  display: flex;
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--phone-dock-gap) + env(safe-area-inset-bottom, 0px));
  z-index: 70;
  align-items: center;
  justify-content: space-between;   /* menu left, arrows right (lichess) */
  padding: 0 1rem;
  pointer-events: none;   /* the band is inert; only the controls take taps */
}
#phone-dock > * { pointer-events: auto; }

/* Nav pill — centered, deliberately quiet. Five targets: the two chevrons and
   the three keys a phone hasn't got (Copy, Prompt, Annotate). The VERTICAL
   padding is load-bearing: --phone-dock-h is derived from it (see :root). */
#phone-nav {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  padding: 0.3rem 0.2rem;
  border-radius: 9999px;
}
#phone-nav button,
#phone-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: var(--phone-tap);
  min-height: var(--phone-tap);
  border-radius: 9999px;
  color: rgb(71 85 105);
  transition: transform 0.15s ease, background-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;   /* no 300ms double-tap wait on the chevrons */
}
#phone-nav button { min-width: var(--phone-nav-w); }
/* The prompt's glyph — what a prompt looks like, since lucide's terminal icon
   isn't in the vendored set index.html uses. */
.phone-glyph {
  font: 800 1.05rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: -0.04em;
}
.dark #phone-nav button,
.dark #phone-menu-btn { color: rgb(203 213 225); }

#phone-nav button:active,
#phone-menu-btn:active { transform: scale(0.92); }

/* Menu button — its own round pill on the left, like lichess. */
#phone-menu-btn { min-width: 3.4rem; min-height: 3.4rem; }

/* Glass treatment shared by the pill and the button. Matches .glass-panel rather
   than inventing a second material. */
.phone-glass {
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(226, 232, 240, 0.7);
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.13);
}
.dark .phone-glass {
  background: rgba(15, 17, 21, 0.6);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
}

/* ---- board wall dots -------------------------------------------------------
   Which demo board of the wall you're standing at. Deliberately tiny: it is a
   position indicator, not a control panel, and the whole point of this screen is
   that there is nothing on it. Hidden entirely at one board — a lone dot is noise.

   Quiet on purpose. The current dot used to be bright yellow and 35% larger,
   which read as a control rather than a position mark (Jeff, 2026-10-19: "make
   the yellow ... indicators less noticeable"). Now a muted grey a shade brighter
   than its neighbours, no scale, same tap target. The same goes for the shelf
   marks in css/shelves.css. */
#wall-dots {
  position: absolute;
  left: 0.9rem;
  bottom: 0.55rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
/* With shelves on, the marks already stand at left:0.9rem; the dots step right
   of them instead of sitting on top. */
#phone-dock:has(#shelf-marks) #wall-dots { left: 1.6rem; }
.wall-dot {
  width: 0.44rem;
  height: 0.44rem;
  border-radius: 9999px;
  background: rgba(100, 116, 139, 0.22);
  transition: background-color 0.18s ease;
  -webkit-tap-highlight-color: transparent;
  /* The dot is 7px but the finger target is 22px — tap-to-jump has to be usable
     without being visible. */
  padding: 0;
  box-shadow: 0 0 0 0.5rem transparent;
}
.wall-dot.on { background: rgba(71, 85, 105, 0.5); }
.dark .wall-dot { background: rgba(203, 213, 225, 0.18); }
.dark .wall-dot.on { background: rgba(226, 232, 240, 0.55); }
/* Ten boards in one row is 120px — into the five-button pill on a phone. Wrap
   three to a row; four rows still sit inside the pill's height. */
@media (max-width: 480px) {
  #wall-dots {
    flex-wrap: wrap;
    row-gap: 0.3rem;
    max-width: calc(3 * 0.44rem + 2 * 0.35rem);
  }
}
/* The menu button took the left edge (2026-11-19), so the shelf marks and wall
   dots stand just right of it. */
body.phone-mode #shelf-marks { left: 5.1rem; }
#wall-dots { left: 5.1rem; }
#phone-dock:has(#shelf-marks) #wall-dots { left: 5.8rem; }

/* The board slides under the finger while paging; the wrapper is the thing that
   moves, never its width — animating layout would retrigger fitBoard(). */
body.phone-mode #board-wrapper { will-change: transform; }

/* ---- the annotation box on the zen board -----------------------------------
   On the desktop, pressing A lifts the board out of the box's way (see
   #board-cell in style.css). On the zen board there is nowhere to lift TO: the
   board already starts ~6px from the top of the screen, so the lift clamps to
   zero — measured, not assumed, in tests/test_annotation_lift.js.

   Until 2026-09-05 the answer was to shrink the BOX to one small row so it fit
   in the ~75px under the board. Jeff wanted the opposite — a big type area with
   big type, on the zen board specifically — so now the box is the desktop's
   size or larger and the BOARD steps aside instead: openAnnotationBox() measures
   how much of the board the box would cover and scales #board-cell down toward
   its top edge by exactly that much (--annotation-scale, a transform, so no
   layout change and no fitBoard churn). Coordinates scale with the board and
   stay clear of the box; the invariant under test is unchanged.

   The type is clamped to the viewport so a phone in portrait still gets a
   sensible line while a desktop zen board gets full text-4xl. */
body.phone-mode #annotation-overlay {
  padding-top: 0.9rem;
  padding-bottom: calc(0.9rem + env(safe-area-inset-bottom, 0px));
}
body.phone-mode #annotation-input {
  font-size: clamp(1.35rem, 2.6vw + 0.6rem, 2.5rem);
  line-height: 1.25;
  height: auto;
  min-height: calc(3 * 1.25em);
}

/* ---- floating feature cards (Puzzle of the Day, ECO flash) -----------------
   Both cards are Tailwind-pinned at bottom-16 (64px) — dead on top of the dock,
   and being z-350 they win the paint AND the taps, burying the chevrons. Lift
   them into the empty band #board-cell already reserves above the dock, same
   trick as the dock itself. */
body.phone-mode #potd-card,
body.phone-mode #eco-card {
  bottom: calc(var(--phone-dock-h) + env(safe-area-inset-bottom, 0px) + 0.5rem) !important;
  max-width: 94vw !important;
}

/* ---- the sheet ----------------------------------------------------------- */
/* Slides up from the bottom. Scrim closes it, so does a swipe down or Esc. */
#phone-sheet {
  position: fixed;
  inset: 0;
  z-index: 620;   /* above the board and dock, below toasts (z-500 is lower) */
  display: none;
}
#phone-sheet.open { display: block; }

#phone-sheet-scrim {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.22s ease;
}
#phone-sheet.open #phone-sheet-scrim { opacity: 1; }

#phone-sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 82vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem 1rem calc(1.4rem + env(safe-area-inset-bottom, 0px));
  border-radius: 1.5rem 1.5rem 0 0;
  background: rgb(248 250 252);
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}
.dark #phone-sheet-panel {
  background: rgb(20 23 30);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
}
#phone-sheet.open #phone-sheet-panel { transform: translateY(0); }

/* Grab handle — the affordance that says "this drags down". */
#phone-sheet-grip {
  width: 2.5rem;
  height: 0.25rem;
  margin: 0.4rem auto 0.9rem;
  border-radius: 9999px;
  background: rgba(100, 116, 139, 0.4);
}

/* The menu is a list of words (Jeff, 2026-10-20: the 4x4 icon grid was "too
   cluttered and icons are stupid"). Search on top, then rows: a name on the
   left, its key in a quiet chip on the right. */
#phone-sheet { --ps-ink: rgb(30 41 59); --ps-soft: rgb(100 116 139); --ps-row: rgba(255, 255, 255, 0.8); --ps-line: rgba(226, 232, 240, 0.95); }
.dark #phone-sheet { --ps-ink: rgb(226 232 240); --ps-soft: rgb(148 163 184); --ps-row: rgba(255, 255, 255, 0.045); --ps-line: rgba(255, 255, 255, 0.07); }
#phone-sheet [hidden] { display: none !important; }
#phone-sheet .ps-search { position: sticky; top: -0.5rem; z-index: 1; margin: 0 -0.25rem 0.6rem; padding: 0.25rem; background: inherit; }
#phone-sheet-search {
  width: 100%; height: 2.9rem; padding: 0 1rem; border-radius: 0.9rem;
  font-size: 1rem;   /* 16px or more, or iOS zooms the page on focus */
  color: var(--ps-ink); background: var(--ps-row); border: 1px solid var(--ps-line);
  outline: none; -webkit-appearance: none; appearance: none;
}
#phone-sheet-search::placeholder { color: var(--ps-soft); }
#phone-sheet-search:focus { border-color: rgb(59 130 246); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2); }
#phone-sheet .ps-label {
  margin: 0.9rem 0.25rem 0.4rem; font-size: 14px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--ps-soft);
}
#phone-sheet .ps-label:first-child { margin-top: 0.2rem; }
#phone-sheet .ps-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.35rem; }
#phone-sheet .ps-item {
  display: flex; align-items: center; justify-content: space-between; gap: 0.4rem;
  min-height: 2.85rem; padding: 0 0.8rem; border-radius: 0.8rem; text-align: left;
  font-size: 0.95rem; font-weight: 600; color: var(--ps-ink);
  background: var(--ps-row); border: 1px solid var(--ps-line);
  -webkit-tap-highlight-color: transparent; transition: transform 0.12s ease, background-color 0.12s ease;
}
#phone-sheet .ps-item span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#phone-sheet .ps-item:active { transform: scale(0.97); background: rgba(59, 130, 246, 0.12); }
/* Keys only where there is a keyboard: on a touch screen they are clutter. */
/* Keys are hidden on the phone sheet altogether (Jeff, 2026-11-18: on the phone
   "just try to remove unnecessary text"); they were 11px and a phone has no keys. */
#phone-sheet .ps-item kbd { display: none !important; }
#phone-sheet .ps-item kbd {
  flex: none; font: 600 0.68rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 0.22rem 0.35rem; border-radius: 0.35rem; color: var(--ps-soft); border: 1px solid var(--ps-line);
}
#phone-sheet .ps-danger { color: rgb(220 38 38); }
.dark #phone-sheet .ps-danger { color: rgb(248 113 113); }
#phone-sheet .ps-more {
  display: block; width: 100%; margin-top: 0.8rem; padding: 0.75rem; border-radius: 0.8rem;
  font-size: 15px; font-weight: 700; color: var(--ps-soft); background: transparent;
  border: 1px solid var(--ps-line); -webkit-tap-highlight-color: transparent;
}
#phone-sheet .ps-more[aria-expanded="true"] { color: var(--ps-ink); }
#phone-sheet .ps-none { grid-column: 1 / -1; margin: 0.6rem 0.25rem; font-size: 0.9rem; color: var(--ps-soft); }
#phone-sheet .ps-keys { display: flex; gap: 0.35rem; margin-bottom: 0.7rem; }
#phone-sheet .ps-keys button {
  flex: 1; min-height: 2.75rem; border-radius: 0.8rem; font-size: 15px; font-weight: 700;
  color: var(--ps-ink); background: transparent; border: 1px solid var(--ps-line);
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
#phone-sheet .ps-keys button:active { background: rgba(59, 130, 246, 0.12); }
#phone-sheet .ps-foot {
  display: flex; gap: 0.35rem; margin-top: 1rem; padding-top: 0.8rem; border-top: 1px solid var(--ps-line);
}
#phone-sheet .ps-foot button {
  flex: 1; min-height: 2.75rem; border-radius: 0.8rem; font-size: 15px; font-weight: 700;
  color: var(--ps-soft); background: transparent; border: 1px solid var(--ps-line);
  -webkit-tap-highlight-color: transparent;
}
#phone-sheet .ps-foot button:active { background: rgba(59, 130, 246, 0.12); }
/* The dock's "more" mark: three dots, the size of the chevrons beside it. */
.phone-more { font: 800 1.35rem/1 system-ui, -apple-system, sans-serif; letter-spacing: 0; }

/* ---- the PGN sheet ---------------------------------------------------------
   Opened by the menu's PGN tile (js/features/phone-pgn.js). Same anatomy and
   materials as the menu sheet above; only the contents differ. */
#phone-pgn-sheet {
  position: fixed;
  inset: 0;
  z-index: 620;
  display: none;
}
#phone-pgn-sheet.open { display: block; }
#phone-pgn-scrim {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.22s ease;
}
#phone-pgn-sheet.open #phone-pgn-scrim { opacity: 1; }
#phone-pgn-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 82vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem 1rem calc(1.4rem + env(safe-area-inset-bottom, 0px));
  border-radius: 1.5rem 1.5rem 0 0;
  background: rgb(248 250 252);
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}
.dark #phone-pgn-panel {
  background: rgb(20 23 30);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
}
#phone-pgn-sheet.open #phone-pgn-panel { transform: translateY(0); }
#phone-pgn-grip {
  width: 2.5rem;
  height: 0.25rem;
  margin: 0.4rem auto 0.9rem;
  border-radius: 9999px;
  background: rgba(100, 116, 139, 0.4);
}
/* The sheet's own box and buttons say what it is; the 13px "GAME PGN" heading
   was extra text on a small screen (Jeff, 2026-11-18). */
#phone-pgn-title { display: none; }
#phone-pgn-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgb(100 116 139);
  margin-bottom: 0.5rem;
}
.dark #phone-pgn-title { color: rgb(148 163 184); }
#phone-pgn-text {
  width: 100%;
  height: 30vh;
  resize: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 16px;   /* under 16px iOS zooms the whole page on focus */
  line-height: 1.45;
  padding: 0.6rem 0.7rem;
  border-radius: 0.75rem;
  color: rgb(51 65 85);
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(226, 232, 240, 0.9);
}
.dark #phone-pgn-text {
  color: rgb(203 213 225);
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
}
#phone-pgn-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
  margin-top: 0.6rem;
}
#phone-pgn-actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--phone-tap);
  border-radius: 1rem;
  font-size: 15px;
  font-weight: 700;
  color: rgb(51 65 85);
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(226, 232, 240, 0.9);
  transition: transform 0.14s ease;
  -webkit-tap-highlight-color: transparent;
}
.dark #phone-pgn-actions button {
  color: rgb(203 213 225);
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.08);
}
#phone-pgn-actions button:active { transform: scale(0.94); }
#phone-pgn-actions button svg,
#phone-pgn-actions button i { width: 1.05rem; height: 1.05rem; }
#phone-pgn-recent-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.7rem;
  border-radius: 1rem;
  font-size: 14px;
  font-weight: 700;
  color: rgb(100 116 139);
  background: transparent;
  border: 1px dashed rgba(148, 163, 184, 0.5);
  -webkit-tap-highlight-color: transparent;
}
.dark #phone-pgn-recent-btn { color: rgb(148 163 184); }
#phone-pgn-recent { margin-top: 0.5rem; }
#phone-pgn-recent.hidden { display: none; }
.phone-pgn-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  width: 100%;
  padding: 0.6rem 0.7rem;
  margin-top: 0.3rem;
  border-radius: 0.75rem;
  font-size: 15px;
  color: rgb(51 65 85);
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(226, 232, 240, 0.8);
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.dark .phone-pgn-row {
  color: rgb(203 213 225);
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.07);
}
.phone-pgn-row-players {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* The time stamp beside each recent game: dropped on the phone, the players'
   names are what you pick by. */
.phone-pgn-row-when { display: none; }
.phone-pgn-row-when {
  flex-shrink: 0;
  font-size: 14px;
  color: rgb(148 163 184);
}
.phone-pgn-empty {
  padding: 0.75rem 0.5rem;
  font-size: 14px;
  color: rgb(148 163 184);
  text-align: center;
}

/* ---- editing on a phone ----------------------------------------------------
   Editing is the one job this mode can't do with a bare board: the palette, turn
   toggle, castling rights, en passant and Cancel/Done all live in #right-panel.
   While the editor is open it comes back as a bottom sheet, the board shares the
   screen with it, and the nav dock stands down (there are no moves to step
   through in the editor anyway, and Done/Cancel are right there instead). */
body.phone-mode.phone-editing #right-panel {
  display: flex !important;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 75;
  max-height: 58vh;
  border-radius: 1.25rem 1.25rem 0 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -8px 30px rgba(2, 6, 23, 0.35);
}
body.phone-mode.phone-editing #phone-dock { display: none; }
/* Board sits above the sheet rather than under it — same reservation trick as
   the dock, so the position stays fully visible while you set it up. */
body.phone-mode.phone-editing #board-cell {
  padding-bottom: 59vh !important;
}
/* The editor's own scroll area is short here; let the sheet do the scrolling so
   the palette and the Done button are always reachable with one thumb. */
body.phone-mode.phone-editing #editor-panel { height: auto; }
body.phone-mode.phone-editing #editor-panel > .flex-1 { padding: 0.75rem 1rem 1.25rem; }
body.phone-mode.phone-editing #piece-palette { gap: 0.6rem; }

/* ---- the command prompt on a phone (M key) ---------------------------------
   Phone mode hides #main-footer wholesale, which used to make M a no-op: the
   handler focused an input inside a display:none ancestor. While the prompt is
   open (body.phone-prompt, added by handleFooterLinkClick and removed by
   hideMoveInput) the footer comes back as a floating box.

   It sits in the BOTTOM-RIGHT corner, which is where the prompt lives in the
   regular layout — the same corner, so the habit carries over. It was a
   full-bleed bar pinned left:0.6rem right:0.6rem, which spanned the whole
   screen for an input that usually holds four characters, and covered rank 1
   and the file labels on the way. */
body.phone-mode.phone-prompt #main-footer {
  display: flex !important;
  position: fixed;
  left: auto;
  right: 0.7rem;
  width: auto;
  max-width: min(17rem, calc(100vw - 1.4rem));
  bottom: calc(var(--phone-dock-h) + env(safe-area-inset-bottom, 0px) + 0.4rem);
  height: auto;
  z-index: 640;   /* above the sheet (620) so M works with the menu open */
  border-radius: 0.9rem;
  border-top: none;
  padding: 0.4rem 0.5rem;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.26);
}
.dark body.phone-mode.phone-prompt #main-footer {
  background: rgba(15, 17, 21, 0.86);
}
body.phone-mode.phone-prompt #move-input {
  width: 11rem;
  max-width: 100%;
  font-size: 16px;   /* anything smaller triggers iOS Safari's focus auto-zoom */
}
body.phone-mode.phone-prompt #footer-author { display: none; }

/* Transparent catcher UNDER the prompt (built by _buildPromptScrim). The prompt
   used to be dismissed by the input's own `onblur`, which fires on pointerdown
   while the SAME tap still lands as a click underneath — so putting the prompt
   away also played a move, opened the menu, or started a whiteboard text block.
   This eats that gesture. */
#prompt-scrim {
  position: fixed;
  inset: 0;
  z-index: 639;    /* directly under the prompt, over everything else */
  background: transparent;
}

/* ---- landscape phones ------------------------------------------------------
   Height is the scarce dimension here (a phone on its side is ~390-430 tall), so
   the dock has to give some back — at the portrait size it would eat 17% of the
   screen. Smaller targets are the right trade when the alternative is a smaller
   board; these are still at the 44px minimum. */
@media (max-height: 560px) {
  /* Only the inputs change; --phone-dock-h recomputes from them. */
  :root { --phone-tap: 2.75rem; --phone-dock-gap: 0.35rem; }
  body.phone-mode #board-cell {
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
  }
  /* The chalkboard can't sit above the board in landscape — there is no band to
     sit in. Tuck it into the left margin the square board leaves behind. */
  body.phone-mode #chalkboard-overlay {
    top: 50% !important;
    left: 0.5rem !important;
    right: auto !important;
    width: 40vw !important;
    max-width: 18rem !important;
    --tw-translate-y: -50% !important;
  }
  /* Same story for the feature cards: no bottom band in landscape, so they take
     the left margin the square board leaves behind. Only the translate vars are
     canceled, keeping the rest of the Tailwind transform intact. */
  body.phone-mode #potd-card,
  body.phone-mode #eco-card {
    left: 0.5rem !important;
    right: auto !important;
    bottom: 50% !important;
    --tw-translate-x: 0 !important;
    --tw-translate-y: 50% !important;
    max-width: 44vw !important;
    min-width: 0 !important;
  }
  #phone-sheet-panel { max-height: 92vh; }
}

/* ---- the FULL layout on a phone (zen board off) ---------------------------
   Jeff, 2026-10-20, circling a screenshot with "SUCK": 21 unlabelled icons in
   three rows, the White/Black/date boxes, and a move list squeezed to 24px —
   the board cell and the panel each took half the height, and the panel's
   fixed rows needed more than its half. Here: the board takes the height its
   width needs and no more, the icon wall becomes one row of four tools in
   words plus More, the boxes fold into one line, and playback is one row.
   Under 601px wide only (phones upright; PhoneMode.BREAKPOINT is 600), so an
   iPad or a laptop window never sees any of it. */
#narrow-tools, #gi-summary { display: none; }
@media (max-width: 600px) {
  body:not(.phone-mode) #board-cell {
    flex: 0 1 calc(100vw - 1.8rem) !important;   /* = the width-limited board + its labels */
  }
  body:not(.phone-mode) #right-panel { min-height: 15rem !important; }
  /* The header squeezed the XP pill to "0 |" (it is overflow:hidden). */
  body:not(.phone-mode) #xp-tally { flex-shrink: 0; }
  body:not(.phone-mode) #analysis-toolbar { padding: 0.45rem 0.5rem; justify-content: stretch; }
  /* Since 2026-11-19 the chip row is hidden; a menu icon at the end of the
     tab bar opens the same sheet ("hideous", Jeff). */
  body:not(.phone-mode) #analysis-toolbar { display: none !important; }
  .panel-tabs .ptab-menu { display: flex; align-items: center; }
  body:not(.phone-mode) #toolbar-icons { display: none !important; }
  body:not(.phone-mode) #narrow-tools {
    display: flex; gap: 0.35rem; width: 100%; overflow-x: auto; scrollbar-width: none;
  }
  body:not(.phone-mode) #narrow-tools::-webkit-scrollbar { display: none; }
  #narrow-tools .nt-chip {
    flex: 1 1 0; min-width: 0; min-height: 2.5rem; padding: 0 0.5rem; border-radius: 0.75rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.85rem; font-weight: 600;
    color: rgb(51 65 85); background: rgba(255, 255, 255, 0.7); border: 1px solid rgba(226, 232, 240, 0.9);
    -webkit-tap-highlight-color: transparent;
  }
  .dark #narrow-tools .nt-chip { color: rgb(226 232 240); background: rgba(255, 255, 255, 0.05); border-color: rgba(255, 255, 255, 0.08); }
  #narrow-tools .nt-chip:active { background: rgba(59, 130, 246, 0.15); }
  #narrow-tools .nt-more { flex: none; padding: 0 0.85rem; color: rgb(37 99 235); }
  /* Four tools fit from ~410px; an iPhone 13-16 (390) or SE gets three. */
  @media (max-width: 409px) { #narrow-tools .nt-chip:nth-child(4):not(.nt-more) { display: none; } }
  .dark #narrow-tools .nt-more { color: rgb(96 165 250); }

  body:not(.phone-mode) #game-info-panel { padding: 0.35rem 0.75rem; }
  body:not(.phone-mode) #game-info-panel:not(.gi-open) > div { display: none; }
  body:not(.phone-mode) #game-info-panel.gi-open > div { margin-top: 0.4rem; }
  body:not(.phone-mode) #gi-summary {
    display: block; width: 100%; padding: 0.3rem 1.4rem 0.3rem 0.1rem; text-align: left; position: relative;
    font-size: 0.85rem; font-weight: 600; color: rgb(71 85 105);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; -webkit-tap-highlight-color: transparent;
  }
  .dark body:not(.phone-mode) #gi-summary { color: rgb(148 163 184); }
  body:not(.phone-mode) #gi-summary::after {
    content: ''; position: absolute; right: 0.35rem; top: 50%; width: 0.45rem; height: 0.45rem;
    border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
    transform: translateY(-70%) rotate(45deg); opacity: 0.7;
  }
  body:not(.phone-mode) #game-info-panel.gi-open #gi-summary::after { transform: translateY(-30%) rotate(-135deg); }

  /* One row: start, back, forward, end, undo. The rest are in More / search. */
  body:not(.phone-mode) #playback-controls { flex-wrap: nowrap; padding: 0.3rem; }
  body:not(.phone-mode) #palette-btn,
  body:not(.phone-mode) #copy-image-btn,
  body:not(.phone-mode) #class-send-btn,
  body:not(.phone-mode) #scoresheet-btn { display: none !important; }
}

/* ---- the moves on the zen board (js/features/phone-moves.js) --------------
   Jeff, 2026-10-20: zen "seems to limit me" — there was no move list. The panel
   takes space the board was already leaving empty: the band under it on an
   upright phone, the margin beside it on a phone on its side. Hidden whenever
   the scoresheet (the classroom version of this panel), the board editor, the
   whiteboard shelf or the annotation box needs the screen. The long :not()
   chain is spelled out on every rule on purpose — a rule missing one of them
   out-specifies the others (TODO.md GOTCHA, the 6px scoresheet board). */
#phone-moves { display: none; }
body.phone-mode.phone-moves:not(.scoresheet-mode):not(.phone-editing):not(.shelf-white):not(.annotating) #phone-moves {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  position: relative; z-index: 60;
  border-radius: 1.1rem; overflow: hidden;
  background: var(--pm-bg);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border: 1px solid var(--pm-line);
  box-shadow: var(--pm-shadow);
  color: var(--pm-ink);
}
/* Colours as variables on the bare id, so dark mode can't lose to the long
   :not() chain above on specificity. */
#phone-moves {
  --pm-bg: rgba(255, 255, 255, 0.86); --pm-line: rgba(226, 232, 240, 0.8);
  --pm-shadow: 0 6px 24px -10px rgba(15, 23, 42, 0.25);
  --pm-ink: #1e293b; --pm-soft: #64748b; --pm-faint: #94a3b8;
}
.dark #phone-moves {
  --pm-bg: rgba(15, 17, 21, 0.66); --pm-line: rgba(255, 255, 255, 0.09);
  --pm-shadow: 0 6px 24px -10px rgba(0, 0, 0, 0.6);
  --pm-ink: #e2e8f0; --pm-soft: #a3b1c6; --pm-faint: #64748b;
}
#phone-moves .pm-body {
  position: relative;            /* offsetTop of a move is measured from here */
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0.55rem 0.75rem; line-height: 2.05;
  font-size: 1.05rem; font-weight: 600; word-spacing: -0.05em;
}
#phone-moves .pm-grp { white-space: nowrap; }   /* "12." never ends a line alone */
#phone-moves .pm-num { color: var(--pm-faint); font-weight: 700; font-size: 0.85em; margin-left: 0.15em; user-select: none; }
#phone-moves .pm-mv {
  display: inline-block; padding: 0 0.3em; border-radius: 0.4rem; line-height: 1.6;
  cursor: pointer; position: relative; -webkit-tap-highlight-color: transparent;
}
#phone-moves .pm-mv:active { background: rgba(37, 99, 235, 0.12); }
#phone-moves .pm-mv.pm-cur { background: #2563eb; color: #fff; }
#phone-moves .pm-var { font-size: 0.86em; font-weight: 500; color: var(--pm-soft); }
#phone-moves .pm-mv.pm-var.pm-cur { color: #fff; }
#phone-moves .pm-par { color: var(--pm-faint); font-weight: 400; }
#phone-moves .pm-dot {
  position: absolute; top: 0.12em; right: 0.02em; width: 0.32rem; height: 0.32rem;
  border-radius: 50%; background: #f59e0b;
}
#phone-moves .pm-empty { margin: 0; color: var(--pm-faint); font-weight: 500; font-size: 0.95rem; }
#phone-moves .pm-note-line {
  flex: none; padding: 0.45rem 0.75rem 0.55rem; font-size: 0.92rem; line-height: 1.35;
  border-top: 1px solid var(--pm-line); color: var(--pm-soft); font-style: italic;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
#phone-moves .pm-note-line[hidden] { display: none; }

/* The homework light (homework.js _scanPill) moves from bottom-left — the
   dock's corner — to the top-left band on the zen board. A tap shows its
   sentence as a toast; there is no hover on a touch screen. */
body.phone-mode #hw-scan-pill {
  top: calc(env(safe-area-inset-top, 0px) + 0.55rem); bottom: auto; left: 0.45rem;
}

/* Upright: the board keeps exactly the size it had (its width decides it), and
   moves down a little so the top pills (XP, clock, name) sit above it instead
   of over rank 8; the panel fills what's left above the dock. On a short phone
   the panel stops at three lines and the board gives way first. */
@media (max-aspect-ratio: 1/1) {
  body.phone-mode.phone-moves:not(.scoresheet-mode):not(.phone-editing):not(.shelf-white):not(.annotating) #board-cell {
    /* 4rem on top: the tallest top pill (the shot clock's ring, 52px at
       top 10px) clears rank 8 — tests/test_shotclock_modes.js measures it. */
    flex: 0 1 calc(100vw + 2.85rem) !important;
    padding: 4rem 0.35rem 0.35rem !important;
  }
  body.phone-mode.phone-moves:not(.scoresheet-mode):not(.phone-editing):not(.shelf-white):not(.annotating) #phone-moves {
    flex: 1 0 4.6rem;
    margin: 0 0.5rem calc(var(--phone-dock-h) + env(safe-area-inset-bottom, 0px));
  }
}
/* On its side (or a wide screen with the zen board pinned): beside the board. */
@media (min-aspect-ratio: 1/1) {
  body.phone-mode.phone-moves:not(.scoresheet-mode):not(.phone-editing):not(.shelf-white):not(.annotating) #main-area {
    flex-direction: row !important; align-items: stretch;
  }
  body.phone-mode.phone-moves:not(.scoresheet-mode):not(.phone-editing):not(.shelf-white):not(.annotating) #phone-moves {
    flex: none; width: clamp(13rem, 30vw, 24rem);
    margin: max(0.6rem, env(safe-area-inset-top, 0px)) max(0.6rem, env(safe-area-inset-right, 0px)) calc(var(--phone-dock-h) + env(safe-area-inset-bottom, 0px)) 0;
  }
}

/* Respect a user who has asked the OS for less motion. */
@media (prefers-reduced-motion: reduce) {
  #board-wrapper,
  .wall-dot,
  #phone-sheet-panel,
  #phone-sheet-scrim,
  #phone-sheet .ps-item,
  #phone-nav button,
  #phone-menu-btn { transition: none; }
}

/* ---- phone-width polish (Jeff, 2026-11-19) ---------------------------------
   1. A picked-up piece grows on a touch screen, so you can see what you hold
      (the dragged copy grows 2x in js/ui/keyboard.js).
   2. The Database (opening explorer) reads smaller on a phone.
   3. The Moves tab drops its clutter on a phone: the "Opening Explorer" title
      bar (the Database tab opens it) and the empty band under the game title. */
@media (hover: none) and (pointer: coarse) {
  #board-surface .sq-picked > img { scale: 1.3; z-index: 30; transition: scale 0.08s ease-out; }
}
@media (max-width: 600px) {
  #explorer-panel-body { font-size: 13px; }
  #explorer-panel .xp-san { font-size: 15px; width: 44px; }
  #explorer-panel .xp-pct { font-size: 15px; min-width: 40px; }
  #explorer-panel .xp-games { font-size: 12px; }
  #explorer-panel .xp-summary { font-size: 12px; }
  #explorer-panel .xp-bar { height: 18px; font-size: 11px; }
  #explorer-panel .xp-row { height: 28px; }
  #explorer-body > .text-sm { font-size: 13px !important; line-height: 1.35 !important; margin-bottom: 6px; }
  #explorer-panel > div:first-child { display: none; }
  #move-list:not(:has(span, button, [data-node])) { display: none; }
  /* Database tab: only the database. The tool chips, game title and moves
     come back on the Moves tab. */
  #right-panel[data-ptab="database"] #analysis-toolbar,
  #right-panel[data-ptab="database"] #game-info-panel,
  #right-panel[data-ptab="database"] #move-list { display: none; }
}
