/* SeeInTheDark — Phase 1 styles.
   Two themes: light (crisp, traditional) for Full light, dark for Selected only and Dark. */

:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --piece-font: "Segoe UI Symbol", "Noto Sans Symbols 2", "Apple Symbols", "DejaVu Sans", serif;
  --radius: 8px;
}

body[data-theme="light"] {
  --page: #f5f2ec;
  --ink: #26231f;
  --muted: #776f65;
  --line: #ddd5c8;
  --control: #ffffff;
  --control-on: #26231f;
  --control-on-ink: #ffffff;
  --sq-light: #efe3cb;
  --sq-dark: #b78f66;
  --frame: #7d5f43;
  --name-light: rgba(80, 58, 36, 0.55);
  --name-dark: rgba(255, 248, 236, 0.75);
  --green-strong: rgba(30, 140, 60, 0.18);
  --green-faint: rgba(30, 140, 60, 0.07);
  --green-corner: rgba(30, 140, 60, 0.09);
  --red-faint: rgba(205, 35, 35, 0.16);
  --red-line: #c62828;
  --last: rgba(255, 205, 40, 0.28);
  --check: rgba(220, 30, 30, 0.45);
  --dim: rgba(40, 30, 20, 0.22);
  --glow: rgba(255, 176, 32, 0.95);
  --white-piece: #fbfaf5;
  --white-stroke: #2a2622;
  --black-piece: #23201d;
  --black-stroke: #23201d;
}

body[data-theme="dark"] {
  --page: #101217;
  --ink: #dde0e7;
  --muted: #8d93a0;
  --line: #262a33;
  --control: #191c23;
  --control-on: #dde0e7;
  --control-on-ink: #101217;
  --sq-light: #3a414f;
  --sq-dark: #272c37;
  --frame: #0a0b0e;
  --name-light: rgba(220, 226, 238, 0.55);
  --name-dark: rgba(220, 226, 238, 0.45);
  --green-strong: rgba(90, 225, 130, 0.20);
  --green-faint: rgba(90, 225, 130, 0.07);
  --green-corner: rgba(90, 225, 130, 0.10);
  --red-faint: rgba(255, 80, 80, 0.18);
  --red-line: #ff5c5c;
  --last: rgba(255, 214, 90, 0.16);
  --check: rgba(255, 70, 70, 0.45);
  --dim: rgba(0, 0, 0, 0.30);
  --glow: rgba(255, 210, 110, 0.9);
  --white-piece: #f4f2ec;
  --white-stroke: #15171c;
  --black-piece: #08090b;
  --black-stroke: #c9ced8;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  transition: background-color 0.25s ease, color 0.25s ease;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Layout ---------- */

.layout {
  min-height: 100%;
  display: grid;
  grid-template-columns: auto minmax(260px, 320px);
  justify-content: center;
  align-items: start;
  gap: 32px;
  padding: 24px;
}

.board-col { display: flex; flex-direction: column; gap: 10px; }

.status {
  font-weight: 600;
  min-height: 1.45em;
  letter-spacing: 0.01em;
}
.status.over { color: var(--red-line); }

.board-frame {
  position: relative;
  width: min(92vw, calc(100vh - 210px), 660px);
  min-width: 280px;
  padding: 6px;
  border-radius: var(--radius);
  background: var(--frame);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; justify-items: center; gap: 18px; padding: 14px; }
  .board-frame { width: min(94vw, 680px); }
  .panel { width: min(94vw, 680px); }
}

/* ---------- Board ---------- */

.board {
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  width: 100%;
  border-radius: 3px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}

.sq { position: relative; display: grid; place-items: center; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }

/* Overlay layers, bottom to top: last move, green path, red threat, dimming. */
.sq::before, .sq::after, .sq .g, .sq .r {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.sq.last::before { background: var(--last); }
.sq.dest .g, .sq.sel .g { background: var(--green-strong); }
.sq.lane .g { background: var(--green-faint); }
.sq.corner .g { background: var(--green-corner); }
.sq.tsq .r { background: var(--red-faint); }
.sq.check .r { background: radial-gradient(circle, var(--check) 0%, transparent 72%); }
.sq.dim::after { background: var(--dim); }
.sq.hit .r { box-shadow: inset 0 0 0 3px var(--red-line); }

.sq.sel .g { box-shadow: inset 0 0 0 2px var(--green-strong); }

/* Pieces */
.pc, .ghost, .promo-btn {
  font-family: var(--piece-font);
  line-height: 1;
  font-variant-emoji: text;
}
.pc {
  position: relative;
  z-index: 1;
  font-size: 10cqw;
  transform: translateY(-3%);
  pointer-events: none;
  transition: opacity 0.15s ease, filter 0.15s ease;
}
.white .pc, .ghost.white, .promo-btn.white {
  color: var(--white-piece);
  -webkit-text-stroke: 0.035em var(--white-stroke);
  paint-order: stroke fill;
}
.black .pc, .ghost.black, .promo-btn.black {
  color: var(--black-piece);
  -webkit-text-stroke: 0.035em var(--black-stroke);
  paint-order: stroke fill;
}

.sq.movable .pc { filter: drop-shadow(0 0 0.06em var(--glow)) drop-shadow(0 0 0.02em var(--glow)); }
.sq.tpc .pc {
  -webkit-text-stroke-color: var(--red-line);
  filter: drop-shadow(0 0 0.03em var(--red-line)) drop-shadow(0 0 0.03em var(--red-line));
}
.sq.dim .pc { opacity: 0.45; }
.sq.lifted .pc { opacity: 0.25; }

/* Square names (coordinate toggle) */
.nm {
  display: none;
  position: absolute;
  left: 4%;
  bottom: 3%;
  z-index: 2;
  font: 600 2.1cqw/1 var(--font);
  pointer-events: none;
}
.board.coords .nm { display: block; }
.sq.light .nm { color: var(--name-light); }
.sq.dark .nm { color: var(--name-dark); }

.board:not(.locked) .sq.movable,
.board:not(.locked) .sq.dest { cursor: pointer; }

/* The piece that follows the pointer while dragging */
.ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
}

/* Promotion picker */
.promo {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  background: var(--control);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  text-align: center;
}
.promo[hidden] { display: none; }
.promo-title { font-weight: 600; margin-bottom: 8px; }
.promo-row { display: flex; gap: 8px; }
.promo-btn {
  width: 64px;
  height: 64px;
  font-size: 46px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--sq-light);
  cursor: pointer;
}
.promo-btn:hover, .promo-btn:focus-visible { outline: 3px solid var(--green-strong); }
.promo-cancel {
  margin-top: 10px;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

/* ---------- Panel ---------- */

.panel { display: flex; flex-direction: column; gap: 22px; padding-top: 4px; }

.brand {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.group { display: flex; flex-direction: column; gap: 10px; }
.label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.hint { margin: 0; color: var(--muted); font-size: 13.5px; }

.dial {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--control);
}
.dial button {
  font: inherit;
  font-size: 13.5px;
  padding: 10px 6px;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.dial button + button { border-left: 1px solid var(--line); }
.dial button[aria-checked="true"] { background: var(--control-on); color: var(--control-on-ink); font-weight: 600; }

.btn {
  font: inherit;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--control);
  color: var(--ink);
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.reveal[aria-pressed="true"] { border-color: var(--red-line); color: var(--red-line); font-weight: 600; }

.dial button:focus-visible, .btn:focus-visible, summary:focus-visible, .check input:focus-visible {
  outline: 2px solid var(--red-line);
  outline-offset: 2px;
}

.actions { flex-direction: row; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1 1 auto; }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--control-on); }

.layers summary { cursor: pointer; color: var(--muted); font-size: 13.5px; }
.layers[open] summary { margin-bottom: 4px; }

