/* ══════════════════════════════════════════════════════════════════
   Diochess — tema visual (carregado por último).
   Paleta escura com tabuleiro verde/creme, botões "3D" verdes,
   barra lateral à esquerda no desktop e tabuleiro dimensionado
   pela altura útil da tela (1366×768, 1280×768, celular).
   ══════════════════════════════════════════════════════════════════ */

:root {
  --bg: #312e2b;
  --bg-deep: #262421;
  --panel: #262522;
  --panel-2: #21201d;
  --panel-border: rgba(255, 255, 255, 0.06);
  --surface: #3c3a37;
  --surface-hover: #4a4744;
  --text: #ffffff;
  --text-2: #c3c2c1;
  --text-3: #8b8987;
  --green: #81b64c;
  --green-hover: #a3d160;
  --green-shadow: #45753c;
  --red: #e02828;
  --sq-light: #ebecd0;
  --sq-dark: #739552;
  --hl-light: #f5f682;
  --hl-dark: #b9ca43;
  --rail-w: 168px;
  --topbar-h: 52px;
  --gap: 16px;
  --panel-w: 360px;

  /* Tamanho do tabuleiro: limitado pela altura útil e pela largura. */
  --board-size: min(
    calc(100vh - var(--topbar-h) - 96px),
    calc(100vw - var(--rail-w) - var(--panel-w) - 72px)
  );
  --sq-size: calc(var(--board-size) / 8);
}

@supports (height: 100dvh) {
  :root {
    --board-size: min(
      calc(100dvh - var(--topbar-h) - 96px),
      calc(100vw - var(--rail-w) - var(--panel-w) - 72px)
    );
  }
}

html { -webkit-text-size-adjust: 100%; }

