/**
 * gym.css — layout specific to the Gym app. Reuses design tokens, board
 * square/piece rendering, .btn/.modal-overlay/#toast etc. from theme.css.
 */

/* Note: this app used to bound #screen-game/#screen-review to
   `calc(100dvh - var(--header-h))`, guessing the header's real rendered
   height via a hardcoded --header-h constant. That guess drifted stale
   (the real header is taller than the guess once icon buttons/logo
   padding are accounted for), leaving a few pixels of unreachable
   "phantom scroll" at the bottom of both screens on mobile — the same
   estimate-vs-guaranteed-bound problem as the live board's width fix
   below. Fixed by just using ordinary flex:1 (see .screen below), which
   #screen-setup already relied on with no bug — flexbox derives the
   real remaining space automatically, so there's no header-height
   constant left to go stale. Don't reintroduce one. */

html { height: 100%; }
body {
  /* Both height AND min-height: `height` gives every flex-column screen
     below (#screen-game, #screen-review, and their own nested
     percentage-height chains — #review-board-col's height:100%, etc.) a
     genuinely DEFINITE size to resolve flex-grow and percentage heights
     against; `min-height` alone left that ambiguous in a way that just
     switching #screen-game/#screen-review to flex:1 exposed — their
     aspect-ratio'd boards were computing height against an indefinite
     ancestor and coming out squashed/stretched (non-square squares)
     instead of the intended guaranteed bound. min-height is kept
     alongside it so the "let the page scroll rather than clip anything"
     safety net (see the overflow:visible override below) still works if
     content is ever pathologically taller than the viewport — a block
     box's declared `height` doesn't prevent overflowing content from
     still expanding the document's scrollable area when overflow isn't
     hidden. */
  height: 100dvh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* Overrides theme.css's `body { overflow: hidden; }` — present TWICE
     there (an unconditional base rule, and a second one inside a
     max-width:767px media query for PCDB's own mobile drawer layout).
     PCDB is a fixed single-viewport app with internally-scrolling panels;
     this app just needs an ordinary page that scrolls normally. Since
     specificity is identical (plain `body` selector, both places) and this
     rule loads later in the cascade, it wins over both occurrences
     regardless of viewport width — media queries gate whether a rule
     applies, they don't add specificity. This was the actual root cause of
     "can't scroll the review screen at all", not the html/body height
     split fixed previously — that fix was necessary but not sufficient.
     This stays a safety net: #screen-review below is sized to fit the
     viewport on its own so this fallback normally never triggers, but nothing
     here uses `overflow: hidden`, so if a screen's content is ever taller
     than expected (unusual viewport, text zoom, etc.) the page can still
     scroll instead of silently clipping something. */
  overflow: visible;
}

#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  min-height: 0; /* overrides theme.css's 96px, sized for PCDB's large logo image */
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}
#btn-account { position: relative; }
#account-logged-in-dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  border: 1.5px solid var(--bg-card);
}
#logo-plate {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 1.65rem;
  letter-spacing: -0.02em;
}
#logo-plate .wordmark-text {
  background: linear-gradient(135deg, var(--gold) 0%, #e8c98a 60%, var(--gold) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  /* This is an <h1> now (was a plain <span>) for SEO — a page should have
     exactly one — but it must look identical to before: reset the
     browser's default h1 margin/font-size/font-weight so it inherits
     #logo-plate's own sizing instead of the UA stylesheet's. */
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
  display: inline;
}
/* Wrapper purely so .wordmark-pocket can be positioned relative to the
   existing wordmark without changing its own size, color, or gradient in
   any way — .wordmark-pocket is position:absolute, so it's removed from
   normal flow and contributes zero extra width/height to this wrapper or
   to #logo-plate as a whole. */
.wordmark-text-wrap {
  position: relative;
  display: inline-block;
  line-height: 1;
}
.wordmark-pocket {
  position: absolute;
  left: 1px;
  top: -0.66em;
  font-size: 0.24em;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: #4a6f94;
  white-space: nowrap;
}
#logo-plate svg { color: var(--gold); flex-shrink: 0; }
#header-icons {
  display: flex;
  align-items: center;
  gap: 8px;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
}
.screen.hidden { display: none; }

