:root {
  --bg: #161512;
  --panel: #23211d;
  --panel-2: #2c2a25;
  --text: #ecebe6;
  --muted: #a19d93;
  --accent: #7fa650;
  --accent-2: #9cc56a;
  --bad: #e06c5a;
  --sq-light: #ecd9b9;
  --sq-dark: #ae8a68;
  --last: rgba(205, 210, 106, .55);
  --sel: rgba(20, 85, 30, .5);
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
button {
  background: var(--panel-2); border: 1px solid #3b3832; border-radius: 8px;
  padding: 7px 12px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: #5a564d; }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #111; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-2); }
button.ghost { background: transparent; }
select, input[type=text] {
  background: #1b1a17; border: 1px solid #3b3832; border-radius: 8px; padding: 7px 10px;
}
input[type=text]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
label.check { cursor: pointer; }
code { background: #1b1a17; padding: 1px 5px; border-radius: 4px; }

/* topo */
.top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: #1e1d1a; border-bottom: 1px solid #2f2d28;
}
.brand { font-weight: 700; font-size: 18px; }
.tabs { display: flex; gap: 4px; }
.tab { background: transparent; border-color: transparent; color: var(--muted); }
.tab.active { color: var(--text); background: var(--panel-2); border-color: #3b3832; }
.voice { margin-left: auto; }
.mic.on { background: #7a2b22; border-color: #b0453a; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(224, 108, 90, .2); } }
.heard {
  height: 22px; line-height: 22px; padding: 0 16px; color: var(--muted); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status { min-height: 24px; }
.play-layout .feedback { min-height: 44px; }

main { max-width: 1100px; margin: 0 auto; padding: 8px 16px 40px; }

/* tabuleiro */
.board {
  display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%; max-width: 100%; aspect-ratio: 1; border-radius: 6px; overflow: hidden;
  box-shadow: 0 6px 24px rgba(0,0,0,.4); user-select: none; container-type: inline-size;
}
.board.clickable .sq { cursor: pointer; }
.sq { position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; overflow: hidden; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last { box-shadow: inset 0 0 0 100px var(--last); }
.sq.selected { box-shadow: inset 0 0 0 100px var(--sel); }
.sq.target::after {
  content: ""; width: 28%; height: 28%; border-radius: 50%; background: rgba(20, 85, 30, .45);
}
.sq.target-capture::after {
  content: ""; position: absolute; inset: 4%; border-radius: 50%; border: 5px solid rgba(20, 85, 30, .45);
}
.sq.answer { box-shadow: inset 0 0 0 100px rgba(80, 140, 220, .55); }
.sq.path { box-shadow: inset 0 0 0 100px rgba(80, 140, 220, .28); }
.sq.hit { box-shadow: inset 0 0 0 100px rgba(110, 180, 70, .6); }
.sq.miss { box-shadow: inset 0 0 0 100px rgba(235, 170, 50, .65); }
.sq.wrong { box-shadow: inset 0 0 0 100px rgba(220, 70, 60, .6); }
.piece {
  font-size: min(9.5vw, 58px); font-size: 10.5cqw; line-height: 1; position: relative; z-index: 1;
  font-family: "Segoe UI Symbol", "DejaVu Sans", "Noto Sans Symbols 2", serif;
}
.piece.white { color: #fff; text-shadow: 0 0 1px #000, 0 0 1px #000, 0 0 2px #000, 0 1px 1px #000; }
.piece.black { color: #1a1a1a; text-shadow: 0 0 1px rgba(255,255,255,.35); }
.mark {
  position: absolute; top: 2px; right: 5px; font-weight: 700; font-size: 13px; color: #10325c; z-index: 2;
}
.coord { position: absolute; font-size: 11px; font-weight: 700; opacity: .8; pointer-events: none; }
.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 1px; right: 4px; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }

/* jogar */
.play-layout { display: grid; grid-template-columns: minmax(0, 560px) minmax(0, 1fr); gap: 20px; align-items: start; }
.panel { background: var(--panel); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.panel h4 { margin: 0 0 6px; color: var(--muted); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 4px 0; }
.status { font-weight: 600; font-size: 16px; margin-bottom: 8px; }
.move-input { display: flex; gap: 8px; }
.move-input input { flex: 1; min-width: 0; font-size: 17px; }
.tools button { font-size: 13px; }
.feedback { min-height: 22px; margin: 8px 0 4px; color: var(--muted); }
.feedback.ok { color: var(--accent-2); }
.feedback.bad { color: var(--bad); }
.moves {
  margin: 0; padding-left: 34px; max-height: 260px; overflow-y: auto;
  font-family: ui-monospace, Consolas, monospace; font-size: 14px;
}
.moves li { padding: 1px 0; }
.moves .mv { display: inline-block; min-width: 72px; }
.blind-card {
  aspect-ratio: 1; width: 100%; border-radius: 6px; background: var(--panel);
  border: 2px dashed #3b3832; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px;
}
.blind-who { color: var(--muted); }
.blind-move { font-size: clamp(44px, 12vw, 88px); font-weight: 700; font-family: ui-monospace, Consolas, monospace; }
.blind-hint { color: var(--muted); font-size: 13px; margin-top: 10px; }
.voice-hint { margin-top: 18px; font-size: 14px; color: var(--muted); line-height: 1.8; }
.voice-hint b { color: var(--accent-2); font-weight: 600; }
button.voice-only { font-weight: 600; }
button.voice-only.on { background: #7a2b22; border-color: #b0453a; }
.plan td:first-child { width: 22%; white-space: nowrap; }
.help ul li { margin-bottom: 6px; }

/* treinar */
.train-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.train-head p { color: var(--muted); margin: 8px 0; }
.ex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 8px; }
.ex-card { text-align: left; background: var(--panel); border-radius: var(--radius); padding: 14px; border: 1px solid #2f2d28; }
.ex-card:hover { border-color: var(--accent); }
.ex-card h3 { margin: 0 0 4px; font-size: 16px; }
.ex-card p { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.ex-stats { font-size: 12px; color: var(--accent-2); }
.ex-top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.ex-top h2 { margin: 0; font-size: 20px; }
.ex-score { margin-left: auto; color: var(--muted); }
.ex-score b { color: var(--text); }
.ex-opts { background: var(--panel); border-radius: var(--radius); padding: 8px 14px; margin: 10px 0; }
.ex-body { max-width: 560px; margin: 0 auto; text-align: center; }
.prompt { font-size: 22px; margin: 14px 0; }
.prompt small { font-size: 14px; color: var(--muted); }
.moves-big { font-family: ui-monospace, Consolas, monospace; font-size: 22px; margin-top: 12px; line-height: 1.6; }
.moves-small { font-family: ui-monospace, Consolas, monospace; font-size: 13px; color: var(--muted); margin-top: 6px; }
.ex-board { max-width: 440px; margin: 0 auto 12px; }
.answer { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.answer .choice { min-width: 90px; font-size: 17px; padding: 10px 16px; }
.answer.wide .choice { min-width: 0; flex: 1 1 calc(33% - 8px); font-size: 14px; padding: 8px; }
.answer.wide .choice:last-child { flex-basis: 100%; }
.choice.pw, .choice.pb { font-family: inherit; }
.answer input { flex: 1; min-width: 0; max-width: 340px; font-size: 18px; }
.timer { align-self: center; font-size: 22px; font-weight: 700; color: var(--accent-2); }
#ex-next { margin-top: 6px; }

/* aprender */
.lesson-num { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 2px; }
.ex-card.done { border-color: #3d4a2e; }
.lesson-body { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 20px; align-items: start; margin-top: 12px; }
.lesson-board { width: 100%; }
.lesson-text { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.lesson-content { font-size: 18px; line-height: 1.55; }
.lesson-content b { color: var(--accent-2); }
.lesson-nav { display: flex; gap: 8px; flex-wrap: wrap; }
.lesson-nav .primary { margin-left: auto; }
.lesson-text .answer { justify-content: flex-start; }
.choice.right { background: var(--accent); border-color: var(--accent); color: #111; }
.choice.wrong-choice { border-color: var(--bad); color: var(--bad); }
.lesson-body .lesson-board:not([hidden]) + .lesson-text { grid-column: 2; }
.lesson-body .lesson-board[hidden] + .lesson-text { grid-column: 1 / -1; max-width: 640px; }

/* ajuda */
.help { max-width: 760px; }
.help li { margin-bottom: 6px; }
.cmds { border-collapse: collapse; width: 100%; }
.cmds td { border-bottom: 1px solid #2f2d28; padding: 6px 8px; vertical-align: top; }
.cmds td:first-child { color: var(--accent-2); width: 55%; }
.muted { color: var(--muted); font-size: 13px; }

.board, .sq, button { touch-action: manipulation; }

@media (max-width: 820px) {
  .play-layout { grid-template-columns: 1fr; gap: 12px; }
  .lesson-body { grid-template-columns: 1fr; }
  .lesson-body .lesson-board:not([hidden]) + .lesson-text { grid-column: 1; }
  .lesson-content { font-size: 17px; }
  .prompt { font-size: 19px; }
}
@media (max-width: 560px) {
  .top { gap: 8px; padding: 8px 12px; }
  .brand { font-size: 16px; width: 100%; display: flex; justify-content: space-between; }
  .tabs { flex: 1; }
  .tab { flex: 1; padding: 9px 6px; }
  .voice { margin-left: 0; }
  #mic-label { display: none; }
  .mic { padding: 9px 14px; }
  main { padding: 6px 10px 32px; }
  .panel { padding: 10px 12px; }
  .row { gap: 8px; }
  .row label { flex: 1 1 140px; }
  .row select { flex: 1; min-width: 0; }
  .tools { display: grid; grid-template-columns: 1fr 1fr; }
  .tools button, button.voice-only, #btn-new { padding: 10px; }
  .move-input input { font-size: 16px; }
  .answer .choice { flex: 1 1 40%; padding: 12px; }
  .answer.wide .choice { flex: 1 1 calc(50% - 8px); }
  .ex-score { margin-left: 0; width: 100%; }
  .coord { font-size: 9px; }
  .cmds td { display: block; width: auto !important; border: 0; padding: 2px 4px; }
  .cmds tr { display: block; border-bottom: 1px solid #2f2d28; padding: 6px 0; }
}
