/* Rooky, a chess tutor — quiet, modern chrome around a wooden board.
   Warm neutral surfaces, hairline borders, one clay accent. The tutor's words
   are set in a serif, like a voice; everything else is a plain sans. */

:root {
  --bg: #faf9f5;
  --side-bg: #f3f1ea;
  --surface: #ffffff;
  --ink: #1f1e1d;
  --muted: #6b6a65;
  --faint: #8f8d86;
  --line: rgba(31, 30, 29, 0.12);
  --line-strong: rgba(31, 30, 29, 0.24);
  --hover: rgba(31, 30, 29, 0.06);
  --selected: rgba(31, 30, 29, 0.1);
  --user: #efede5;
  --clay: #c96442;
  --clay-soft: #f6e6dd;
  --ok: #3d7a56;
  --warn: #a4521c;
  --wood-a: #a06f42;
  --wood-b: #6a4424;
  --radius: 12px;
  --side: 216px;
  --shadow: 0 1px 2px rgba(31, 30, 29, 0.05), 0 4px 16px rgba(31, 30, 29, 0.06);
  --shadow-lift: 0 2px 6px rgba(31, 30, 29, 0.08), 0 12px 32px rgba(31, 30, 29, 0.1);
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #262624;
    --side-bg: #1f1e1d;
    --surface: #30302e;
    --ink: #f5f4ef;
    --muted: #b8b5a9;
    --faint: #8f8d86;
    --line: rgba(240, 238, 225, 0.12);
    --line-strong: rgba(240, 238, 225, 0.26);
    --hover: rgba(240, 238, 225, 0.07);
    --selected: rgba(240, 238, 225, 0.13);
    --user: #3a3a37;
    --clay: #d97757;
    --clay-soft: #47302a;
    --ok: #7fc79d;
    --warn: #e2a36f;
    --wood-a: #7d5632;
    --wood-b: #4a2f18;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow-lift: 0 2px 6px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

.ico {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

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

/* ---------- sidebar ---------- */

.side {
  position: sticky;
  top: 0;
  flex: none;
  width: var(--side);
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 10px 12px;
  background: var(--side-bg);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 10px 16px;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.22rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.brand .logo {
  width: 26px;
  height: 26px;
  flex: none;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav button,
.side-foot button {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 0.93rem;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s;
}

.nav button:hover,
.side-foot button:hover {
  background: var(--hover);
}

.nav button[aria-current="true"] {
  background: var(--selected);
}

.side-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.side-foot button {
  color: var(--muted);
  font-weight: 400;
}

.side-foot button:hover {
  color: var(--ink);
}

.side-foot #tutor-status[data-on="true"] .ico {
  color: var(--clay);
}

/* ---------- layout ---------- */

main {
  flex: 1;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
}

#table {
  display: grid;
  grid-template-columns: auto minmax(300px, 520px);
  gap: 28px;
  padding: 20px 24px 0;
  justify-content: center;
  align-items: start;
}

/* as tall as the window allows, as wide as leaves room for the conversation */
.board-col {
  width: min(calc(100vh - 170px), calc(100vw - var(--side) - 376px));
  min-width: 280px;
  padding-bottom: 20px;
}

/* the board sits in a wooden frame; the frame hugs it exactly */

.board-frame {
  width: fit-content;
  padding: 10px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--wood-a), var(--wood-b));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    inset 0 -2px 0 rgba(0, 0, 0, 0.25),
    var(--shadow-lift);
}

/* --board is set from js/board.js: the largest size chessground can draw exactly */
.board-area {
  position: relative;
  z-index: 0;
  width: var(--board, 320px);
  height: var(--board, 320px);
}

#board {
  width: 100%;
  height: 100%;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

/* coordinates: inside the edge squares, above the board and below the pieces */

.coords {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  font-family: var(--sans);
  font-weight: 600;
  font-size: clamp(9px, calc(var(--board, 320px) / 50), 13px);
  line-height: 1;
}