/* ── About You page ── */
.about-you-card {
  width: 100%;
  max-width: 480px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.about-you-card h2 {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  color: var(--gold);
  margin: 20px 0 8px;
}
.about-you-card h2:first-of-type { margin-top: 4px; }
.about-you-story {
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.35;
  background: rgba(200, 169, 110, 0.1);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 6px;
  min-height: 1.2em;
}
.ay-stat-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 2px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.ay-stat-row:last-child { border-bottom: none; }
.ay-stat-row span:first-child { color: var(--text-secondary); }
.ay-stat-row span:last-child { color: var(--text-primary); font-weight: 600; text-align: right; }
.ay-empty {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-style: italic;
  padding: 4px 2px;
}

/* ── Setup screen ── */
.setup-card {
  width: 100%;
  max-width: 480px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.setup-card h2 {
  font-family: var(--font-ui);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin-bottom: 16px;
  text-align: center;
}
.round-subheading {
  display: block;
  font-size: 0.7em;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 2px;
}
.setup-row {
  margin-bottom: 16px;
}
#opponent-preview { position: relative; }
.corner-link {
  position: absolute;
  top: 0;
  right: 0;
  font-size: 0.72rem;
}
.setup-row label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.elo-display {
  display: flex;
  align-items: center;
  gap: 10px;
}
.elo-display label {
  display: inline;
  margin-bottom: 0;
  text-transform: none;
  letter-spacing: normal;
  font-size: 0.95rem;
}
#elo-value {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  color: var(--text-active);
}
.opponent-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.opponent-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid var(--border-light);
  background: var(--bg-panel);
}
.opponent-card-text {
  flex: 1;
  min-width: 0;
}
.opponent-name {
  font-family: var(--font-ui);
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 1.15rem;
  color: var(--gold);
}
.opponent-flavor {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin: 6px 0 10px;
}
.opponent-award-badge {
  display: inline-block;
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 600;
  background: rgba(200, 169, 110, 0.12);
  border-radius: var(--radius);
  padding: 2px 8px;
  margin: -4px 0 8px;
}
.opponent-history {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
  margin: -4px 0 10px;
  min-height: 1.1em;
}

/* ── Tournament (Club Championship) ── */
#tournament-actions-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 14px;
}
#btn-start-game {
  margin-top: 3px; /* was 10px — most of that gap is now absorbed into the button's own bigger box below */
  padding: 12px;
  font-size: 1.05rem;
  font-weight: 700;
  /* Solid fill instead of .btn-primary's subtle tint — this is the one
     true primary action on the page ("Ready for a practice round?" is
     the call to action, this button is the action), so it should read
     as unmistakably the button here, with nothing else on the page
     sharing its treatment. */
  background: var(--gold);
  border-color: var(--gold);
  color: var(--bg-panel);
}
#btn-start-game:hover { background: #d9bd85; border-color: #d9bd85; }
#setup-tournament-divider {
  margin: 22px 0 16px;
}
#tournament-bottom-section {
  margin-top: 0;
  background: rgba(200, 169, 110, 0.1);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  padding: 10px 12px;
}
#tournament-bottom-title {
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 8px;
}
#tournament-mode-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
#tournament-mode-toggle .color-btn { flex: 1; }
#tournament-start-row { display: flex; flex-direction: column; gap: 8px; }
#tournament-new-time-control-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
#tournament-new-time-control-row label {
  color: var(--text-secondary);
  font-size: 0.85rem;
  white-space: nowrap;
}
#tournament-new-time-control-row select { flex: 1; }
#tournament-custom-time-fields { display: flex; gap: 6px; }
#tournament-time-control-display {
  color: var(--text-secondary);
  font-family: var(--font-mono);
}
#standings-modal-box, #pairings-modal-box {
  width: min(92vw, 480px);
  max-width: none;
}
.standings-row, .standings-header {
  display: grid;
  grid-template-columns: 28px 1fr 52px 48px;
  gap: 6px;
  align-items: center;
  padding: 4px 6px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.standings-row.standings-row-roster, .standings-header.standings-header-roster {
  grid-template-columns: 28px 1fr 52px;
}
.standings-row.standings-row-challenge, .standings-header.standings-header-challenge {
  /* Last column is just wide enough for the fixed-size challenge icon
     button below — was 78px to fit a "Challenge" text button, but that
     button's own min-content width silently forced this column wider
     than declared (each row is its own independent grid, so the header
     row — with an empty cell there — didn't grow to match, throwing off
     alignment between the header and every data row below it). A small
     fixed-size icon button doesn't have that problem. */
  grid-template-columns: 28px 1fr 52px 76px 32px;
}
.challenge-icon-btn {
  width: 30px;
  height: 30px;
  min-width: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--gold);
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
.challenge-icon-btn:hover { background: var(--bg-hover); border-color: var(--border-light); }
.challenge-icon-btn:active { background: var(--bg-active); }
.challenge-icon-btn svg { flex-shrink: 0; }
.standings-record {
  font-family: var(--font-mono);
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.78rem;
}
.standings-header {
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-light);
}
.standings-header span:nth-child(3), .standings-header span:nth-child(4) { text-align: center; }
.standings-row:last-child { border-bottom: none; }
.standings-row-user { background: rgba(200, 169, 110, 0.12); border-radius: 4px; }
.standings-rank { color: var(--text-muted); font-family: var(--font-mono); }
.standings-elo, .standings-score { font-family: var(--font-mono); text-align: center; color: var(--text-secondary); }
.award-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.award-row:last-child { border-bottom: none; }
.award-icon { flex-shrink: 0; }
.award-label { flex: 1; color: var(--text-secondary); }
.award-winner { font-weight: 600; color: var(--gold); text-align: right; }

