:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --text: #1f1c18;
  --muted: #6b645b;
  --accent: #7a4b2a;
  --accent-ink: #ffffff;
  --border: #e3ddd3;
  --light: #f0d9b5;
  --dark: #b58863;
  --sel: rgba(255, 213, 79, .65);
  --last: rgba(155, 199, 0, .45);
  --check: rgba(220, 40, 40, .7);
  --pw: #ffffff;
  --pws: 0 0 2px #000, 0 0 1px #000, 0 1px 2px rgba(0,0,0,.5);
  --pb: #111111;
  --pbs: 0 1px 1px rgba(255,255,255,.25);
  --coin: #c9a227;
  --danger: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161412;
    --surface: #211e1b;
    --text: #ece6dc;
    --muted: #a39a8e;
    --accent: #d9a066;
    --accent-ink: #1a1410;
    --border: #36302a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.55;
}
a { color: var(--accent); }
header.top {
  display: flex; align-items: center; gap: 12px 20px; flex-wrap: wrap;
  max-width: 1040px; margin: 0 auto; padding: 16px;
}
header.top .account { margin-left: auto; display: flex; align-items: center; }
@media (max-width: 640px) {
  header.top nav.top { order: 3; width: 100%; display: flex; justify-content: space-between; }
  nav.top a { margin-left: 0 !important; }
}
.brand { font-weight: 700; font-size: 1.35rem; text-decoration: none; color: var(--text); letter-spacing: .02em; }
.brand span { color: var(--accent); }
nav.top a { margin-left: 16px; color: var(--muted); text-decoration: none; font-size: .95rem; padding: 4px 0; border-bottom: 2px solid transparent; }
nav.top a.on { color: var(--text); border-bottom-color: var(--accent); }
nav.top a:hover { color: var(--text); }
main { max-width: 1040px; margin: 0 auto; padding: 0 16px 32px; }

/* Gioco */
.game { display: grid; grid-template-columns: minmax(0, 560px) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 820px) { .game { grid-template-columns: 1fr; } }
.board-wrap { width: 100%; max-width: 560px; }
.board {
  display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%; aspect-ratio: 1 / 1;
  border-radius: 6px; overflow: hidden; box-shadow: 0 6px 24px rgba(0,0,0,.18);
  user-select: none; touch-action: manipulation;
}
.sq { position: relative; min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.sq.l { background: var(--light); }
.sq.d { background: var(--dark); }
.sq.last::before, .sq.sel::before, .sq.check::before { content: ""; position: absolute; inset: 0; }
.sq.last::before { background: var(--last); }
.sq.sel::before { background: var(--sel); }
.sq.check::before { background: radial-gradient(circle, var(--check) 0%, transparent 75%); }
.sq .pc { position: relative; font-size: min(9vw, 52px); line-height: 1; }
.pc.w { color: var(--pw); text-shadow: var(--pws); }
.pc.b { color: var(--pb); text-shadow: var(--pbs); }
.sq.hint::after {
  content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%; background: rgba(0,0,0,.22);
}
.sq.hint.cap::after { width: 86%; height: 86%; background: transparent; border: 5px solid rgba(0,0,0,.22); }
.coord { position: absolute; font-size: 11px; font-weight: 600; opacity: .75; pointer-events: none; }
.coord.f { bottom: 2px; right: 4px; }
.coord.r { top: 2px; left: 4px; }
.sq.l .coord { color: var(--dark); }
.sq.d .coord { color: var(--light); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 1.05rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
label.f { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
select, button {
  font: inherit; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); padding: 8px 12px;
}
button { cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }
.status { font-weight: 600; margin: 4px 0 12px; min-height: 1.5em; }
.moves {
  max-height: 260px; overflow: auto; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9rem;
  border-top: 1px solid var(--border); padding-top: 8px;
}
.moves ol { margin: 0; padding-left: 2.2em; }
.captured { min-height: 1.6em; font-size: 1.3rem; letter-spacing: 1px; }

dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); padding: 16px; }
dialog::backdrop { background: rgba(0,0,0,.45); }
.promo { display: flex; gap: 8px; }
.promo button { font-size: 2.4rem; width: 64px; height: 64px; padding: 0; }

.intro { margin: 8px 0 20px; color: var(--muted); }
.intro h1 { color: var(--text); margin: 0 0 4px; font-size: 1.6rem; }

