/* ===== Design tokens ===== */
:root {
  --bg: #f5f6f3;
  --bg-elevated: #ffffff;
  --bg-sunken: #edefe9;
  --fg: #1b201d;
  --muted: #626e66;
  --border: #dde1d9;
  --border-strong: #c7cec1;

  --accent: #3c8552;
  --accent-hover: #2f6b41;
  --accent-soft: #e5f2e8;
  --accent-fg: #ffffff;

  --danger: #c0392b;
  --danger-soft: #fbe9e6;
  --warning: #a9720f;
  --warning-soft: #fbf1de;
  --gold: #b8912b;

  /* Clasificación de jugadas estilo chess.com */
  --c-brilliant: #1baaa6;
  --c-best: #3c8552;
  --c-excellent: #4f9e63;
  --c-good: #6b8f74;
  --c-book: #8a6d3b;
  --c-inaccuracy: #b8912b;
  --c-miss: #d2691e;
  --c-mistake: #c9761e;
  --c-blunder: #c0392b;

  --radius-sm: 6px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(20, 30, 20, 0.06);
  --shadow: 0 2px 10px rgba(20, 30, 20, 0.07);
  --shadow-lg: 0 12px 32px rgba(20, 30, 20, 0.14);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a;
    --bg-elevated: #1a1e24;
    --bg-sunken: #0e1114;
    --fg: #e8ebe6;
    --muted: #909a92;
    --border: #2a2f35;
    --border-strong: #3a4048;

    --accent: #4fae6c;
    --accent-hover: #63c281;
    --accent-soft: rgba(79, 174, 108, 0.16);
    --accent-fg: #0d1a10;

    --danger: #e0685a;
    --danger-soft: rgba(224, 104, 90, 0.14);
    --warning: #d9a441;
    --warning-soft: rgba(217, 164, 65, 0.14);
    --gold: #d9bc5c;

    --c-brilliant: #2fd0cb;
    --c-best: #4fae6c;
    --c-excellent: #6cbf7f;
    --c-good: #8fac97;
    --c-book: #c2a06a;
    --c-inaccuracy: #d9bc5c;
    --c-miss: #e08a4d;
    --c-mistake: #e0975a;
    --c-blunder: #e0685a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 700; letter-spacing: -0.01em; line-height: 1.25; }
h1 { font-size: 1.75rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.15rem; margin: 0 0 1rem; }
h3 { font-size: 1rem; margin: 0 0 0.25rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Top bar ===== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 1.5rem;
  display: flex; justify-content: space-between; align-items: center; height: 60px;
}
.brand {
  display: flex; align-items: center; gap: 0.5rem;
  font-weight: 800; font-size: 1.05rem; color: var(--fg); text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-fg); font-size: 1.2rem;
}
.topnav { display: flex; align-items: center; gap: 0.25rem; }
.topnav a {
  color: var(--muted); text-decoration: none; font-weight: 500; font-size: 0.9rem;
  padding: 0.45rem 0.75rem; border-radius: var(--radius-sm);
}
.topnav a:hover { color: var(--fg); background: var(--bg-sunken); }
.topnav a.active { color: var(--accent); background: var(--accent-soft); }
.logout-form { display: inline; margin-left: 0.25rem; }

.link-button {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font: inherit; font-size: 0.9rem; padding: 0.45rem 0.75rem; border-radius: var(--radius-sm);
}
.link-button:hover { color: var(--fg); background: var(--bg-sunken); text-decoration: none; }

.container { max-width: 1080px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }

/* ===== Cards ===== */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem 1.75rem;
}
.card + .card { margin-top: 1.5rem; }

.auth-card { max-width: 380px; margin: 3rem auto; box-shadow: var(--shadow-lg); }
.auth-card button[type="submit"] { width: 100%; justify-content: center; margin-top: 0.25rem; }
.auth-card p:last-child { text-align: center; color: var(--muted); font-size: 0.88rem; }

/* ===== Forms ===== */
form label { display: block; margin-bottom: 1rem; font-size: 0.88rem; font-weight: 500; color: var(--muted); }
form input, form select, form textarea {
  display: block; width: 100%; margin-top: 0.35rem;
  padding: 0.55rem 0.7rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 0.95rem; font-family: inherit; background: var(--bg-elevated); color: var(--fg);
}
form input:focus, form select:focus, form textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
form textarea { font-family: "SF Mono", Menlo, monospace; font-size: 0.82rem; }

