:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #1e2229;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #6a9a3f;
  --brand-ink: #3f6a1f;
  --accent: #4a86c9;
  --sq-light: #ebecd0;
  --sq-dark: #6f9350;
  --ok: #3f8f4f;
  --bad: #cc4d43;
  --shadow: 0 6px 24px rgba(20, 30, 20, 0.12);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a {
  color: var(--accent);
}
h1 {
  font-size: 1.5rem;
  margin: 0;
}
h2 {
  font-size: 1.15rem;
  margin: 0;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.85rem;
}
.tiny {
  font-size: 0.75rem;
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}
.grow {
  flex: 1;
  min-width: 0;
}

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.55rem 1rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: transform 0.05s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn-icon {
  padding: 0.55rem 0.65rem;
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.btn-primary {
  background: var(--brand);
  color: #fff;
}
.btn-primary:hover {
  background: var(--brand-ink);
}
.btn-ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}
.btn-ghost:hover {
  background: #f0f2f4;
}
.btn-danger-ghost {
  background: #fff;
  border-color: #f0c7c3;
  color: var(--bad);
}

/* Brand */
.brand {
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--ink);
}
.brand-mark {
  color: var(--brand);
  font-size: 1.35rem;
}

/* Landing */
.landing {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}
.landing-card {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 2.4rem;
  max-width: 520px;
  text-align: center;
}
.landing-card h1 {
  margin: 1rem 0 0.6rem;
  font-size: 1.8rem;
}
.landing-actions {
  margin-top: 1.6rem;
  display: flex;
  gap: 0.7rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* Board */
.board {
  --board-size: min(92vw, 560px);
  width: var(--board-size);
  height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: none;
}
.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.square.light {
  background: var(--sq-light);
}
.square.dark {
  background: var(--sq-dark);
}
.piece {
  font-size: calc(var(--board-size) / 8 * 0.82);
  line-height: 1;
  user-select: none;
  pointer-events: none;
}
.piece.white {
  color: #fafafa;
  -webkit-text-stroke: 1.4px #4a4a4a;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}
.piece.black {
  color: #2c2c2c;
  -webkit-text-stroke: 1.2px #0c0c0c;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}
.piece.ghost {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  transform: translateZ(0);
}
.piece.pop {
  animation: pop 0.16s ease;
}
@keyframes pop {
  0% {
    transform: scale(0.82);
  }
  100% {
    transform: scale(1);
  }
}
.coord {
  position: absolute;
  font-size: calc(var(--board-size) / 8 * 0.16);
  font-weight: 700;
  opacity: 0.55;
}
.coord.rank {
  top: 2px;
  left: 3px;
}
.coord.file {
  bottom: 1px;
  right: 3px;
}
.square.selected {
  box-shadow: inset 0 0 0 100px rgba(255, 240, 120, 0.35);
}
.square.last-from,
.square.last-to {
  box-shadow: inset 0 0 0 100px rgba(255, 232, 90, 0.42);
}
.square.drag-over {
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.8);
}
.square.hint {
  box-shadow: inset 0 0 0 5px rgba(74, 134, 201, 0.85);
}
.square.wrong {
  animation: wrong 0.45s ease;
}
@keyframes wrong {
  0%,
  100% {
    box-shadow: inset 0 0 0 100px rgba(204, 77, 67, 0);
  }
  30% {
    box-shadow: inset 0 0 0 100px rgba(204, 77, 67, 0.55);
  }
}
.move-dest::after {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(30, 40, 30, 0.28);
}
.move-dest-capture::after {
  content: '';
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  border: 5px solid rgba(30, 40, 30, 0.28);
}

/* Player layout */
.player {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem 1.2rem 3rem;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0 1rem;
}
.who {
  font-weight: 600;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}
.switch-btn {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  color: var(--muted);
  cursor: pointer;
}
.switch-btn:hover {
  background: #f0f2f4;
}
.rail {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.dot {
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #fff;
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--muted);
}
.dot.current {
  outline: 2px solid var(--accent);
}
.dot.solved {
  background: var(--ok);
  color: #fff;
  border-color: var(--ok);
}
.dot.failed {
  background: var(--bad);
  color: #fff;
  border-color: var(--bad);
}
.dot.clickable {
  cursor: pointer;
}
.dot.clickable:hover {
  outline: 2px solid var(--accent);
  transform: translateY(-1px);
}
.play-main {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  flex-wrap: wrap;
}
.board-wrap {
  flex: 0 0 auto;
}
.panel {
  flex: 1;
  min-width: 240px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem;
}
.puzzle-title {
  margin-bottom: 0.4rem;
}
.intro {
  color: var(--muted);
  margin: 0 0 0.8rem;
  font-size: 0.95rem;
}
.status {
  min-height: 1.6rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
}
.coach {
  display: none;
  background: #eaf1fa;
  border: 1px solid #cfe0f2;
  color: #274b6d;
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.8rem;
  font-size: 0.9rem;
}
.coach.show {
  display: block;
}
.commentary {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 190px;
  overflow-y: auto;
  margin-bottom: 1rem;
}
.commentary:empty {
  margin-bottom: 0;
}
.comment {
  font-size: 0.9rem;
  line-height: 1.35;
}
.comment-move {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  background: #eef1f4;
  border-radius: 5px;
  padding: 0 0.3rem;
  margin-right: 0.15rem;
}
.comment-text {
  color: var(--ink);
}
.status.ok {
  color: var(--ok);
}
.status.bad {
  color: var(--bad);
}
.status.done {
  color: #9a6b1a;
}
.controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.summary {
  margin: 2rem auto;
}
.summary .rail {
  justify-content: center;
}

/* Overlays / modal. Flex + margin:auto keeps tall content scrollable
   instead of clipping it off the top of the viewport. */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 25, 20, 0.5);
  display: flex;
  overflow: auto;
  z-index: 100;
  padding: 1rem;
}
.overlay > * {
  margin: auto;
}
.modal {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 2rem;
  width: min(420px, 92vw);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.text-input,
.code-input {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  width: 100%;
  background: #fff;
  color: var(--ink);
}
.code-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
}
.promo {
  display: flex;
  gap: 0.5rem;
  background: var(--surface);
  padding: 1rem;
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.promo-piece {
  font-size: 2.4rem;
  width: 3.4rem;
  height: 3.4rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  line-height: 1;
}
.promo-piece.white {
  color: #fafafa;
  -webkit-text-stroke: 1.4px #4a4a4a;
}
.promo-piece.black {
  color: #2c2c2c;
  -webkit-text-stroke: 1.2px #0c0c0c;
}

/* Teacher */
.teacher {
  max-width: 980px;
  margin: 0 auto;
  padding: 1rem 1.2rem 4rem;
}
.section-head {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin: 1.4rem 0 0.6rem;
}
.section-head h1,
.section-head h2 {
  flex: 1;
}
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
}
.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.playlist-card,
.puzzle-card {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.card-title {
  font-weight: 700;
}
.new-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
}
.new-form .text-input {
  flex: 1;
  min-width: 180px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.3rem;
  border-bottom: 2px solid var(--line);
  margin-top: 1rem;
}
.tab {
  font: inherit;
  font-weight: 600;
  border: none;
  background: none;
  padding: 0.6rem 1rem;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}
