:root {
  --bg: #f6f4ef; --fg: #24221f; --muted: #6d675e; --panel: #fff; --line: #d9d3c7;
  --accent: #2f6f4f; --good: #2f6f4f; --bad: #a8362b;
  --sq-light: #ead9b8; --sq-dark: #a98863;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1d1c1a; --fg: #ece8e0; --muted: #a39c90; --panel: #2a2826; --line: #45413b; --accent: #6fbf95; --good: #6fbf95; --bad: #ef8a7e; }
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  background: var(--bg); color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
header, main, footer { width: min(100%, 560px); padding: 0 16px; }
header { display: flex; flex-wrap: wrap; row-gap: 6px; justify-content: space-between; align-items: baseline; padding-top: 14px; }
h1 { display: flex; align-items: center; gap: 9px; font-size: 1.2rem; margin: 0; letter-spacing: .02em; }
.logo {
  width: 22px; height: 22px; border-radius: 5px;
  background: conic-gradient(var(--sq-light) 25%, var(--accent) 0 50%, var(--sq-light) 0 75%, var(--accent) 0);
}
h2 { font-size: 1.3rem; margin: 28px 0 4px; }
.kinds { display: flex; gap: 6px; margin: 0 auto 0 14px; }
.kinds[hidden] { display: none; }
.kinds button { padding: 3px 12px; font-size: .9rem; border-radius: 999px; }
.kinds button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 600; }
.stats { display: flex; gap: 14px; font-size: .95rem; }
.muted { color: var(--muted); }
.prompt { font-size: 1.1rem; font-weight: 600; margin: 14px 0 10px; }
.tag {
  display: inline-block; margin: 14px 0 0; padding: 2px 10px; border-radius: 999px;
  background: var(--accent); color: var(--bg); font-size: .8rem; font-weight: 600; letter-spacing: .03em;
}
.tag[hidden] { display: none; }
#lesson h2 { margin: 8px 0 4px; }
#lesson p#lesson-text { margin: 0; }

button {
  font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 16px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 600; }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 4px; font-size: .85rem; }