button[type="submit"], .sync-button, .btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: var(--accent); color: var(--accent-fg); border: none;
  padding: 0.6rem 1.3rem; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 0.92rem; font-weight: 600; font-family: inherit;
  transition: background 0.15s, transform 0.1s;
}
button[type="submit"]:hover, .sync-button:hover, .btn:hover { background: var(--accent-hover); }
button[type="submit"]:active, .sync-button:active { transform: scale(0.98); }
button[disabled] { opacity: 0.45; cursor: not-allowed; }

.error { color: var(--danger); font-weight: 500; }
.hint, .empty-state { color: var(--muted); }
.empty-state { padding: 1rem 0; }

/* ===== Dashboard ===== */
.dashboard-header {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  margin-bottom: 1.75rem; flex-wrap: wrap;
}
.dashboard-header h1 { margin: 0; }
.header-actions { display: flex; align-items: center; gap: 0.5rem; }
.dashboard-section { margin-top: 1.75rem; }

.opponent-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem;
  margin-top: 1rem;
}
.opponent-card {
  transition: transform 0.12s, box-shadow 0.12s;
  display: flex; flex-direction: column;
}
.opponent-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.opponent-card h3 {
  margin-top: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; /* nombres largos truncan en vez de envolver y desparejar la fila */
}
.opponent-card p { color: var(--muted); font-size: 0.85rem; margin: 0.35rem 0 0.75rem; flex-grow: 1; }
.opponent-card a { margin-top: auto; } /* "Ver reporte →" siempre pegado abajo */

.linked-list { list-style: none; padding: 0; margin: 0; }
.linked-list li { padding: 0.55rem 0; border-bottom: 1px solid var(--border); }
.linked-list li:last-child { border-bottom: none; }

/* ===== Report / stats ===== */
.record { color: var(--muted); font-size: 0.95rem; margin-top: -0.25rem; }