.coords span {
  position: absolute;
  display: flex;
  width: 12.5%;
  height: 12.5%;
}

.coords .rank {
  left: 0;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 3px 0 0 4px;
}

.coords .file {
  bottom: 0;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 0 4px 3px 0;
}

.coords .on-dark {
  color: #f0d9b5;
}

.coords .on-light {
  color: #a57a55;
}

.promo {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.5);
}

.promo button {
  width: 18%;
  aspect-ratio: 1;
  font-size: clamp(28px, 6vw, 56px);
  line-height: 1;
  border-radius: 14px;
  border: 0;
  background: #faf9f5;
  color: #1f1e1d;
  cursor: pointer;
  transition: transform 0.12s;
}

.promo button:hover {
  background: #fff;
  outline: 3px solid var(--clay);
  transform: translateY(-3px);
}

/* Taken pieces, under the board: what the player at the bottom has won on
   the left, what they have lost on the right. The pieces are chessground's
   own, on a strip the colour of a light square so both colours read well. */
.captured.cg-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  margin-top: 10px;
}

.captured.cg-wrap[hidden] {
  display: none;
}

.captured .half {
  display: flex;
  align-items: center;
  gap: 7px;
}

.captured .grp {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 8px;
  background: #ead7b3;
}

.captured .kind {
  display: inline-flex;
}

.captured.cg-wrap piece {
  position: static;
  display: block;
  width: 22px;
  height: 22px;
  background-size: cover;
  will-change: auto;
}

/* several of a kind overlap, like a stack */
.captured .kind piece + piece {
  margin-left: -10px;
}

.captured .lead {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.controls:empty {
  display: none;
}

.moves {
  position: relative; /* so a move's offset is measured within the list */
  margin-top: 10px;
  font-size: 0.86rem;
  color: var(--muted);
  max-height: 4.8em;
  overflow-y: auto;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}

/* Each move is a button: click it to look at that position. */
.moves .mv,
.mv-link {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  margin: 0;
  padding: 0 3px;
  border-radius: 5px;
  cursor: pointer;
}

.moves .mv:hover {
  color: var(--ink);
  background: var(--hover);
}

.moves .mv.cur {
  color: var(--ink);
  font-weight: 600;
  background: var(--selected);
}

.moves.looking .mv.cur {
  color: #fff;
  background: var(--clay);
}

.moves .tip {
  margin-left: 6px;
  color: var(--faint);
  font-style: italic;
}

.moves .link.live {
  margin-left: 6px;
  font-size: inherit;
  white-space: nowrap;
}

/* A move in the tutor's text that leads to its position on the board. */
.mv-link {
  padding: 0 1px;
  font-weight: inherit;
  text-decoration: underline dotted;
  text-decoration-color: var(--clay);
  text-underline-offset: 3px;
  white-space: nowrap;
}

.mv-link:hover {
  color: var(--clay);
  text-decoration-style: solid;
}

.moves .mv:focus-visible,
.mv-link:focus-visible {
  outline: 2px solid var(--clay);
  outline-offset: 1px;
}

.moves .n {
  color: var(--faint);
}

/* player names above and below the board */

.player {
  display: flex;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 6px 2px;
  min-height: 32px;
}

.player .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player .you {
  margin-left: 8px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
}

.dot.w,
.dot.b {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  border: 1px solid #8a8377;
  flex: none;
}

.dot.w {
  background: #fff;
}

.dot.b {
  background: #222;
}

/* ---------- buttons ---------- */

.btn {
  border: 1px solid var(--line-strong);
  background: transparent;
  border-radius: 9px;
  padding: 6px 13px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}

.btn:hover:not(:disabled) {
  background: var(--hover);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.btn.primary:hover:not(:disabled) {
  background: var(--ink);
  opacity: 0.86;
}

.btn.quiet {
  border-color: transparent;
  color: var(--muted);
}

.btn.quiet:hover:not(:disabled) {
  color: var(--ink);
}

.icon-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  color: var(--muted);
  padding: 4px 9px;
  border-radius: 8px;
}

.icon-btn:hover {
  background: var(--hover);
  color: var(--ink);
}

/* ---------- the conversation ---------- */

.panel {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 20px);
  min-height: 420px;
  min-width: 0;
}

