/* ── Commentary Progress Bar ─────────────────────── */
.review-commentary-bar {
  height: 4px;
  background: var(--border);
  overflow: hidden;
  margin: 0.5rem 1rem;
  border-radius: 2px;
}

.review-commentary-fill {
  height: 100%;
  width: 0%;
  background: var(--red);
  transition: width 0.3s ease;
  position: relative;
}

.review-commentary-fill.indeterminate {
  width: 100% !important;
  background: linear-gradient(90deg, transparent, var(--red), transparent);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .review-commentary-fill.indeterminate { animation: none; background: var(--red); }
}

/* ── API Key Masking (avoids Chrome password save prompt) ── */
.api-key-mask {
  -webkit-text-security: disc;
}

.input-hint {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 0.3rem;
}

/* ── Review Page Layout ───────────────────────────── */
.review-main {
  padding: 5rem 2rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* ── Demo Banner ─────────────────────────────────── */
.demo-banner {
  padding: 0.6rem 1rem;
  background: var(--red-faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 1rem;
  text-align: center;
}

.demo-banner a {
  color: var(--red);
  text-decoration: none;
  font-weight: 500;
}

.demo-banner a:hover {
  text-decoration: underline;
}

/* ── Input Panel ─────────────────────────────────── */
.input-panel {
  max-width: 600px;
  margin: 0 auto 2rem;
}

.input-panel .input-row {
  margin-bottom: 0.8rem;
}

.source-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.2rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.source-tab {
  flex: 1;
  padding: 0.6rem 1rem;
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  background: transparent;
  color: var(--text-dim);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.source-tab:not(:last-child) {
  border-right: 1px solid var(--border);
}

.source-tab.active {
  background: var(--red-faint);
  color: var(--red);
}

.source-tab:hover:not(.active) {
  background: var(--bg-elevated);
  color: var(--text);
}

.source-form {
  margin-bottom: 1.2rem;
}

.hidden {
  display: none !important;
}

/* File drop */
.file-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s;
  text-align: center;
}

.file-drop:hover,
.file-drop.dragover {
  border-color: var(--red);
  background: var(--red-faint);
}

.file-drop-text {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.file-drop-name {
  font-size: 0.75rem;
  color: var(--red);
  font-weight: 500;
}

/* Inputs */

/* .btn-browse promoted to .btn-compact-input in style.css so the
   same compact sizing can be reused across pages (Browse on the
   review input, Editor on the position-analysis input, etc.). */

/* Game picker */
.game-picker {
  max-height: clamp(140px, 30vh, 300px);
  overflow-y: auto;
  margin-top: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
}

.game-picker-loading {
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.game-picker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
  font-size: 0.75rem;
}

.game-picker-item:last-child {
  border-bottom: none;
}

.game-picker-item:hover {
  background: var(--bg-elevated);
}

.game-picker-item.selected {
  background: rgba(255, 10, 43, 0.1);
  border-left: 3px solid var(--red);
}

.game-picker-players {
  font-weight: 500;
  color: var(--text);
}

.game-picker-meta {
  display: flex;
  gap: 0.5rem;
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.game-picker-eco {
  color: var(--red);
  border: 1px solid var(--red-dim);
  padding: 0 0.3rem;
  border-radius: 2px;
  font-size: 0.55rem;
}

.game-picker-load-more {
  cursor: pointer;
  color: var(--red);
  transition: background 0.2s;
}

.game-picker-load-more:hover {
  background: var(--bg-elevated);
}

.game-picker-result {
  font-weight: 600;
  color: var(--red);
  font-size: 0.75rem;
}

/* Shared action stack, primary button, and Settings disclosure styles
   live in style.css so Review, Position Analysis, and Coach stay aligned. */

/* Match the placeholder size to .input-subtitle so "Enter username or
   game url" sits at the same visual weight as "Import a game from…"
   on both desktop and mobile. Scoped to the source-form inputs only;
   the input keeps its iOS-safe 16px font so focus doesn't trigger
   auto-zoom. */
.source-form .text-input::placeholder {
  font-size: 0.85rem;
}

.input-error {
  margin-top: 0.8rem;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--red);
  background: var(--red-faint);
  border: 1px solid rgba(255, 10, 43, 0.3);
  border-radius: 4px;
}

/* ── Progress Panel ──────────────────────────────── */
.progress-panel {
  max-width: 600px;
  margin: 0 auto 2rem;
}

.progress-header {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 1rem;
  letter-spacing: 0.05em;
}

.progress-stages {
  margin-bottom: 1rem;
}

.progress-stage {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.progress-stage.active {
  color: var(--red);
}

.progress-stage.done {
  color: var(--text-dim);
}

.progress-stage-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.progress-stage.active .progress-stage-dot {
  background: var(--red);
  box-shadow: 0 0 8px var(--red-glow);
  animation: pulse-dot 1.5s ease-in-out infinite;
}

.progress-stage.done .progress-stage-dot {
  background: #51cf66;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.progress-bar-wrap {
  height: 3px;
  background: var(--bg-elevated);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 0.6rem;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--red);
  box-shadow: 0 0 10px var(--red-glow);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.progress-message {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.progress-cancel {
  margin-top: 1rem;
  font-size: 0.7rem;
  padding: 0.4rem 1.5rem;
}

/* ── Review Panel ────────────────────────────────── */
.review-layout {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2rem;
  align-items: start;
}

/* Board column */
.review-board-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: sticky;
  top: 5rem;
}

.review-board-wrap {
  display: flex;
  gap: 0;
}

.review-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(480px, calc(100vw - 4rem));
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 0 30px var(--red-faint);
}

.review-board .sq {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: default;
}

.review-board .sq.light {
  background: var(--sq-light);
}

.review-board .sq.dark {
  background: var(--sq-dark);
}

.review-board .sq.highlight {
  background: var(--sq-highlight) !important;
  box-shadow: inset 0 0 8px var(--sq-highlight);
}

.review-board .sq .piece-img {
  width: 85%;
  height: 85%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.5));
}

.review-board .sq .piece-img.black-piece {
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.4));
}

