/* ---------- Tokens de tema ---------- */
:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #f0ebe1;
  --border: #e0d8c8;
  --text: #24211c;
  --text-muted: #6b6457;
  --accent: #2f6f5e;
  --accent-strong: #245a4c;
  --accent-soft: #dcebe5;
  --danger: #b4483a;
  --warning: #a8741a;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 4px 16px rgba(40, 30, 10, .06);
  --sq-light: #ecdcc0;
  --sq-dark: #b58b63;
  --sev-inaccuracy: #b98a12;
  --sev-mistake: #d26a1e;
  --sev-blunder: #c0392b;
  --sev-missed: #7a4fb5;
  --radius: 12px;
  --sidebar-w: 220px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #171a19;
  --surface: #212625;
  --surface-2: #2a302f;
  --border: #353c3a;
  --text: #ece8df;
  --text-muted: #a39d91;
  --accent: #5fb39a;
  --accent-strong: #7cc8b0;
  --accent-soft: #24403a;
  --danger: #e07a6c;
  --warning: #e0b05a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --sq-light: #d9c7a7;
  --sq-dark: #9a7352;
  --sev-inaccuracy: #e0b23a;
  --sev-mistake: #ec8a45;
  --sev-blunder: #ee6b5d;
  --sev-missed: #ad8ae6;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171a19;
    --surface: #212625;
    --surface-2: #2a302f;
    --border: #353c3a;
    --text: #ece8df;
    --text-muted: #a39d91;
    --accent: #5fb39a;
    --accent-strong: #7cc8b0;
    --accent-soft: #24403a;
    --danger: #e07a6c;
    --warning: #e0b05a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --sq-light: #d9c7a7;
    --sq-dark: #9a7352;
  --sev-inaccuracy: #e0b23a;
  --sev-mistake: #ec8a45;
  --sev-blunder: #ee6b5d;
  --sev-missed: #ad8ae6;
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 .75em; }
a { color: var(--accent); }
.muted { color: var(--text-muted); }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--text-muted); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); }
.theme-toggle {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border: 0; border-radius: 8px; background: none;
  color: var(--text-muted); font: inherit; cursor: pointer;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }
#sound-toggle[aria-pressed="true"] .sound-off,
#sound-toggle[aria-pressed="false"] .sound-on { display: none; }
.content { flex: 1; min-width: 0; padding: 28px 32px; outline: none; }

/* ---------- Componentes ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: .9rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-muted); font-size: .8rem; font-weight: 600; }
.badge.ok { background: var(--accent-soft); color: var(--accent-strong); }
.badge.warn { background: rgba(168, 116, 26, .15); color: var(--warning); }
.alert { border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; border: 1px solid; }
.alert.error { border-color: var(--danger); color: var(--danger); background: rgba(180, 72, 58, .08); }
.alert.warn { border-color: var(--warning); color: var(--warning); background: rgba(168, 116, 26, .08); }
.alert code { color: var(--text); }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; color: var(--text-muted); }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
.field { margin-bottom: 18px; }
.field > .label { display: block; font-weight: 600; margin-bottom: 6px; }
select {
  font: inherit; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Tabuleiro ---------- */
.board-wrap { width: min(100%, calc(100vh - 64px)); max-width: 760px; position: relative; }
.board { width: 100%; aspect-ratio: 1; position: relative; border-radius: 6px; overflow: hidden; box-shadow: var(--shadow); }
.board .cg-wrap { width: 100%; height: 100%; }
.board cg-board {
  background-color: var(--sq-light);
  background-image: none;
}
.board cg-board::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  /* Casa a8 clara e a1 escura: em cada bloco 2x2, escuras em cima à direita e embaixo à esquerda. */
  background: conic-gradient(transparent 90deg, var(--sq-dark) 90deg 180deg, transparent 180deg 270deg, var(--sq-dark) 270deg);
  background-size: 25% 25%;
}
.board coords { font-weight: 700; font-size: clamp(9px, 1.4vw, 12px) !important; }
/* O Chessground desloca as letras 24px para a direita e os números 20px para cima, medidas fixas
   que passam de meia casa num tabuleiro de celular (a letra caía na coluna seguinte). Aqui cada
   letra ocupa exatamente 1/8 da largura, no canto de baixo à direita da sua casa, e cada número
   fica no canto de cima à esquerda da sua fileira. */
