:root {
  --bg-top: #f4efe3;
  --bg-bottom: #d6e4f1;
  --panel: #fffdfa;
  --ink: #11263b;
  --ink-soft: #4a6278;
  --line: #c4d4e3;
  --accent: #0a5f72;
  --accent-strong: #084b5b;
  --good: #1e7b44;
  --bad: #a63a1b;
  --board-light: #f1dcc0;
  --board-dark: #a36a43;
  --board-pending: #f6c21d;
  --board-selected: #54a0ff;
  --shadow: 0 16px 36px rgba(17, 38, 59, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(158deg, var(--bg-top), var(--bg-bottom));
}

.training-shell {
  width: min(1160px, 94vw);
  margin: 0 auto;
  padding: 2rem 0 2.5rem;
}

.hero {
  margin-bottom: 1.25rem;
}

.eyebrow {
  margin: 0;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent-strong);
  font-weight: 700;
}

.hero h1 {
  margin: 0.28rem 0;
  font-size: clamp(1.9rem, 4.2vw, 3rem);
  line-height: 1.08;
}

.subtitle {
  margin: 0;
  max-width: 58ch;
  color: var(--ink-soft);
}

.workspace {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr);
  grid-template-areas:
    "board controls"
    "board stats";
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1rem;
}

.card h2,
.card h3 {
  margin-top: 0;
}

.board-card {
  grid-area: board;
}

.controls-card {
  grid-area: controls;
}

.stats-card {
  grid-area: stats;
}

.meta-row {
  margin-bottom: 0.65rem;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.board-wrap {
  width: 100%;
  max-width: 640px;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  border: 3px solid #835235;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 12px 24px rgba(17, 38, 59, 0.22);
  aspect-ratio: 1 / 1;
}

.square {
  border: 0;
  margin: 0;
  padding: 0;
  position: relative;
  cursor: pointer;
  font-size: clamp(1.2rem, 5vw, 2.35rem);
  line-height: 1;
  color: #111111;
}

.square.light {
  background: var(--board-light);
}

.square.dark {
  background: var(--board-dark);
}

.square[data-empty="true"] {
  color: transparent;
}

.square .piece {
  display: inline-flex;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
}

.square .coord {
  position: absolute;
  bottom: 4px;
  right: 5px;
  font-size: 0.56rem;
  opacity: 0.72;
  color: #1c1c1c;
  pointer-events: none;
}

.square[data-selected="true"] {
  box-shadow: inset 0 0 0 4px var(--board-selected);
}

.square[data-target="true"]::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22%;
  height: 22%;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: rgba(12, 34, 52, 0.48);
}

.square[data-pending-from="true"],
.square[data-pending-to="true"] {
  box-shadow: inset 0 0 0 4px var(--board-pending);
}

.board-help {
  margin: 0.65rem 0 0;
  color: var(--ink-soft);
}

.position-details {
  margin-top: 1rem;
}

.fen {
  margin: 0 0 0.8rem;
  background: #eef5fb;
  border: 1px solid #d2e1ee;
  border-radius: 10px;
  padding: 0.75rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.legal-moves {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.legal-move-empty {
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.legal-move-btn {
  border: 1px solid #bdd0df;
  background: #eaf3fa;
  color: #214463;
  border-radius: 999px;
  padding: 0.26rem 0.55rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.legal-move-btn[data-active="true"] {
  border-color: #7ca0c0;
  background: #d5e8f7;
  font-weight: 700;
}

.answer-form {
  display: grid;
  gap: 0.6rem;
}

.repertoire-controls {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 0.95rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid #d8e3ec;
}

.repertoire-help {
  margin: 0 0 0.1rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.field-label {
  font-size: 0.86rem;
  color: var(--ink-soft);
  font-weight: 700;
}

.field-control {
  border: 1px solid #b9ccdc;
  border-radius: 8px;
  background: #f6fafd;
  color: var(--ink);
  padding: 0.45rem 0.55rem;
  font: inherit;
}

.field-control:focus-visible {
  outline: 2px solid #6ca4d1;
  outline-offset: 1px;
}

.openings-select {
  min-height: 8.6rem;
}

.field-help {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.recovery-note {
  margin: 0.65rem 0 0.2rem;
  font-size: 0.86rem;
  color: var(--ink-soft);
}

.selected-label {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.selected-move {
  display: block;
  font-weight: 700;
  font-size: 1.15rem;
  min-height: 1.4rem;
}

.promotion-choices {
  border: 1px solid #d5e3ef;
  background: #f4f9fd;
  border-radius: 10px;
  padding: 0.55rem;
}

.promotion-title {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.promotion-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.promotion-btn {
  border: 1px solid #9eb8ce;
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  background: #e6f0f8;
  color: #214463;
  cursor: pointer;
}

.answer-actions,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

button {
  border: 0;
  border-radius: 9px;
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

button:hover {
  background: var(--accent-strong);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.feedback {
  margin-top: 0.85rem;
  border-radius: 10px;
  padding: 0.72rem 0.8rem;
  border: 1px solid #d2dfe9;
  background: #f4f9fc;
  min-height: 2.8rem;
}

.feedback[data-state="correct"] {
  border-color: #9dd1b2;
  background: #eaf8ef;
  color: var(--good);
}

.feedback[data-state="incorrect"],
.feedback[data-state="error"] {
  border-color: #e3b8ad;
  background: #fbeeea;
  color: var(--bad);
}

.error-box {
  margin-top: 0.8rem;
  border: 1px solid #d78f7a;
  background: #fff1eb;
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  color: #7d2f14;
}

.stats-grid {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem;
}

.stats-grid dt {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.stats-grid dd {
  margin: 0.08rem 0 0;
  font-size: 1.22rem;
  font-weight: 700;
}

.session-id {
  margin: 0.95rem 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "board"
      "controls"
      "stats";
  }

  .training-shell {
    padding-top: 1.3rem;
  }
}

@media (max-width: 560px) {
  .training-shell {
    width: min(100%, 96vw);
  }

  .card {
    padding: 0.82rem;
  }

  .square .coord {
    font-size: 0.48rem;
    bottom: 3px;
    right: 4px;
  }

  button {
    width: 100%;
  }

  .answer-actions,
  .actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .openings-select {
    min-height: 7.6rem;
  }
}