/* ── Position Q&A ─────────────────────────────── */
.position-qa {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.qa-messages {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.qa-msg {
  padding: 0.4rem 0.6rem;
  border-radius: 5px;
  font-size: 0.8rem;
  line-height: 1.5;
  max-width: 92%;
  word-wrap: break-word;
}

.qa-msg-user {
  align-self: flex-end;
  background: rgba(255, 10, 43, 0.1);
  border: 1px solid rgba(255, 10, 43, 0.15);
  color: var(--text);
}

.qa-msg-ai {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
}

.qa-input-row {
  display: flex;
  gap: 0.4rem;
}

.qa-input {
  flex: 1;
  font-size: 0.8rem;
  padding: 0.4rem 0.6rem;
}

.qa-send {
  padding: 0.4rem 0.75rem;
  font-size: 0.75rem;
  white-space: nowrap;
}

.qa-thinking {
  color: var(--text-dim);
  font-style: italic;
}

/* Move refs inside Q&A answers */
.qa-msg-ai .move-ref-move,
.qa-msg-ai .move-ref-sq,
.qa-msg-ai .comment-move-ref {
  cursor: pointer;
  border-bottom: 1px dashed var(--text-dim);
}


/* Captured pieces inline with player names */
.player-captured {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  margin-left: 0.4rem;
}

.player-captured-piece {
  width: 16px;
  height: 16px;
  object-fit: contain;
  opacity: 0.7;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
}

.player-captured-piece.black-piece {
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2));
}

/* Eval bar */
.eval-bar {
  width: 20px;
  align-self: stretch;
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: 3px 0 0 3px;
  overflow: hidden;
  position: relative;
}

.eval-bar-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: #d4d0c8;
  transition: height 0.4s ease;
}
.eval-bar-fill.eval-bar-tablebase {
  background: linear-gradient(to top, #d4d0c8, #b0bec5);
}

/* Active comment strip (mobile only — shown below board controls) */
.active-comment-strip {
  display: none;
}

/* Board controls */
.board-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.8rem;
  touch-action: manipulation;
}