.board coords.files { left: 0; bottom: 0; width: 100%; height: auto; }
.board coords.files coord { flex: 1 1 0; min-width: 0; text-align: right; padding: 0 3px 1px 0; }
.board coords.ranks { left: 0; top: 0; width: auto; }
.board coords.ranks coord { flex: 1 1 0; min-height: 0; transform: none; padding: 2px 0 0 3px; }

.promotion {
  position: absolute; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: center; justify-content: center;
}
.promotion .choices { display: flex; gap: 8px; background: var(--surface); padding: 10px; border-radius: 12px; box-shadow: var(--shadow); }
.promotion button { width: 72px; height: 72px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); cursor: pointer; padding: 6px; }
.promotion button:hover { background: var(--accent-soft); }
.promotion piece { display: block; width: 100%; height: 100%; background-size: cover; position: static !important; }

/* ---------- Tela Jogar ---------- */
.play { display: flex; gap: 24px; align-items: flex-start; }
.play .side { flex: 1; min-width: 280px; max-width: 420px; display: flex; flex-direction: column; gap: 16px; }
.player { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.player .name { font-weight: 700; }
.status-line { font-weight: 600; }
.status-line.thinking::after { content: ""; display: inline-block; width: 1em; animation: dots 1.2s steps(4) infinite; overflow: hidden; vertical-align: bottom; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.result-banner { border-radius: 10px; padding: 14px; text-align: center; background: var(--accent-soft); color: var(--accent-strong); font-weight: 700; }
.result-banner.derrota { background: rgba(180, 72, 58, .12); color: var(--danger); }
.result-banner.empate { background: var(--surface-2); color: var(--text); }
.result-banner small { display: block; font-weight: 500; opacity: .85; }

.movelist { max-height: 340px; overflow-y: auto; margin: 0; padding: 0; list-style: none; font-variant-numeric: tabular-nums; }
.movelist li { display: grid; grid-template-columns: 3em 1fr 1fr; padding: 3px 6px; border-radius: 6px; }
.movelist li:nth-child(odd) { background: var(--surface-2); }
.movelist .num { color: var(--text-muted); }
.movelist .san { font-weight: 600; }
.movelist .san.last { color: var(--accent-strong); }
.movelist-empty { color: var(--text-muted); font-style: italic; }
.review-bar { margin-top: 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border-radius: 10px; border: 2px solid var(--warning); background: rgba(168, 116, 26, .10); }
.review-bar[hidden] { display: none; }
.review-bar .review-text { font-weight: 600; }
.review-bar .review-text small { display: block; font-weight: 400; color: var(--text-muted); }
.review-bar .review-new { color: var(--warning); }
.board-wrap.reviewing .board { filter: saturate(.55) brightness(.97); }

/* Tela Jogar no computador (acima de 1000 px): a tela inteira sem rolar a página.
   Coluna do tabuleiro: o tabuleiro tem o tamanho da menor dimensão disponível e os botões ficam logo
   abaixo dele. Painel ao lado: rolagem própria; o texto do Tutor e a lista de lances rolam dentro do
   próprio cartão, para dar para ler o Tutor olhando o tabuleiro. */
@media (min-width: 1001px) {
  .play.game {
    --side-min: 300px; --gap: 24px;
    --bar: 0px;      /* barra de avaliação + espaço (só no treino) */
    --clocks: 0px;   /* os dois relógios, acima e abaixo do tabuleiro */
    --below: 104px;  /* as duas fileiras de botões embaixo do tabuleiro */
    /* Lado do tabuleiro: a menor dimensão que sobra (largura sem o painel, altura sem os botões). */
    --board: min(100cqw - var(--side-min) - var(--gap) - var(--bar), 100cqh - var(--below) - var(--clocks), 960px);
    container-type: size;
    height: max(480px, calc(100dvh - 56px));
    align-items: stretch; justify-content: center; gap: var(--gap);
  }
  .play.game:has(#eval-bar:not([hidden])) { --bar: 30px; }
  .play.game:has(.board-wrap.with-clock) { --clocks: 92px; }
  .play.game .board-col {
    flex: none; min-height: 0; display: flex; flex-direction: column; gap: 12px;
    width: calc(var(--board) + var(--bar));
  }
  .play.game .board-wrap, .play.game .board-wrap.with-clock {
    width: 100%; max-width: none; height: calc(var(--board) + var(--clocks)); flex: 0 1 auto; min-height: 0;
    container-type: size;
    display: flex; flex-direction: column;
  }
  .play.game .board-with-bar { align-self: center; }
  .play.game .board { flex: none; width: min(100cqw - var(--bar), 100cqh - var(--clocks)); }
  .play.game .btn-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .play.game .btn-row .btn { min-width: 0; padding-left: 8px; padding-right: 8px; white-space: nowrap; }
  .play.game .side {
    flex: 1 1 0; min-width: var(--side-min); max-width: 520px; min-height: 0;
    overflow-y: auto; overscroll-behavior: contain; padding: 0 4px 4px 0;
  }
  .play.game .side > * { flex: none; }
  .play.game .side > .player, .play.game .side > .status-card { padding: 12px 16px; }
  .play.game .review-bar { margin-top: 0; }
  .play.game .tutor { flex: 0 1 auto; min-height: 220px; display: flex; flex-direction: column; }
  .play.game .tutor > h2 { flex: none; }
  .play.game #tutor-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    margin-right: -10px; padding-right: 10px; }
  /* Com o Tutor aberto, a lista de lances cede mais espaço que ele (encolhe 4 vezes mais). */
  .play.game .moves-card { flex: 0 4 auto; min-height: 150px; display: flex; flex-direction: column; }
  .play.game .moves-card .movelist { flex: 1 1 auto; min-height: 0; }
}
@media (min-width: 1001px) and (max-width: 1200px) {
  .play.game { height: max(480px, calc(100dvh - 48px)); }
}

/* ---------- Escolha do adversário ---------- */
.setup { max-width: 980px; }
.opponents { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.opponent-card { position: relative; cursor: pointer; }
.opponent-card input { position: absolute; opacity: 0; pointer-events: none; }
.opponent-body {
  display: flex; flex-direction: column; gap: 6px; height: 100%;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 2px solid var(--border); box-shadow: var(--shadow);
  font-size: .9rem;
}
.opponent-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 1rem; }
.opponent-card:hover .opponent-body { border-color: var(--text-muted); }
.opponent-card input:checked + .opponent-body { border-color: var(--accent); background: var(--accent-soft); }
.opponent-card input:focus-visible + .opponent-body { outline: 2px solid var(--accent); outline-offset: 2px; }
.setup-options { max-width: 560px; }
.strength-help { margin: 8px 0 0; font-size: .9rem; }
.strength-manual { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.strength-manual input { flex: 1; accent-color: var(--accent); }
.strength-manual output { font-weight: 700; min-width: 3.5em; text-align: right; font-variant-numeric: tabular-nums; }
.opening-line { font-size: .88rem; margin-top: 4px; }
.rating-change { margin-top: 6px; }

/* ---------- Gráficos ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; outline: none; }
.chart svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-reference { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 4 4; opacity: .7; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-cross { stroke: var(--text-muted); stroke-width: 1; }
.chart-tip {
  position: absolute; pointer-events: none; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  border-radius: 8px; padding: 6px 10px; font-size: .85rem;
  display: flex; flex-direction: column; line-height: 1.3;
}
.chart-tip strong { font-size: 1rem; font-variant-numeric: tabular-nums; }
.chart-tip span { color: var(--text-muted); }
.chart-empty { color: var(--text-muted); padding: 24px 0; text-align: center; }

/* Gráfico de avaliação */
.eval-chart { cursor: pointer; }
.eval-white-zone { fill: var(--surface); }
.eval-black-zone { fill: var(--surface-2); }
.eval-area { fill: var(--accent); opacity: .12; }
.eval-cursor { stroke: var(--text); stroke-width: 1.5; }
.eval-mark { stroke: var(--surface); stroke-width: 2; }
.mark-imprecisao { fill: var(--sev-inaccuracy); }
.mark-erro { fill: var(--sev-mistake); }
.mark-erro_grave { fill: var(--sev-blunder); }
.mark-oportunidade_perdida { fill: var(--sev-missed); }

/* Barra de resultados V/E/D */
.wdl { display: flex; height: 10px; border-radius: 5px; overflow: hidden; gap: 2px; background: var(--surface); margin: 8px 0 6px; }
.wdl span { display: block; height: 100%; }
.wdl .w { background: var(--accent); }
.wdl .d { background: var(--text-muted); opacity: .55; }
.wdl .l { background: var(--danger); opacity: .8; }
.wdl-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--text-muted); }
.wdl-legend b { color: var(--text); font-variant-numeric: tabular-nums; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.key.w { background: var(--accent); }
.key.d { background: var(--text-muted); opacity: .55; }
.key.l { background: var(--danger); opacity: .8; }

/* Tabelas */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; font-variant-numeric: tabular-nums; }
.table th { text-align: left; font-weight: 600; color: var(--text-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.table td { padding: 8px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table a { color: inherit; font-weight: 600; text-decoration: none; }
.table a:hover { color: var(--accent); }
.table-wrap { overflow-x: auto; }
.outcome { font-weight: 700; }
.outcome.vitoria { color: var(--accent-strong); }
.outcome.derrota { color: var(--danger); }
.outcome.empate { color: var(--text-muted); }
.delta.up { color: var(--accent-strong); }
.delta.down { color: var(--danger); }

/* Painel */
.dash { display: grid; gap: 16px; grid-template-columns: repeat(12, 1fr); }
.dash > * { grid-column: span 12; min-width: 0; }
@media (min-width: 900px) {
  .dash .span-4 { grid-column: span 4; }
  .dash .span-6 { grid-column: span 6; }
  .dash .span-8 { grid-column: span 8; }
}
.stat-label { color: var(--text-muted); font-size: .85rem; }
.stat-value { font-size: 1.9rem; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: .95rem; font-weight: 500; color: var(--text-muted); }
/* Plano adaptativo: "Seu próximo passo" */
.plan-card { border-left: 4px solid var(--accent); }
.plan-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 10px; }
.plan-step { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--border); }
.plan-step:first-child { border-top: 0; padding-top: 2px; }
.plan-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent-strong); }
.plan-text h2 { margin: 0 0 2px; font-size: 1.05rem; }
.plan-text p { margin: 0; }
.plan-step .btn { white-space: nowrap; }
.plan-note { margin: 8px 0 0; }
@media (max-width: 560px) {
  .plan-step { grid-template-columns: auto 1fr; }
  .plan-step .btn { grid-column: 1 / -1; justify-content: center; }
}
.card h2 .badge { margin-left: 6px; vertical-align: 2px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

/* Análise */
.text-input, .pgn-input {
  font: inherit; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.pgn-input { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; resize: vertical; }
.alert.ok { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft); }
.alert ul { margin: 6px 0 0; padding-left: 1.2em; }
.progress { display: inline-block; width: 120px; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; vertical-align: middle; }
.progress span { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.progress.big { width: 100%; height: 12px; border-radius: 6px; margin: 8px 0; }
.board-with-bar { display: flex; gap: 8px; align-items: stretch; }
.board-with-bar .board { flex: 1; min-width: 0; }
.eval-bar { width: 22px; flex: none; border-radius: 6px; overflow: hidden; position: relative; background: #3a3a3a; display: flex; flex-direction: column-reverse; }
.eval-bar span { display: block; background: #f2f2f2; transition: height .3s; }
.eval-bar b { position: absolute; left: 0; right: 0; bottom: 4px; font-size: 9px; text-align: center; color: #444; font-variant-numeric: tabular-nums; }
.eval-bar[hidden] { display: none; }
/* Tela de jogo: com as pretas embaixo, a barra também vira (brancas em cima). */
.eval-bar.flipped { flex-direction: column; }
.eval-bar.flipped b { bottom: auto; top: 4px; }
.eval-bar b.black-ahead { color: #ddd; bottom: auto; top: 4px; }
.eval-bar.flipped b.black-ahead { top: auto; bottom: 4px; }
.eval-bar.loading span { opacity: .6; }
.chart-caption { font-size: .82rem; margin: 6px 0 0; }
.sev { font-weight: 700; white-space: nowrap; }
.sev-imprecisao { color: var(--sev-inaccuracy); }
.sev-erro { color: var(--sev-mistake); }
.sev-erro_grave { color: var(--sev-blunder); }
.sev-oportunidade_perdida { color: var(--sev-missed); }
.sev-badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-weight: 700; background: var(--surface-2); }
.sev-badge.sev-imprecisao, .sev-badge.sev-erro, .sev-badge.sev-erro_grave, .sev-badge.sev-oportunidade_perdida { color: #fff; }
.sev-badge.sev-imprecisao { background: var(--sev-inaccuracy); }
.sev-badge.sev-erro { background: var(--sev-mistake); }
.sev-badge.sev-erro_grave { background: var(--sev-blunder); }
.sev-badge.sev-oportunidade_perdida { background: var(--sev-missed); }
.sev-badge.sev-melhor, .sev-badge.sev-teoria { background: var(--accent-soft); color: var(--accent-strong); }
.detail-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-bottom: 10px; }
.explain { padding-left: 1.2em; margin: 0 0 8px; display: flex; flex-direction: column; gap: 8px; }
.small-text { font-size: .85rem; }
.analysis-moves { max-height: 260px; }
.analysis-moves sup { font-weight: 800; margin-left: 1px; }
.cls-imprecisao sup { color: var(--sev-inaccuracy); }
.cls-erro sup { color: var(--sev-mistake); }
.cls-erro_grave sup { color: var(--sev-blunder); }
.cls-oportunidade_perdida sup { color: var(--sev-missed); }
.movelist .san.current sup { color: #fff; }
.variation { margin-top: 12px; padding: 10px; border-radius: 10px; background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.variation-moves { display: flex; flex-wrap: wrap; gap: 4px 8px; font-weight: 600; }
.summary-sides { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.summary-counts { font-size: .92rem; }
/* Análise no computador: a coluna do tabuleiro (tabuleiro, navegação e legenda) cabe na tela e fica
   fixa enquanto a explicação, a lista de lances e o gráfico rolam ao lado. */
@media (min-width: 1001px) {
  .play.analysis .board-wrap { position: sticky; top: 12px; }
}
.reinforce-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.reinforce-list li { display: flex; justify-content: space-between; gap: 12px; }

/* Visualizador */
.viewer-nav { display: flex; gap: 6px; justify-content: center; }
/* Navegação logo abaixo do tabuleiro (análise e partida): botões grandes o bastante para o dedo. */
.board-wrap.with-nav { width: min(100%, calc(100vh - 150px)); }
.board-nav { margin-top: 10px; flex-wrap: wrap; }
.board-nav .btn { min-width: 44px; min-height: 40px; justify-content: center; }
.board-nav #arrows-toggle[aria-pressed="false"] { opacity: .75; }
.arrow-legend { text-align: center; margin: 6px 0 0; }
.arrow-key { display: inline-block; width: 18px; height: 4px; border-radius: 2px; vertical-align: middle; }
.arrow-key.played { background: #003088; }
.arrow-key.best { background: #15781b; }
.movelist .san.clickable { cursor: pointer; border-radius: 4px; padding: 0 4px; margin: 0 -4px; }
.movelist .san.clickable:hover { background: var(--accent-soft); }
.movelist .san.current { background: var(--accent); color: #fff; }

/* ---------- Início ---------- */
.rating-card { display: flex; flex-wrap: wrap; align-items: center; gap: 16px 32px; margin-bottom: 16px; }
.rating-number { font-size: 2rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.rating-number .muted { font-size: 1rem; font-weight: 500; }
.hero { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.module-card h2 { display: flex; align-items: center; gap: 10px; }
.module-card .badge { margin-bottom: 8px; }
.placeholder { max-width: 680px; }
.placeholder ul { padding-left: 1.2em; }

/* ---------- Responsivo ---------- */
@media (max-width: 1200px) and (min-width: 721px) {
  /* Menu só com ícones, para sobrar espaço ao tabuleiro. */
  :root { --sidebar-w: 68px; }
  .brand span, .nav a span, .theme-toggle span { display: none; }
  .brand, .nav a, .theme-toggle { justify-content: center; padding-left: 0; padding-right: 0; }
  .content { padding: 24px; }
}
@media (max-width: 1000px) {
  .play { flex-direction: column; align-items: stretch; }
  .board-wrap { width: min(100%, 72vh); margin: 0 auto; }
  .play .side { max-width: none; }
}
/* Celular e tablet em pé, tela Jogar: adversário acima do tabuleiro, situação e comandos logo abaixo,
   Tutor e lista de lances por último (no computador, tudo fica na coluna ao lado). */
@media (max-width: 1000px) {
  .play.game { gap: 12px; }
  .play.game .side, .play.game .board-col { display: contents; }
  .play.game .side > .player { order: -1; padding: 10px 14px; }
  .play.game .board-wrap, .play.game .review-bar { order: 0; }
  .play.game .review-bar { margin-top: 0; }
  .play.game .side > .status-card { order: 1; padding: 10px 14px; }
  .play.game .game-actions { order: 2; }
  .play.game .side > .tutor { order: 3; }
  .play.game .side > .moves-card { order: 4; }
  .play.game .game-more { order: 5; }
  .play.game .moves-card .movelist { max-height: 180px; }
  /* Análise: tabuleiro e navegação, depois a explicação do lance e a lista; gráfico e resumo por último. */
  .play.analysis { gap: 12px; }
  .play.analysis .board-wrap, .play.analysis .side { display: contents; }
  .play.analysis .board-with-bar, .play.analysis .board-nav, .play.analysis .arrow-legend {
    width: min(100%, 72vh); margin-left: auto; margin-right: auto; }
  .play.analysis .board-nav { margin-top: 0; }
  .play.analysis .arrow-legend { margin-top: -4px; }
  .play.analysis .side > #detail { order: 1; }
  .play.analysis .side > .moves-card { order: 2; }
  .play.analysis .side > .chart-card { order: 3; }
  .play.analysis .side > .summary-card { order: 4; }
  .play.analysis .side > .analysis-actions { order: 5; }
  .play.analysis .side > .analysis-note { order: 6; }
  .play.analysis .moves-card .movelist { max-height: 180px; }
}
@media (max-width: 560px) {
  /* Tabelas de partidas: no celular, só as colunas essenciais. */
  .table .hide-sm { display: none; }
  /* Analisar: as partidas (o uso mais comum) antes da importação de PGN. */
  .dash > .import-card { order: 1; }
  .play.game .btn-row .btn { flex: 1 1 auto; justify-content: center; }
  .board-nav .btn { flex: 1 1 0; padding-left: 6px; padding-right: 6px; }
  .board-nav [data-go="error"], .board-nav #arrows-toggle { flex-basis: 40%; }
}
@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; z-index: 30;
    width: 100%; height: auto; flex-direction: row; padding: 4px;
    border-right: 0; border-top: 1px solid var(--border);
  }
  .brand, .theme-toggle span { display: none; }
  .nav { flex-direction: row; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: .68rem; }
  .theme-toggle { padding: 6px; }
  .content { padding: 16px 16px 84px; }
}

/* Menu recolhido pelo botão "Recolher menu" (só em tela larga: entre 721 e 1200 px ele já fica só
   com ícones, e no celular vira a barra de baixo). A escolha fica gravada no navegador. */
#nav-toggle .icon { transition: transform .2s; }
.app.nav-collapsed #nav-toggle .icon { transform: rotate(180deg); }
@media (min-width: 1201px) {
  .app.nav-collapsed { --sidebar-w: 68px; }
  .app.nav-collapsed .brand span, .app.nav-collapsed .nav a span, .app.nav-collapsed .theme-toggle span,
  .app.nav-collapsed .account-info, .app.nav-collapsed .credit { display: none; }
  .app.nav-collapsed .brand, .app.nav-collapsed .nav a, .app.nav-collapsed .theme-toggle {
    justify-content: center; padding-left: 0; padding-right: 0; }
}
@media (max-width: 1200px) { #nav-toggle { display: none; } }

/* Crédito do autor, no pé do menu lateral. Some quando o menu fica só com ícones. */
.credit { margin: 10px 0 0; padding: 0 10px; font-size: .72rem; color: var(--text-muted, var(--muted, #888)); }
@media (max-width: 1200px) { .credit { display: none; } }

/* Tutor (tela de jogo) */
.tutor[hidden] { display: none; }
.tutor h2 svg { width: 18px; height: 18px; vertical-align: -3px; }
.tutor-intro { margin: 0 0 10px; }
.tutor-warn { margin: 0 0 10px; color: var(--warning); }
.tutor-wait { display: block; margin-top: 6px; }
.tutor-step { margin-bottom: 12px; }
.tutor-step h3 { font-size: 0.95rem; margin: 0 0 6px; }
.tutor-step p { margin: 0 0 6px; line-height: 1.45; }
.tutor-where { margin: 0 0 10px; font-size: .9rem; }
.tutor-line { white-space: normal; }
.tutor-move { font: inherit; font-weight: 600; color: var(--accent-strong); background: none; border: 0; cursor: pointer;
  border-radius: 4px; padding: 0 3px; margin: 0 -1px; }
.tutor-move:hover { background: var(--accent-soft); }
.tutor-move.current { background: var(--accent); color: #fff; }
.tutor-variant-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 4px 0 8px; }
.tutor-variant-nav .muted { flex: 1 1 auto; font-size: .85rem; }
/* Tutor professor: quem explica (programa, Carlsen ou Tal) e a marca discreta do texto da IA */
.tutor-professors { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 8px; }
.tutor-professors .chip { font: inherit; font-size: .82rem; padding: 2px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: transparent; color: var(--text); }
.tutor-professors .chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tutor-professors .chip:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 1px; }
.tutor-ia-badge { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 4px; font-size: .72rem;
  color: var(--text-muted); border: 1px dashed var(--border); white-space: nowrap; cursor: help; }
.tutor-ia-program { margin: 0 0 6px; font-size: .9rem; }
.tutor-ia-program summary { cursor: pointer; color: var(--text-muted); }
.tutor-ia-note, .tutor-ia-off { font-size: .82rem; margin: 0 0 6px; }
.tutor-step button.link { font: inherit; background: none; border: 0; padding: 0; color: var(--accent-strong);
  text-decoration: underline; cursor: pointer; }

/* ---------- Contas: tela de entrada, conta no menu e administração ---------- */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: min(100%, 420px); text-align: center; padding: 28px 24px; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 1.5rem; font-weight: 800; margin-bottom: 12px; }
.login-card .alert { text-align: left; }
.google-btn { display: inline-flex; align-items: center; justify-content: center; gap: 12px; width: 100%; padding: 12px 16px; font-weight: 600; text-decoration: none; color: var(--text); margin: 8px 0 12px; }
.google-mark { width: 20px; height: 20px; flex: none; }
.login-credit { display: block !important; margin-top: 18px; }

.account { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 8px; }
.account-info { display: flex; flex-direction: column; padding: 4px 12px 6px; min-width: 0; }
.account-name { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-email { color: var(--text-muted); font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .theme-toggle { width: 100%; }

.admin-form .text-input { flex: 1 1 220px; min-width: 0; }
.table-scroll { overflow-x: auto; }
.table td.right { text-align: right; }
.row-actions { justify-content: flex-end; flex-wrap: nowrap; }
.row-actions .btn { white-space: nowrap; }

/* ---------- Tela de abertura ----------
   Aparece desde o primeiro desenho (inclusive no iPhone, que não monta tela de abertura pela
   manifest) e some quando a interface fica pronta. Não atrasa nada: só cobre a espera real. */
.splash {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: var(--bg); color: var(--text);
  transition: opacity .25s ease, visibility .25s;
}
.splash img { width: 96px; height: 96px; }
.splash-name { font-size: 1.35rem; font-weight: 700; letter-spacing: .01em; }
.splash.done { opacity: 0; visibility: hidden; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { .splash { transition: none; } }

@media (max-width: 1200px) and (min-width: 721px) {
  .account-info { display: none; }
  .account .theme-toggle { justify-content: center; padding-left: 0; padding-right: 0; }
}
@media (max-width: 720px) {
  .account { border-top: 0; margin: 0; padding: 0; display: flex; align-items: center; }
  .account-info, .account .theme-toggle span { display: none; }
  .account .theme-toggle { width: auto; }
}
@media (max-width: 720px) {
  /* Com "Contas" e "Sair", os botões podem passar da largura: a barra rola na horizontal. */
  .sidebar { overflow-x: auto; scrollbar-width: none; }
  .sidebar::-webkit-scrollbar { display: none; }
  .nav { flex: 1 0 auto; }
}

/* ---------- Treinar (Fase 5) ---------- */
.train-tabs { margin-bottom: 18px; }
.train-tabs a { display: block; padding: 7px 16px; border-radius: 8px; color: var(--text-muted); font-weight: 600; text-decoration: none; }
.train-tabs a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.train-resume { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.subject-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.subject-card { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; text-align: left; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; cursor: pointer; }
.subject-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.subject-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.subject-name { font-weight: 700; }
.subject-card .progress { width: 100%; height: 6px; }
.small-head { font-size: .95rem; margin: 10px 0 6px; }
.small-head:first-child { margin-top: 0; }
.solution-list { max-height: 220px; }
.solution-list li { grid-template-columns: 3.5em 1fr; }
.solution-list li.voce .san { color: var(--accent-strong); }
.solution-list li.voce .san.current { color: #fff; }
.lesson-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; counter-reset: lesson; }
.lesson-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid transparent; }
.lesson-list li.next { border-color: var(--accent); }
.lesson-list li.done b { color: var(--accent-strong); }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.status-line.end-resolvido { color: var(--accent-strong); }
.status-line.end-errou { color: var(--danger); }
.section-title .badge { white-space: nowrap; }
.reinforce-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.reinforce-list li > span:first-child { flex: 1; min-width: 0; }
.tree-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 360px; overflow-y: auto; }
.tree-list li { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 4px 6px; border-radius: 6px; }
.tree-list li:hover { background: var(--surface-2); }
.tree-list a { color: var(--text); text-decoration: none; display: flex; flex-direction: column; min-width: 0; }
.variation-moves a { color: var(--text); text-decoration: none; }
.variation-moves a:hover { color: var(--accent); }

/* ---------- Repertório de aberturas (Fase 6) ---------- */
.rep-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }
.rep-card { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.rep-card p, .rep-card ul { margin: 0; }
.rep-progress .progress.big { margin: 0 0 4px; }
.rep-lines { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rep-lines li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 8px; background: var(--surface-2); }
.rep-lines li > div { min-width: 0; }
.rep-lines .btn-row { flex-wrap: nowrap; }
.rep-line-tabs { margin-bottom: 14px; }
.rep-notes { margin: 0; display: grid; gap: 4px; }
.rep-notes dt { font-weight: 700; margin-top: 6px; }
.rep-notes dt:first-child { margin-top: 0; }
.rep-notes dd { margin: 0; }
.rep-wrong, .rep-bad { color: var(--danger); }
.rep-good { color: var(--accent-strong); }
.rep-movelist a { padding: 0 4px; border-radius: 4px; }
.rep-movelist a.own { font-weight: 700; }
.rep-movelist a:not(.own) { font-weight: 500; color: var(--text-muted); }
.rep-movelist a.current { background: var(--accent); color: #fff; }
.rep-movelist sup { font-size: .7em; margin-left: 1px; }
.rep-ok { color: var(--accent-strong); }
.rep-due { color: var(--warning); }
.rep-deviation { margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); }
.rep-deviation p { margin: 0; }
.rep-deviation .btn-row { margin-top: 6px; }
.rep-dash-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rep-dash-list li { display: flex; flex-direction: column; gap: 2px; }
.rep-dash-list .progress { width: 100%; height: 6px; }
@media (max-width: 560px) {
  .rep-grid { grid-template-columns: 1fr; }
  .rep-lines li { flex-direction: column; align-items: flex-start; }
}

/* ---------- Janela de confirmação (confirmDialog em ui.js) ---------- */
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-fill:hover:not(:disabled) { filter: brightness(.92); }
.confirm-dialog {
  width: min(440px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
.confirm-dialog::backdrop { background: rgba(0, 0, 0, .45); }
.confirm-dialog form { padding: 20px; }
.confirm-dialog h2 { margin: 0 0 10px; font-size: 1.15rem; }
.confirm-dialog p { margin: 0 0 10px; line-height: 1.45; }
.confirm-dialog p + p { color: var(--text-muted); }
.confirm-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }
@media (max-width: 480px) {
  .confirm-actions { flex-direction: column-reverse; }
  .confirm-actions .btn { width: 100%; justify-content: center; }
}

/* Lichess e Chess.com na tela Analisar (item 6 do backlog) */
.external-sites { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.external-site { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.external-site h3 { margin: 0 0 6px; font-size: 1rem; }
.external-site p { margin: 0 0 10px; }
.external-site .text-input { flex: 1 1 160px; min-width: 0; }
.ext-analysis { margin: 14px 0 0; }
.source-tag { font-size: .8rem; }

/* ---------- Relógio (item 10) ---------- */
/* Acima e abaixo do tabuleiro: o tabuleiro encolhe um pouco para os dois caberem sem rolagem. */
.board-wrap.with-clock { width: min(100%, calc(100vh - 150px)); }
.clock-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0; }
.clock-row[hidden] { display: none; }
.clock-name { font-weight: 600; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clock-time {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.35rem; line-height: 1.2;
  padding: 3px 12px; min-width: 5.2em; text-align: right; border-radius: 8px;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.clock-row.running .clock-name { color: var(--text); }
.clock-row.running .clock-time { background: var(--accent); border-color: var(--accent); color: #fff; }
.clock-row.low .clock-time { color: var(--danger); border-color: var(--danger); }
.clock-row.low.running .clock-time { background: var(--danger); border-color: var(--danger); color: #fff; }
.clock-row.over .clock-time { font-style: italic; }
.clock-custom { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.clock-custom[hidden] { display: none; }
.clock-custom label { display: flex; align-items: center; gap: 6px; }
.clock-custom input { width: 5em; }
@media (max-width: 1000px) {
  .board-wrap.with-clock { width: min(100%, calc(72vh - 70px)); }
}
@media (max-width: 560px) {
  .clock-row { margin: 4px 0; }
  .clock-time { font-size: 1.15rem; padding: 2px 10px; }
}