body,
body.app-layout {
  background: var(--bg);
  color: var(--text-2);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body.app-layout { height: 100vh; }
@supports (height: 100dvh) { body.app-layout { height: 100dvh; } }

a { color: inherit; }

/* ── Topbar ─────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-deep);
  border-bottom: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  padding: 0 1rem;
}

.logo-text {
  background: none;
  -webkit-text-fill-color: #fff;
  color: #fff;
  filter: none;
  font-size: 1.25rem;
  letter-spacing: -0.2px;
}
.brand img { filter: none; }

.user-nav-link { color: var(--text-2); font-weight: 600; }
.user-nav-link:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }

.auth-nav { gap: 0.5rem; }
.auth-nav a,
.btn-logout {
  color: #fff;
  background: var(--surface);
  border: none;
  border-radius: 6px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  font-weight: 700;
  padding: 0.45rem 0.9rem;
}
.auth-nav a:hover,
.btn-logout:hover {
  background: var(--surface-hover);
  color: #fff;
  border: none;
  transform: none;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.auth-nav a[href="/signup/request"] {
  background: var(--green);
  box-shadow: 0 3px 0 var(--green-shadow);
}
.auth-nav a[href="/signup/request"]:hover { background: var(--green-hover); }

.lang-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-2);
}
.lang-btn:hover { background: rgba(255, 255, 255, 0.06); border-color: transparent; }
.lang-menu { background: var(--panel); border-color: var(--panel-border); }
.lang-option { color: var(--text-2); }
.lang-option:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }

.stat-pill { background: var(--surface); border-color: transparent; }
.stat-pill .label { color: var(--text-3); }
.stat-pill .value { color: #fff; }
.xp-progress-container { background: var(--surface); }
.xp-progress-bar { background: var(--green); }

/* ── Shell ─────────────────────────────────────────────────────── */
.main-content {
  background: var(--bg);
  padding: var(--gap) 20px;
  scroll-behavior: auto;
}

/* Barra lateral fixa à esquerda no desktop (estilo rail). */
@media (min-width: 769px) {
  .user-nav { display: none; }

  .sidebar {
    display: flex;
    position: static;
    transform: none;
    width: var(--rail-w);
    background: var(--panel-2);
    border-right: 1px solid rgba(0, 0, 0, 0.3);
    box-shadow: none;
    overflow-y: auto;
  }

  .sidebar-nav { padding: 0.5rem 0; gap: 0; }
}

.sidebar { background: var(--panel-2); }

.sidebar .nav-item {
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-radius: 0;
  color: var(--text-2);
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.2;
}
.sidebar .nav-item:hover {
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  transform: none;
}
.sidebar .nav-item.active {
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  transform: none;
  box-shadow: inset 3px 0 0 var(--green);
}
.nav-icon {
  width: 1.6rem;
  font-size: 1.25rem;
  text-align: center;
  flex-shrink: 0;
  color: var(--green);
  line-height: 1;
}

@media (max-width: 768px) {
  .sidebar { top: var(--topbar-h); bottom: 0; }
}

/* Rail compacto (só ícones) em larguras médias. */
@media (min-width: 769px) and (max-width: 1099px) {
  :root { --rail-w: 64px; --panel-w: 300px; }
  .sidebar .nav-item { justify-content: center; padding: 0.85rem 0; }
  .sidebar .nav-item .nav-label { display: none; }
}

/* ── Bottombar (celular) ──────────────────────────────────────── */
.bottombar {
  background: var(--bg-deep);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-top: 1px solid rgba(0, 0, 0, 0.4);
  box-shadow: none;
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(60px + env(safe-area-inset-bottom));
}
.bottom-nav { height: 60px; }
.bottom-nav .nav-item { color: var(--text-3); font-weight: 700; }
.bottom-nav .nav-item.active,
.bottom-nav .nav-item:hover { color: #fff; }
.bottom-nav .nav-item.active .icon { color: var(--green); }

/* ── Botões ───────────────────────────────────────────────────── */
.btn {
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.95rem;
  padding: 0.7rem 1rem;
  background: var(--surface);
  color: #fff;
  border: none;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  transition: background-color 0.12s, transform 0.06s, box-shadow 0.06s;
  touch-action: manipulation;
}
.btn:hover { filter: none; background: var(--surface-hover); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }

.btn-confirm,
.btn.primary {
  background: var(--green);
  color: #fff;
  font-size: 1.15rem;
  padding: 0.85rem 1rem;
  box-shadow: 0 4px 0 var(--green-shadow);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}
.btn-confirm:hover,
.btn.primary:hover { background: var(--green-hover); }
.btn-confirm:active,
.btn.primary:active { box-shadow: 0 1px 0 var(--green-shadow); }

.btn-nav { background: var(--green); box-shadow: 0 4px 0 var(--green-shadow); font-size: 1.05rem; }
.btn-nav:hover { background: var(--green-hover); }
.btn-reveal,
.btn-toggle,
.btn-skip { background: var(--surface); color: var(--text-2); border: none; }
.btn-reveal:hover,
.btn-toggle:hover,
.btn-skip:hover { background: var(--surface-hover); color: #fff; }

.btn-ai {
  background: #5d4bb7;
  box-shadow: 0 3px 0 #3d2f85;
  color: #fff;
}
.btn-ai:hover { background: #6f5cd0; box-shadow: 0 3px 0 #3d2f85; }

/* ══ Treino ════════════════════════════════════════════════════ */
.round-card {
  background: transparent;
  border: none;
  box-shadow: none;
  max-width: none;
  width: fit-content;
  margin: 0 auto;
}

.pos-meta {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0 0 8px;
  font-size: 0.82rem;
  color: var(--text-3);
}
.pos-id { color: #fff; }
.pos-tags, .target-label { color: var(--text-3); }
.turn-label { color: var(--text-2); font-weight: 700; }
.pos-diff { color: #f7c045; }

.round-body {
  flex-wrap: nowrap;
  gap: var(--gap);
  align-items: flex-start;
}

.board-area { padding: 0; }

.board-shell {
  border-radius: 4px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  background: transparent;
}

.chess-board {
  width: var(--board-size);
  height: var(--board-size);
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  touch-action: manipulation;
}

.square {
  width: auto;
  height: auto;
  min-width: 0;
  min-height: 0;
  transition: none;
}
.square.light { background: var(--sq-light); }
.square.dark { background: var(--sq-dark); }
.square.selectable:hover { filter: none; }
.square.selectable:hover::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 calc(var(--sq-size) * 0.05) rgba(255, 255, 255, 0.65);
  pointer-events: none;
}

/* Seleção: destaque vermelho translúcido, como as marcações de casa. */
.square.selected::after,
.square.selected:hover::after {
  content: "";
  position: absolute;
  inset: 0;
  border: none;
  border-radius: 0;
  background: rgba(235, 97, 80, 0.8);
  box-shadow: none;
  pointer-events: none;
}
.square.selected .piece { z-index: 2; }
.square.selectable:not(:has(.piece)):hover::before { display: none; }

.piece {
  width: 100%;
  height: 100%;
  filter: none;
  transition: none;
}
.square.selectable:hover .piece { transform: none; }

.square.mark-correct { background: #81b64c !important; }
.square.mark-wrong { background: #e05d4b !important; }
.square.mark-missed { background: #f0a43a !important; }
.square.mark-answer { background: #f5d547 !important; }

/* Coordenadas dentro das casas da borda. */
.coord {
  position: absolute;
  font-size: max(10px, calc(var(--sq-size) * 0.2));
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  user-select: none;
  z-index: 3;
}
.coord-rank { top: 4%; left: 5%; }
.coord-file { bottom: 4%; right: 6%; }
.square.light .coord, .live-square.light .coord { color: var(--sq-dark); }
.square.dark .coord, .live-square.dark .coord { color: var(--sq-light); }

/* Painel de controle ao lado do tabuleiro. */
.control-panel {
  flex: 0 0 var(--panel-w);
  width: var(--panel-w);
  max-width: none;
  min-width: 0;
  min-height: var(--board-size);
  max-height: var(--board-size);
  overflow-y: auto;
  background: var(--panel);
  border: none;
  border-radius: 8px;
  padding: 16px;
  gap: 12px;
}

.instruction-card,
.summary-box {
  background: rgba(0, 0, 0, 0.2);
  border-left: none;
  border-radius: 6px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 1rem;
}
.instruction-card p:first-child { font-weight: 700; }
.instruction-card .hint { color: var(--text-3); font-size: 0.85rem; }
.summary-box.perfect { box-shadow: inset 4px 0 0 var(--green); }
.summary-msg { font-size: 1.1rem; color: #fff; }
.summary-stats { font-size: 0.9rem; }
.stat-hit { color: var(--green); }

.sel-count { color: var(--text-3); font-size: 0.85rem; }
.divider { background: rgba(255, 255, 255, 0.06); }

.anon-login-hint {
  background: rgba(0, 0, 0, 0.18);
  border: none;
  color: var(--text-3);
  font-size: 0.8rem;
}
.anon-login-hint a { color: var(--green); }

.ai-section { background: rgba(0, 0, 0, 0.2); border: none; box-shadow: none; }
.ai-title { color: #b6a7ff; }
.ai-result { border-top-color: rgba(255, 255, 255, 0.08); }
.ai-feedback-msg { color: var(--text-2); }
.ai-pos-card { background: rgba(0, 0, 0, 0.25); }
.legend-chip { border-radius: 4px; }
.lc-correct { background: #81b64c; }
.lc-wrong { background: #e05d4b; }
.lc-missed { background: #f0a43a; }
.lc-answer { background: #f5d547; color: #222; }

/* ── Telas médias / notebooks ─────────────────────────────────── */
@media (max-width: 1099px) and (min-width: 721px) {
  .main-content { padding: 12px; }
}

/* ── Celular / tablet em pé: tabuleiro ocupa a largura toda ───── */
@media (max-width: 720px) {
  :root {
    --rail-w: 0px;
    --board-size: min(calc(100vw - 12px), 620px);
    --topbar-h: 52px;
  }

  .main-content {
    padding: 8px 6px calc(72px + env(safe-area-inset-bottom));
  }

  .round-card { width: 100%; }
  .pos-meta { padding: 2px 4px 8px; font-size: 0.76rem; gap: 0.4rem; }
  .round-body { flex-direction: column; align-items: center; gap: 10px; }
  .board-area { padding: 0; justify-content: center; }
  .board-shell { border-radius: 2px; }

  .control-panel {
    flex: none;
    width: 100%;
    min-height: 0;
    max-height: none;
    overflow: visible;
    padding: 12px;
    border-top: none;
  }

  .btn-confirm, .btn.primary { font-size: 1.05rem; }
}

@media (max-width: 520px) {
  .auth-nav a[href="/signup/request"] { display: none; }
}

/* Tabuleiro com altura muito limitada (paisagem no celular). */
@media (max-height: 520px) and (min-width: 721px) {
  :root { --board-size: calc(100vh - var(--topbar-h) - 48px); }
  .pos-meta { padding-bottom: 4px; }
}

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

/* ── Login / solicitação de cadastro ──────────────────────────── */
body .login-card,
body .request-card {
  background: var(--panel);
  border: none;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
body .login-header h1 {
  background: none;
  -webkit-text-fill-color: #fff;
  color: #fff;
}
body .request-header h1 { color: #fff; }
body .form-group input,
body .form-row input {
  background: var(--panel-2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
}
body .form-group input:focus,
body .form-row input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(129, 182, 76, 0.25);
  outline: none;
}
body .btn-submit {
  background: var(--green);
  color: #fff;
  border: none;
  box-shadow: 0 4px 0 var(--green-shadow);
  font-weight: 800;
}
body .btn-submit:hover { background: var(--green-hover); transform: none; }
body .login-footer a { color: var(--green); }
body .btn-back { background: var(--surface); color: #fff; border: none; }

/* ── Login com Google ─────────────────────────────────────────── */
.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: #fff;
  color: #1f1f1f;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
.btn-google:hover { background: #f1f1f1; }
.btn-google:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
.login-sep {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0;
  color: var(--text-3);
  font-size: 0.85rem;
}
.login-sep::before, .login-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
}
.notice-msg {
  background: rgba(129, 182, 76, 0.12);
  color: #cfe8b4;
  border-radius: 6px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