/* Welcome screen */
.hero {
  margin-top: 20px; padding: 26px 20px; border: 1px solid var(--line); border-radius: 16px; text-align: center;
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 16%, var(--panel)), var(--panel) 70%);
}
.hero h2 { margin: 0 0 6px; font: 700 clamp(1.5rem, 6vw, 1.9rem)/1.2 Georgia, "Times New Roman", serif; text-wrap: balance; }
.hero p { margin: 0 auto; max-width: 26em; text-wrap: balance; }
#welcome h3 { margin: 24px 0 10px; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.games { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.games button, .levels button { border-radius: 12px; transition: border-color .15s, transform .15s, box-shadow .15s; }
.games button:hover, .levels button:hover { transform: translateY(-2px); box-shadow: 0 6px 16px #0000001f; }
.games button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 8px; }
.games button[aria-pressed="true"] {
  border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
}
.games .icon {
  display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 4px; border-radius: 50%;
  background: var(--sq-light); color: #2b241a; font-size: 1.9rem; line-height: 1;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", "Apple Symbols", sans-serif;
}
.games [data-kind="checkers"] .icon::before {
  content: ""; width: 32px; height: 32px; border-radius: 50%; background: #c23b2e;
  box-shadow: 0 2px 3px #0006, inset 0 0 0 4px #0000002e, inset 0 0 0 7px #ffffff22;
}
.title { font-weight: 600; line-height: 1.25; }
.note { color: var(--muted); font-size: .85rem; line-height: 1.3; }
.levels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.levels button { display: flex; flex-direction: column; gap: 3px; text-align: left; padding: 14px 16px; }
@media (max-width: 420px) {
  .levels { grid-template-columns: 1fr; }
  .games .note { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .games button, .levels button { transition: none; }
  .games button:hover, .levels button:hover { transform: none; }
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .primary { margin-left: auto; }
.feedback { min-height: 3em; margin: 10px 0; font-weight: 600; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
footer { margin-top: auto; padding: 24px 16px 14px; text-align: center; }

/* Chess board */
#stage { position: relative; container-type: inline-size; }
.board {
  display: grid; grid-template-columns: repeat(8, 1fr); width: 100%; aspect-ratio: 1;
  border-radius: 6px; overflow: hidden; touch-action: none; user-select: none;
}
.square {
  position: relative; display: grid; place-items: center; padding: 0; border: none; border-radius: 0;
  aspect-ratio: 1; font-size: 9.6cqw; line-height: 1; cursor: pointer;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", "Apple Symbols", sans-serif;
}
.square.light { background: var(--sq-light); }
.square.dark { background: var(--sq-dark); }
.square.white { color: #fff; text-shadow: 0 0 2px #000, 0 0 2px #000, 0 1px 2px #000; }
.square.black { color: #1b1b1b; text-shadow: 0 0 1px #fff8; }
.square.last { box-shadow: inset 0 0 0 100vmax #f5d64255; }
.square.selected { box-shadow: inset 0 0 0 100vmax #4c9a6e88; }
.square.hint { box-shadow: inset 0 0 0 .9cqw #2f7fd1; }
.square.wrong { box-shadow: inset 0 0 0 100vmax #c9453799; }
.square.refute { box-shadow: inset 0 0 0 .9cqw #c94537; }
.square.check { box-shadow: inset 0 0 3cqw 1cqw #d2372b; }
.square.target::after {
  content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%; background: #0000002e;
}
.square.target.white::after, .square.target.black::after {
  width: 86%; height: 86%; background: none; border: .9cqw solid #0000002e;
}
.square:focus-visible { outline: none; box-shadow: inset 0 0 0 .7cqw var(--accent); }
.square[data-rank]::before, .square[data-file]::before {
  position: absolute; font: 600 2.2cqw system-ui, sans-serif; color: #0008; text-shadow: none;
}
.square[data-rank]::before { content: attr(data-rank); top: 3%; left: 5%; }
.square[data-file]:not([data-rank])::before { content: attr(data-file); bottom: 2%; right: 6%; }
.promotion {
  position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%);
  display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px; gap: 4px; box-shadow: 0 6px 24px #0006;
}
.promotion[hidden] { display: none; }
.promotion .square { width: 14cqw; background: var(--sq-dark); border-radius: 6px; }

/* Checkers board */
.board.checkers .square.dark { background: var(--sq-dark); }
.board.checkers .square.light { background: var(--sq-light); }
.board.checkers .square.dark::before {
  content: attr(data-num); position: absolute; top: 4%; left: 6%;
  font: 600 2.2cqw system-ui, sans-serif; color: #0009; text-shadow: none;
}
.piece {
  position: relative; display: block; width: 78%; height: 78%; border-radius: 50%;
  box-shadow: 0 .4cqw .6cqw #0006, inset 0 0 0 .8cqw #0000002e, inset 0 0 0 1.6cqw #ffffff22;
}
.piece.red { background: #c23b2e; }
.piece.white { background: #f4efe4; box-shadow: 0 .4cqw .6cqw #0006, inset 0 0 0 .8cqw #0000003a; }
.piece.king::after {
  content: "♛︎"; position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 6cqw; line-height: 1; color: #f5d642; text-shadow: 0 0 1px #000, 0 0 2px #000;
}
.piece.white.king::after { color: #b8860b; text-shadow: none; }

/* Knights and knaves */
.kk-says { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.kk-says li { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; }
.kk-says li.muted { background: none; border-style: dashed; }
.kk-says li.hint { border-color: #2f7fd1; box-shadow: 0 0 0 1px #2f7fd1; }
.kk-name { font-weight: 600; }
.kk-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.kk-table caption { text-align: left; color: var(--muted); font-size: .9rem; padding-bottom: 4px; }
.kk-table th, .kk-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.kk-table th:first-child, .kk-table td:first-child { width: 2.6rem; padding-left: 0; }
.kk-table tbody tr { cursor: pointer; }
.kk-table tbody tr:hover td { background: #8881; }
.kk-table tr.hint td { background: #2f7fd12e; }
.kk-table tr.marked td { background: #c9453730; }
.kk-role { text-transform: capitalize; }
.kk-table tr.crossed .kk-role { text-decoration: line-through; color: var(--muted); }
.kk-cross { width: 2rem; height: 2rem; padding: 0; line-height: 1; color: var(--bad); font-weight: 700; }
.kk-why { color: var(--muted); font-size: .85rem; }
.kk-answers { display: grid; gap: 8px; margin-bottom: 14px; }
.kk-answer { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.kk-answer .kk-name { min-width: 5.5em; }
.kk-answer button { padding: 6px 12px; }
.kk-answer button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 600; opacity: 1; }
