:root {
  color-scheme: light;
  background: #f6f4ed;
  color: #202b25;
  font-family: system-ui, sans-serif;
  --ink: #202b25;
  --muted: #515e54;
  --accent: #315b49;
  --line: #d6dace;
  --paper: #fffef8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

.shell {
  width: min(100% - 3rem, 67rem);
  margin-inline: auto;
}

.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.site-header nav {
  display: flex;
  align-items: center;
  min-height: 4.25rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 700;
  text-decoration: none;
}

.brand-icon {
  display: grid;
  width: 1.9rem;
  height: 1.9rem;
  place-items: center;
  border-radius: 0.4rem;
  background: var(--accent);
  color: var(--paper);
  font: 1.3rem/1 "DejaVu Sans", "Segoe UI Symbol", sans-serif;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 17ch;
  font: 650 clamp(2.45rem, 5vw, 4.35rem) / 1.03 Georgia, serif;
  letter-spacing: -0.055em;
}

p {
  color: var(--muted);
  line-height: 1.55;
}

.topic-picker {
  max-width: 43rem;
  margin: clamp(3.25rem, 10vw, 7rem) auto;
}

.instructions > p {
  margin-top: 1rem;
}

.topic-card {
  margin-top: 2.5rem;
  padding: clamp(1rem, 4vw, 1.75rem);
  border: 1px solid var(--line);
  border-left: 0.25rem solid var(--accent);
  border-radius: 0.5rem;
  background: var(--paper);
  color: var(--ink);
}

.topic-card h2 {
  margin-bottom: 0.3rem;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
}

.position-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1.15rem 0 0;
  padding: 0;
  list-style: none;
}

.position-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.back-link {
  display: inline-block;
  margin-block: clamp(1rem, 4vw, 2.25rem);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 650;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

.practice {
  display: grid;
  grid-template-areas:
    "instructions board"
    "controls board";
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.72fr);
  grid-template-rows: auto 1fr;
  align-items: start;
  gap: 1rem clamp(1.5rem, 5vw, 5rem);
  padding-bottom: 3rem;
}

.instructions {
  grid-area: instructions;
  padding-top: clamp(0rem, 2vw, 1.5rem);
}

.practice-controls {
  grid-area: controls;
  display: grid;
  gap: 0.75rem;
}

.position-status {
  display: grid;
  align-content: center;
  gap: 0.25rem;
  min-height: 5.5rem;
  margin-top: clamp(0.75rem, 5vw, 2rem);
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--paper);
}

.position-status [role="status"] {
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 650;
}

.last-move {
  font-size: 0.8rem;
}

.last-move:empty {
  display: none;
}

.exercise-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.exercise-actions button,
.position-link {
  min-height: 2.75rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--paper);
  color: var(--accent);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
  cursor: pointer;
}

.position-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.exercise-actions button:hover:enabled,
.position-link:hover {
  border-color: var(--accent);
}

.exercise-actions button:disabled {
  color: var(--muted);
  opacity: 0.6;
  cursor: default;
}

#sample-progress {
  color: var(--muted);
  font-size: 0.85rem;
}

#explanation {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--paper);
}

#explanation summary {
  padding: 0.75rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 650;
  cursor: pointer;
}

#explanation p {
  padding: 0 0.9rem 0.9rem;
  font-size: 0.92rem;
}

.position-status[hidden],
.exercise-actions[hidden] {
  display: none;
}

#board {
  grid-area: board;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  container-type: inline-size;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 1;
  border: 0.35rem solid #273b31;
  border-radius: 0.5rem;
  background: #ede3c6;
  box-shadow: 0 0.8rem 2.5rem #223d2918;
}

.square {
  --coordinate: #3a5345;
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #ede3c6;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.square:has(.piece-w) {
  touch-action: none;
}

.square.dragging {
  z-index: 2;
  cursor: grabbing;
  overflow: visible;
}

.square.dark {
  --coordinate: #fff9e9;
  background: #678779;
}

#board[aria-busy="true"] .square {
  cursor: progress;
}

#board[data-preview] .square {
  cursor: default;
}

.square.previous {
  background: #d6cc7f;
}

.square.dark.previous {
  --coordinate: #293524;
  background: #a9aa64;
}

.square[aria-pressed="true"] {
  --coordinate: #293524;
  background: #e5bb63;
}

.square::before,
.square::after {
  position: absolute;
  color: var(--coordinate);
  font-size: clamp(0.48rem, 2cqi, 0.78rem);
  font-weight: 750;
  pointer-events: none;
}

.square[data-rank]::before {
  inset: 0.12rem auto auto 0.2rem;
  content: attr(data-rank);
}