.moves-scroll { max-height: 220px; overflow-y: auto; }
.moves {
  margin: 0;
  padding-left: 2.2em;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}
.moves li { padding: 2px 0; }
.moves li span { display: inline-block; min-width: 7.5em; }

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

/* ---------- Phase 2: modes, score bar, move notes ---------- */

.dial.two { grid-template-columns: repeat(2, 1fr); }
.dial.small button { font-size: 13px; padding: 8px 6px; }
.dial button:disabled { opacity: 0.45; cursor: default; }

.cpu-opts { display: flex; flex-direction: column; gap: 10px; }
.cpu-opts[hidden] { display: none; }
.range { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; color: var(--muted); }
.range output { color: var(--ink); font-weight: 600; margin-left: 4px; }
.range input { width: 100%; accent-color: var(--control-on); }

.scorebar { display: flex; align-items: center; gap: 10px; min-height: 20px; }
.scorebar[hidden] { display: none; }
.score-track {
  flex: 0 0 120px;
  height: 8px;
  border-radius: 4px;
  background: #1c1c1f;
  overflow: hidden;
  border: 1px solid var(--muted);
}
.score-fill { height: 100%; width: 50%; background: #ffffff; transition: width 0.4s ease; }
.score-text { font-size: 13.5px; color: var(--muted); }

.coach { display: flex; flex-direction: column; gap: 8px; max-width: min(92vw, 660px); }
.coach[hidden] { display: none; }
.note {
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: var(--radius);
  background: var(--control);
  padding: 9px 12px;
  font-size: 14px;
}
.note p { margin: 2px 0 0; }
.note.pending { color: var(--muted); font-style: italic; }
.note-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 2px; }
.note .tag { font-weight: 700; }
.note-move { color: var(--muted); font-size: 13px; }
.note-muted { margin: 0; color: var(--muted); font-size: 13.5px; }
.note-end { margin: 0; font-weight: 600; }

body[data-theme="light"] { --v-good: #2e7d32; --v-ok: #b26a00; --v-bad: #c62828; }
body[data-theme="dark"] { --v-good: #6fd38a; --v-ok: #f0b450; --v-bad: #ff6b6b; }
.note.v-best, .note.v-good { border-left-color: var(--v-good); }
.note.v-best .tag, .note.v-good .tag { color: var(--v-good); }
.note.v-inaccuracy { border-left-color: var(--v-ok); }
.note.v-inaccuracy .tag { color: var(--v-ok); }
.note.v-mistake, .note.v-blunder { border-left-color: var(--v-bad); }
.note.v-mistake .tag, .note.v-blunder .tag { color: var(--v-bad); }

.moves .mv-inaccuracy { color: var(--v-ok); }
.moves .mv-mistake, .moves .mv-blunder { color: var(--v-bad); font-weight: 600; }

.about { margin: 0; font-size: 12px; color: var(--muted); }
.about a { color: inherit; }

/* ---------- Phase 3: learn, quiz, hints ---------- */

.dial.area button { font-weight: 600; }
.learn-panel { display: flex; flex-direction: column; gap: 18px; }
.learn-panel[hidden], #play-opts[hidden], .btn[hidden] { display: none; }

.lesson-group { gap: 6px; }
.lesson-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}
.lesson-name { display: flex; flex-direction: column; min-width: 0; }
.lesson-meta { font-size: 12px; color: var(--muted); }
.lesson-meta.done { color: var(--v-good); }
.lesson-btns { display: flex; gap: 6px; flex-shrink: 0; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.primary { background: var(--control-on); color: var(--control-on-ink); border-color: var(--control-on); font-weight: 600; }
.btn.quiet { background: transparent; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.btn.chip { padding: 4px 10px; font-size: 12.5px; border-radius: 999px; }
.btn.chip[aria-pressed="true"] { background: var(--control-on); color: var(--control-on-ink); border-color: var(--control-on); }
.select {
  font: inherit;
  font-size: 13.5px;
  padding: 7px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--control);
  color: var(--ink);
}

.session-head { display: flex; flex-direction: column; gap: 2px; }
.session-title { font-weight: 650; font-size: 16px; }

.lesson-note { font-size: 15px; }
.lesson-title { font-weight: 700; margin-bottom: 4px; }
.lesson-note p { margin: 3px 0 0; }
.lesson-note p:first-of-type { margin-top: 0; }
.tone-ok { border-left-color: var(--v-good); }
.tone-bad { border-left-color: var(--v-bad); }
.tone-warn { border-left-color: var(--v-ok); }
.tone-info { border-left-color: var(--muted); }
.lesson-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.note .teach { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); color: var(--muted); font-size: 13.5px; }
.note-hint { margin: 0; font-size: 14px; font-weight: 600; color: var(--v-ok); }

/* Hint ring on the piece to move, and the square answer in threat questions */
.sq.hintsq::before {
  background: none;
  box-shadow: inset 0 0 0 4px var(--v-ok);
  border-radius: 2px;
  animation: hint-pulse 1.4s ease-in-out infinite;
}
@keyframes hint-pulse { 50% { box-shadow: inset 0 0 0 2px var(--v-ok); } }
.board.picking .sq { cursor: crosshair; }

/* ---------- Phase 4: who is playing, PIN screen ---------- */

.who { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-top: -14px; font-size: 13.5px; }
.who-name { font-weight: 650; }
.who-rating { color: var(--muted); }
.who-note { flex-basis: 100%; color: var(--muted); font-size: 12.5px; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); text-decoration: underline; cursor: pointer; }
.range input:disabled { opacity: 0.5; }