.tc-line { margin: 6px 0; color: var(--text-secondary); }
.tc-award { color: var(--gold); font-weight: 600; }

.pairings-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.pairings-row:last-child { border-bottom: none; }
.pairings-vs { color: var(--text-muted); font-size: 0.75rem; }
.color-toggle {
  display: flex;
  gap: 8px;
}
.color-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-ui);
}
.color-btn.active {
  border-color: var(--gold);
  background: var(--bg-active);
  color: var(--text-active);
}
#time-control-select {
  width: 100%;
  padding: 8px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  font-family: var(--font-ui);
}
#custom-time-fields {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
#custom-time-fields input {
  flex: 1;
}
#tournament-time-control-select {
  padding: 8px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  font-family: var(--font-ui);
}
#tournament-custom-time-fields input {
  flex: 1;
  padding: 8px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  font-family: var(--font-ui);
}

/* ── Live game screen ── */
/* #game-side wraps clocks/controls/status/move-list purely for the desktop
   2-column layout below; on mobile it should have zero effect on layout,
   so its children keep behaving exactly as if they were direct children of
   #screen-game (each still sized/spaced by its own existing rule below). */
#game-side { display: contents; }

/* Same "flatten on mobile, real column on desktop" trick as #game-side
   above — a wrapper purely so the desktop board can get a guaranteed
   (not estimated) width share of the row. See the desktop media query
   for why this exists. */
#game-board-col { display: contents; }

/* Bounds the whole live game screen to the space below the header, same
   treatment #screen-review has, and for the same reason: in the normal
   case only #move-list needs to scroll, not the page. This is just the
   plain flex:1 every .screen already gets (see .screen above) — no
   hardcoded header-height guess, so it always matches the header's real
   rendered size exactly, on every device. min-height:0 is still needed
   so this flex item is actually allowed to shrink to that size instead
   of growing to fit its own content (the row-direction analogue of the
   min-height:auto flexbox footgun noted elsewhere in this file). */
#screen-game {
  flex: 1;
  min-height: 0;
}

#board-wrap {
  width: min(96vw, 620px);
  aspect-ratio: 1 / 1;
  margin: 6px 0;
  flex-shrink: 0;
}
#board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 2px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
}