.panel-head {
  position: relative;
  padding: 4px 4px 12px;
  border-bottom: 1px solid var(--line);
}

/* An icon button in the heading's top right corner (New game). */
.panel-head.has-action .title {
  padding-right: 44px;
}

.head-action {
  position: absolute;
  top: 0;
  right: 0;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
}

.head-action:focus-visible {
  outline: 2px solid var(--clay);
  outline-offset: 1px;
}

.panel-head .title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.22rem;
  line-height: 1.3;
  letter-spacing: -0.005em;
}

.panel-head .sub {
  color: var(--muted);
  font-size: 0.86rem;
}

.head-line {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
}

.link {
  border: 0;
  padding: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
  cursor: pointer;
}

.link:hover {
  text-decoration-color: currentColor;
}

.panel-head .back {
  float: right;
  margin: -2px -6px 0 8px;
}

.feed {
  flex: 1;
  overflow-y: auto;
  padding: 20px 4px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg,
.sheet {
  animation: rise 0.25s ease-out;
}

.msg {
  max-width: 100%;
}

.msg .body > :first-child {
  margin-top: 0;
}

.msg .body > :last-child {
  margin-bottom: 0;
}

.msg p {
  margin: 0.6em 0;
}

.msg ul,
.msg ol {
  margin: 0.5em 0;
  padding-left: 1.3em;
}

.msg li {
  margin: 0.2em 0;
}

.msg code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.86em;
  background: var(--hover);
  padding: 1px 5px;
  border-radius: 5px;
}

/* a choice card: a question and a few options to pick from */

/* "Who's better?": an evaluation bar the student sets, running from Black
   winning (dark, left) to White winning (light, right). The handle is their
   guess, the green line the engine's. */
.msg.evalcard {
  padding: 12px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.evalcard .q {
  margin-bottom: 14px;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--muted);
}

.evalbar {
  position: relative;
  height: 30px;
}

.evalbar .track {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: linear-gradient(90deg, #1c1b1a 0%, #45423e 30%, #8d887f 50%, #cfcabf 70%, #f6f3ea 100%);
}

.evalbar .mid {
  position: absolute;
  left: 50%;
  top: -4px;
  bottom: -4px;
  width: 1px;
  background: var(--clay);
  opacity: 0.7;
  pointer-events: none;
}

.evalbar .truth {
  position: absolute;
  top: -6px;
  bottom: -6px;
  width: 4px;
  margin-left: -2px;
  border-radius: 2px;
  background: #3f9b63;
  box-shadow: 0 0 0 1.5px var(--surface);
  pointer-events: none;
}

.evalbar .truth[hidden] {
  display: none;
}

.evalbar input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: ew-resize;
}

.evalbar input[type="range"]:disabled {
  cursor: default;
}

.evalbar input[type="range"]:focus {
  outline: none;
}

.evalbar input[type="range"]::-webkit-slider-runnable-track {
  height: 100%;
  background: transparent;
}

.evalbar input[type="range"]::-moz-range-track {
  height: 100%;
  background: transparent;
}

/* 14px wide: judge.js places the fill and the engine's line to match */
.evalbar input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  box-sizing: border-box;
  width: 14px;
  height: 40px;
  margin-top: -5px;
  border: 2px solid #fff;
  border-radius: 6px;
  background: var(--clay);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.evalbar input[type="range"]::-moz-range-thumb {
  box-sizing: border-box;
  width: 14px;
  height: 40px;
  border: 2px solid #fff;
  border-radius: 6px;
  background: var(--clay);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.evalbar input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--clay) 35%, transparent), 0 1px 4px rgba(0, 0, 0, 0.4);
}