.board-btn {
  padding: 0.4rem 0.8rem;
  font-family: var(--font);
  font-size: 1rem;
  color: var(--text-dim);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.board-btn:hover:not(:disabled) {
  color: var(--red);
  border-color: var(--border-hover);
}

.board-btn:disabled {
  cursor: default;
  opacity: 0.3;
}

.board-btn-flip {
  margin-left: 0.5rem;
  font-size: 1.1rem;
}

.board-btn-analyze {
  font-size: 0.9rem;
}

/* Mobile-only Q&A trigger button (deeper red filled chat bubble) — inline with board controls */
.board-btn-qa {
  display: none;
  background: var(--red-dim);
  border-color: var(--red-dim);
  color: #fff;
  padding: 0;
  line-height: 1;
  border-radius: 50%;
  /* Keep it sized like the other board buttons — don't let SVG intrinsic size blow it up */
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  flex: 0 0 auto;
}

.board-btn-qa .icon-chat {
  width: 22px;
  height: 22px;
  display: block;
}

.board-btn-qa:hover:not(:disabled) {
  filter: brightness(1.15);
}

.board-btn-qa:disabled {
  /* Keep red fill when disabled — just fade it so it's clearly inactive */
  background: var(--red-dim);
  border-color: var(--red-dim);
  color: #fff;
  opacity: 0.4;
}

/* Mobile-only options menu (⋮) — popover anchored to button */
.board-menu-wrap {
  position: relative;
  display: none;
}

.board-btn-menu {
  font-size: 1.2rem;
  line-height: 1;
}

.board-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.3rem);
  min-width: 11rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 20;
  padding: 0.3rem 0;
  display: flex;
  flex-direction: column;
}

.board-menu.hidden {
  display: none;
}

.board-menu-item {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  text-decoration: none;
  display: block;
}

.board-menu-item:hover {
  background: var(--red-faint);
  color: var(--red);
}

.board-menu-item[aria-disabled="true"] {
  opacity: 0.4;
  pointer-events: none;
}

/* PGN column */
.review-pgn-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.review-card {
  width: 100%;
  max-height: 70vh;
  overflow-y: auto;
  animation: none;
}

/* Shortcuts overlay */
.shortcuts-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  backdrop-filter: blur(3px);
}

.shortcuts-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem 2rem;
  min-width: 280px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.shortcuts-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1rem;
  letter-spacing: 0.05em;
}

.shortcuts-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 1rem;
  align-items: center;
  margin-bottom: 1.2rem;
}

.shortcuts-grid kbd {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: var(--text);
  text-align: center;
  min-width: 2rem;
}