#controls-row {
  width: min(96vw, 620px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 8px 0;
  flex-shrink: 0;
}
.clock-display {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  padding: 6px 12px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  min-width: 88px;
  text-align: center;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  justify-content: center;
}
.clock-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid var(--border-light);
  flex-shrink: 0;
}
.clock-color-dot.dot-white { background: #f0e8d8; }
.clock-color-dot.dot-black { background: #2a241c; }
.clock-display.clock-active {
  border-color: var(--gold);
  color: var(--text-active);
  background: var(--bg-active);
}
#game-controls {
  display: flex;
  gap: 8px;
  flex: 1;
  justify-content: center;
}
#game-controls .ctrl-btn { font-size: 1.4rem; } /* glyph fills the 34px button instead of leaving it mostly empty */

/* Mated king: a few slow pulses during the delay before the result modal
   appears, so the final move has a moment to actually register. Only
   box-shadow animates — background-color is left alone since that's what
   gives each square its light/dark checkerboard color. */
.king-pulse {
  animation: kingPulse 0.6s ease-in-out var(--king-pulse-count, 3);
}
@keyframes kingPulse {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: inset 0 0 0 4px rgba(220, 60, 60, 0.85), inset 0 0 14px 2px rgba(220, 60, 60, 0.5); }
}

/* Ordinary check (not mate) — a gentler, continuous amber pulse for as
   long as the check lasts, distinct from the harsher red one-shot pulse
   checkmate gets above. */
.king-check {
  animation: kingCheckPulse 1.1s ease-in-out infinite;
}
@keyframes kingCheckPulse {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: inset 0 0 0 3px rgba(230, 160, 40, 0.75), inset 0 0 10px 1px rgba(230, 160, 40, 0.4); }
}
   each theme's own --sq-selected hue at reduced strength via color-mix(),
   rather than a fixed color that wouldn't match every board theme, and
   stays visually distinct from the (fully opaque) .selected highlight. */
.square.last-move {
  background: color-mix(in srgb, var(--sq-selected) 55%, transparent);
}
#status-line {
  min-height: 1.2em;
  color: var(--text-secondary);
  font-style: italic;
  flex-shrink: 0;
}
#debug-move-source {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--gold);
  background: var(--bg-card);
  border: 1px dashed var(--border-light);
  border-radius: var(--radius);
  padding: 2px 8px;
  margin-top: 2px;
  flex-shrink: 0;
}
#move-list {
  width: min(96vw, 620px);
  flex: 1;
  min-height: 60px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ── Review screen ──
   .review-card no longer has its own border/background/padding — it's a
   flush layout wrapper now, matching #screen-game's borderless style,
   rather than a boxed panel nested inside the already-padded .screen. */
.review-card {
  width: 100%;
  max-width: 560px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.review-card h2 {
  font-family: var(--font-ui);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--gold);
}
/* Overrides theme.css's serif .modal-box h3 (a PCDB leftover) to match the
   wordmark's own Inter treatment, used app-wide now. */
.modal-box h3 {
  font-family: var(--font-ui);
  font-weight: 700;
  letter-spacing: -0.01em;
}
#review-top-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 8px;
  flex-shrink: 0;
}
#result-modal-elo {
  font-family: var(--font-mono);
  color: var(--text-active);
  margin: 8px 0 4px;
}
#reviewing-modal-progress {
  color: var(--text-secondary);
  font-size: 1rem;
  padding: 10px 0;
}
/* This modal's content is always short and fixed (one line of heading,
   one line of tally) — it never needed the general max-height:90dvh cap
   .modal-box now has for modals whose content can grow long. Worse, dvh
   is the *dynamic* viewport height, which shifts live as the mobile
   browser's address bar shows/hides during the scan running in the
   background — recalculating this modal's height mid-scan and visibly
   drifting it out of center until the page settles and it snaps back.
   Opting out restores its simpler pre-existing behavior: centered by the
   overlay only, nothing dvh-driven to recalculate. */