.evalbar input[type="range"]:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--clay) 35%, transparent), 0 1px 4px rgba(0, 0, 0, 0.4);
}

.evalcard .ends {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  margin-top: 9px;
  font-size: 0.74rem;
  color: var(--faint);
}

.evalcard .ends span:last-child {
  text-align: right;
}

.evalcard .readout {
  margin-top: 10px;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

.evalcard .readout b {
  font-weight: 600;
}

.evalcard .readout .key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 16px;
  font-weight: 500;
}

.evalcard .readout .key::before {
  content: "";
  width: 6px;
  height: 14px;
  border-radius: 2px;
  background: var(--clay);
}

.evalcard .readout .key.engine::before {
  background: #3f9b63;
}

.evalcard .actions {
  margin-top: 12px;
}

.msg.choice {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.choice .q {
  padding: 11px 14px 9px;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--muted);
}

.choice .opts {
  display: flex;
  flex-direction: column;
}

.choice .opt {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 11px;
  align-items: start;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
}

.choice .opt:hover {
  background: var(--hover);
}

.choice .opt:focus-visible {
  outline: 2px solid var(--clay);
  outline-offset: -2px;
}

.choice .radio {
  width: 16px;
  height: 16px;
  margin-top: 3px;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
}

.choice .opt[aria-checked="true"] .radio {
  border-color: var(--clay);
  background: radial-gradient(circle, var(--clay) 0 45%, transparent 50%);
}

.choice .txt {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.choice .txt b {
  font-weight: 600;
}

.choice .txt span {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.msg.choice.settled {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 10px;
  box-shadow: none;
  font-size: 0.87rem;
}

.choice .tick {
  color: var(--clay);
  font-weight: 600;
}

.choice .picked {
  font-weight: 500;
  margin-right: auto;
}

.choice.settled .link {
  color: var(--muted);
}

/* the tutor's words: plain text on the page, in a serif */

.msg.tutor {
  font-family: var(--serif);
  font-size: 1.06rem;
  line-height: 1.6;
}

.msg.tutor strong {
  font-weight: 600;
}

/* the student's words: a quiet bubble on the right */

.msg.student {
  align-self: flex-end;
  max-width: 85%;
  background: var(--user);
  padding: 9px 14px;
  border-radius: 16px;
}

.msg.aside {
  color: var(--muted);
  font-size: 0.87rem;
}

.msg.aside strong {
  color: var(--ink);
  font-weight: 600;
}

.msg .label {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--clay);
  margin-bottom: 4px;
}

.msg .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  font-family: var(--sans);
}

.msg.aside .actions {
  margin-top: 7px;
}

.dots i {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 4px;
  border-radius: 50%;
  background: var(--clay);
  animation: blink 1.2s infinite ease-in-out;
}

.dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.dots i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

.msg .status {
  margin-left: 6px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.86rem;
}

/* the composer */

.ask {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 16px;
  padding: 7px 7px 7px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  transition: border-color 0.12s, box-shadow 0.12s;
}

.ask:focus-within {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-lift);
}

.ask input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 7px 0;
  outline: none;
}

.ask input::placeholder {
  color: var(--faint);
}

.send {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: var(--clay);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.12s, transform 0.12s;
}

.send:hover {
  opacity: 0.88;
}

.send:active {
  transform: scale(0.95);
}

.send .ico {
  stroke-width: 2.25;
}

.field input:focus,
.field select:focus,
.btn:focus-visible,
.send:focus-visible,
.nav button:focus-visible,
.side-foot button:focus-visible,
.chip:focus-visible,
.card:focus-visible,
.fcard:focus-visible,
.option:focus-visible {
  outline: 2px solid var(--clay);
  outline-offset: 2px;
}

/* fact sheet at the top of a famous game */

.sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
  font-size: 0.9rem;
}

.sheet-players {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.04rem;
}

.sheet-players .pl {
  display: inline-flex;
  align-items: center;
}