.shortcuts-grid span {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.shortcuts-close {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  padding: 0.4rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.shortcuts-close:hover {
  color: var(--text);
  border-color: var(--border-hover);
}

.review-preamble {
  padding: 0.8rem 1.2rem;
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  font-style: italic;
}

.time-management-summary {
  padding: 0.6rem 1.2rem;
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

/* ── Live local engine panel ──────────────────────── */
.live-engine {
  margin-top: 0.6rem;
  padding: 0.45rem 0.7rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.78rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.live-engine-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  font-family: var(--font);
  letter-spacing: 0.02em;
  user-select: none;
}

.live-engine-toggle input[type="checkbox"] {
  margin: 0;
  accent-color: var(--red);
  cursor: pointer;
}

.live-engine-label {
  font-weight: 500;
  color: var(--text);
}

.live-engine-readout {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}

.live-engine-score {
  font-weight: 700;
  color: var(--text);
  min-width: 3.5em;
}

.live-engine-depth {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.live-engine-line {
  font-family: var(--font);
  color: var(--text-dim);
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.review-card .game-body {
  padding: 1rem 1.2rem;
}

/* Move highlighting in review */
.review-card .move {
  cursor: pointer;
  padding: 0.1rem 0.2rem;
  border-radius: 2px;
  transition: background 0.15s;
}

.review-card .move:hover {
  background: var(--bg-elevated);
}

/* Board clocks — displayed above and below the board */
.board-clock {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: min(480px, calc(100vw - 4rem));
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  /* Push right to align with board, past the 20px eval bar + 1px border */
  margin-left: 21px;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.board-clock.clock-active {
  opacity: 1;
  color: var(--text);
}
.board-clock .clock-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60%;
}
.board-clock .clock-time {
  font-weight: 600;
  font-family: var(--font-mono, monospace);
}

.review-card .move.active-move {
  background: rgba(255, 10, 43, 0.25);
  color: #fff;
  border-radius: 3px;
  padding: 0.1rem 0.3rem;
  box-shadow: 0 0 8px rgba(255, 10, 43, 0.3);
}

/* Review actions */
.review-actions {
  display: flex;
  gap: 0.6rem;
  padding: 0.8rem 0;
  flex-shrink: 0;
}

.review-actions .btn {
  font-size: 0.75rem;
  padding: 0.5rem 1rem;
}

/* ── Engine Variations ───────────────────────────── */
.engine-variation {
  margin: 0.25rem 0 0.5rem 0.75rem;
  font-size: 0.78rem;
}

.variation-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.2rem 0;
  transition: color 0.2s;
}

.variation-toggle:hover {
  color: #5ec4c0;
}

.variation-toggle strong {
  color: #5ec4c0;
}

.variation-line {
  display: none;
  padding: 0.3rem 0 0.2rem 0.5rem;
  border-left: 2px solid rgba(94, 196, 192, 0.3);
  margin-top: 0.2rem;
}

.engine-variation.expanded .variation-line {
  display: block;
}

.variation-move {
  background: none;
  border: none;
  padding: 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: inherit;
  color: #5ec4c0;
  cursor: pointer;
  transition: color 0.2s, text-shadow 0.2s;
}

.variation-move:hover {
  color: #7de0dc;
  text-shadow: 0 0 8px rgba(94, 196, 192, 0.5);
}

.variation-move.variation-active {
  color: #fff;
  text-shadow: 0 0 10px rgba(94, 196, 192, 0.7);
  font-weight: 600;
}

.variation-indicator {
  text-align: center;
  font-size: 0.75rem;
  color: #5ec4c0;
  padding: 0.3rem 0;
  margin-top: 0.25rem;
}

.variation-back-btn {
  background: none;
  border: none;
  color: #5ec4c0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  cursor: pointer;
  text-decoration: underline;
}

.variation-back-btn:hover {
  color: #7de0dc;
}

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 1100px) {
  .review-layout {
    grid-template-columns: 1fr;
  }

  .review-board-col {
    position: static;
    align-items: center;
  }

  .review-board {
    width: min(360px, calc(100vw - 4rem));
  }

  .review-pgn-col {
    max-height: none;
  }

  .review-card {
    max-height: none;
  }

  /* On mobile, the full scrolling comment list duplicates the active
     comment strip below the board and pushes the action buttons
     (Download / Share / Save / New) out of view. Hide the review-card
     annotated-PGN chrome and let the strip be the only comment surface.
     Note: .game-body itself stays visible so the Similar GM Games
     section (appended inside it) can render. Its move-list children
     are hidden individually below. The time-management summary stays
     visible — it's a compact standalone paragraph, not duplicated
     elsewhere. */
  .review-preamble,
  .review-card .game-header,
  .review-commentary-bar {
    display: none !important;
  }

  /* Mobile: the standalone time-management block is folded into the
     opening-preamble paragraph by updateCommentStrip (review-board.js),
     so the element in the PGN column is hidden to avoid duplication.
     Desktop keeps it via the default rule outside this media block. */
  .time-management-summary {
    display: none;
  }

  /* The second paragraph inside the start-position strip carries the
     time-management text — same dim color so it reads as a separate
     "aside" from the preamble above it. */
  .active-comment-strip .comment-strip-tm {
    color: var(--text-dim);
    font-style: italic;
  }

  /* Hide move groups / comments / empty state inside game-body on mobile,
     but keep the Similar GM Games section visible. */
  .review-card .game-body > *:not(.sg-section) {
    display: none !important;
  }

  /* Surface the engine variation for the current move on mobile —
     desktop shows them all inline; mobile only the active one. */
  .review-card .game-body > .engine-variation[data-active="true"] {
    display: block !important;
    margin-top: 0.6rem;
  }

  .review-card .game-body {
    padding: 0;
  }

  .review-card {
    border: none;
    background: transparent;
    padding: 0;
  }

  /* Show active comment strip below board on stacked layout.
     No inner scrollbar — comment flows in the page so the user scrolls once. */
  .active-comment-strip {
    display: block;
    margin-top: 0.6rem;
    padding: 0.6rem 0.8rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--text);
    line-height: 1.5;
    width: 100%;
  }

  .active-comment-strip.hidden {
    display: none;
  }

  .active-comment-strip .comment-strip-move {
    font-weight: 600;
    color: var(--red);
    margin-right: 0.4rem;
  }

  /* Mobile structure and trending blocks — inline flex-row children of
   * the active-comment-strip. Styled to echo the desktop green/orange
   * blocks without duplicating the entire desktop padding treatment. */
  .active-comment-strip .comment-strip-structure,
  .active-comment-strip .comment-strip-trending {
    display: block;
    margin: 0.35rem 0;
    padding: 0.45rem 0.6rem;
    border-left-width: 3px;
    border-left-style: solid;
    border-radius: 3px;
    font-size: 0.78rem;
    line-height: 1.4;
    width: 100%;
  }
  .active-comment-strip .comment-strip-structure {
    background: rgba(126, 200, 164, 0.08);
    border-left-color: #7ec8a4;
    color: #c8e4d0;
  }
  .active-comment-strip .comment-strip-structure strong {
    color: #9fd9b6;
  }
  .active-comment-strip .comment-strip-trending {
    background: rgba(232, 165, 71, 0.08);
    border-left-color: #e8a547;
    color: #f3d8b8;
  }
  .active-comment-strip .comment-strip-trending strong {
    color: #f5b76e;
  }

  /* Novelty move label — match desktop's gold/orange treatment */
  .active-comment-strip .comment-strip-move.move-novelty {
    color: #ffa726;
  }

  /* Final game result appended at the last move */
  .active-comment-strip .comment-strip-result {
    font-weight: 600;
    color: var(--red);
    margin: 0 0.4rem 0 0.2rem;
  }

  /* Hide Similar GM Games except at the two endpoints (mobile only) */
  .sg-section.sg-hidden-mobile {
    display: none !important;
  }

  .active-comment-strip .comment-strip-eval {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-left: 0.4rem;
  }

  /* Clamp long comments to ~3 lines so the board + controls stay
     near the top of the viewport. Users can expand any comment
     that's actually clipped via the Show more toggle. Use
     -webkit-inline-box so the clamped span still flows inline with
     the move label and eval tail instead of forcing its own line. */
  .active-comment-strip .comment-strip-text {
    display: -webkit-inline-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
    vertical-align: top;
  }

  .active-comment-strip.expanded .comment-strip-text {
    -webkit-line-clamp: unset;
    line-clamp: unset;
    overflow: visible;
    display: inline;
  }

  .active-comment-strip .comment-strip-toggle {
    display: block;
    margin-top: 0.35rem;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--red);
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.02em;
  }

  .active-comment-strip .comment-strip-toggle:hover {
    color: var(--text);
  }

  /* Preserve a visible focus ring for keyboard users — colour alone
     isn't enough for accessibility. */
  .active-comment-strip .comment-strip-toggle:focus-visible {
    color: var(--text);
    outline: 2px solid var(--red);
    outline-offset: 2px;
  }

  /* Hide desktop Q&A on mobile — use modal trigger instead */
  .position-qa {
    display: none !important;
  }

  /* Show the inline red Q&A chat bubble on mobile */
  .board-btn-qa {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .board-btn-qa.hidden {
    display: none !important;
  }

  /* Hide flip / analyze / help from inline row — available via options menu */
  .board-controls #btn-flip,
  .board-controls #btn-board-analyze-position {
    display: none;
  }

  /* Show the options menu wrap on mobile */
  .board-menu-wrap {
    display: inline-block;
  }

  /* Hide Download PGN and Share from review-actions on mobile — they live in the options menu */
  .review-actions #btn-download,
  .review-actions #btn-share {
    display: none;
  }

  /* Sticky bottom action bar: Save Review + New Review, centered, above safe area */
  .review-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.6rem 1rem calc(0.6rem + env(safe-area-inset-bottom, 0px));
    background: var(--bg);
    border-top: 1px solid var(--border);
    z-index: 15;
  }

  .review-actions .btn {
    flex: 0 1 auto;
    min-width: 7rem;
  }

  /* Ensure main content isn't hidden under the sticky bar */
  .review-main {
    padding-bottom: 5rem;
  }
}

