/* Chess piece glyphs from a small bundled subset of Noto Sans Symbols 2 (OFL),
   so pieces look the same on every phone instead of depending on system fonts. */
@font-face {
  font-family: "Chess Glyphs";
  src: url("vendor/fonts/noto-sans-symbols-2-chess.woff2") format("woff2");
  font-display: block;
}

:root {
  /* Board size on wide screens (two-column layout). Phones use the full width. */
  --board-max: clamp(320px, 56vmin, 600px);
  --gutter: 10px;

  --bg-1: #0f1320;
  --bg-2: #161c2b;
  --panel: #19202e;
  --panel-2: #212a3b;
  --line: rgba(255, 255, 255, 0.075);

  --text: #e9edf4;
  --muted: #94a1b8;
  --accent: #6d9eeb;
  --accent-strong: #588be4;
  --accent-ink: #0b1322;
  --good: #5fc28d;
  --warn: #e0a955;
  --bad: #e5675f;

  --light: #e8edf3;
  --dark: #6f81a1;
  --hl: rgba(246, 201, 96, 0.5);
  --sel: rgba(246, 201, 96, 0.95);
  --check: rgba(231, 76, 76, 0.5);

  --piece-w: #f6f8fb;
  --piece-w-stroke: #4a505c;
  --piece-b: #2a2f3a;
  --piece-b-stroke: #0b0d12;

  --piece-font: "Chess Glyphs", "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols 2", "DejaVu Sans", sans-serif;
}

* { box-sizing: border-box; }
html {
  height: 100%;
  background: var(--bg-1);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1100px 700px at 78% -12%, #243049, transparent),
    linear-gradient(180deg, var(--bg-2), var(--bg-1));
  background-repeat: no-repeat;
  color: var(--text);
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: break-word;
}

#app {
  max-width: 1120px;
  margin: 0 auto;
  padding:
    max(12px, env(safe-area-inset-top))
    max(var(--gutter), env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
}

.topbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 19px; font-weight: 700; letter-spacing: 0.2px; }
.brand .logo { color: var(--accent); font-family: var(--piece-font); font-size: 24px; line-height: 1; }
.tag { display: none; color: var(--muted); font-size: 13.5px; }

/* ---- layout: one column on phones ---- */
.layout { display: flex; flex-direction: column; gap: 14px; }
/* The height cap keeps the whole board on screen when a phone is held sideways. */
.board-area { width: 100%; max-width: min(600px, max(280px, calc(100vh - 150px))); margin: 0 auto; }
@supports (height: 100svh) {
  .board-area { max-width: min(600px, max(280px, calc(100svh - 150px))); }
}
.board-row { display: flex; flex-direction: column; gap: 6px; }

/* Eval bar: a thin horizontal bar above the board on phones (White fills from
   the left), the original vertical bar beside the board on wide screens. */
.evalbar {
  position: relative;
  width: 100%;
  height: 8px;
  background: #10141d;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.eval-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: var(--eval, 50%);
  background: linear-gradient(90deg, #ccd5e3, #eef1f6);
  transition: width 0.25s ease;
}

/* The board sizes itself from its container; squares and pieces scale with it
   through container units (cqw = 1% of the board width). */
.board-wrap { position: relative; width: 100%; container-type: inline-size; }
.board-wrap, .board { --sq: 12.5cqw; }
.board {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04);
  container-type: inline-size;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
}
/* Blue: the hint. Green: the better move. Red: how your move gets punished.
   Grey: the next move while stepping through a line. */
.arrows line { stroke: var(--arrow, rgba(109, 158, 235, 0.9)); stroke-width: 0.17; stroke-linecap: round; }
.arrows polygon { fill: var(--arrow, rgba(109, 158, 235, 0.9)); }
.arrows .good { --arrow: rgba(95, 194, 141, 0.92); }
.arrows .bad { --arrow: rgba(229, 103, 95, 0.92); }
.arrows .next { --arrow: rgba(160, 172, 194, 0.85); }
.board.previewing { box-shadow: 0 0 0 3px rgba(109, 158, 235, 0.6), 0 18px 50px rgba(0, 0, 0, 0.5); }

.sq { position: relative; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }

.piece {
  font-family: var(--piece-font);
  font-size: calc(var(--sq) * 0.74);
  line-height: 1;
  pointer-events: none;
  user-select: none;
  will-change: transform;
}
.piece.w { color: var(--piece-w); -webkit-text-stroke: calc(var(--sq) * 0.02) var(--piece-w-stroke); text-shadow: 0 2px 3px rgba(0, 0, 0, 0.35); }
.piece.b { color: var(--piece-b); -webkit-text-stroke: calc(var(--sq) * 0.02) var(--piece-b-stroke); text-shadow: 0 2px 3px rgba(0, 0, 0, 0.25); }

.coord { position: absolute; font-size: max(9px, calc(var(--sq) * 0.15)); font-weight: 700; pointer-events: none; opacity: 0.75; }
.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 0; right: 3px; }
.sq.light .coord { color: var(--dark); }
.sq.dark .coord { color: var(--light); }

.sq.last::before { content: ""; position: absolute; inset: 0; background: var(--hl); }
.sq.sel { box-shadow: inset 0 0 0 calc(var(--sq) * 0.055) var(--sel); }
.sq.check { box-shadow: inset 0 0 0 9999px var(--check); }
.sq.target::after { content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: rgba(15, 18, 28, 0.3); }
.sq.capture::after { content: ""; position: absolute; inset: 7%; border-radius: 50%; border: calc(var(--sq) * 0.065) solid rgba(15, 18, 28, 0.28); }

.board-controls { display: flex; gap: 8px; margin-top: 12px; }
.board-controls button { flex: 1 1 0; min-width: 0; padding: 10px 6px; gap: 5px; }
.icon-btn { display: inline-flex; align-items: center; gap: 7px; }
.icon { width: 18px; height: 18px; flex: 0 0 auto; }

.panel {
  width: 100%;
  min-width: 0;
  background: linear-gradient(180deg, var(--panel), #161d2a);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.3);
}

.status { font-size: 20px; font-weight: 700; }
.eval-line { font-size: 13px; color: var(--muted); margin-top: 4px; min-height: 16px; }
.thinking { display: flex; align-items: center; gap: 8px; color: var(--accent); font-size: 13.5px; margin-top: 6px; }
.thinking .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: blink 1s infinite; }
.thinking .dot:nth-child(2) { animation-delay: 0.2s; }
.thinking .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

