@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("fonts/inter-latin.woff2") format("woff2");
}

/* Tema scuro (predefinito): blu notte + ciano del logo */
:root {
  --bg: #060b18;
  --bg-2: #0a1226;
  --card: rgba(16, 26, 52, 0.72);
  --card-solid: #0f1830;
  --card-hi: rgba(255, 255, 255, 0.045); /* riflesso in alto sulle schede */
  --line: rgba(130, 170, 255, 0.13);
  --line-strong: rgba(130, 170, 255, 0.24);
  --text: #e9f1ff;
  --muted: #8a9ab8;
  --accent: #2ee6ff;
  --accent-2: #12b8e0;
  --accent-ink: #03141f; /* testo sopra il colore principale */
  --accent-soft: rgba(46, 230, 255, 0.12);
  --accent-grad: linear-gradient(135deg, #8ff6ff 0%, #2ee6ff 45%, #12b0e0 100%);
  --danger: #ff6b7a;
  --page-glow: radial-gradient(900px 600px at 12% -10%, rgba(46, 230, 255, 0.10), transparent 60%),
               radial-gradient(800px 700px at 100% 110%, rgba(90, 80, 255, 0.10), transparent 60%);
  --sq-light: #dfe6f0;
  --sq-dark: #7189ab;
  --sq-last: rgba(46, 230, 255, 0.38);
  --sq-sel: rgba(46, 230, 255, 0.5);
  --sq-check: radial-gradient(circle, rgba(255, 40, 70, 0.95) 0%, rgba(255, 40, 70, 0.5) 45%, transparent 75%);
  --dot: rgba(6, 11, 24, 0.3);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 6px 18px rgba(0, 0, 0, 0.3);
  --radius: 18px;
  --sidebar-w: 232px;
  --bottom-nav-h: 64px;
  /* Categorie delle mosse */
  --cls-brilliant: #1fb3aa;
  --cls-great: #4a86e8;
  --cls-best: #3aa64a;
  --cls-excellent: #67b75a;
  --cls-good: #8a9e7a;
  --cls-book: #a7825c;
  --cls-inaccuracy: #e0a91c;
  --cls-mistake: #ec7f22;
  --cls-blunder: #e0444a;
  /* Grafico della valutazione */
  --graph-white: #eceef2;
  --graph-black: #26304a;
  --graph-line: #8a9ab8;
  --graph-cursor: #2ee6ff;
}

:root[data-theme="light"] {
  --bg: #f5f7fb;
  --bg-2: #ffffff;
  --card: rgba(255, 255, 255, 0.86);
  --card-solid: #ffffff;
  --card-hi: rgba(255, 255, 255, 0.6);
  --line: rgba(20, 40, 90, 0.10);
  --line-strong: rgba(20, 40, 90, 0.2);
  --text: #0b1430;
  --muted: #5a6784;
  --accent: #0aa5cc;
  --accent-2: #0789ab;
  --accent-ink: #ffffff;
  --accent-soft: rgba(10, 165, 204, 0.1);
  --accent-grad: linear-gradient(135deg, #22c4e8 0%, #0aa5cc 55%, #0787b0 100%);
  --danger: #d63c4f;
  --page-glow: radial-gradient(900px 600px at 12% -10%, rgba(10, 165, 204, 0.08), transparent 60%),
               radial-gradient(800px 700px at 100% 110%, rgba(90, 80, 255, 0.06), transparent 60%);
  --sq-last: rgba(10, 165, 204, 0.32);
  --sq-sel: rgba(10, 165, 204, 0.45);
  --shadow: 0 14px 34px rgba(20, 40, 90, 0.12);
  --shadow-sm: 0 4px 14px rgba(20, 40, 90, 0.08);
  --graph-white: #ffffff;
  --graph-black: #4d5a78;
  --graph-line: #5a6784;
  --graph-cursor: #0aa5cc;
}

* { box-sizing: border-box; }

/* L'attributo hidden vince sempre sul display dei componenti (es. .move-input è flex) */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body { background: var(--page-glow), var(--bg); background-attachment: fixed; min-height: 100vh; }

button { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }

/* ---------- Struttura: barra laterale + contenuto ---------- */
.app { min-height: 100vh; }
.main { min-width: 0; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: calc(22px + env(safe-area-inset-top)) 16px 18px;
  background: linear-gradient(180deg, rgba(10, 18, 38, 0.92), rgba(6, 11, 24, 0.92));
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  z-index: 30;
}
:root[data-theme="light"] .sidebar { background: rgba(255, 255, 255, 0.82); }
.sidebar-foot { margin-top: auto; }
.sidebar-foot .link-btn { font-size: 0.78rem; text-decoration: none; }
.sidebar-foot .link-btn:hover { color: var(--text); }

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-icon { width: 38px; height: 38px; border-radius: 10px; box-shadow: 0 4px 16px rgba(46, 230, 255, 0.18); }
.logo-text { font-weight: 800; font-size: 1.32rem; letter-spacing: 0.01em; }
.logo-text > span { color: var(--accent); }
.logo-text small { font-size: 0.8rem; color: var(--muted); font-weight: 600; margin-left: 1px; }

.tabs { display: flex; flex-direction: column; gap: 4px; }
.tabs button {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid transparent; background: transparent;
  padding: 11px 12px; border-radius: 12px; min-height: 44px;
  font-weight: 600; font-size: 0.95rem; color: var(--muted); cursor: pointer; text-align: left;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tabs button svg {
  width: 21px; height: 21px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.tabs button svg .fill { fill: currentColor; stroke: none; opacity: 0.35; }
.tabs button:hover { color: var(--text); background: var(--accent-soft); }
.tabs button.active {
  color: var(--text);
  background: linear-gradient(90deg, rgba(46, 230, 255, 0.16), rgba(46, 230, 255, 0.04));
  border-color: rgba(46, 230, 255, 0.22);
  box-shadow: inset 3px 0 0 var(--accent);
}
.tabs button.active svg { color: var(--accent); }
:root[data-theme="light"] .tabs button.active { background: var(--accent-soft); }

.main { margin-left: var(--sidebar-w); }

/* ---------- Intestazione ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: calc(18px + env(safe-area-inset-top)) 28px 14px;
  max-width: 1280px;
  margin: 0 auto;
}
.section-head { flex: 1; min-width: 0; }
.section-head h1 { margin: 0; font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; }
.section-head p { margin: 3px 0 0; color: var(--muted); font-size: 0.9rem; }
.mobile-only { display: none; }
.icon-btn {
  width: 42px; height: 42px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  font-size: 1.1rem;
  transition: border-color 0.15s, background 0.15s;
}
.icon-btn:hover { border-color: var(--line-strong); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }

/* ---------- Layout della scacchiera ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
  padding: 8px 28px 28px;
  max-width: 1280px;
  margin: 0 auto;
}
@media (min-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1.2fr) minmax(340px, 1fr); align-items: start; }
  .board-area { position: sticky; top: 20px; }
}

.view { padding: 8px 28px 28px; max-width: 1280px; margin: 0 auto; }
.hero-card { max-width: 640px; padding: 28px; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.card.hero-card h2 { font-size: 1.35rem; margin: 4px 0 0; letter-spacing: -0.01em; }
.hero-card p { margin: 0; color: var(--muted); line-height: 1.55; }
.hero-icon {
  width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(46, 230, 255, 0.2);
}
.hero-icon svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.hero-icon svg .fill { fill: currentColor; stroke: none; }
.pill {
  display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); background: var(--accent-soft);
}

/* ---------- Telefono e tablet stretto: barra di navigazione in basso ---------- */
@media (max-width: 860px) {
  .main { margin-left: 0; padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom)); }
  .sidebar {
    inset: auto 0 0 0; width: auto; height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
    flex-direction: row; padding: 0 6px env(safe-area-inset-bottom); gap: 0;
    border-right: 0; border-top: 1px solid var(--line);
  }
  .sidebar .brand, .sidebar-foot { display: none; }
  .tabs { flex-direction: row; flex: 1; gap: 2px; }
  .tabs button {
    flex: 1 1 0; min-width: 0; flex-direction: column; justify-content: center; gap: 3px;
    padding: 6px 2px; font-size: 0.68rem; font-weight: 600; border-radius: 10px; text-align: center;
  }
  .tabs button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  /* Etichetta corta sul telefono (il testo completo resta per il titolo della sezione e i lettori di schermo) */
  .tabs button span[data-short] { font-size: 0; }
  .tabs button span[data-short]::after { content: attr(data-short); font-size: 0.68rem; }
  .tabs button.active, :root[data-theme="light"] .tabs button.active { box-shadow: none; background: transparent; border-color: transparent; color: var(--accent); }
  .tabs button.active svg { filter: drop-shadow(0 0 8px rgba(46, 230, 255, 0.55)); }
  .topbar { padding: calc(12px + env(safe-area-inset-top)) 16px 8px; gap: 12px; }
  .mobile-only { display: flex; }
  .topbar .brand { padding: 0; }
  .topbar .brand-icon { width: 34px; height: 34px; }
  .topbar .logo-text { display: none; }
  .section-head h1 { font-size: 1.2rem; }
  .section-head p { font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .layout, .view { padding: 4px 16px 20px; gap: 14px; }
}

.board-area { display: flex; flex-direction: column; gap: 8px; }
.board-row { display: flex; gap: 8px; align-items: stretch; }
.board-wrap { flex: 1; min-width: 0; }

.player-tag {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--muted);
  padding-left: 30px;
  min-height: 1.2em;
}
.player-tag.to-move { color: var(--text); font-weight: 600; }
.player-tag.to-move::before { content: "● "; color: var(--accent); }

/* ---------- Eval bar ---------- */
.evalbar {
  width: 22px;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  background: #2b2b2b;
  flex-shrink: 0;
  box-shadow: var(--shadow);
}
.evalbar-fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 50%;
  background: #f4f4f4;
  transition: height 0.45s cubic-bezier(.2,.8,.3,1);
}
.evalbar.flipped .evalbar-fill { background: #2b2b2b; }
.evalbar.flipped { background: #f4f4f4; }
.evalbar-label {
  position: absolute;
  left: 0; right: 0;
  bottom: 4px;
  text-align: center;
  font-size: 0.6rem;
  font-weight: 700;
  color: #222;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  mix-blend-mode: difference;
  filter: invert(1);
}

/* ---------- Board ---------- */
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow), 0 0 0 1px var(--line-strong), 0 0 60px rgba(46, 230, 255, 0.06);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.squares {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
}
.sq { position: relative; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::after, .sq.sel::after, .sq.check::after {
  content: "";
  position: absolute;
  inset: 0;
}
.sq.last::after { background: var(--sq-last); }
.sq.sel::after { background: var(--sq-sel); }
.sq.check::after { background: var(--sq-check); }
.sq.dest::before {
  content: "";
  position: absolute;
  left: 35%; top: 35%;
  width: 30%; height: 30%;
  border-radius: 50%;
  background: var(--dot);
  z-index: 3;
  pointer-events: none;
}
.sq.dest.capture::before {
  left: 4%; top: 4%; width: 92%; height: 92%;
  background: transparent;
  border: 5px solid var(--dot);
}
.coord {
  position: absolute;
  font-size: clamp(8px, 1.8vw, 12px);
  font-weight: 700;
  pointer-events: none;
  z-index: 1;
}
.coord.file { right: 4%; bottom: 2%; }
.coord.rank { left: 4%; top: 2%; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }

.pieces { position: absolute; inset: 0; pointer-events: none; }
.piece {
  position: absolute;
  left: 0; top: 0;
  width: 12.5%;
  height: 12.5%;
  background-size: 100% 100%;
  will-change: transform;
  z-index: 4;
}
.piece.anim { transition: transform 0.22s cubic-bezier(.2,.8,.3,1); }
.piece.dragging { z-index: 10; transform-origin: center; scale: 1.15; filter: drop-shadow(0 6px 8px rgba(0,0,0,.35)); }

.arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 6;
}

/* ---------- Panel ---------- */
.panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.move-input { display: flex; gap: 8px; }
.move-input input {
  flex: 1;
  min-width: 0;
  font-size: 16px; /* evita lo zoom automatico su iOS */
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--card-solid);
  color: var(--text);
  outline: none;
}
.move-input input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-error { color: var(--danger); font-size: 0.9rem; min-height: 0; }
.input-error:empty { display: none; }

.btn {
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.2s, transform 0.1s;
}
.btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .segmented button:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary {
  background: var(--accent-grad); border-color: transparent; color: var(--accent-ink); font-weight: 700;
  box-shadow: 0 6px 20px rgba(46, 230, 255, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.btn.primary:hover { background: var(--accent-grad); box-shadow: 0 8px 28px rgba(46, 230, 255, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.35); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.45; cursor: default; }

.toolbar { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 520px) { .toolbar { grid-template-columns: repeat(4, 1fr); } }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 9px 6px;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}
.segmented button { transition: background 0.15s, color 0.15s; }
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--accent-grad); color: var(--accent-ink); box-shadow: 0 2px 10px rgba(46, 230, 255, 0.25); }

