:root {
  --bg: #0a0e19;
  /* degradê: base escura com três "luzes" de cor (verde-água, índigo e azul) */
  --bg-gradient:
    radial-gradient(70vmax 55vmax at 0% 0%, rgba(45, 212, 191, 0.34), transparent 60%),
    radial-gradient(65vmax 55vmax at 100% 0%, rgba(124, 92, 255, 0.40), transparent 60%),
    radial-gradient(80vmax 60vmax at 50% 118%, rgba(14, 165, 233, 0.30), transparent 62%),
    linear-gradient(160deg, #111a35 0%, #0a0e19 52%, #0d1326 100%);
  --panel: #131a2a;
  --panel-2: #1b2437;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #49d8b8;
  --danger: #f43f5e;
  --blue: #4c9dff;
  --light: #d2dee3;
  --dark: #6d90a6;
  /* tabuleiro: nunca encosta na borda (20px de respiro) nem estoura a altura */
  /* Desktop: o tabuleiro ocupa quase toda a altura (sobram topo, rodapé e a linha do
     rating do puzzle) e o painel fica à direita. O celular redefine isto lá embaixo. */
  --side: 300px;
  --size: min(calc(100dvh - 164px), calc(100vw - var(--side) - 68px), 900px);
}

* { box-sizing: border-box; }

body { min-height: 100dvh; }

body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- topo ---------- */
.top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 22px;
  padding: 14px 20px;
  padding-top: max(14px, env(safe-area-inset-top));
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand img { display: block; border-radius: 50%; }
.brand-name { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name small { font-size: 10.5px; font-weight: 600; letter-spacing: 0.04em; color: var(--muted); opacity: 0.8; }
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.nav a:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.nav a.active { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.top-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.icon-btn, .user-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.icon-btn { width: 38px; }
.user-btn { padding: 0 12px; font-size: 14px; font-weight: 600; color: var(--text); }
.user-name { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn:hover, .icon-btn[aria-expanded="true"], .user-btn:hover, .user-btn[aria-expanded="true"] {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--blue);
}
.flag { display: block; width: 22px; height: 15px; border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14); flex: none; }
.flag svg { display: block; width: 100%; height: 100%; }
.menu { position: relative; }
.burger { display: none; }
.burger .menu-list { left: 0; right: auto; }
.burger .menu-list [aria-current="page"] { color: var(--accent); font-weight: 700; }
.menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  min-width: 176px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.5);
}
.menu-list[hidden] { display: none; }
.menu-list form { display: contents; }
.menu-list a, .menu-list button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
}
.menu-list a:hover, .menu-list button:hover, .menu-list a:focus-visible, .menu-list button:focus-visible { outline: none; background: var(--panel-2); }
.menu-list [aria-checked="true"] { color: var(--accent); font-weight: 700; }
.flash {
  /* aviso passageiro ("você entrou como…"): no topo, centralizado, some sozinho */
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  translate: -50% 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: calc(100vw - 32px);
  pointer-events: none;
  animation: flash 5s ease forwards;
}
.flash span { padding: 7px 14px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; font-weight: 600; box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35); }