.setup { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
select {
  font: inherit;
  font-size: 16px; /* 16px or more stops iPhone zooming in when a dropdown opens */
  width: 100%;
  min-width: 0;
  color: var(--text);
  background-color: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 28px 9px 10px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a1b8' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.material { display: flex; flex-direction: column; gap: 3px; background: var(--panel-2); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.mat-row { display: flex; align-items: center; gap: 8px; min-height: 22px; }
.mat-label { color: var(--muted); width: 74px; flex: 0 0 auto; font-size: 12px; }
.mat-pieces { display: flex; flex-wrap: wrap; gap: 1px; line-height: 1; }
.cap { font-family: var(--piece-font); font-size: 18px; }
.cap.w { color: #eef1f6; -webkit-text-stroke: 0.7px var(--piece-w-stroke); }
.cap.b { color: #11141b; }
.cap-none { color: var(--muted); }
.mat-net { font-size: 12.5px; color: var(--good); font-weight: 700; }

.movelist-wrap { position: relative; flex: 1 1 auto; min-height: 130px; max-height: 280px; overflow-y: auto; background: var(--panel-2); border-radius: 10px; padding: 8px 10px; }
.movelist { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.movelist td { padding: 4px 6px; }
.movelist .num { color: var(--muted); width: 34px; text-align: right; user-select: none; }
.movelist td.cur { background: rgba(109, 158, 235, 0.22); border-radius: 6px; font-weight: 700; }
.movelist-empty { color: var(--muted); font-size: 14px; padding: 6px; }
.mk { font-weight: 700; margin-left: 2px; }
.mk.blunder { color: var(--bad); }
.mk.mistake { color: var(--warn); }
.mk.inacc { color: #c9b25e; }

.review { display: flex; flex-direction: column; gap: 8px; background: var(--panel-2); border-radius: 10px; padding: 12px 14px; }
.review-head { font-weight: 700; font-size: 14px; }
.review-counts { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; font-weight: 700; }
.rq.blunder { color: var(--bad); }
.rq.mistake { color: var(--warn); }
.rq.inacc { color: #c9b25e; }
.review-list { margin: 2px 0 0; padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; }
.review-list li { line-height: 1.45; }
.rv-item details { border-top: 1px solid var(--line); padding-top: 4px; }
.rv-item:first-child details { border-top: 0; padding-top: 0; }
.rv-item summary { list-style: none; cursor: pointer; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; padding: 6px 0 6px 18px; position: relative; min-height: 36px; }
.rv-item summary::-webkit-details-marker { display: none; }
.rv-item summary::before { content: "›"; position: absolute; left: 3px; top: 5px; color: var(--muted); font-weight: 800; transition: transform 0.16s ease; }
.rv-item details[open] > summary::before { transform: rotate(90deg); }
.rv-item summary .rq { font-weight: 800; white-space: nowrap; }
.rv-head { color: var(--text); }
.rv-body { padding: 0 0 8px 18px; }
.rv-body p { margin: 0 0 5px; }
.rv-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.rv-actions button { min-height: 38px; padding: 7px 12px; font-size: 13.5px; }
.review-empty { color: var(--good); font-size: 13.5px; }
.review-tip { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.export { display: flex; flex-direction: column; gap: 10px; }
.export-row { display: flex; gap: 10px; }
.export-row button { flex: 1; }
.hint-line { color: var(--accent); font-size: 13px; min-height: 18px; }

button {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 40px;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  touch-action: manipulation;
}
button:active { background: #2f3a4f; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent-strong); color: var(--accent-ink); font-weight: 700; }
@media (hover: hover) {
  button:hover { background: #2a3447; }
  button.primary:hover { background: #7eaef0; }
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 8px; background: rgba(8, 10, 16, 0.6); border-radius: 8px; z-index: 10; }
.hidden { display: none !important; }

.promo-card, .go-card { max-width: 100%; background: #1d2433; border: 1px solid var(--line); padding: 18px 20px; border-radius: 16px; box-shadow: 0 16px 44px rgba(0, 0, 0, 0.55); text-align: center; }
.promo-title, .go-title { font-weight: 700; margin-bottom: 12px; font-size: 18px; }
.promo-row { display: flex; gap: 10px; justify-content: center; }
.promo-btn { width: 66px; height: 66px; font-family: var(--piece-font); font-size: 42px; line-height: 1; padding: 0; }
.promo-btn.w { color: var(--piece-w); -webkit-text-stroke: 1.4px var(--piece-w-stroke); background: #424b61; }
.promo-btn.b { color: var(--piece-b); -webkit-text-stroke: 1.4px var(--piece-b-stroke); background: #cfd6e6; }
.go-card button { margin: 6px 6px 0; }

/* Small boards (phones): shrink the overlay cards to fit inside the board. */
@container (max-width: 420px) {
  .promo-card, .go-card { padding: 14px 12px; border-radius: 14px; }
  .promo-title, .go-title { font-size: 16px; margin-bottom: 10px; }
  .promo-row { gap: 2.5cqw; }
  .promo-btn { width: 17cqw; height: 17cqw; min-height: 0; font-size: 11.5cqw; }
  .go-card button { margin: 5px 3px 0; padding: 9px 11px; font-size: 13.5px; }
}

/* ---- tabs ---- */
.tabs { display: flex; gap: 6px; margin-left: auto; }
.tab { background: transparent; border: 1px solid transparent; color: var(--muted); border-radius: 9px; padding: 7px 14px; font-weight: 600; min-height: 38px; }
.tab.on { color: var(--text); background: var(--panel-2); border-color: var(--line); }
@media (hover: hover) {
  .tab:hover { background: #222c3e; }
}
.pill { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 800; margin-left: 4px; }

/* ---- learn view ---- */
.learn-nav { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.learn-nav button { background: var(--panel); border: 1px solid var(--line); color: var(--muted); padding: 9px 14px; border-radius: 10px; font-weight: 600; }
.learn-nav button.on { color: var(--text); background: var(--panel-2); border-color: var(--accent-strong); }
.learn-body { max-width: 760px; }
.learn-pad { color: var(--muted); padding: 20px; }
.roadmap-intro { color: var(--muted); font-size: 14px; line-height: 1.6; margin-bottom: 18px; }
.roadmap-intro p { margin: 0 0 8px; }

.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: 12px; }
.level-card { text-align: left; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; padding: 14px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
.level-card.open { border-color: var(--accent-strong); }
.level-card.done { border-color: var(--good); }
.level-card.locked { opacity: 0.55; }
.lc-top { display: flex; justify-content: space-between; width: 100%; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.lc-status { font-weight: 700; }
.level-card.done .lc-status { color: var(--good); }
.level-card.open .lc-status { color: var(--accent); }
.lc-title { font-size: 15.5px; font-weight: 700; }
.lc-band, .lc-prog { font-size: 12.5px; color: var(--muted); }

.back { background: transparent; border: none; color: var(--accent); padding: 4px 0; margin-bottom: 8px; font-size: 14px; }
@media (hover: hover) {
  .back:hover { background: transparent; text-decoration: underline; }
}
.lv-h { font-size: 22px; margin: 4px 0 2px; }
.lv-band { color: var(--muted); font-size: 13px; margin-bottom: 14px; }

.lesson-list { display: flex; flex-direction: column; gap: 8px; }
.lesson-row { display: flex; align-items: center; justify-content: flex-start; gap: 12px; text-align: left; padding: 12px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.lesson-row.done { border-color: var(--good); }
.ls-check { width: 20px; flex: 0 0 auto; color: var(--good); font-weight: 800; }
.ls-text { display: flex; flex-direction: column; gap: 2px; }
.ls-title { font-weight: 700; }
.ls-sum { font-size: 12.5px; color: var(--muted); }

.lesson-content { line-height: 1.65; font-size: 15px; }
.lesson-content p { margin: 0 0 10px; }
.learn-body h3 { font-size: 13px; margin: 16px 0 6px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.4px; }
.learn-body ul, .learn-body ol { margin: 0 0 8px; padding-left: 20px; line-height: 1.6; }
.learn-body li { margin: 3px 0; }
.lesson-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

/* Scoped to the Learn view: the game review also uses a "blunder" class for its counts and marks. */
#learn-view .blunder { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.bl-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.bl-name { font-weight: 700; }
.bl-lv { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.bl-def { margin-top: 4px; font-size: 14px; line-height: 1.55; }
.bl-ex, .bl-fix { margin-top: 5px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.bl-ex b, .bl-fix b { color: var(--text); }
.ref-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }

.plan-block { line-height: 1.6; }
.plan-block p { margin: 0 0 10px; }

.rv-progress { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.rv-kind { font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--accent); margin-bottom: 6px; }
.rv-q { font-size: 17px; font-weight: 600; margin-bottom: 12px; line-height: 1.4; }
.rv-a { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; line-height: 1.6; }
.rv-actions { display: flex; gap: 10px; margin-top: 12px; }
.rv-boardwrap { display: flex; justify-content: center; margin: 6px 0 10px; }
.rv-boardwrap .board { width: min(100%, 600px); }
.rv-feedback { min-height: 20px; font-size: 14px; line-height: 1.5; margin-top: 6px; }
.rv-feedback .ok { color: var(--good); font-weight: 700; }
.rv-feedback .no { color: var(--warn); font-weight: 700; }
.review-done { line-height: 1.6; }

/* ---- coach / cct / practice ---- */
.opening { font-size: 13px; color: var(--accent); margin-top: 3px; min-height: 16px; }
.cct { margin-top: 8px; font-size: 12.5px; color: var(--muted); background: var(--panel-2); border-radius: 8px; padding: 7px 10px; line-height: 1.45; }
.cct b { color: var(--text); }
.toggles { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.chk { display: flex; align-items: center; gap: 10px; min-height: 36px; font-size: 14px; color: var(--muted); cursor: pointer; }
.chk input { width: 18px; height: 18px; flex: 0 0 auto; accent-color: var(--accent); cursor: pointer; }

/* ---- the coach panel and the tip card, right under the board ---- */
.why, .tipcard { margin-top: 10px; }
.why-card {
  --grade: var(--accent);
  background: linear-gradient(180deg, var(--panel), #161d2a);
  border: 1px solid var(--line);
  border-left: 4px solid var(--grade);
  border-radius: 12px;
  padding: 9px 12px 10px;
  font-size: 14.5px;
  line-height: 1.45;
}
.g-best { --grade: var(--good); }
.g-good { --grade: #8cc9a0; }
.g-inaccuracy { --grade: #d4bd66; }
.g-mistake { --grade: var(--warn); }
.g-blunder { --grade: var(--bad); }
.g-hint { --grade: var(--accent); }
.why-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 2px 0;
  min-height: 34px;
  background: transparent;
  border: 0;
  border-radius: 6px;
  text-align: left;
  color: var(--text);
  font-size: 15px;
}
.why-head:active { background: transparent; }
@media (hover: hover) {
  .why-head:hover { background: transparent; }
}
.why-head.static { cursor: default; }
.grade {
  flex: 0 0 auto;
  align-self: flex-start;
  margin-top: 2px;
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--grade);
  color: var(--accent-ink);
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.why-title { flex: 1 1 auto; min-width: 0; font-weight: 650; }
.why-title b { font-weight: 800; margin-right: 3px; }
.chev { width: 18px; height: 18px; flex: 0 0 auto; color: var(--muted); transition: transform 0.16s ease; }
.why-card.folded .chev { transform: rotate(-90deg); }
.why-card.folded .why-body { display: none; }
.why-body { margin-top: 4px; }
.why-body p { margin: 0 0 6px; }
.why-lead { font-weight: 650; }
.better-move { font-weight: 800; color: var(--good); margin-right: 2px; }
.why-lesson { display: flex; flex-direction: column; align-items: flex-start; gap: 0; margin-top: 2px; }
.why-cat { font-size: 12.5px; color: var(--muted); }
.why-note { color: var(--muted); font-size: 13.5px; }
.linkish {
  min-height: 34px;
  padding: 4px 0;
  background: transparent;
  border: 0;
  justify-content: flex-start;
  text-align: left;
  color: var(--accent);
  font-size: 14px;
  font-weight: 650;
}
.linkish:active { background: transparent; }
@media (hover: hover) {
  .linkish:hover { background: transparent; text-decoration: underline; }
}
.why-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.why-card.nudge .why-actions { margin: 6px 0 8px; }
.why-actions button { flex: 1 1 auto; min-height: 40px; padding: 8px 12px; }
.why-card.loading { display: flex; align-items: center; gap: 10px; min-height: 52px; color: var(--accent); }
.dots { display: inline-flex; gap: 4px; }
.dots .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: blink 1s infinite; }
.dots .dot:nth-child(2) { animation-delay: 0.2s; }
.dots .dot:nth-child(3) { animation-delay: 0.4s; }

/* "Show me": step through a line */
.why-card.stepper { border-left-color: var(--accent); }
.step-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.step-tabs button { flex: 1 1 0; min-height: 38px; padding: 6px 8px; font-size: 14px; color: var(--muted); }
.step-tabs button.on { color: var(--text); border-color: var(--accent-strong); font-weight: 700; }
.step-text { margin: 0 0 8px; min-height: 42px; }
.step-ctl { display: flex; align-items: center; gap: 8px; }
.step-ctl button { min-width: 50px; min-height: 42px; padding: 8px 10px; }
.step-ctl .primary { margin-left: auto; padding: 8px 18px; }
.step-count { min-width: 52px; text-align: center; color: var(--muted); font-size: 13.5px; font-variant-numeric: tabular-nums; }

/* tip card */
.tip-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 6px 6px 2px 12px; font-size: 14px; line-height: 1.45; }
.tip-card.repeat { border-color: rgba(224, 169, 85, 0.55); }
.tip-top { display: flex; align-items: center; gap: 8px; }
.tip-label { flex: 1 1 auto; font-size: 11.5px; font-weight: 800; letter-spacing: 0.4px; text-transform: uppercase; color: var(--accent); }
.tip-card.repeat .tip-label { color: var(--warn); text-transform: none; letter-spacing: 0; font-size: 13px; }
.tip-x { min-width: 36px; min-height: 36px; padding: 0; background: transparent; border: 0; border-radius: 8px; color: var(--muted); font-size: 22px; line-height: 1; }
.tip-text { margin: 0 6px 0 0; }

/* ---- copy-by-hand sheet (when the browser blocks the clipboard) ---- */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(8, 10, 16, 0.72); }
.copy-card { width: min(560px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 10px; background: #1d2433; border: 1px solid var(--line); border-radius: 16px; padding: 16px; box-shadow: 0 16px 44px rgba(0, 0, 0, 0.55); }
.copy-title { font-weight: 700; font-size: 17px; }
.copy-sub { color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.copy-text {
  width: 100%;
  min-height: 120px;
  height: min(48vh, 360px);
  resize: none;
  color: var(--text);
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font: 16px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.copy-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---- credits ---- */
.credits { margin-top: 22px; color: var(--muted); font-size: 12px; line-height: 1.7; text-align: center; }
.credits a { color: var(--accent); text-decoration: none; }
.credits a:hover { text-decoration: underline; }

/* ---- narrow phones: keep the title and the tabs on one line ---- */
@media (max-width: 374px) {
  .topbar { gap: 8px; }
  .brand { font-size: 17px; gap: 6px; }
  .brand .logo { font-size: 21px; }
  .tabs { gap: 4px; }
  .tab { padding: 7px 10px; }
  /* A smaller grade label leaves more of the line for the reason. */
  .grade { font-size: 10.5px; padding: 2px 5px; letter-spacing: 0.1px; }
  .why-card { padding: 8px 10px 9px; font-size: 14px; }
  .why-head { font-size: 14.5px; gap: 6px; }
  .why-actions { gap: 6px; }
  .why-actions button { padding: 8px 8px; }
}

/* ---- medium screens: show the tagline ---- */
@media (min-width: 600px) {
  .tag { display: block; flex-basis: 100%; order: 3; }
}

/* ---- wide screens: the desktop app's two-column layout ---- */
@media (min-width: 900px) {
  #app {
    padding:
      max(22px, env(safe-area-inset-top))
      max(26px, env(safe-area-inset-right))
      max(32px, env(safe-area-inset-bottom))
      max(26px, env(safe-area-inset-left));
  }
  .topbar { align-items: baseline; flex-wrap: nowrap; gap: 14px; margin-bottom: 18px; }
  .brand { font-size: 22px; }
  .brand .logo { font-size: 26px; }
  .tabs { margin-left: 10px; }
  .tag { flex-basis: auto; order: 0; margin-left: auto; }

  .layout { flex-direction: row; gap: 26px; align-items: flex-start; }
  .board-area { flex: 0 0 auto; width: auto; max-width: none; margin: 0; }
  .board-row { flex-direction: row; gap: 10px; align-items: stretch; }
  .evalbar { width: 16px; height: auto; border-radius: 6px; }
  .eval-fill {
    top: auto; right: 0;
    width: auto;
    height: var(--eval, 50%);
    background: linear-gradient(180deg, #eef1f6, #ccd5e3);
    transition: height 0.25s ease;
  }
  .board-wrap { width: var(--board-max); }
  .board { border-radius: 10px; }
  .overlay { border-radius: 10px; }
  .coord.rank { top: 3px; left: 5px; }
  .coord.file { bottom: 1px; right: 5px; }

  .board-controls { gap: 10px; margin-top: 14px; margin-left: 26px; flex-wrap: wrap; }
  .board-controls button { flex: 0 0 auto; padding: 10px 14px; gap: 7px; }
  /* Same width as the board, lined up past the eval bar. */
  .why, .tipcard { margin-left: 26px; width: var(--board-max); }
  .why-actions button { flex: 0 0 auto; }

  .panel { flex: 1 1 auto; width: auto; min-width: 300px; align-self: stretch; border-radius: 16px; padding: 18px; gap: 14px; }
  select { font-size: 14px; padding: 8px 28px 8px 10px; }
  .chk { min-height: 0; font-size: 13px; gap: 8px; }
  .chk input { width: 15px; height: 15px; }
  .toggles { gap: 6px; }
  .rv-boardwrap .board { width: min(100%, var(--board-max)); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