.sheet-players .vs {
  color: var(--faint);
  font-family: var(--sans);
  font-weight: 400;
  font-size: 0.86rem;
}

.sheet dl {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 3px 16px;
  margin: 10px 0 0;
}

.sheet dt {
  color: var(--muted);
}

.sheet dd {
  margin: 0;
}

.sheet-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 11px;
  font-size: 0.76rem;
}

/* ---------- library (study / famous) ---------- */

#library {
  max-width: 1040px;
  margin: 0 auto;
  padding: 44px 28px 72px;
}

.hero {
  margin-bottom: 8px;
  animation: rise 0.3s ease-out;
}

.hero h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2rem, 4vw, 2.6rem);
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 10px;
}

.hero .lead {
  color: var(--muted);
  font-size: 1.02rem;
  margin: 0;
  max-width: 66ch;
}

.hero .progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  font-size: 0.86rem;
  color: var(--muted);
}

.hero .bar {
  flex: 0 1 220px;
  height: 5px;
  border-radius: 999px;
  background: var(--selected);
  overflow: hidden;
}

.hero .bar i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--clay);
}

#library h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
  margin: 40px 0 2px;
}

#library .hint {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0 0 14px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.card,
.fcard {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.card:hover,
.fcard:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.card {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.card .t,
.fbody .t {
  font-weight: 600;
  font-size: 0.98rem;
  line-height: 1.35;
}

.card .d {
  color: var(--muted);
  font-size: 0.87rem;
  line-height: 1.45;
}

.card .meta {
  margin-top: 9px;
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.tag {
  border-radius: 999px;
  padding: 1px 9px;
  border: 1px solid var(--line);
  white-space: nowrap;
}

.tag.rec {
  background: var(--clay-soft);
  border-color: transparent;
  color: var(--clay);
  font-weight: 600;
}

.tag.done {
  border-color: transparent;
  background: var(--hover);
  color: var(--ok);
  font-weight: 600;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--line-strong);
  background: transparent;
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.12s, border-color 0.12s;
}

.chip:hover {
  background: var(--hover);
}

.chip.rec {
  border-color: var(--clay);
  color: var(--clay);
}

/* famous positions: cards with a small board */

.fcards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(370px, 1fr));
  gap: 14px;
}

.fcard {
  display: grid;
  grid-template-columns: 152px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  padding: 13px;
}

.fboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mini {
  width: 144px;
  height: 144px;
  margin: 4px;
  border-radius: 3px;
  overflow: hidden;
  pointer-events: none;
  box-shadow:
    0 0 0 3px var(--wood-b),
    0 4px 12px rgba(40, 25, 5, 0.25);
}

.fcap {
  font-size: 0.74rem;
  color: var(--faint);
  text-align: center;
}

.fbody {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.fbody .t {
  font-family: var(--serif);
  font-size: 1.1rem;
}

.fbody .who {
  font-size: 0.82rem;
  color: var(--muted);
}

.fbody .d {
  font-size: 0.88rem;
  line-height: 1.45;
  margin-top: 3px;
}

.fbody .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 9px;
  font-size: 0.74rem;
  color: var(--muted);
}

.fbody .foot {
  margin-top: 8px;
  font-size: 0.76rem;
  color: var(--faint);
}

/* ---------- modal ---------- */

dialog {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

dialog[open] {
  animation: pop 0.2s ease-out;
}

dialog::backdrop {
  background: rgba(20, 18, 14, 0.42);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 24px 0;
}

.modal-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.5rem;
  letter-spacing: -0.015em;
  line-height: 1.25;
}

.modal-body {
  padding: 10px 24px 22px;
}

.modal-body p {
  margin: 0.5em 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 15px 0;
}

.field label {
  font-weight: 500;
  font-size: 0.9rem;
}

.field input,
.field select {
  border: 1px solid var(--line-strong);
  background: var(--bg);
  border-radius: 9px;
  padding: 8px 12px;
}

.field .help,
.small {
  color: var(--muted);
  font-size: 0.85rem;
}