.tab.active {
  color: var(--ink);
  border-bottom-color: var(--brand);
}
.tab-panels {
  background: var(--surface);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem;
  margin-bottom: 1rem;
}
.panel-pane {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.import-result {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.import-result .ok,
.ok {
  color: var(--ok);
  font-weight: 600;
}
.import-result .bad,
.bad {
  color: var(--bad);
  font-weight: 600;
}

/* PGN picker */
.ply-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}
.ply-num {
  color: var(--muted);
  font-size: 0.8rem;
  margin-left: 0.3rem;
}
.ply {
  font: inherit;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 0.15rem 0.45rem;
  cursor: pointer;
  font-size: 0.85rem;
}
.ply.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.pgn-preview {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-start;
}
.pgn-preview .text-input {
  margin: 0.5rem 0;
}
/* Board() adds the .board class to the wrap element itself. */
.mini-board-wrap.board {
  --board-size: 128px;
  box-shadow: none;
  border: 1px solid var(--line);
}
.mini-board-wrap.large.board {
  --board-size: 260px;
}

/* Editor */
.editor {
  display: flex;
  gap: 1.4rem;
  flex-wrap: wrap;
  align-items: flex-start;
}
.editor-side {
  flex: 1;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.3rem;
}
.palette-piece {
  font-size: 1.7rem;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  line-height: 1;
}
.palette-piece.white {
  color: #fafafa;
  -webkit-text-stroke: 1.3px #4a4a4a;
}
.palette-piece.black {
  color: #2c2c2c;
  -webkit-text-stroke: 1.1px #0c0c0c;
}
.palette-piece.eraser {
  color: var(--muted);
  -webkit-text-stroke: 0;
  font-size: 1.2rem;
}
.palette-piece.active {
  outline: 2px solid var(--accent);
}
.editor-opts {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
}
.editor-opts select {
  font: inherit;
  margin-left: 0.3rem;
  padding: 0.25rem;
  border-radius: 6px;
  border: 1px solid var(--line);
}
.editor-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.move-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  min-height: 1.5rem;
}
.move-chip,
.move-list .muted {
  font-size: 0.8rem;
}
.move-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #eef1f4;
  border-radius: 6px;
  padding: 0.1rem 0.4rem;
}

