/* ChessTutor - Learn · Think · Win
   Palette del brandbook: Deep Navy #071A3A (testi, header, fondi scuri), Tutor Blue #1264D8 (azioni, link, mosse suggerite),
   Scholar Gold #F5B51B (solo accenti e badge), Pure White, Board Mist #F3F6FB (superfici), Slate #65738A (testi secondari).
   Rosso e arancione sono riservati alle zone critiche e agli errori. */
@font-face { font-family: "Inter"; src: url("fonts/inter-latin-wght.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Manrope"; src: url("fonts/manrope-latin-wght.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }

:root {
  --navy: #071A3A;
  --blue: #1264D8;
  --blue-hover: #0E52B4;
  --gold: #F5B51B;
  --white: #FFFFFF;
  --mist: #F3F6FB;
  --slate: #65738A;

  --bg: var(--mist);            /* fondo pagina */
  --bg2: var(--white);          /* card */
  --bg3: #E8EEF7;               /* superfici dentro le card, hover */
  --line: #DCE3EE;              /* bordi leggeri */
  --text: var(--navy);
  --muted: var(--slate);
  --accent: var(--blue);
  --accent2: var(--blue);
  --on-accent: #FFFFFF;
  --shadow: 0 1px 2px rgba(7, 26, 58, .06), 0 4px 14px rgba(7, 26, 58, .06);
  --header-bg: var(--white);
  --graph-bg: var(--mist);
  --ok: #12805C;
  --ko: #D92D20;

  /* scacchiera neutra: le case non competono con i colori delle frecce e delle zone */
  --light: #E9EDF2;
  --dark: #9AA9BD;
  --last: rgba(245, 181, 27, .38);
  --sel: rgba(18, 100, 216, .38);
  --bw: min(92vw, calc(100vh - 170px), 640px);
}
/* tema scuro facoltativo, su Deep Navy */
:root[data-theme="dark"] {
  --bg: #071A3A;
  --bg2: #0D2550;
  --bg3: #15315F;
  --line: #22406F;
  --text: #EEF3FA;
  --muted: #A3B1C6;
  --accent2: #6FA4F0;
  --shadow: 0 4px 16px rgba(0, 0, 0, .3);
  --header-bg: #051430;
  --graph-bg: #051430;
  --ok: #4CC79A;
  --ko: #FF6B5E;
  --light: #C9D3E0;
  --dark: #6F819C;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 400 16px/1.5 "Inter", "Segoe UI", system-ui, sans-serif; }
h1, h2, h3 { font-family: "Manrope", "Inter", sans-serif; color: var(--text); }
h1 { font-size: 40px; font-weight: 700; line-height: 1.15; }
h2 { font-size: 26px; font-weight: 700; line-height: 1.25; }
button { font: 500 15px/1.3 "Inter", system-ui, sans-serif; color: var(--text); background: var(--bg2); border: 1.5px solid var(--line); border-radius: 8px; padding: 7px 14px; cursor: pointer; transition: background .15s, border-color .15s; }
button:hover { border-color: var(--blue); background: var(--bg3); }
button:focus-visible { outline: 3px solid rgba(18, 100, 216, .35); outline-offset: 1px; }
/* bottone primario: Tutor Blue, testo bianco */
button.accent { background: var(--blue); border-color: var(--blue); color: var(--on-accent); font-weight: 600; }
button.accent:hover { background: var(--blue-hover); border-color: var(--blue-hover); }
button:disabled { opacity: .45; cursor: default; }
input, select, textarea { font: inherit; font-size: 15px; color: var(--text); background: var(--bg2); border: 1.5px solid var(--line); border-radius: 8px; padding: 6px 9px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); }
input[type="checkbox"] { accent-color: var(--blue); }
textarea { width: 100%; min-height: 140px; resize: vertical; font-family: Consolas, monospace; font-size: 13px; }

header { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--header-bg); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 50; }
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; text-decoration: none; }
.brand img { width: 40px; height: 40px; display: block; }
.brand .wordmark { display: flex; flex-direction: column; line-height: 1; }
.brand .name { font: 800 22px/1 "Manrope", "Inter", sans-serif; letter-spacing: -.01em; color: var(--text); }
.brand .name b { color: var(--blue); font-weight: 800; }
:root[data-theme="dark"] .brand .name b { color: #6FA4F0; }
.brand .payoff { font-size: 10.5px; font-weight: 600; letter-spacing: .22em; color: var(--muted); margin-top: 4px; text-transform: uppercase; }
#tabs { display: flex; gap: 2px; flex-wrap: wrap; }
#tabs button { background: transparent; border: none; color: var(--muted); padding: 8px 12px; font-weight: 500; border-radius: 8px; }
#tabs button:hover { color: var(--text); background: var(--bg3); }
#tabs button.active { color: var(--blue); background: rgba(18, 100, 216, .09); font-weight: 600; }
:root[data-theme="dark"] #tabs button.active { color: #fff; background: var(--bg3); }
#theme-btn { padding: 6px 10px; font-size: 16px; line-height: 1; }

main { display: flex; gap: 24px; padding: 20px 16px; justify-content: center; align-items: flex-start; flex-wrap: wrap; }
#board-area { display: flex; flex-direction: column; gap: 10px; }
#board-row { display: flex; gap: 8px; }

#evalbar { width: 26px; height: var(--bw); background: var(--navy); border-radius: 6px; position: relative; overflow: hidden; box-shadow: var(--shadow); }
#evalfill { position: absolute; bottom: 0; left: 0; right: 0; height: 50%; background: #fff; transition: height .4s ease; }
#evaltext { position: absolute; left: 0; right: 0; text-align: center; font-size: 11px; font-weight: 700; bottom: 4px; color: var(--navy); }
#evaltext.top { top: 4px; bottom: auto; color: #fff; }
body.flipped #evalbar { transform: rotate(180deg); }
body.flipped #evaltext { transform: rotate(180deg); }
#evalbar.hidden { visibility: hidden; }

#board-wrap { position: relative; width: var(--bw); height: var(--bw); }
#board { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 100%; height: 100%; border-radius: 8px; overflow: hidden; position: relative; user-select: none; touch-action: none; box-shadow: 0 2px 4px rgba(7, 26, 58, .08), 0 10px 30px rgba(7, 26, 58, .12); }
.sq { position: relative; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.last::before, .sq.sel::before, .sq.hint::before { content: ""; position: absolute; inset: 0; }
.sq.last::before { background: var(--last); }
.sq.sel::before { background: var(--sel); }
.sq.hint::before { background: rgba(18, 100, 216, .55); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .4; } to { opacity: 1; } }
.sq.check { background: radial-gradient(circle, #ff3b3b 0%, #e33 30%, rgba(200, 0, 0, .25) 70%, transparent 80%), var(--light); }
.sq.dark.check { background: radial-gradient(circle, #ff3b3b 0%, #e33 30%, rgba(200, 0, 0, .25) 70%, transparent 80%), var(--dark); }
.sq.dot::after { content: ""; position: absolute; left: 36%; top: 36%; width: 28%; height: 28%; border-radius: 50%; background: rgba(7, 26, 58, .22); z-index: 3; pointer-events: none; }
.sq.ring::after { content: ""; position: absolute; inset: 4%; border-radius: 50%; border: calc(var(--bw) / 8 * .08) solid rgba(7, 26, 58, .22); z-index: 3; pointer-events: none; }
.coord { position: absolute; font-size: calc(var(--bw) / 8 * .17); font-weight: 700; pointer-events: none; z-index: 1; }
.coord.rank { left: 3px; top: 2px; }
.coord.file { right: 4px; bottom: 1px; }
.sq.light .coord { color: var(--dark); }
.sq.dark .coord { color: var(--light); }

/* pezzi ad alto contrasto: bianchi con contorno navy, neri quasi neri */
.piece { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: calc(var(--bw) / 8 * .80); line-height: 1; z-index: 2; cursor: grab;
  font-family: "Segoe UI Symbol", "DejaVu Sans", "Noto Sans Symbols 2", serif; }
.piece.w { color: #fff; text-shadow: 0 0 1px #071A3A, 1px 1px 0 #071A3A, -1px -1px 0 #071A3A, 1px -1px 0 #071A3A, -1px 1px 0 #071A3A, 0 2px 3px rgba(7, 26, 58, .45); }
.piece.b { color: #0B1222; text-shadow: 0 0 1px rgba(255, 255, 255, .35), 0 2px 3px rgba(7, 26, 58, .35); }
.piece.ghost { position: absolute; z-index: 20; pointer-events: none; }
.piece.dragging { z-index: 30; cursor: grabbing; transform: scale(1.12); }
.piece.hide { visibility: hidden; }

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

#promo { position: absolute; inset: 0; background: rgba(7, 26, 58, .55); z-index: 40; display: flex; align-items: center; justify-content: center; gap: 8px; }
#promo[hidden], #toast[hidden] { display: none; }
#promo button { font-size: calc(var(--bw) / 8 * .7); width: calc(var(--bw) / 8); height: calc(var(--bw) / 8); padding: 0; font-family: "Segoe UI Symbol", serif; background: #fff; color: var(--navy); }

#controls { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; padding-left: 34px; }
#controls .sep { flex: 1; }

#panel { width: 440px; max-width: 100%; display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 100px); overflow-y: auto; padding: 2px 6px 6px 2px; }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 10px; font: 600 13px/1.3 "Inter", sans-serif; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }

.coach { display: flex; gap: 12px; align-items: flex-start; }
.coach .avatar { width: 40px; height: 40px; flex: none; font-size: 0; background: url("brand/emblem.png") center / cover no-repeat; border-radius: 50%; }
.coach .bubble { background: var(--mist); border: 1px solid var(--line); border-radius: 4px 12px 12px 12px; padding: 10px 13px; flex: 1; position: relative; }
:root[data-theme="dark"] .coach .bubble { background: var(--bg3); }
.coach .bubble p { margin: 0 0 6px; }
.coach .bubble p:last-child { margin: 0; }

.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; font-size: 12px; font-weight: 800; color: #fff; }
/* badge oro per i suggerimenti e i traguardi */
.badge.gold, .tip-badge { background: var(--gold); color: var(--navy); }
.tip-badge { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .04em; padding: 2px 8px; border-radius: 10px; text-transform: uppercase; }
.label { font-weight: 700; }

.lines .line { display: flex; gap: 10px; padding: 6px 7px; border-radius: 8px; cursor: pointer; align-items: baseline; }
.lines .line:hover { background: var(--bg3); }
.lines .score { min-width: 54px; font-weight: 700; text-align: center; border-radius: 5px; padding: 0 4px; font-size: 14px; }
.score.w { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.score.b { background: var(--navy); color: #fff; }
.lines .pv { color: var(--muted); font-size: 14px; }
.lines .pv b { color: var(--text); }

.moves { display: grid; grid-template-columns: 36px 1fr 1fr; gap: 2px 6px; font-size: 15px; max-height: 260px; overflow-y: auto; }
.moves .num { color: var(--muted); text-align: right; padding: 3px 0; }
.moves .mv { padding: 3px 6px; border-radius: 6px; cursor: pointer; display: flex; gap: 6px; align-items: center; }
.moves .mv:hover { background: var(--bg3); }
.moves .mv.cur { background: rgba(18, 100, 216, .12); color: var(--blue); font-weight: 700; }
:root[data-theme="dark"] .moves .mv.cur { color: #fff; background: var(--bg3); }
.moves .badge { min-width: 18px; height: 18px; font-size: 10px; }

.botlist { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.botlist button { display: flex; flex-direction: column; align-items: center; padding: 8px 4px; }
.botlist button.on { border-color: var(--blue); background: rgba(18, 100, 216, .09); color: var(--blue); }
.botlist .elo { font-size: 12px; color: var(--muted); }

.summary { display: grid; grid-template-columns: 1fr auto auto; gap: 4px 12px; align-items: center; }
.summary .hdr { font-weight: 700; text-align: center; }
.summary .acc { font: 800 26px/1.2 "Manrope", sans-serif; text-align: center; }
.summary .cnt { text-align: center; font-weight: 700; }

/* grafico della revisione: sopra il bianco, sotto il nero (navy) */
#graph { width: 100%; height: 90px; display: block; cursor: pointer; background: var(--navy); border-radius: 8px; }
.chart { width: 100%; background: var(--graph-bg); border-radius: 8px; display: block; }

.book button { margin: 0 4px 4px 0; }
.oplist { max-height: 300px; overflow-y: auto; }
.oplist div { padding: 5px 7px; border-radius: 6px; cursor: pointer; font-size: 15px; }
.oplist div:hover { background: var(--bg3); }

.ok { color: var(--ok); font-weight: 700; }
.ko { color: var(--ko); font-weight: 700; }
/* correzione gentile: mai rosso per un tentativo sbagliato */
.nudge { color: var(--text); font-weight: 600; border-left: 3px solid var(--blue); padding-left: 8px; }
table.stats { width: 100%; border-collapse: collapse; font-size: 14px; }
table.stats td, table.stats th { padding: 5px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.stats th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
.big { font: 800 28px/1.2 "Manrope", "Inter", sans-serif; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 100; box-shadow: 0 6px 20px rgba(7, 26, 58, .3); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--blue); border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
label.tog { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; font-size: 14px; font-weight: 500; }

@media (max-width: 1100px) { #panel { width: var(--bw); max-height: none; } }

#elobadge { margin-left: auto; font-size: 14px; font-weight: 500; background: var(--mist); border: 1px solid var(--line); padding: 5px 12px; border-radius: 16px; white-space: nowrap; cursor: help; }
#elobadge b { color: var(--blue); }
:root[data-theme="dark"] #elobadge { background: var(--bg3); }
:root[data-theme="dark"] #elobadge b { color: #fff; }
.elotable td:last-child { text-align: right; font-weight: 700; }
a { color: var(--accent2); font-weight: 500; }

/* indicatore del motore (Stockfish WASM) */
#engine-status { padding-left: 34px; font-size: 12.5px; color: var(--muted); cursor: pointer; min-height: 18px; }
#engine-status:hover { color: var(--text); }
#engine-status select { font-size: 12px; padding: 2px 4px; }

/* touch: niente menu/selezione con la pressione lunga */
#board { -webkit-touch-callout: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.sq.mark::before { content: ""; position: absolute; inset: 0; background: rgba(229, 72, 77, .6); }
@media (max-width: 700px) {
  :root { --bw: min(calc(100vw - 58px), calc(100vh - 150px)); }
  main { padding: 12px 8px; }
  header { gap: 10px; padding: 8px 12px; position: static; }
  .brand img { width: 34px; height: 34px; }
  .brand .name { font-size: 19px; }
  #tabs { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  #tabs button { white-space: nowrap; padding: 7px 10px; font-size: 14px; }
}

/* evidenziazioni: case/frecce dell'utente e zone critiche del tutor (js/highlights.js) */
.hl-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.hl-layer .mark { fill-opacity: .62; }
.hl-layer .zone { fill-opacity: .16; stroke-width: .07; }
.hl-layer .zone.red { fill: #D92D20; stroke: #D92D20; }
.hl-layer .zone.orange { fill: #F79009; stroke: #F79009; stroke-dasharray: .16 .09; }
#zones-bar { padding-left: 34px; max-width: calc(var(--bw) + 34px); display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; font-size: 13px; }
#zones-bar[hidden] { display: none; }
#zones-bar .legend { display: inline-flex; flex-wrap: wrap; white-space: nowrap; gap: 6px; align-items: center; color: var(--muted); }
#zones-bar .sw { display: inline-block; width: 13px; height: 13px; border-radius: 3px; margin-left: 6px; }
#zones-bar .sw.red { border: 2px solid #D92D20; background: rgba(217, 45, 32, .16); }
#zones-bar .sw.orange { border: 2px dashed #F79009; background: rgba(247, 144, 9, .16); }
#zones-bar .sw.user { background: rgba(229, 72, 77, .62); }
#zone-info { flex-basis: 100%; color: var(--muted); min-height: 18px; max-width: var(--bw); }
#zone-tip { position: absolute; z-index: 35; width: 260px; background: #fff; color: #071A3A; border-radius: 10px; padding: 8px 11px; font-size: 13.5px; line-height: 1.4;
  box-shadow: 0 6px 20px rgba(7, 26, 58, .25); border-left: 4px solid #D92D20; pointer-events: none; }
#zone-tip.orange { border-left-color: #F79009; }
#zone-tip p { margin: 0 0 4px; }
#zone-tip p:last-child { margin: 0; }
#zone-tip[hidden] { display: none; }

/* tema scuro: la barra di valutazione non deve sparire nel fondo navy */
:root[data-theme="dark"] #evalbar { background: #000814; outline: 1px solid var(--line); }

/* errori ricorrenti e classifica */
.stats.themes td { vertical-align: middle; }
.bar { height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--blue); border-radius: 4px; }
button.small { padding: 3px 9px; font-size: 13px; }
.stats tr.me td { font-weight: 700; color: var(--blue); }
.badge.gold { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.6; }

/* selettore lingua EN / IT nell'header */
#lang-switch { display: inline-flex; border: 1.5px solid var(--line); border-radius: 8px; overflow: hidden; }
#lang-switch button { border: none; border-radius: 0; padding: 5px 9px; font-size: 13px; font-weight: 600; background: transparent; color: var(--muted); }
#lang-switch button.on { background: var(--blue); color: #fff; }
#lang-switch button:not(.on):hover { background: var(--bg3); color: var(--text); }

/* scacchiera e pezzi (js/appearance.js) */
#look-btn { padding: 4px 9px; font-size: 18px; line-height: 1; }
#appearance { position: fixed; inset: 0; z-index: 100; background: rgba(7, 26, 58, .45); display: flex; align-items: center; justify-content: center; padding: 16px; }
#appearance[hidden] { display: none; }
.ap-dialog { background: var(--bg2); color: var(--text); border-radius: 14px; box-shadow: 0 16px 48px rgba(7, 26, 58, .35); width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 18px 20px; }
.ap-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ap-head h2 { margin: 0; font-size: 22px; }
.ap-close { padding: 4px 10px; }
.ap-body h3 { margin: 16px 0 8px; font: 600 13px/1.3 "Inter", sans-serif; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.ap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.ap-opt { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 8px; font-size: 13.5px; }
.ap-opt.on { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue) inset; font-weight: 600; }
.ap-board { display: grid; grid-template-columns: repeat(3, 22px); grid-template-rows: repeat(3, 22px); border-radius: 5px; overflow: hidden; }
.ap-board i { background: var(--l); }
.ap-board i:nth-child(even) { background: var(--d); }
.ap-pieces { display: flex; gap: 2px; height: 48px; align-items: center; }
.ap-pieces img { width: 44px; height: 44px; }
.ap-pieces.glyph .piece { position: static; font-size: 38px; width: 44px; height: 44px; cursor: default; }
@media (max-width: 700px) {
  .ap-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .ap-dialog { padding: 14px; }
}

/* accesso con Google (card Account) */
.google-btn { display: block; width: 100%; padding: 10px 14px; font-weight: 600; background: var(--bg2); border: 1.5px solid var(--line); }
.google-btn:hover { border-color: var(--blue); background: var(--bg3); }
.card .or { text-align: center; margin: 10px 0 8px; }