.card {
  background: linear-gradient(180deg, var(--card-hi), transparent 40%), var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card h2 { font-size: 0.98rem; font-weight: 700; letter-spacing: -0.005em; margin: 0 0 10px; }
.depth-info { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 8px 0 0; }

.footnote { color: var(--muted); font-size: 0.75rem; text-align: center; margin: 4px 0 calc(8px + env(safe-area-inset-bottom)); }

/* ---------- Dialogs ---------- */
.dialog {
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  background: var(--card-solid);
  color: var(--text);
  padding: 22px;
  width: min(92vw, 380px);
  box-shadow: var(--shadow);
}
.dialog.wide { width: min(94vw, 560px); }
.dialog::backdrop { background: rgba(3, 6, 15, 0.65); backdrop-filter: blur(6px); }
.dialog h2 { margin: 0 0 6px; font-size: 1.2rem; }
.dialog p { margin: 0 0 14px; color: var(--muted); }
.dialog label { display: block; font-size: 0.85rem; color: var(--muted); margin: 10px 0 4px; }
.dialog textarea {
  width: 100%;
  font: 14px ui-monospace, Menlo, Consolas, monospace;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  padding: 10px;
  resize: vertical;
}
.dialog .toolbar { margin-top: 14px; }

.promo-choice { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.promo-choice button {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--sq-light);
  cursor: pointer;
  padding: 4px;
}
.promo-choice button:hover { border-color: var(--accent); }
.promo-choice img { width: 100%; height: 100%; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 30px);
  background: var(--card-solid);
  color: var(--text);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  padding: 11px 18px;
  border-radius: 999px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Navigazione e grafico ---------- */
.navbar { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-left: 30px; }
.navbar .btn { padding: 8px 0; font-size: 1rem; }
.graph-card { padding: 8px; margin-left: 30px; }
.graph { position: relative; height: 92px; border-radius: 8px; overflow: hidden; cursor: pointer; touch-action: none; border: 1px solid var(--line); }
.graph:focus-visible { outline: 2px solid var(--accent); }
.graph svg { display: block; width: 100%; height: 100%; }
.graph-black { fill: var(--graph-black); }
.graph-white { fill: var(--graph-white); }
.graph-mid { stroke: var(--graph-line); stroke-width: 1; stroke-dasharray: 3 3; }
.graph-line { stroke: var(--graph-line); stroke-width: 1.2; }
.graph-cursor { stroke: var(--graph-cursor); stroke-width: 2; }
.graph-dot {
  position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%;
  border: 1.5px solid var(--card); pointer-events: none;
}

/* ---------- Icone delle categorie ---------- */
.cls-icon { width: 1.25em; height: 1.25em; flex-shrink: 0; vertical-align: -0.25em; }
.cls-brilliant { color: var(--cls-brilliant); }
.cls-great { color: var(--cls-great); }
.cls-best { color: var(--cls-best); }
.cls-excellent { color: var(--cls-excellent); }
.cls-good { color: var(--cls-good); }
.cls-book { color: var(--cls-book); }
.cls-inaccuracy { color: var(--cls-inaccuracy); }
.cls-mistake { color: var(--cls-mistake); }
.cls-blunder { color: var(--cls-blunder); }
.dot-brilliant { background: var(--cls-brilliant); }
.dot-great { background: var(--cls-great); }
.dot-inaccuracy { background: var(--cls-inaccuracy); }
.dot-mistake { background: var(--cls-mistake); }
.dot-blunder { background: var(--cls-blunder); }
.cls-text { font-weight: 700; font-size: 0.9rem; }

/* Icona sulla casa d'arrivo della mossa */
.badge {
  position: absolute; width: 5.5%; height: 5.5%; transform: translate(-70%, -30%);
  z-index: 8; pointer-events: none; filter: drop-shadow(0 1px 2px rgba(0,0,0,.45));
}
.badge .cls-icon { width: 100%; height: 100%; }

/* ---------- Campi e pulsanti ---------- */
.card textarea, .select {
  width: 100%;
  font: 14px ui-monospace, Menlo, Consolas, monospace;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  padding: 10px;
  resize: vertical;
  margin: 4px 0 8px;
}
.select { font-family: inherit; }
.field-label { display: block; font-size: 0.85rem; color: var(--muted); margin: 10px 0 6px; }
.btn.wide { width: 100%; margin-top: 12px; }
.file-btn { display: flex; align-items: center; justify-content: center; text-align: center; }
.toolbar.two { grid-template-columns: repeat(2, 1fr); }
.hint.first { margin: 0 0 8px; }
.segmented.small button { padding: 6px 4px; font-size: 0.85rem; }
.engine-settings { display: grid; gap: 6px; margin-top: 10px; }

.progress { height: 10px; border-radius: 999px; background: var(--bg); overflow: hidden; border: 1px solid var(--line); }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
#review-progress .btn { margin-top: 10px; }

/* ---------- Linee del motore ---------- */
.elines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.eline {
  display: flex; gap: 10px; align-items: baseline;
  padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line);
  cursor: pointer; transition: border-color 0.15s;
}
.eline:hover, .eline.hl, .eline:focus-visible { border-color: var(--accent); outline: none; }
.eline.best { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.eline.placeholder { cursor: default; color: var(--muted); display: block; border-style: dashed; }
.eline-score {
  font-weight: 800; font-variant-numeric: tabular-nums; min-width: 4.2em; text-align: center;
  padding: 2px 6px; border-radius: 6px; font-size: 0.85rem;
}
.eline-score.white { background: #eceef2; color: #1b1e25; }
.eline-score.black { background: #2a2e37; color: #eceef2; border: 1px solid var(--line); }
.eline-score.even { background: var(--bg); }
.eline-moves { font-size: 0.9rem; line-height: 1.35; overflow-wrap: anywhere; }

/* ---------- Lista mosse ---------- */
.movelist {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: 1fr; gap: 2px;
  max-height: 280px; overflow-y: auto; font-variant-numeric: tabular-nums;
}
@media (min-width: 520px) { .movelist { grid-template-columns: 1fr 1fr; column-gap: 12px; } }
.movelist li { display: grid; grid-template-columns: 2.4em 1fr 1fr; align-items: center; }
.movelist .num { color: var(--muted); font-size: 0.85rem; }
.mv, .mv-empty {
  display: flex; align-items: center; gap: 5px; text-align: left;
  border: 0; background: transparent; padding: 4px 6px; border-radius: 6px; cursor: pointer; font-size: 0.95rem;
}
.mv-empty { color: var(--muted); cursor: default; }
.mv:hover { background: var(--bg); }
.mv.current { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.movelist:empty::after { content: "Nessuna mossa."; color: var(--muted); font-size: 0.9rem; }

/* ---------- Riepilogo della revisione ---------- */
.sum-players { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; font-weight: 700; }
.sum-name { overflow-wrap: anywhere; }
.sum-name small { color: var(--muted); font-weight: 600; }
.sum-name.right { text-align: right; }
.sum-result { color: var(--muted); font-variant-numeric: tabular-nums; }
.sum-acc { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; margin: 10px 0 4px; }
.sum-acc > span { color: var(--muted); font-size: 0.85rem; }
.acc-box { border-radius: 10px; padding: 6px 10px; font-size: 1.5rem; text-align: center; font-variant-numeric: tabular-nums; }
.acc-box.white { background: #eceef2; color: #1b1e25; }
.acc-box.black { background: #2a2e37; color: #eceef2; border: 1px solid var(--line); }
.sum-opening { text-align: center; color: var(--muted); font-size: 0.9rem; margin: 6px 0; }
.sum-table { width: 100%; border-collapse: collapse; margin: 6px 0; }
.sum-table td { padding: 3px 4px; border-top: 1px solid var(--line); }
.sum-table .cnt { width: 3em; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.sum-table .cls { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 0.9rem; }
#review-summary .toolbar { margin-top: 10px; }

/* ---------- Scheda della mossa ---------- */
.move-card { display: flex; flex-direction: column; gap: 6px; }
.mc-head { display: flex; gap: 10px; align-items: flex-start; }
.mc-head > .cls-icon { width: 2em; height: 2em; }
.mc-title { font-weight: 800; font-size: 1.05rem; }
.mc-sub { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.mc-best, .mc-key, .mc-feedback { margin: 0; font-size: 0.92rem; }
.mc-line { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.mc-key { color: var(--accent); font-weight: 600; }
.move-card .toolbar { margin-top: 4px; }

/* Link-pulsante e finestra informazioni */
.link-btn { border: 0; background: none; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: inherit; padding: 6px; }
.dialog a { color: var(--accent); overflow-wrap: anywhere; }
#dlg-about p { color: var(--text); font-size: 0.9rem; }
#dlg-about small { color: var(--muted); font-weight: 600; font-size: 0.8rem; }

/* Spiegazioni */
.mc-explain { margin: 2px 0 0; padding-left: 1.1em; display: flex; flex-direction: column; gap: 4px; font-size: 0.92rem; }
.mc-explain li::marker { color: var(--muted); }

/* ---------- Libreria partite ---------- */
.dialog.library { display: none; flex-direction: column; gap: 10px; max-height: min(88vh, 760px); padding: 18px; }
.dialog.library[open] { display: flex; }
.lib-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.lib-head h2 { margin: 0; }
.lib-close { width: 44px; height: 44px; flex-shrink: 0; }
.lib-search {
  width: 100%; min-height: 44px; padding: 10px 12px; font-size: 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text);
}
.lib-search:focus { outline: none; border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 40px; padding: 8px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--muted); font-weight: 600;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.lib-count { margin: 0; }
.lib-list {
  list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1 1 auto; min-height: 120px;
  display: flex; flex-direction: column; gap: 8px; overscroll-behavior: contain;
}
.lib-item {
  width: 100%; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 3px;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text);
}
.lib-item:hover, .lib-item:focus-visible { border-color: var(--accent); }
.lib-item:disabled { opacity: 0.6; cursor: progress; }
.lib-players { font-weight: 700; }
.lib-meta, .lib-opening { font-size: 0.8rem; color: var(--muted); }
.lib-opening { font-style: italic; }
.lib-famous { font-size: 0.88rem; line-height: 1.35; margin-top: 2px; }
.dialog .lib-note { margin: 0; }
.lib-note a { color: var(--accent); }
@media (max-width: 520px) {
  .dialog.library { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; border: 0;
    padding: calc(14px + env(safe-area-inset-top)) 16px calc(12px + env(safe-area-inset-bottom)); }
}

/* ---------- Analisi partita ---------- */
.setup-names { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.text-input {
  width: 100%; min-height: 44px; padding: 10px 12px; font-size: 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
}
.text-input:focus { outline: none; border-color: var(--accent); }
.setup-fen { margin-top: 12px; }
.setup-fen summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; padding: 8px 0; min-height: 40px; }
.setup-fen textarea {
  width: 100%; font: 14px ui-monospace, Menlo, Consolas, monospace; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text); padding: 10px; resize: vertical;
}
#game-setup .btn.wide + .btn.wide { margin-top: 8px; }

.adv-card { display: flex; flex-direction: column; gap: 6px; }
.adv-title { font-weight: 700; font-size: 1.05rem; }
.adv-title::before { content: "●"; margin-right: 6px; font-size: 0.8em; vertical-align: 0.1em; }
.adv-title.adv-w::before { color: var(--graph-white); text-shadow: 0 0 1px #000; }
.adv-title.adv-b::before { color: var(--graph-black); text-shadow: 0 0 1px #fff; }
.adv-title.adv-none::before { color: var(--muted); }
.adv-meter { height: 10px; border-radius: 999px; background: var(--graph-black); overflow: hidden; border: 1px solid var(--line); }
.adv-meter-fill { height: 100%; background: var(--graph-white); transition: width 0.3s; }
.adv-sub { color: var(--muted); font-size: 0.82rem; }
.adv-turn { margin: 2px 0 0; font-size: 0.88rem; border-left: 3px solid var(--cls-mistake); padding-left: 8px; }
.adv-turn .link-btn { color: var(--text); font-weight: 700; padding: 6px 2px; }

.variation-bar { border-color: var(--cls-great); }
.variation-bar p { margin: 0 0 8px; font-size: 0.9rem; }

.toolbar.three { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 520px) { .toolbar.three { grid-template-columns: repeat(3, 1fr); } }

.dot-turning { background: transparent; border: 2.5px solid var(--cls-mistake); width: 14px; height: 14px; margin: -7px 0 0 -7px; }

/* ---------- Allenatore ---------- */
.coach-card { display: flex; flex-direction: column; gap: 8px; }
.coach-card h2 { margin: 0; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.85rem; color: var(--muted); min-height: 40px; }
.switch input { appearance: none; width: 40px; height: 24px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; transition: background 0.15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--text); transition: transform 0.15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); background: var(--accent-ink); }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.coach-body { display: flex; flex-direction: column; gap: 6px; }
.coach-body .hint { margin: 0; }
.coach-hint {
  display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; cursor: pointer; min-height: 44px;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); border-left: 4px solid #f59e0b;
  background: var(--bg-2); color: var(--text);
}
.coach-hint.threat { border-left-color: #ef4444; }
.coach-hint.picked { border-color: #f59e0b; }
.coach-hint.threat.picked { border-color: #ef4444; }
.coach-title { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.coach-text { font-size: 0.92rem; line-height: 1.35; }
.coach-more { font-size: 0.75rem; color: var(--muted); }
.coach-card .card-head { align-items: center; }
@media (max-width: 520px), (pointer: coarse) { .segmented.small button { min-height: 40px; } }

@media (min-width: 861px) {
  .toast { left: calc(50% + var(--sidebar-w) / 2); }
}
@media (max-width: 860px) {
  .toast { bottom: calc(var(--bottom-nav-h) + 16px + env(safe-area-inset-bottom)); }
}

/* Campi di testo: stesso stile ovunque */
.card textarea, .select, .text-input, .setup-fen textarea, .dialog textarea, .lib-search {
  background: var(--card-solid);
  border-color: var(--line-strong);
}
.card textarea:focus, .select:focus, .text-input:focus, .setup-fen textarea:focus, .dialog textarea:focus, .lib-search:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.progress-fill { background: var(--accent-grad); }
.mv.current { background: var(--accent-grad); }
.chip.active { background: var(--accent-grad); border-color: transparent; }
.eline { background: rgba(255, 255, 255, 0.02); }
.navbar .btn { background: var(--card); }

/* ---------- Problemi (fase F) ---------- */
.pz-card { display: flex; flex-direction: column; gap: 8px; border-left: 3px solid var(--line-strong); transition: border-color 0.2s, box-shadow 0.3s; }
.pz-card[data-state="good"] { border-left-color: var(--cls-best); }
.pz-card[data-state="solved"] { border-left-color: var(--cls-best); box-shadow: var(--shadow-sm), 0 0 0 1px color-mix(in srgb, var(--cls-best) 35%, transparent); }
.pz-card[data-state="done"] { border-left-color: var(--accent); }
.pz-card[data-state="wrong"] { border-left-color: var(--cls-blunder); }
.pz-meta { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--accent); }
.card .pz-title { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.01em; margin: 0; }
.pz-card[data-state="solved"] .pz-title { color: var(--cls-best); }
.pz-card[data-state="wrong"] .pz-title { color: var(--cls-blunder); }
.pz-feedback { display: flex; flex-direction: column; gap: 4px; }
.pz-feedback:empty { display: none; }
.pz-feedback p { margin: 0; font-size: 0.92rem; line-height: 1.45; }
.pz-feedback .pz-note { color: var(--muted); font-size: 0.85rem; }
.pz-actions { margin-top: 4px; }
.pz-actions .btn[hidden] + .btn { grid-column: auto; }

.pz-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 14px 10px; text-align: center; }
.pz-stats b { display: block; font-size: 1.45rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.pz-stats div:first-child b { color: var(--accent); }
.pz-stats span { font-size: 0.72rem; color: var(--muted); font-weight: 600; }

#pz-themes { margin-bottom: 4px; }
#pz-themes .chip { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; }
#pz-source { text-align: left; line-height: 1.5; }
#pz-source a { color: var(--muted); }
.pz-hint-icon { width: 100%; height: 100%; fill: var(--accent); stroke: var(--accent-ink); stroke-width: 2.4; stroke-linecap: round; }
@media (max-width: 520px), (pointer: coarse) { #pz-themes .chip { min-height: 40px; } }

/* ---------- Lezioni (fase G) ---------- */
.sq.mark::after {
  content: ""; position: absolute; inset: 6%; border-radius: 50%;
  border: 3px solid var(--accent); box-shadow: 0 0 10px rgba(46, 230, 255, 0.55); pointer-events: none; z-index: 2;
}
.ls-progress { max-width: 1280px; margin-bottom: 22px; }
.ls-progress-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.ls-progress-head span { color: var(--muted); font-size: 0.88rem; }
.ls-progress .progress { height: 8px; }
.ls-group { margin-bottom: 26px; }
.ls-group h2 { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px 2px; }
.ls-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.ls-item {
  display: flex; flex-direction: column; gap: 6px; text-align: left; cursor: pointer; min-height: 120px;
  color: var(--text); font: inherit; position: relative;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.2s;
}
.ls-item:hover, .ls-item:focus-visible { border-color: rgba(46, 230, 255, 0.45); transform: translateY(-2px); box-shadow: var(--shadow); outline: none; }
.ls-item-title { font-weight: 700; font-size: 1.02rem; }
.ls-item-sum { color: var(--muted); font-size: 0.88rem; line-height: 1.45; flex: 1; }
.ls-item-meta { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.ls-item.done { border-color: color-mix(in srgb, var(--cls-best) 45%, transparent); }
.ls-item.done::after {
  content: "✓"; position: absolute; top: 14px; right: 14px; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; font-size: 0.8rem; font-weight: 800; color: #fff; background: var(--cls-best);
}
.ls-item.done .ls-item-meta { color: var(--cls-best); }

.layout.ls-player { padding: 0; }
.ls-card { display: flex; flex-direction: column; gap: 10px; border-left: 3px solid var(--line-strong); transition: border-color 0.2s; }
.ls-card[data-state="solved"] { border-left-color: var(--cls-best); }
.ls-card[data-state="wrong"] { border-left-color: var(--cls-blunder); }
.ls-back { align-self: flex-start; padding: 4px 0; text-decoration: none; font-size: 0.85rem; min-height: 40px; }
.ls-back:hover { color: var(--text); }
.ls-steps-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ls-steps-row .hint { margin: 0; }
.ls-steps { display: flex; gap: 6px; }
.ls-dot { width: 22px; height: 6px; border-radius: 999px; background: var(--line-strong); }
.ls-dot.ex { width: 10px; }
.ls-dot.past { background: color-mix(in srgb, var(--accent) 55%, transparent); }
.ls-dot.current { background: var(--accent); box-shadow: 0 0 8px rgba(46, 230, 255, 0.6); }
.ls-text { margin: 0; font-size: 0.98rem; line-height: 1.6; }
.ls-good { color: var(--cls-best); font-weight: 600; }
.ls-bad { color: var(--cls-blunder); font-weight: 600; }
.ls-nav { margin-top: 2px; padding-top: 12px; border-top: 1px solid var(--line); }

/* Problema del giorno */
.pz-daily { display: flex; align-items: center; gap: 14px; padding: 14px 16px; }
.pz-daily-icon {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(46, 230, 255, 0.2);
}
.pz-daily-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.pz-daily-icon .tick { opacity: 0; }
.pz-daily.done .pz-daily-icon { color: var(--cls-best); background: color-mix(in srgb, var(--cls-best) 14%, transparent); border-color: color-mix(in srgb, var(--cls-best) 35%, transparent); }
.pz-daily.done .pz-daily-icon .tick { opacity: 1; }
.pz-daily-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pz-daily-text span { font-size: 0.82rem; color: var(--muted); }
.pz-daily .btn { min-width: 96px; }
.pz-daily.done .btn.primary { background: transparent; color: var(--text); border-color: var(--line-strong); box-shadow: none; }

/* Partite online */
.btn.on-open { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 2px 0 10px; }
.btn.on-open svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.on-form { display: flex; gap: 8px; }
.on-form .lib-search { flex: 1; min-width: 0; }
.lib-item[data-outcome="win"] { border-left: 3px solid var(--cls-best); }
.lib-item[data-outcome="loss"] { border-left: 3px solid var(--cls-blunder); }
.lib-item[data-outcome="draw"] { border-left: 3px solid var(--muted); }

/* Salva gli errori come esercizi (riepilogo della revisione) */
.sum-save { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.sum-save > span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 8px; }

/* I tuoi dati (backup) */
.data-box { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 0 0 14px; background: rgba(0, 0, 0, 0.12); }
.data-box p { margin: 0 0 10px; }
.data-box .toolbar.three { margin-top: 0; }
.data-msg p { margin: 10px 0 0; color: var(--text); font-size: 0.9rem; }
.data-msg:empty { display: none; }
.data-msg .toolbar { margin-top: 8px; }

/* Gioca contro Stockfish */
.pl-moves {
  list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto;
  display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; font-variant-numeric: tabular-nums;
}
.pl-moves li { display: grid; grid-template-columns: 2.4em 1fr 1fr; padding: 3px 4px; font-size: 0.95rem; }
.pl-moves .num { color: var(--muted); font-size: 0.85rem; }
#pl-level button { padding: 8px 2px; }

/* Teoria delle aperture (Analisi partita) */
.opening-name { margin: 0 0 8px; font-weight: 600; font-size: 0.92rem; }
.opening-moves { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.opening-move {
  display: flex; align-items: baseline; gap: 10px; text-align: left; cursor: pointer; min-height: 40px;
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.02); color: var(--text);
}
.opening-move:hover, .opening-move:focus-visible { border-color: var(--accent); outline: none; }
.opening-move b { min-width: 3.2em; font-variant-numeric: tabular-nums; }
.opening-move span { color: var(--muted); font-size: 0.85rem; }
.lang-btn { font-size: 0.78rem; font-weight: 800; letter-spacing: 0.04em; }

/* ---------- Audio (musica lofi e suoni) ---------- */
.audio-wrap { position: relative; }
.audio-btn { position: relative; }
.audio-btn .eq { display: none; position: absolute; right: 5px; bottom: 6px; gap: 1.5px; align-items: flex-end; height: 9px; }
.audio-btn.playing { border-color: rgba(46, 230, 255, 0.45); color: var(--accent); box-shadow: 0 0 14px rgba(46, 230, 255, 0.25); }
.audio-btn.playing .eq { display: flex; }
.audio-btn.playing svg { opacity: 0.35; }
.audio-btn .eq i { display: block; width: 2.5px; height: 100%; border-radius: 2px; background: var(--accent); transform-origin: bottom; animation: eq 1.1s ease-in-out infinite; }
.audio-btn .eq i:nth-child(2) { animation-delay: -0.35s; }
.audio-btn .eq i:nth-child(3) { animation-delay: -0.7s; }
@keyframes eq { 0%, 100% { transform: scaleY(0.3); } 50% { transform: scaleY(1); } }
@media (prefers-reduced-motion: reduce) { .audio-btn .eq i { animation: none; transform: scaleY(0.7); } }
.audio-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; width: min(300px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 12px; padding: 14px 16px; border-radius: 16px;
  background: var(--card-solid); border: 1px solid var(--line-strong); box-shadow: var(--shadow);
}
.audio-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.audio-row b { display: block; font-size: 0.92rem; }
.audio-row span { display: block; font-size: 0.76rem; color: var(--muted); line-height: 1.35; margin-top: 2px; }
.audio-vol { display: flex; align-items: center; gap: 10px; font-size: 0.8rem; color: var(--muted); }
.audio-vol input { flex: 1; accent-color: var(--accent); min-height: 32px; }
@media (max-width: 860px) {
  .topbar { gap: 8px; }
  .topbar .icon-btn { width: 40px; height: 40px; }
}
@media (max-width: 860px) {
  .audio-panel { position: fixed; left: 16px; right: 16px; top: calc(62px + env(safe-area-inset-top)); width: auto; }
}