#reviewing-modal .modal-box {
  max-height: none;
}
#reviewing-modal-tally {
  color: var(--gold);
  font-size: 0.9rem;
  min-height: 1.2em;
  padding-bottom: 4px;
}
#review-elo-change {
  font-family: var(--font-mono);
  color: var(--text-active);
  margin: 8px 0 4px;
}
.reviewing-dots span {
  display: inline-block;
  animation: reviewingPulse 1.2s infinite;
  opacity: 0.2;
}
.reviewing-dots span:nth-child(2) { animation-delay: 0.2s; }
.reviewing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes reviewingPulse {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

/* #review-main holds the board (left/top) and the engine/graph/move-list
   panel (right/bottom) — a column on mobile (matching the old stacked
   layout), a row on desktop (see the desktop media query below). */
#review-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}
#review-board-col {
  flex-shrink: 0;
}
#review-side-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

#review-board-wrap {
  width: min(100%, 360px); /* a little smaller than before, to leave more room on small phones */
  aspect-ratio: 1 / 1;
  margin: 0 auto 6px;
  position: relative;
}
#review-arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#review-board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 2px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
}
#review-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}
#btn-play-again-desktop { display: none; } /* shown only on desktop, below the board — see the desktop media query */
/* Mini eval-graph sparkline, sitting to the right of the back/forward nav
   buttons — a compact stand-in for the full graph below on mobile/tablet.
   Tapping it opens #eval-graph-modal (the full, annotated graph). Hidden
   entirely on desktop, where the full graph is always visible inline
   instead (see the desktop media query). */
#mini-graph-wrap {
  flex: 1;
  min-width: 60px;
  max-width: 140px;
  height: 34px; /* matches .ctrl-btn's height so it lines up with the nav row */
  cursor: pointer;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-left: 4px;
}
#mini-graph { display: block; }

#eval-graph-wrap {
  width: 100%;
  height: 118px;
  cursor: pointer;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
#eval-graph { display: block; }

/* Doubles as a real modal (mobile/tablet) and a permanently-visible inline
   panel (desktop) — see the desktop override below. As a modal, it's just
   .modal-overlay's usual fixed/centered treatment. */
#eval-graph-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
#eval-graph-modal-box {
  width: min(92vw, 420px);
}

/* ── Engine analysis lines: gym.css loads after theme.css, so these
   override the inherited PCDB rules for what this app needs different from
   PCDB — a single flush box (no divider between the two lines), text
   left-justified starting at the same inset as the "Stockfish" header
   label (not indented behind a rank column), single-line truncation
   instead of wrapping, and a fixed height reserved for exactly two rows so
   the panel never resizes as analysis toggles on/off or streams in. ── */
.engine-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 10px;
  border-bottom: none;
}
.engine-line-score {
  flex: 0 0 44px;
  text-align: left;
}
.engine-line-moves {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: normal;
}
#engine-lines {
  display: flex;
  flex-direction: column;
  min-height: calc(2 * (6px + 0.78rem * 1.5)); /* 2 rows' padding+line-height, no border between them anymore */
}
.engine-message-box {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85rem;
  text-align: center;
}
#engine-panel { flex-shrink: 0; margin-top: 0; }

/* The one section that actually scrolls on the review screen — see
   #screen-review below for how the rest of the screen is bounded to the
   viewport so this, not the whole page, is what scrolls when a game runs
   long. */
#review-move-list-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  margin: 6px 0 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
#review-opening-name {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 8px 4px;
  min-height: 1em;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#review-opening-name:empty {
  border-bottom: none;
  padding: 0;
}
#review-move-list {
  padding: 8px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-secondary);
  flex: 1;
  min-height: 60px;
  overflow-y: auto;
}
.review-move {
  cursor: pointer;
  padding: 1px 3px;
  border-radius: 3px;
}
.review-move:hover { background: var(--bg-hover); color: var(--text-active); }
.review-move.move-inaccuracy { color: #e6c229; }
.review-move.move-mistake { color: #e8720c; }
.review-move.move-blunder { color: var(--red); font-weight: 600; }
.review-move.move-great { color: var(--green); font-weight: 600; }
.review-move.current { background: var(--bg-active); color: var(--text-active); }

/* Bounds the whole review screen to the space below the header, so in the
   normal case only #review-move-list needs to scroll — not the page.
   Plain flex:1 (see .screen above), not a hardcoded header-height guess —
   see the note at the top of this file for why. */
#screen-review {
  flex: 1;
  min-height: 0;
}

/* ── Promotion modal ── */
#promo-pieces {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 12px 0;
}
.promo-choice {
  width: 56px;
  height: 56px;
  cursor: pointer;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 6px;
}
.promo-choice:hover { border-color: var(--gold); background: var(--bg-active); }