/* Minha conta: largura de página normal, seções em duas colunas no computador */
.auth.account { width: min(640px, calc(100vw - 40px)); }
.auth.account h1 { margin-bottom: 22px; }
.acc-grid { display: grid; gap: 16px; }
.acc-grid .acc-card { margin: 0; }
.auth a.rk-btn { color: var(--text); text-decoration: none; }
.account .acc-card { margin: 0 0 16px; padding: 18px 20px; border: 1px solid var(--line); border-radius: 14px; background: rgba(19, 26, 42, 0.72); }
.account h2 { margin: 0 0 6px; font-size: 16px; }
.account .acc-help { margin: 0 0 12px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.account form { margin: 0; }
.account .acc-row { display: flex; flex-direction: row; gap: 10px; margin: 0; }
.account .acc-row input { flex: 1; min-width: 0; }
.account form .acc-row button[type="submit"] { flex: none; width: auto; margin: 0; padding: 0 22px; }
.account .acc-links { margin: 16px 0 0; }
.account .acc-help + .acc-links, .account h2 + .acc-links { margin-top: 14px; }
.account form button.acc-save[type="submit"] { display: inline-flex; align-self: flex-start; width: auto; margin: 4px 0 0; padding: 12px 26px; }
.auth .name-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.auth .check-row { margin: 4px 0 16px; }
.auth .check-row label { display: flex; align-items: center; gap: 10px; font-weight: 500; color: var(--muted); cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- palco: tabuleiro + painel ---------- */
.stage {
  flex: 1;
  display: grid;
  grid-template-columns: var(--size) var(--side);
  grid-template-areas: "board side" "meta side";
  justify-content: center;
  align-content: center;
  gap: 10px 28px;
  padding: 6px 20px 8px;
  min-height: 0;
}
.board-wrap { grid-area: board; }
.meta { grid-area: meta; color: var(--muted); font-size: 13px; min-height: 18px; min-width: 0; }
.meta a { color: var(--muted); }
.side {
  grid-area: side;
  align-self: start;
  min-height: var(--size);
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(19, 26, 42, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 18px 32px -16px rgba(0, 0, 0, 0.7), 0 6px 14px -8px rgba(0, 0, 0, 0.5);
}
.status { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.turn { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 600; min-width: 0; white-space: nowrap; }
.turn-dot {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.18);
}
.turn.black .turn-dot { background: #10141f; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.45); }
.timer {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  color: var(--text);
}
.timer.stopped { color: var(--muted); }
.rating {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.rating-label { flex-basis: 100%; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.rating-value { font-weight: 700; font-size: 30px; letter-spacing: -0.02em; }
.rating-delta { font-size: 15px; font-weight: 700; }
.rating-delta:empty { display: none; }       /* sem variação, não reserva espaço */
.rating-delta.up { color: var(--accent); }
.rating-delta.down { color: var(--danger); }

/* ---------- tabuleiro ---------- */
.board-wrap { width: var(--size); height: var(--size); }
/* antes do JavaScript montar o tabuleiro: as casas já aparecem (CSS) com um "carregando" */
#board:empty {
  position: relative;
  width: 100%; height: 100%;
  background: repeating-conic-gradient(var(--dark) 0 25%, var(--light) 0 50%) 0 0 / 25% 25%;
  border-radius: 8px;
}
#board:empty::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 44px; height: 44px;
  border: 4px solid rgba(10, 14, 25, 0.25); border-top-color: rgba(10, 14, 25, 0.75); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.board {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  /* a sombra projetada do ChessMaker */
  box-shadow: 0 18px 32px -16px rgba(0, 0, 0, 0.7), 0 6px 14px -8px rgba(0, 0, 0, 0.5);
}
.squares { position: absolute; inset: 0; display: grid; grid-template: repeat(8, 1fr) / repeat(8, 1fr); border-radius: inherit; overflow: hidden; }
.sq { position: relative; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.last::before, .sq.sel::before, .sq.hint::before, .sq.check::before {
  content: "";
  position: absolute;
  inset: 0;
}
.sq.last::before { background: rgba(247, 214, 76, 0.5); }
.sq.sel::before { background: rgba(73, 216, 184, 0.55); }
.sq.check::before { background: radial-gradient(circle, rgba(244, 63, 94, 0.9) 0%, rgba(244, 63, 94, 0.45) 45%, transparent 72%); }
.sq.hint::before { background: rgba(73, 216, 184, 0.55); animation: pulse 1.1s ease-in-out infinite; }
.sq.dot::after, .sq.ring::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
  pointer-events: none;
}
.sq.dot::after { width: 30%; height: 30%; background: rgba(11, 15, 25, 0.22); }
.sq.ring::after { width: 86%; height: 86%; border: calc(var(--size) / 8 * 0.09) solid rgba(11, 15, 25, 0.22); }
.coord {
  position: absolute;
  font-size: clamp(9px, calc(var(--size) / 8 * 0.17), 13px);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}
.coord.rank { top: 4%; left: 5%; }
.coord.file { bottom: 4%; right: 6%; }
.sq.light .coord { color: var(--dark); }
.sq.dark .coord { color: var(--light); }

.pieces { position: absolute; inset: 0; pointer-events: none; }
.piece {
  position: absolute;
  top: 0;
  left: 0;
  width: 12.5%;
  height: 12.5%;
  background-size: 94%;
  background-position: center;
  background-repeat: no-repeat;
  transition: transform 190ms cubic-bezier(0.25, 0.8, 0.3, 1);
  will-change: transform;
}
.piece.no-anim, .piece.dragging { transition: none; }
.piece.dragging { z-index: 5; scale: 1.12; filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.35)); }
.board.shake { animation: shake 0.34s ease-in-out; }

/* selos (✓, ✕, #) no canto superior direito da casa; podem passar um pouco da borda */
.badges { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
/* seta do melhor lance (análise) */
.arrows { position: absolute; inset: 0; z-index: 4; width: 100%; height: 100%; pointer-events: none; opacity: 0.85; }
.arrows path { stroke: #2f9d86; fill: #2f9d86; }
.arrows .head { stroke: none; }
.badge {
  position: absolute;
  width: 5.4%;
  aspect-ratio: 1;
  translate: -64% -36%;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
  animation: pop 0.24s cubic-bezier(0.3, 1.7, 0.5, 1) both;
}
.badge svg { display: block; width: 100%; height: 100%; }

.promo {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(11, 15, 25, 0.55);
}
.promo-card { display: flex; gap: 8px; padding: 10px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
.promo-card button {
  width: calc(var(--size) / 8);
  height: calc(var(--size) / 8);
  border-radius: 10px;
  border: 1px solid transparent;
  background-color: var(--light);
  background-size: 90%;
  background-position: center;
  background-repeat: no-repeat;
}
.promo-card button:hover, .promo-card button:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

/* ---------- mensagem e botões ---------- */
.feedback { display: flex; align-items: center; gap: 8px; margin-top: auto; font-size: 16px; font-weight: 600; line-height: 1.3; min-height: 24px; }
.feedback-icon { flex: none; width: 22px; height: 22px; }
.feedback-icon svg { display: block; width: 100%; height: 100%; }
.feedback.good { color: var(--accent); }
.feedback.bad { color: var(--danger); }
.actions { display: flex; flex-direction: column; gap: 8px; }
.actions button, .actions .btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
}
.actions .btn { color: inherit; text-decoration: none; }
.actions [hidden] { display: none; }
.actions button, .actions .btn { transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease; }
.actions button:hover:not(:disabled), .actions .btn:hover {
  background: var(--panel-2);
  border-color: var(--blue);
  box-shadow: 0 0 0 1px var(--blue);
}
.actions button:disabled { opacity: 0.4; cursor: default; }
.actions button svg { flex: none; }
.actions button.primary.ready, .actions a.primary { background: var(--accent); border-color: var(--accent); color: #06231d; }
.actions button.primary.ready:hover, .actions a.primary:hover {
  background: #6fe6cb;
  border-color: #b9f5e6;
  box-shadow: 0 0 0 1px #b9f5e6, 0 8px 20px -8px rgba(73, 216, 184, 0.7);
}
.actions button:focus-visible, .actions .btn:focus-visible, .icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--accent); }

/* ---------- treino de aberturas ---------- */
.crumb { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.crumb a, .crumb small { color: var(--muted); text-decoration: none; font-size: 14px; }
.crumb a:hover { color: var(--text); }
.crumb span { font-size: 20px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; }
.trainer .status { flex-direction: column; align-items: stretch; gap: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.daily .status { padding-top: 14px; border-top: 1px solid var(--line); }

/* ---------- análise (Stockfish) ---------- */
.analysis { display: flex; flex-direction: column; gap: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.analysis[hidden] { display: none; }
.an-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.an-eval { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.an-depth { color: var(--muted); font-size: 12px; text-align: right; }
.an-bar { height: 8px; border-radius: 999px; background: #10141f; box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
.an-bar i { display: block; width: 50%; height: 100%; background: #f8fafc; transition: width 0.3s ease; }
.an-line { min-height: 38px; color: #cbd5e1; font-size: 13px; line-height: 1.45; font-variant-numeric: tabular-nums; }
.an-nav { display: flex; gap: 6px; }
.an-nav button {
  flex: 1;
  display: grid;
  place-items: center;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.an-nav button:hover:not(:disabled) { background: var(--panel-2); border-color: var(--blue); }
.an-nav button:disabled { opacity: 0.35; cursor: default; }
.an-nav button:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--accent); }
/* no desktop o calendário dá lugar à análise (os dois não cabem na altura do painel) */
.side.analyzing .calendar { display: none; }

/* ---------- calendário do puzzle do dia ---------- */
.calendar { padding-top: 14px; border-top: 1px solid var(--line); }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { font-size: 14px; font-weight: 700; }
.cal-nav {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.cal-nav:hover:not(:disabled) { background: var(--panel-2); border-color: var(--blue); color: var(--text); }
.cal-nav:disabled { opacity: 0.3; cursor: default; }
.cal-nav:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--accent); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-dow { padding-bottom: 2px; text-align: center; color: var(--muted); font-size: 11px; font-weight: 600; }
.cal-day {
  position: relative;
  display: grid;
  place-items: center;
  height: 30px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  isolation: isolate;
}
/* Todo estado de um dia (hover, hoje, aberto, resolvido) é o MESMO círculo atrás do número. */
.cal-day::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  margin: auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}
.cal-day.off { color: rgba(148, 163, 184, 0.32); }
a.cal-day:not(.selected):hover::before { background: var(--panel-2); box-shadow: 0 0 0 1px var(--blue); }
.cal-day.today::before { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4); }
.cal-day.solved { color: #06231d; font-weight: 700; }
.cal-day.solved::before { background: var(--accent); }
a.cal-day.solved:hover::before { background: #6fe6cb; }
.cal-day.selected { color: #0b0f19; }
.cal-day.selected::before { background: var(--text); box-shadow: none; }
/* dia aberto que também está resolvido: verde, com um contorno branco por dentro */
.cal-day.selected.solved::before { background: var(--accent); box-shadow: inset 0 0 0 2px var(--text); }
.cal-day:focus-visible { outline: none; box-shadow: none; }
.cal-day:focus-visible::before { box-shadow: 0 0 0 2px var(--accent); }
.cal-today { display: inline-block; margin-top: 8px; color: var(--accent); font-size: 13px; font-weight: 600; text-decoration: none; }
.cal-today:hover { text-decoration: underline; }
.trainer .segmented button { flex: 1; }
.progress { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dots { display: flex; gap: 5px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: rgba(255, 255, 255, 0.14); }
.dots i.on { background: var(--accent); }
.dots i.next { background: transparent; box-shadow: inset 0 0 0 2px var(--accent); }
.count { color: var(--muted); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* seletor Brancas/Pretas: uma pílula desliza por trás da opção escolhida. Ela só aparece
   quando o JavaScript já sabe a cor (data-side), sem piscar "nada escolhido" ao carregar,
   e só anima depois do primeiro desenho (data-ready). */
.segmented {
  position: relative; display: grid; grid-template-columns: 1fr 1fr;
  padding: 3px; border-radius: 10px; background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line);
}
.segmented::before {
  content: ""; position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc((100% - 6px) / 2);
  border-radius: 7px; background: var(--text); opacity: 0;
}
.segmented[data-side]::before { opacity: 1; }
.segmented[data-side="black"]::before { transform: translateX(100%); }
.segmented[data-ready]::before { transition: transform 0.28s cubic-bezier(0.3, 0.7, 0.2, 1); }
.segmented button {
  position: relative; z-index: 1;
  padding: 6px 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  transition: color 0.2s ease;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { color: #0b0f19; }
@media (prefers-reduced-motion: reduce) { .segmented[data-ready]::before { transition: none; } }
/* aviso sobre o tabuleiro (treino de aberturas) */
.board-wrap { position: relative; }
.board-note {
  position: absolute; inset: 0; z-index: 8; display: grid; place-items: center; padding: 20px;
  border-radius: 8px; background: rgba(5, 8, 16, 0.55); backdrop-filter: blur(2px);
}
.board-note[hidden] { display: none; }
.board-note-card {
  max-width: 400px; padding: 32px 30px 28px; border: 1px solid var(--line); border-radius: 16px;
  background: var(--panel); text-align: center; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.board-note-card p { margin: 0 0 24px; font-size: 18px; font-weight: 700; line-height: 1.5; }
.board-note-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.board-note-actions button:not([hidden]) + button { min-width: 0; }
.board-note-card .board-note-actions button.secondary, .board-note-card .board-note-actions button.secondary + button { padding: 12px 20px; }
.board-note-card button.secondary { background: rgba(255, 255, 255, 0.06); color: var(--text); border: 1px solid var(--line); }
.board-note-card button.secondary:hover { background: rgba(255, 255, 255, 0.1); }
.board-note-card button { padding: 12px 30px; border: 0; border-radius: 10px; background: var(--accent); color: #06231d; font-weight: 700; }
.board-note-card button:hover { background: #5fe3c6; }

/* botão liga/desliga (Setas no treino de aberturas) */
.actions button.toggle[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.segmented button:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--accent); }

/* ---------- listas (aberturas e variantes) ---------- */
.page { flex: 1 0 auto; width: min(760px, calc(100vw - 40px)); margin: 0 auto; padding: 18px 0 56px; }
.page h1 { margin: 6px 0 6px; font-size: 30px; letter-spacing: -0.02em; }
.lead { margin: 0 0 22px; color: var(--muted); }
.back { display: inline-block; color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--text); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
/* variantes de uma abertura: um pouco mais de respiro entre voltar, título e cards */
.opening-detail .back { margin-top: 6px; }
.opening-detail h1 { margin: 10px 0 24px; }
.opening-detail .cards { gap: 16px; }
.opening-detail .card { gap: 8px; padding: 16px; }
.opening-detail .card-board { margin-bottom: 10px; }
.card, .row {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(19, 26, 42, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, translate 0.15s ease;
}
.card:hover, .row:hover { background: rgba(27, 36, 55, 0.9); border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.card:hover { translate: 0 -2px; }
.card:focus-visible, .row:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--accent); }
.card { display: flex; flex-direction: column; gap: 6px; padding: 14px; }
/* mini tabuleiro do card: não interativo (o clique é do card) e sem coordenadas */
.card-board { aspect-ratio: 1; margin-bottom: 8px; pointer-events: none; }
.mini.board { box-shadow: 0 8px 18px -10px rgba(0, 0, 0, 0.7); border-radius: 5px; touch-action: auto; }
.mini .coord { display: none; }
.mini .sq.dot::after, .mini .sq.ring::after { display: none; }
.card-title { font-size: 18px; font-weight: 700; }
.row-moves { color: var(--muted); font-size: 13px; line-height: 1.45; font-variant-numeric: tabular-nums; }
.card-foot { margin-top: auto; padding-top: 8px; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.card-pills { display: flex; flex-wrap: wrap; gap: 6px; text-transform: none; letter-spacing: 0; }
.rows { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; }
.row-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.row-title { font-size: 17px; font-weight: 700; }
.row-progress { display: flex; gap: 6px; flex: none; }
.pill { padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--muted); background: rgba(255, 255, 255, 0.06); white-space: nowrap; }
.pill.some { color: var(--text); }
.pill.done { color: #06231d; background: var(--accent); }
/* abertura com todas as variantes completas: moldura verde e etiqueta no rodapé */
.card.complete { border-color: rgba(73, 216, 184, 0.65); box-shadow: 0 0 0 1px rgba(73, 216, 184, 0.35), 0 10px 30px -12px rgba(73, 216, 184, 0.55); }
.card.complete .card-foot { text-transform: none; letter-spacing: 0; }
.done-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; background: var(--accent); color: #06231d; font-size: 12.5px; font-weight: 700; }

/* ---------- rodapé ---------- */
.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 20px;
  padding: 12px 20px max(12px, env(safe-area-inset-bottom));
  font-size: 13px;
  color: var(--muted);
}
.foot nav { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.foot a { color: var(--muted); text-decoration: none; transition: color 0.15s ease; }
.foot a:hover { color: var(--text); }
/* botão "Configurar cookies" dentro da página de cookies */
.consent-open { padding: 9px 16px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, 0.04); color: var(--text); font-weight: 600; }
.consent-open:hover { border-color: var(--accent); }
/* reportar bug */
.report textarea { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, 0.04); color: var(--text); font: inherit; resize: vertical; }
.report textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.report .hp { position: absolute; left: -9999px; }
.report-meta { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.report-meta code { color: var(--text); }
/* aviso de cookies: faixa discreta embaixo, não cobre o tabuleiro */
.consent {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 70;
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: 14px 18px;
  width: min(720px, calc(100vw - 28px));
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #131a2a;
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.6);
}
.consent[hidden] { display: none; }
.consent p { margin: 0; flex: 1; color: #cbd5e1; font-size: 14px; line-height: 1.45; }
.consent a { color: var(--accent); text-underline-offset: 3px; white-space: nowrap; }
.consent-actions { display: flex; gap: 8px; flex: none; }
.consent button {
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-weight: 600;
  font-size: 14px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.consent button:hover { border-color: var(--blue); }
.consent button.primary { background: var(--accent); border-color: var(--accent); color: #06231d; }
.consent button.primary:hover { background: #6fe6cb; border-color: #b9f5e6; }
.foot-yt { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
.foot-yt:hover svg { color: #ff3b30; }

/* ---------- ranking: pódio + lista ---------- */
.rk { width: min(820px, calc(100vw - 40px)); }
.av {
  display: inline-grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 50%;
  background: color-mix(in srgb, var(--c, #94a3b8) 14%, transparent); color: var(--c, var(--muted));
  font-weight: 700; font-size: 14px;
}
.podium { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: end; margin: 8px 0 24px; }
.pd { display: flex; flex-direction: column; align-items: center; gap: 7px; text-align: center; min-width: 0; }
.pd .av { width: 52px; height: 52px; font-size: 21px; }
.pd.p1 .av { width: 64px; height: 64px; font-size: 26px; }
.pd .crown { color: #f5c451; }
.pd-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.pd-rating { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.pd-rating small { display: block; font-size: 12px; font-weight: 600; letter-spacing: 0; color: var(--muted); }
.step {
  display: grid; place-items: center; width: 100%;
  border: 1px solid var(--line); border-bottom: 0; border-radius: 12px 12px 0 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  font-size: 28px; font-weight: 800;
}
.pd.p1 .step { height: 120px; border-top: 3px solid #f5c451; color: #f5c451; }
.pd.p2 .step { height: 88px; border-top: 3px solid #c6d0dc; color: #c6d0dc; }
.pd.p3 .step { height: 66px; border-top: 3px solid #d79a6b; color: #d79a6b; }
.pd.free .av { background: transparent; border: 2px dashed rgba(255, 255, 255, 0.18); color: var(--muted); }
.pd.free .pd-name { color: var(--muted); font-weight: 600; }
.pd.mine .pd-name { color: var(--accent); }
.rk-cta {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px 18px;
  margin: 0 0 22px; padding: 18px 20px;
  border: 1px solid rgba(73, 216, 184, 0.25); border-radius: 14px; background: rgba(73, 216, 184, 0.06);
}
.rk-cta b { display: block; font-size: 16px; }
.rk-cta b::first-letter { text-transform: uppercase; }   /* "faltam 3 puzzles…" também serve no meio de frase */
.rk-cta p { margin: 4px 0 0; color: var(--muted); }
.rk-cta .acts { display: flex; flex-wrap: wrap; gap: 10px; }
.rk-btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); color: var(--text);
  font-weight: 600; text-decoration: none; transition: border-color 0.15s ease, background-color 0.15s ease;
}
.rk-btn:hover { border-color: var(--blue); }
.rk-btn.primary { border-color: transparent; background: var(--accent); color: #06231d; font-weight: 700; }
.rk-btn.primary:hover { border-color: transparent; background: #5fe3c6; }
.rk-list { border: 1px solid var(--line); border-radius: 14px; background: rgba(19, 26, 42, 0.72); overflow: hidden; }
.rk-row {
  display: grid; grid-template-columns: 44px minmax(0, 1fr) 100px 130px 80px; align-items: center; gap: 10px;
  padding: 11px 18px; border-bottom: 1px solid var(--line);
}
.rk-row:last-child { border-bottom: 0; }
.rk-row .pos { color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.rk-row .who { display: flex; align-items: center; gap: 12px; min-width: 0; font-weight: 600; }
.who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-row .n { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.rk-row .r { color: var(--text); font-weight: 800; font-size: 16px; }
.rk-head { padding: 10px 18px; color: var(--muted); font-size: 11.5px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; }
.rk-head .n { color: var(--muted); font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.rk-row.mine { background: rgba(73, 216, 184, 0.1); }
.pill-you { flex: none; padding: 2px 8px; border-radius: 99px; background: var(--accent); color: #06231d; font-size: 11px; font-weight: 700; }

/* ---------- conta (telas do allauth) ---------- */
.auth { width: min(400px, calc(100vw - 40px)); padding-top: 34px; }
.auth h1 { margin: 0 0 8px; font-size: 26px; }
.auth > p, .auth form > p { margin: 0 0 14px; color: var(--muted); line-height: 1.5; }
.auth a { color: var(--accent); text-underline-offset: 3px; }
.auth form { display: flex; flex-direction: column; margin-top: 18px; }
.auth form.google-form { margin-top: 0; }
.auth form > p { display: flex; flex-direction: column; gap: 6px; }
.auth label { color: var(--text); font-size: 14px; font-weight: 600; }
.auth input[type="text"], .auth input[type="password"], .auth input[type="email"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(11, 15, 25, 0.6);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.auth input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.auth form > p:has(input[type="checkbox"]) { flex-direction: row; align-items: center; gap: 8px; }
.auth input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); }
.auth .helptext, .auth form ul:not(.errorlist) { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.auth .errorlist { margin: 0 0 10px; padding: 0; list-style: none; color: var(--danger); font-size: 14px; font-weight: 600; }
.auth button[type="submit"]:not(.google), .auth form + a, .auth form button:not(.google) {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 4px;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #06231d;
  font-weight: 700;
  font-size: 15px;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}
.auth button[type="submit"]:not(.google):hover { background: #6fe6cb; box-shadow: 0 8px 20px -8px rgba(73, 216, 184, 0.7); }
.or { display: flex; align-items: center; gap: 12px; margin: 20px 0 14px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: #1f2937 !important;
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
}
.google:hover:not(:disabled) { box-shadow: 0 0 0 1px var(--blue); border-color: var(--blue); }
.google:disabled { opacity: 0.55; cursor: not-allowed; }
.soon { margin-left: 4px; padding: 2px 8px; border-radius: 999px; background: #e5e7eb; color: #4b5563; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- páginas de texto ---------- */
.prose { width: min(680px, calc(100vw - 40px)); line-height: 1.65; }
.prose h2 { margin: 28px 0 8px; font-size: 19px; letter-spacing: -0.01em; }
.prose p, .prose ul { margin: 0 0 12px; color: #cbd5e1; }
.prose .lead { color: var(--muted); }
.prose ul { padding-left: 20px; }
.prose a { color: var(--accent); text-underline-offset: 3px; }
.prose strong { color: var(--text); }
.prose code { padding: 1px 6px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); font-size: 0.92em; }
.table-wrap { overflow-x: auto; margin: 0 0 14px; border: 1px solid var(--line); border-radius: 12px; }
.prose table { width: 100%; border-collapse: collapse; font-size: 14px; }
.prose th, .prose td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); color: #cbd5e1; }
.prose th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.prose tr:last-child td { border-bottom: 0; }
.prose td:first-child { white-space: nowrap; }

/* ---------- ajustes ---------- */
.settings {
  position: fixed;
  top: 62px;
  right: 16px;
  z-index: 30;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100dvh - 80px);
  overflow: auto;
  padding: 16px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
}
.settings h2 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.settings h2:not(:first-child) { margin-top: 18px; }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.swatch {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px solid transparent;
  padding: 0;
  background: linear-gradient(135deg, var(--l) 50%, var(--d) 50%);
}
.piece-sets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.piece-set {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px 5px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--panel-2);
  font-size: 11px;
  color: var(--muted);
}
.piece-set i { width: 44px; height: 44px; background-size: contain; background-position: center; background-repeat: no-repeat; border-radius: 6px; background-color: var(--dark); }
.swatch[aria-pressed="true"], .piece-set[aria-pressed="true"] { border-color: var(--accent); color: var(--text); }
.switch { display: flex; align-items: center; gap: 10px; padding: 0; border: 0; background: none; font-size: 14px; font-weight: 600; }
.switch-track { position: relative; width: 38px; height: 22px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); transition: background-color 0.15s ease; }
.switch-track i { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: translate 0.15s ease; }
.switch[aria-checked="true"] .switch-track { background: var(--accent); }
.switch[aria-checked="true"] .switch-track i { translate: 16px 0; }
.switch:focus-visible { outline: none; }
.switch:focus-visible .switch-track { box-shadow: 0 0 0 2px var(--blue); }
.credits { margin: 16px 0 0; font-size: 11px; line-height: 1.5; color: var(--muted); }
.credits a { color: var(--muted); }

@keyframes pop { from { scale: 0; } }
@keyframes flash { 0% { opacity: 0; } 8%, 80% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }
@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes shake {
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
@media (prefers-reduced-motion: reduce) {
  .piece { transition: none; }
  .board.shake, .sq.hint::before, .badge { animation: none; }
}
@media (max-width: 860px) {
  /* Empilhado: o painel se desfaz e seus itens vão para cima e para baixo do tabuleiro.
     O rodapé fica abaixo da dobra, para o tabuleiro usar a tela toda. */
  :root { --size: min(calc(100vw - 40px), calc(100dvh - 334px), 640px); }
  .stage {
    flex: none;                 /* não estica: o rodapé vem logo depois dos botões */
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "status status" "board board" "meta rating" "feedback feedback" "actions actions" "analysis analysis";
    align-content: start;
    width: calc(var(--size) + 40px);
    max-width: 100%;
    margin: 0 auto;
    gap: 10px 12px;
    padding: 20px 20px 8px;     /* respiro entre o menu e o tabuleiro */
  }
  .foot { margin-top: 14px; }
  .side { display: contents; }
  .status { grid-area: status; }
  .rating { grid-area: rating; flex-wrap: nowrap; gap: 6px; padding: 0; border: 0; align-self: center; }
  .rating-label { flex-basis: auto; font-size: 11px; }
  .rating-value { font-size: 17px; letter-spacing: 0; }
  .rating-delta { font-size: 13px; }
  .meta { align-self: center; }
  .feedback { grid-area: feedback; margin-top: 0; }
  /* botões: os dois de ajuda lado a lado, o principal embaixo, de ponta a ponta */
  .actions { grid-area: actions; flex-direction: row; flex-wrap: wrap; }
  .actions button, .actions .btn { flex: 1 1 40%; }
  .actions .primary { flex-basis: 100%; }

  .stage.trainer {
    --size: min(calc(100vw - 40px), calc(100dvh - 372px), 640px);
    grid-template-areas: "crumb crumb" "status status" "board board" "meta meta" "feedback feedback" "actions actions";
  }
  .crumb { grid-area: crumb; flex-direction: row; align-items: baseline; gap: 10px; }
  .crumb a, .crumb small { white-space: nowrap; font-size: 15px; }
  /* puzzle do dia: título antes da data, sem a linha do rating */
  .stage.daily {
    --size: min(calc(100vw - 40px), calc(100dvh - 360px), 640px);
    grid-template-areas: "crumb crumb" "status status" "board board" "meta meta" "feedback feedback" "actions actions" "analysis analysis" "calendar calendar";
  }
  .daily .crumb small { order: 2; }
  .daily .status { padding: 0; border: 0; }
  /* no celular o calendário vai para depois dos botões, com dias maiores para o dedo */
  .calendar { grid-area: calendar; margin-top: 10px; }
  .side.analyzing .calendar { display: block; }
  .analysis { grid-area: analysis; margin-top: 6px; }
  .cal-day { height: 38px; font-size: 14px; }
  .cal-day::before { width: 32px; height: 32px; }
  .cal-nav { width: 34px; height: 34px; }
  .crumb span { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .trainer .status { flex-direction: row; align-items: center; padding: 0; border: 0; }
  .trainer .segmented button { flex: none; }
}
@media (max-width: 680px) {
  .consent { flex-direction: column; align-items: stretch; }
  .consent-actions button { flex: 1; }
  /* celular: a navegação vira menu hambúrguer; à direita ficam idioma, conta e ajustes */
  .burger { display: block; }
  .nav { display: none; }
  .top { gap: 10px; }
  .foot { justify-content: center; text-align: center; }
  .foot nav { justify-content: center; }
  .row { flex-direction: column; align-items: flex-start; }
  .hide-s { display: none; }
  .rk-row { grid-template-columns: 34px minmax(0, 1fr) 64px; padding: 11px 14px; }
  .podium { gap: 8px; }
  .pd-rating { font-size: 20px; }
  .pd.p1 .step { height: 92px; }
  .pd.p2 .step { height: 68px; }
  .pd.p3 .step { height: 52px; }
}
@media (max-width: 420px) {
  .brand { font-size: 15px; }
  .segmented button { padding: 6px 10px; }
  .turn { font-size: 17px; }
  .timer { font-size: 20px; }
  .user-btn { width: 38px; padding: 0; }
  .user-name { display: none; }
}