/* Landscape phone: restore side-by-side layout */
@media (orientation: landscape) and (max-height: 500px) {
  .review-layout {
    grid-template-columns: auto 1fr;
    gap: 1rem;
  }

  /* In landscape the pgn column scrolls in its own container — keep review-actions
     in flow instead of fixed to the viewport bottom. */
  .review-actions {
    position: static;
    padding: 0.5rem 0;
    background: transparent;
    border-top: none;
  }

  .review-main {
    padding-bottom: 1rem;
  }

  .review-board {
    width: min(280px, calc(100vh - 6rem));
  }

  .review-main {
    padding-top: 3.5rem;
  }

  /* Hide the comment strip — comments are visible in the side panel */
  .active-comment-strip {
    display: none !important;
  }

  .review-pgn-col {
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
  }

  .review-card {
    max-height: calc(100vh - 8rem);
  }

  /* Compact board controls for landscape */
  .board-controls {
    gap: 0.3rem;
    margin-top: 0.4rem;
  }

  .board-btn {
    padding: 0.3rem 0.6rem;
    min-height: 32px;
    min-width: 32px;
    font-size: 0.9rem;
  }
}

@media (max-width: 768px) {
  .board-btn {
    padding: 0.6rem 1rem;
    min-height: 44px;
    min-width: 44px;
  }

  .review-card .move {
    padding: 0.25rem 0.4rem;
  }

  .review-card .move.active-move {
    padding: 0.25rem 0.5rem;
  }

  /* Keep the four review actions on a single row on mobile.
     Shrink font/padding/gap aggressively so "Download PGN" still
     fits even at ~360px viewport widths. */
  .review-actions {
    flex-wrap: nowrap;
    gap: 0.3rem;
  }

  .review-actions .btn {
    flex: 0 1 auto;
    min-width: 0;
    padding: 0.45rem 0.55rem;
    font-size: 0.65rem;
    white-space: nowrap;
  }

  .shortcuts-panel {
    max-width: 90vw;
  }
}