.square[data-file]::after {
  inset: auto 0.2rem 0.12rem auto;
  content: attr(data-file);
}

.piece {
  pointer-events: none;
  font: 9.5cqi/1 "DejaVu Sans", "Segoe UI Symbol", "Noto Sans Symbols 2", sans-serif;
}

.piece-w {
  color: #fffbeb;
  -webkit-text-stroke: 0.24cqi #34483b;
  paint-order: stroke fill;
}

.piece-b {
  color: #1b2b24;
  -webkit-text-stroke: 0.14cqi #eee9d0;
  paint-order: stroke fill;
}

.square.destination .piece:empty {
  width: 24%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #263f3266;
}

.square.capture {
  box-shadow: inset 0 0 0 0.35rem #263f3266;
}

.square:focus-visible {
  z-index: 1;
  outline: 3px solid #182e29;
  outline-offset: -3px;
}

@media (max-width: 640px) {
  .shell {
    width: calc(100% - 1.5rem);
  }

  .site-header nav {
    min-height: 3.4rem;
  }

  .practice {
    grid-template-areas: "instructions" "board" "controls";
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 0.9rem;
  }

  .practice h1 {
    max-width: none;
    font-size: clamp(1.85rem, 7vw, 2.9rem);
  }

  .instructions > p {
    margin-top: 0.5rem;
    font-size: 0.9rem;
  }

  .position-status {
    min-height: 3.2rem;
    padding: 0.45rem 0.65rem;
  }

  #board {
    border-width: 0.22rem;
  }
}

.opening-picker {
  display: grid;
  gap: 0.25rem;
  margin-top: 0.85rem;
}

.opening-picker select {
  width: 100%;
  min-width: 0;
  padding: 0.45rem;
  font: inherit;
}

.book-toggle {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.85rem;
  cursor: pointer;
}

.square.book-source,
.square.suggestion-source {
  box-shadow: inset 0 0 0 3px #164b88;
}

.square.book-target,
.square.suggestion-target {
  outline: 3px dashed #164b88;
  outline-offset: -5px;
}

.square.book-target:focus-visible {
  box-shadow: inset 0 0 0 2px white;
}

#board[data-evaluation] {
  border-color: #314971;
}

#board[data-evaluation] .square {
  background: #e3edff;
}

#board[data-evaluation] .square.dark {
  background: #8199be;
}

#suggested-moves li + li {
  margin-top: 0.45rem;
}

#suggested-moves button {
  display: inline-block;
  padding: 0.35rem 0.5rem;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

#suggested-moves button:is(:hover, :focus-visible, [aria-current="step"]) {
  background: #e3edf7;
}

#suggested-moves .suggestion-score {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.suggestion-score progress {
  width: 4rem;
  height: 0.65rem;
  accent-color: #315583;
}

.variation-moves {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.variation-moves button + button::before {
  content: "·";
  color: #87918a;
  margin-right: 0.5rem;
}

.opening-picker input[type="search"] {
  width: 100%;
  min-width: 0;
  padding: 0.45rem;
  font: inherit;
}

.topic-card .position-link + .position-link {
  margin-left: 0.5rem;
}

.exploring .practice-options,
.exploring #sample-navigation,
.exploring #sample-position,
.exploring #retry,
.exploring #sample-toggle,
.exploring #explanation {
  display: none;
}

.exploring #board {
  border-color: #675486;
}

.exploring .square:has(.piece-b) {
  touch-action: none;
}

.board-panel { grid-area: board; min-width: 0; }

#game-outcome { margin-top: 0.75rem; }

.outcome-track {
  display: flex;
  height: 0.75rem;
  overflow: hidden;
  border: 1px solid #777f7b;
  border-radius: 0.4rem;
}

.outcome-track .white-win { background: #fffdf7; }
.outcome-track .black-win { background: #26312d; }

#game-outcome p {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.promotion-picker {
  max-width: min(26rem, 90vw);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  color: var(--ink);
  background: var(--paper);
}

.promotion-picker::backdrop { background: #17271f70; }
.promotion-picker form { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.promotion-picker button { padding: 0.5rem 0.75rem; font: inherit; cursor: pointer; }

/* Overlay the check marker on both the live and evaluation board colours. */
#board .square.in-check,
#board[data-evaluation] .square.in-check {
  background-image: radial-gradient(circle, #ffdfac 5%, #f07464 43%, #b22e42 64%, transparent 76%);
}

.endgame-group {
  margin-top: 0.75rem;
}
.endgame-group summary {
  cursor: pointer;
  font-weight: 650;
}