#error-modal-message {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin: 10px 0;
}

/* ── Account modal ── */
#account-modal input {
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-ui);
}
.account-note {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 12px;
}
#register-password-mismatch {
  color: var(--red);
  font-size: 0.8rem;
  margin: -4px 0 8px;
}
.settings-checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
}
#persistent-storage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
#persistent-storage-status {
  color: var(--text-secondary);
  font-size: 0.82rem;
  flex: 1;
  min-width: 180px;
}
#persistent-storage-note {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 6px;
  line-height: 1.4;
}
#clear-history-note {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 6px;
  line-height: 1.4;
}
#sync-debug-output {
  background: var(--bg-deepest);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
  margin: 6px 0;
}

/* ── Mobile ── */
@media (max-width: 600px) {
  .screen { padding: 8px; }
  .setup-card { padding: 10px; }
  .clock-display { font-size: 1.15rem; min-width: 76px; padding: 5px 10px; }
  #game-controls { gap: 6px; }
  #review-nav .ctrl-btn { width: 30px; height: 30px; font-size: 0.9rem; }
  #review-board-wrap { width: min(100%, 290px); }

  /* Tightening the rest of the review screen's vertical spacing on
     mobile, to give #review-move-list more room — none of these
     individually matter much, but stacked together they free up real
     space. Desktop is untouched (its two-column layout already has
     plenty of room). */
  #review-top-row { margin-bottom: 5px; }
  #review-nav { margin-bottom: 5px; }
  #review-board-wrap { margin: 0 auto 4px; }
  #engine-header { padding: 4px 8px; }
  .engine-line { padding: 2px 10px; }
  #engine-lines { min-height: calc(2 * (4px + 0.78rem * 1.4)); }
  #review-move-list-wrap { margin: 4px 0 0; }
  #review-opening-name { padding: 4px 8px 3px; }
  #review-move-list { padding: 6px; }

  /* Header: with four icon buttons now (Settings/Account/About You/
     Fullscreen) instead of the original three, there's less room left
     for the wordmark on a narrow phone before it wraps to a second
     line. Tighten padding/gaps on both sides and shrink the icon
     buttons slightly, rather than letting either side crowd the other. */
  #app-header { padding: 6px 8px 6px 6px; gap: 4px; }
  #logo-plate { gap: 5px; }
  .wordmark-text-wrap { font-size: 1.35rem; }
  #logo-plate .wordmark-text { font-size: 1em; }
  #header-icons { gap: 3px; }
  #header-icons .ctrl-btn { width: 30px; height: 30px; }
}

/* ── Desktop: two-column layout (board + side panel), sized to fit the
   viewport without page scrolling — see --header-h at the top of this
   file. The review screen already gets the same viewport-bounded height
   at every width (so its move list, not the page, scrolls on mobile too);
   here #screen-game gets that same treatment, and both screens switch
   from a single stacked column to a board + side-panel row. ── */