.pin-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: var(--page);
}
.pin-screen[hidden] { display: none; }
.pin-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(86vw, 300px);
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--control);
  text-align: center;
}
.pin-card h2 { margin: 0 0 6px; font-size: 20px; }
.pin-card label { color: var(--muted); }
.pin-card input {
  font: 600 32px/1.2 var(--font);
  letter-spacing: 0.4em;
  text-align: center;
  padding: 10px 0 10px 0.4em;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--page);
  color: var(--ink);
}
.pin-error { margin: 0; min-height: 1.3em; color: var(--red-line); font-size: 14px; }

/* ---------- Showing the other side's move, captured pieces ---------- */

body[data-theme="light"] { --intent: #1f6fd6; }
body[data-theme="dark"] { --intent: #7fb2ff; }

/* The piece about to move pulses, and its target square is outlined. */
.sq.pv-from .g { box-shadow: inset 0 0 0 4px var(--intent); animation: pv-pulse 0.9s ease-in-out infinite; }
.sq.pv-to .g { box-shadow: inset 0 0 0 3px var(--intent); background: color-mix(in srgb, var(--intent) 22%, transparent); }
@keyframes pv-pulse { 50% { box-shadow: inset 0 0 0 2px var(--intent); } }
.sq.moving .pc { opacity: 0; }
.note-replay { margin: 0; font-size: 14px; font-weight: 600; color: var(--intent); }

.tray {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 26px;
  font-size: 13px;
  color: var(--muted);
}
.tray-label { white-space: nowrap; }
.tray-pieces { display: flex; flex-wrap: wrap; }
.cap {
  font-family: var(--piece-font);
  font-size: 22px;
  line-height: 1;
  margin-right: -3px;
  font-variant-emoji: text;
}
.cap.white { color: var(--white-piece); -webkit-text-stroke: 0.04em var(--white-stroke); paint-order: stroke fill; }
.cap.black { color: var(--black-piece); -webkit-text-stroke: 0.04em var(--black-stroke); paint-order: stroke fill; }
.tray-lead { font-weight: 700; color: var(--ink); margin-left: 4px; }
