:root {
  --bg: #0f1117; --bg2: #1a1d29; --fg: #eef0f6; --muted: #9aa1b5;
  --a1: #ff5f6d; --a2: #ffc371; --card: rgba(20, 22, 32, .82); --border: rgba(255,255,255,.1);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--fg); background: linear-gradient(180deg, var(--bg), var(--bg2));
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden; touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
#app { height: 100%; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; padding: 12px 16px 16px; gap: 10px; }

#hud { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.title { font-weight: 700; font-size: 18px; white-space: nowrap; }
.stat { display: flex; flex-direction: column; min-width: 80px; }
.stat.right { align-items: flex-end; }
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.stat span:last-child { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }

#board {
  position: relative; flex: 1; min-height: 0; border-radius: 20px; overflow: hidden;
  border: 1px solid var(--border);
  --board-bg:
    radial-gradient(800px 400px at 50% -10%, rgba(255,195,113,.18), transparent 60%),
    radial-gradient(600px 400px at 50% 120%, rgba(80,200,120,.18), transparent 60%),
    #151824;
  background: var(--board-bg);
  transition: background .3s;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }

.overlay {
  position: absolute; inset: 0; display: none; place-items: center; padding: 16px;
  background: rgba(10, 12, 18, .55); backdrop-filter: blur(4px);
}
.overlay.visible { display: grid; }
.card {
  width: 100%; max-width: 380px; text-align: center; padding: 28px 22px;
  background: var(--card); border: 1px solid var(--border); border-radius: 20px;
}
.card h1 {
  margin: 8px 0; font-size: 30px;
  background: linear-gradient(90deg, var(--a1), var(--a2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.card p { color: var(--muted); line-height: 1.5; margin: 8px 0; }
.card .warn { color: #ffb4b4; font-weight: 600; }
.big { font-size: 44px; }
.final { font-size: 20px; color: var(--fg) !important; }
.final strong { font-size: 32px; }
.record { color: var(--a2) !important; font-weight: 700; min-height: 1.5em; }
.sub { font-size: 14px; }

.legend { list-style: none; padding: 0; margin: 14px 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.legend li { background: rgba(255,255,255,.05); border-radius: 10px; padding: 6px 4px; font-size: 13px; color: var(--muted); }
.legend li span { display: block; font-size: 22px; }

.btn {
  margin-top: 10px; border: 0; cursor: pointer; font: inherit; font-weight: 700; font-size: 18px;
  color: #1b1020; padding: 12px 34px; border-radius: 999px;
  background: linear-gradient(90deg, var(--a1), var(--a2));
  box-shadow: 0 8px 24px rgba(255,95,109,.35); transition: transform .1s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: scale(.97); }

@media (max-width: 420px) {
  .title { font-size: 15px; }
  .stat { min-width: 60px; }
  .stat span:last-child { font-size: 22px; }
}

/* ---------- Réglages ---------- */
.title { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  border: 1px solid var(--border); background: rgba(255,255,255,.06); color: inherit;
  border-radius: 10px; width: 34px; height: 34px; font-size: 17px; cursor: pointer; line-height: 1;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }
.card.settings { text-align: left; max-height: 100%; overflow-y: auto; }
.card.settings h1 { text-align: center; }
.field { margin: 18px 0; }
.field-label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.theme {
  height: 52px; border-radius: 12px; border: 2px solid transparent; cursor: pointer;
  color: #fff; font: inherit; font-size: 12px; font-weight: 600; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 5px;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
}
.theme.light { color: #222; text-shadow: none; }
.theme[aria-pressed="true"], .custom-color.active { border-color: var(--a2); box-shadow: 0 0 0 2px rgba(255,195,113,.3); }
.custom-color {
  margin-top: 8px; display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 6px 8px; border-radius: 12px; border: 2px solid transparent; color: var(--fg); font-size: 14px;
}
.custom-color input { width: 40px; height: 32px; border: 0; padding: 0; background: none; cursor: pointer; }
.segmented { display: flex; background: rgba(255,255,255,.06); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button {
  flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-size: 14px; padding: 8px 4px; border-radius: 9px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: rgba(255,255,255,.14); color: var(--fg); font-weight: 700; }
.toggles label { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; color: var(--fg); font-size: 15px; }
.toggles input { width: 18px; height: 18px; accent-color: #ff8a65; }
.settings-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.link-btn { border: 0; background: none; color: var(--muted); font: inherit; font-size: 14px; text-decoration: underline; cursor: pointer; }

/* ---------- Classement ---------- */
.link-btn.light { color: var(--muted); }
#start .link-btn, #gameover .link-btn { margin-top: 12px; }
.center { text-align: center; }
.submit { margin: 14px 0 4px; text-align: left; }
.submit-row { display: flex; gap: 8px; }
.submit input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; color: var(--fg);
  background: rgba(255,255,255,.07); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
}
.submit input:focus { outline: 2px solid var(--a2); outline-offset: 1px; }
.btn.small { margin-top: 0; font-size: 15px; padding: 10px 16px; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.submit-msg { font-size: 13px; min-height: 1.2em; margin: 6px 0 0 !important; color: #ffb4b4 !important; }
.card.lb { max-height: 100%; overflow-y: auto; }
.lb-list { list-style: none; padding: 0; margin: 14px 0; text-align: left; }
.lb-list li {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px;
  font-variant-numeric: tabular-nums;
}
.lb-list li:nth-child(odd) { background: rgba(255,255,255,.04); }
.lb-list li.me { background: rgba(255,195,113,.18); outline: 1px solid rgba(255,195,113,.5); }
.lb-list li.empty { justify-content: center; color: var(--muted); background: none; font-size: 14px; }
.lb-list .rank { width: 28px; text-align: center; font-weight: 700; color: var(--muted); }
.lb-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list .pts { font-weight: 800; }
.overlay .card { max-height: 100%; overflow-y: auto; }