.recommendation-list { list-style: none; padding: 0; margin: 0; counter-reset: rec; }
.recommendation-list li {
  counter-increment: rec;
  padding: 0.9rem 0 0.9rem 2.25rem; position: relative;
  border-bottom: 1px solid var(--border);
}
.recommendation-list li:last-child { border-bottom: none; }
.recommendation-list li::before {
  content: counter(rec);
  position: absolute; left: 0; top: 0.85rem;
  width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: 0.78rem; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.recommendation-list p { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.9rem; }

.bar-list { display: flex; flex-direction: column; gap: 0.7rem; }
.bar-row { display: grid; grid-template-columns: minmax(9rem, 14rem) 1fr auto; align-items: center; gap: 0.9rem; }
.bar-label { font-size: 0.88rem; }
.bar-track { background: var(--bg-sunken); border-radius: 99px; height: 0.7rem; overflow: hidden; }
.bar-fill { background: linear-gradient(90deg, var(--accent), var(--gold)); height: 100%; border-radius: 99px; }
.bar-value { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

.opening-code-link {
  color: var(--accent); font-weight: 600; text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}
.opening-code-link:hover { text-decoration: none; border-bottom-style: solid; }
.opening-external-link { font-size: 0.78rem; color: var(--muted); margin-left: 0.4rem; }

/* ===== Tables ===== */
.games-table, .move-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.games-table th, .games-table td, .move-table th, .move-table td {
  text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border);
}
.games-table th, .move-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.games-table tbody tr:hover, .move-table tbody tr:hover { background: var(--bg-sunken); }

/* Badges de resultado */
.result-win, .result-loss, .result-draw {
  display: inline-block; padding: 0.15rem 0.55rem; border-radius: 99px;
  font-size: 0.78rem; font-weight: 700;
}
.result-win { background: var(--accent-soft); color: var(--accent); }
.result-loss { background: var(--danger-soft); color: var(--danger); }
.result-draw { background: var(--bg-sunken); color: var(--muted); }

.move-table td, .move-table th { cursor: pointer; }
.move-table tr.active { background: var(--accent-soft); }
.move-table .class-brilliant { color: var(--c-brilliant); font-weight: 700; }
.move-table .class-best { color: var(--c-best); }
.move-table .class-excellent { color: var(--c-excellent); }
.move-table .class-good { color: var(--c-good); }
.move-table .class-book { color: var(--c-book); }
.move-table .class-inaccuracy { color: var(--c-inaccuracy); font-weight: 600; }
.move-table .class-miss { color: var(--c-miss); font-weight: 700; }
.move-table .class-mistake { color: var(--c-mistake); font-weight: 600; }
.move-table .class-blunder { color: var(--c-blunder); font-weight: 700; }

/* Símbolo estilo chess.com (!!, !, ?!, ?, ??, etc) inyectado por CSS a partir de la
   clase — un solo lugar para mantener el mapeo (ver también web/static/js/move-classification.js). */
.move-symbol { font-weight: 800; margin-left: 0.15rem; }
.move-symbol-brilliant::before { content: "!!"; color: var(--c-brilliant); }
.move-symbol-best::before { content: "★"; color: var(--c-best); }
.move-symbol-excellent::before { content: "!"; color: var(--c-excellent); }
.move-symbol-book::before { content: "📖"; }
.move-symbol-inaccuracy::before { content: "?!"; color: var(--c-inaccuracy); }
.move-symbol-miss::before { content: "✗"; color: var(--c-miss); }
.move-symbol-mistake::before { content: "?"; color: var(--c-mistake); }
.move-symbol-blunder::before { content: "??"; color: var(--c-blunder); }

.move-nav {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  margin-top: 0.9rem; padding: 0.6rem; background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.move-nav button {
  background: var(--bg-sunken); border: 1px solid var(--border-strong); color: var(--fg);
  border-radius: var(--radius-sm); width: 2.1rem; height: 2.1rem; cursor: pointer; font-size: 1rem;
}
.move-nav button:hover { background: var(--accent-soft); border-color: var(--accent); }
.move-indicator { flex: 1; text-align: center; font-size: 0.9rem; font-weight: 600; min-width: 8rem; }

.best-move-btn { width: 100%; justify-content: center; margin-top: 0.75rem; }
#best-move-result { min-height: 1.3em; margin-top: 0.5rem; text-align: center; font-weight: 600; }

/* ===== Tablero ===== */
.board-layout { display: flex; gap: 2rem; flex-wrap: wrap; align-items: flex-start; }
.board-container { width: 520px; max-width: 100%; }
.moves-container { flex: 1; min-width: 260px; max-height: 560px; overflow-y: auto; }
.moves-container .card { padding: 0; }

.board-controls {
  display: flex; gap: 1rem; margin-bottom: 0.9rem; font-size: 0.85rem;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
}
.board-controls label { display: flex; align-items: center; gap: 0.4rem; margin: 0; font-weight: 500; color: var(--muted); }
.board-controls select { width: auto; margin-top: 0; padding: 0.25rem 0.4rem; }

.board-theme-green .white-1e1d7 { background-color: #eeeed2; }
.board-theme-green .black-3c85d { background-color: #769656; }
.board-theme-blue .white-1e1d7 { background-color: #dee3e6; }
.board-theme-blue .black-3c85d { background-color: #8ca2ad; }
.board-theme-gray .white-1e1d7 { background-color: #dcdcdc; }
.board-theme-gray .black-3c85d { background-color: #888888; }

#feedback { min-height: 1.4em; font-weight: 600; margin-top: 0.75rem; }
#feedback.error { color: var(--danger); }

.puzzle-context {
  background: var(--warning-soft); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.7rem 1rem; margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

.puzzle-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem; margin-top: 0.5rem;
}
.puzzle-toolbar #step-indicator { margin: 0; }
.puzzle-toolbar .link-button { padding: 0.3rem 0.6rem; font-size: 0.85rem; }

/* Casilla resaltada por el botón de pista — chessboard.js marca cada casilla con
   data-square, así que basta un box-shadow interno para no romper el drag&drop. */
.hint-square { box-shadow: inset 0 0 0 4px var(--gold) !important; }

/* ===== Sync status ===== */
.sync-list { list-style: none; padding: 0; margin: 0; }
.sync-list li { padding: 0.4rem 0; font-size: 0.88rem; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 0.75rem 1rem; gap: 0.5rem; }
  .topnav { flex-wrap: wrap; }
  .container { padding: 1.25rem 1rem 3rem; }
  .card { padding: 1.1rem 1.25rem; }
  .bar-row { grid-template-columns: 1fr; gap: 0.3rem; }
}