/* the level picker */

.options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 14px 0;
}

.option {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 13px;
  text-align: left;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 12px;
  padding: 9px 14px 9px 10px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.option:hover {
  background: var(--hover);
  border-color: var(--line-strong);
}

.option .piece {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 9px;
  font-size: 1.55rem;
  line-height: 1;
  background: var(--hover);
}

.option .what {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.option .what b {
  font-weight: 600;
}

.option .what span {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.option .rating {
  font-family: var(--serif);
  font-size: 1.08rem;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* keyboard shortcuts list */

.shortcuts h3 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--clay);
  margin: 18px 0 6px;
}

.shortcuts h3:first-child {
  margin-top: 6px;
}

.shortcuts > div {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  font-size: 0.92rem;
}

.shortcuts .keys {
  display: flex;
  gap: 5px;
}

kbd {
  display: inline-block;
  min-width: 26px;
  text-align: center;
  font: 500 0.8rem var(--sans);
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  background: var(--bg);
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 14px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
}

.stat .v {
  font-family: var(--serif);
  font-size: 1.6rem;
  font-weight: 500;
  line-height: 1.2;
}

.stat .k {
  color: var(--muted);
  font-size: 0.8rem;
}

.history {
  max-height: 180px;
  overflow-y: auto;
  font-size: 0.88rem;
  border-top: 1px solid var(--line);
  margin-top: 8px;
}

.history div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.up {
  color: var(--ok);
  font-weight: 500;
}

.down {
  color: var(--warn);
  font-weight: 500;
}

/* ---------- narrower windows: the sidebar becomes an icon rail ---------- */

@media (max-width: 1180px) {
  :root {
    --side: 60px;
  }

  .side .lbl {
    display: none;
  }

  .side {
    padding-inline: 8px;
    align-items: stretch;
  }

  .brand,
  .nav button,
  .side-foot button {
    justify-content: center;
    padding-inline: 0;
  }

  .brand {
    padding-bottom: 12px;
  }
}

/* ---------- board above the conversation ---------- */

@media (max-width: 820px) {
  #table {
    grid-template-columns: minmax(0, 1fr);
    padding: 14px 14px 0;
    gap: 16px;
  }

  .board-col {
    width: min(100%, calc(100vh - 150px));
    min-width: 0;
    margin: 0 auto;
    padding-bottom: 0;
  }

  .panel {
    height: auto;
    min-height: 380px;
    max-height: 82vh;
  }
}

/* ---------- phones: the sidebar becomes a top bar ---------- */

@media (max-width: 700px) {
  :root {
    --side: 0px;
  }

  body {
    flex-direction: column;
  }

  .side {
    position: static;
    width: auto;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 2px;
    padding: 8px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    padding: 2px 6px;
    margin-right: auto;
  }

  .brand .lbl {
    display: inline;
  }

  .side-foot {
    flex-direction: row;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .side-foot button {
    width: auto;
    padding: 8px 9px;
  }

  /* no keyboard on a phone */
  #shortcuts-btn {
    display: none;
  }

  .nav {
    order: 5;
    flex-direction: row;
    width: 100%;
  }

  .nav button {
    flex: 1;
    padding: 7px 4px;
    gap: 7px;
    font-size: 0.86rem;
  }

  .nav .lbl {
    display: inline;
  }

  main {
    height: auto;
    overflow: visible;
  }

  #table {
    padding: 12px 12px 0;
  }

  .board-frame {
    padding: 7px;
    border-radius: 8px;
  }

  #library {
    padding: 24px 14px 48px;
  }

  .fcards {
    grid-template-columns: minmax(0, 1fr);
  }

  .fcard {
    grid-template-columns: 118px minmax(0, 1fr);
    gap: 12px;
  }

  .mini {
    width: 112px;
    height: 112px;
  }

  .option {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 10px;
  }

  .option .piece {
    width: 34px;
    height: 34px;
    font-size: 1.35rem;
  }
}