/* Pagine legali */
.legal { max-width: 760px; }
.legal h1 { font-size: 1.7rem; margin-bottom: 4px; }
.legal h2 { font-size: 1.15rem; margin-top: 28px; }
.legal .updated { color: var(--muted); margin-top: 0; }
.legal table { border-collapse: collapse; width: 100%; font-size: .92rem; }
.legal th, .legal td { border: 1px solid var(--border); padding: 8px; text-align: left; vertical-align: top; }
.ph { background: rgba(255, 200, 0, .25); padding: 0 3px; border-radius: 3px; }

footer.site {
  border-top: 1px solid var(--border); margin-top: 32px; padding: 20px 16px; text-align: center;
  color: var(--muted); font-size: .88rem;
}
footer.site a { color: var(--muted); margin: 0 8px; }

.notice {
  position: fixed; left: 16px; right: 16px; bottom: 16px; max-width: 560px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.2); padding: 14px 16px; font-size: .92rem; display: none;
}
.notice.show { display: block; }
.notice p { margin: 0 0 10px; }

/* Account */
[hidden] { display: none !important; }
.me { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.coins { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; }
.coins::before, .coin-ic::before { content: ""; display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffe28a, var(--coin) 60%, #8a6d10); box-shadow: inset 0 0 0 1.5px #8a6d10; }
.coin-ic { display: inline-flex; margin-right: 5px; vertical-align: -2px; }
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; overflow: hidden; background: var(--accent); color: var(--accent-ink); font-weight: 700; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 32px; height: 32px; font-size: .9rem; }
.avatar.lg { width: 84px; height: 84px; font-size: 2rem; }
.needs-account { background: var(--surface); border: 1px dashed var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 20px; }
.muted { color: var(--muted); }
input[type=text], input:not([type]), input[type=email], input[type=password] {
  font: inherit; width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); margin-bottom: 12px;
}
input[type=file] { font: inherit; color: var(--text); margin-bottom: 4px; max-width: 100%; }
.hint { font-size: .82rem; color: var(--muted); margin: -6px 0 12px; }
.form-msg { min-height: 1.2em; margin: 8px 0; font-size: .92rem; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.big { font-size: 1.1rem; padding: 12px 28px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: .9rem; margin: 4px 0; }
.check input { margin-top: 4px; }
dialog { width: min(420px, calc(100vw - 32px)); }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tabs button { flex: 1; }
.tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

.toast { position: fixed; left: 50%; top: 16px; transform: translate(-50%, -24px); opacity: 0; visibility: hidden; transition: transform .3s, opacity .3s, visibility .3s; background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; z-index: 50; max-width: calc(100vw - 32px); text-align: center; }
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }

/* Negozio */
.shop-h { font-size: 1.1rem; margin: 20px 0 10px; }
.shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.card.using { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.card-b { padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.card-b button { width: 100%; }
.price { font-weight: 700; }
.pv-board { display: grid; grid-template-columns: repeat(4, 1fr); aspect-ratio: 2 / 1; }
.pv-board i { display: block; }
.pv-pieces { display: flex; justify-content: center; align-items: center; aspect-ratio: 2 / 1; font-size: 1.7rem; }

/* Ruota */
.wheel-wrap { position: relative; width: min(360px, 100%); margin: 8px auto 0; }
.wheel { width: 100%; display: block; transition: transform 5s cubic-bezier(.15, .85, .2, 1); filter: drop-shadow(0 6px 18px rgba(0,0,0,.2)); }
.wheel-pointer { position: absolute; left: 50%; top: -6px; transform: translateX(-50%); width: 0; height: 0; border-left: 14px solid transparent; border-right: 14px solid transparent; border-top: 26px solid var(--text); z-index: 2; }
.wheel-actions { text-align: center; margin-top: 18px; }
.wheel-msg { min-height: 1.4em; font-weight: 600; }

/* Classifica */
table.rank { width: 100%; border-collapse: collapse; }
table.rank th, table.rank td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
table.rank th { color: var(--muted); font-size: .85rem; font-weight: 600; }
table.rank tr.me-row td { font-weight: 700; }
.who { display: inline-flex; align-items: center; gap: 10px; }

/* Profilo */
.profile { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; align-items: start; }
.pf-head { display: flex; gap: 16px; align-items: center; margin-bottom: 18px; }
.pf-name { font-size: 1.3rem; font-weight: 700; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stats div { background: var(--bg); border-radius: 10px; padding: 12px; }
.stats b { display: block; font-size: 1.5rem; }
.stats span { color: var(--muted); font-size: .85rem; }