@media (min-width: 1024px) {
  /* .review-card's max-width:560px (base rule above) is sized for the
     mobile single-column layout — it was never widened when the desktop
     two-column layout (board + 340px side panel + 28px gap, ~830px+
     total) was added, so the whole row was being squeezed into a box far
     narrower than it needs, and the board sized itself correctly small
     within that too-narrow space. This is the actual remaining cause of
     "the review board is square now but tiny" — not a board-sizing bug
     at all. */
  .review-card { max-width: 900px; }
  #screen-game {
    flex: 1;
    min-height: 0;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 28px;
    width: 100%;
  }
  /* Guaranteed bound, not an estimate: #game-board-col gets a real,
     flex-computed share of the row (row width minus #game-side's fixed
     320px minus the gap) — the same technique #review-board-col already
     uses. #board-wrap's max-width can then reference that column's own
     actual width via `100%`, instead of guessing at "side panel + gaps +
     padding" via calc(100vw - 400px), which used to underguess the real
     available space on some layouts. */
  #game-board-col {
    flex: 1;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Establishes this column's own already-definite size (from flex:1 +
       height:100% above) as a query container, so #board-wrap below can
       size itself directly off BOTH real dimensions at once via cqw/cqh
       units — see #board-wrap's own comment for why this replaces the
       width-only fix from the previous round. */
    container-type: size;
  }
  #board-wrap {
    /* The largest square that fits BOTH the column's real width and its
       real height at once, capped at 620px — not derived from just one
       dimension via aspect-ratio. That one-dimension approach (first
       height-driven, then "fixed" to width-driven) kept only solving
       half the problem: deriving from height alone let the previous
       round's board grow past 620px tall on some layouts (this bug —
       overflowing the available height); deriving from width alone
       (last round's fix) let it grow taller than the available height
       whenever the column was wide but short. cqw/cqh sidestep the
       whole direction-of-derivation issue by reading the column's two
       real dimensions directly and take whichever (plus the flat
       ceiling) is smallest. */
    width: min(100cqw, 100cqh, 620px);
    aspect-ratio: 1 / 1;
    margin: auto;
    flex-shrink: 0;
  }
  #game-side {
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 320px;
    flex-shrink: 0;
    height: 100%;
  }
  #controls-row, #move-list { width: 100%; max-width: none; }
  #move-list {
    flex: 1;
    min-height: 60px;
    max-height: none;
  }

  /* Review screen: board + nav in the left column, engine panel/graph/move
     list stacked in the right column. */
  #review-main {
    flex-direction: row;
    align-items: flex-start;
    gap: 28px;
  }
  #review-board-col {
    flex: 1;
    height: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  /* This is what actually reserves room for #review-nav/the Play Again
     button below: flex:1 + min-height:0 give it exactly whatever's left
     in the column after those two take their own natural height —
     guaranteed, not an estimate — and container-type:size turns that
     real remaining space into query units #review-board-wrap can size
     itself against directly (same technique and reasoning as
     #game-board-col/#board-wrap above). */
  #review-board-square {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    container-type: size;
  }
  #review-board-wrap {
    width: min(100cqw, 100cqh, 460px);
    aspect-ratio: 1 / 1;
    margin: 0;
  }
  #review-nav {
    flex-shrink: 0;
  }
  /* Desktop-only: "Play again" relocates below the board/nav column and
     becomes the prominent primary action there, instead of the small
     button up in the summary row (which stays for mobile — see the base
     rule above). Same click handler wired to both in app.js. */
  #btn-play-again { display: none; }
  #btn-play-again-desktop {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 12px;
    font-size: 1.05rem;
    font-weight: 700;
  }
  #review-side-col {
    width: 340px;
    flex-shrink: 0;
    height: 100%;
  }
  #review-move-list {
    font-size: 1rem; /* more room on desktop than the mobile-tuned 0.85rem */
  }
  /* The mini-graph is a mobile/tablet stand-in for the full graph below —
     on desktop the full graph is always visible in the side column, so the
     mini one is redundant. */
  #mini-graph-wrap { display: none; }
  /* Un-modal the full eval graph: instead of a fixed full-screen overlay
     triggered by the mini-graph, show it permanently inline as a normal
     panel in the side column — same markup/canvas either way, just
     reinterpreted here rather than duplicated. */
  #eval-graph-modal {
    position: static;
    inset: auto;
    background: none;
    backdrop-filter: none;
    display: flex !important; /* overrides .hidden's display:none */
    z-index: auto;
    flex-shrink: 0;
  }
  #eval-graph-modal-box {
    width: 100%;
    max-width: none;
    min-width: 0;
    padding: 0;
    border: none;
    background: none;
    box-shadow: none;
    /* Resets the sticky-footer/max-height treatment .modal-box now has
       (see theme.css) — this box is un-modal'd into a permanently
       visible side-column panel here, not an actual overlay, so none of
       that should apply to it in desktop mode. */
    max-height: none;
    overflow: visible;
    display: block;
  }
  #eval-graph-modal-header { display: none; }
}