/* Annotation editor */
.annotate {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-top: 0.8rem;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.field-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}
.annotate-moves {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.annotate-row {
  display: grid;
  grid-template-columns: 130px 1fr 1fr;
  gap: 0.5rem;
  align-items: center;
}
.annotate-label {
  font-weight: 600;
  font-size: 0.9rem;
}
@media (max-width: 620px) {
  .annotate-row {
    grid-template-columns: 1fr;
  }
}

/* Results grid */
.grid {
  border-collapse: collapse;
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.grid th,
.grid td {
  border: 1px solid var(--line);
  padding: 0.5rem;
  text-align: center;
  font-size: 0.85rem;
}
.grid th {
  background: #f0f2f4;
  font-weight: 700;
}
.name-cell {
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}
.grid-cell.empty {
  color: var(--muted);
}
.cell-mark {
  font: inherit;
  font-weight: 700;
  border: none;
  border-radius: 6px;
  padding: 0.2rem 0.4rem;
  cursor: pointer;
  color: #fff;
}
.cell-mark.solved {
  background: var(--ok);
}
.cell-mark.failed {
  background: var(--bad);
}

/* Replay */
.replay-modal {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.4rem;
  width: min(560px, 94vw);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  align-items: center;
}
.replay-modal .board {
  --board-size: min(84vw, 380px);
}
.replay-comment {
  background: #f0f2f4;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  text-align: center;
  max-width: 460px;
}
.replay-moves {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: center;
}
.replay-move {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  padding: 0.12rem 0.45rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: #fff;
}
.replay-move.active {
  outline: 2px solid var(--accent);
}
.replay-move.start {
  color: var(--muted);
}
.replay-move.correct {
  background: #e3f2e5;
  border-color: #bfe0c4;
}
.replay-move.wrong {
  background: #fbe3e1;
  border-color: #f2c4bf;
}
.replay-move.opponent {
  background: #e4eef8;
  border-color: #c3daf0;
}
.replay-move.shown {
  background: #fdf0d8;
  border-color: #f0dcac;
}
.replay-nav {
  display: flex;
  gap: 0.5rem;
}