@media (max-width: 600px) {
  .review-main {
    padding: 5rem 1rem 5rem;
  }

  .game-header {
    padding: 0.8rem 0.75rem;
    word-break: break-word;
  }

  .review-board-col {
    align-items: center;
    width: 100%;
  }

  .review-board-wrap {
    justify-content: center;
    /* Add right spacer to match eval bar width for visual symmetry */
    padding-right: 20px;
  }

  .board-controls {
    justify-content: center;
    flex-wrap: wrap;
  }

  .board-btn-help {
    display: none;
  }

  .review-board {
    width: min(calc(100vw - 4rem), 340px);
  }

  /* Make disabled buttons more visible on small screens */
  .board-btn:disabled {
    opacity: 0.5;
  }

  .input-row-half {
    grid-template-columns: 1fr;
  }

  .input-hint {
    display: none;
  }

  .input-label {
    font-size: 0.85rem;
  }

  .btn-analyze {
    position: sticky;
    bottom: 0;
    z-index: 10;
    background: var(--red-faint);
    border: 1px solid var(--red-dim);
    border-radius: 6px;
    padding: 1rem;
    margin: 0.5rem 0;
  }

  .source-tab {
    font-size: 0.65rem;
    padding: 0.6rem 0.5rem;
    min-height: 44px;
  }

  /* When Settings is expanded on mobile, hide the form chrome above so
     the expanded config fits without being pushed off-screen.
     Clicking Settings again collapses and restores them. */
  .input-panel:has(.llm-config:not(.collapsed)) .input-title,
  .input-panel:has(.llm-config:not(.collapsed)) .input-subtitle,
  .input-panel:has(.llm-config:not(.collapsed)) .source-tabs,
  .input-panel:has(.llm-config:not(.collapsed)) .source-form {
    display: none !important;
  }


  .review-card .game-body {
    padding: 0.8rem;
  }

  .game-picker-item {
    min-height: 44px;
    padding: 0.75rem;
  }

  .shortcuts-panel {
    min-width: auto;
  }
}

/* Sticky bottom bar — keep Save/New Review readable on phones
   (overrides the cramped font-size/padding set in the 768px block above) */
@media (max-width: 768px) {
  .review-actions .btn {
    padding: 0.6rem 0.9rem;
    font-size: 0.85rem;
    min-width: 7rem;
  }
}
