@font-face { font-family: 'Fredoka'; src: url('fonts/fredoka-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Fredoka'; src: url('fonts/fredoka-600.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Fredoka'; src: url('fonts/fredoka-700.woff2') format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --bg: #14163a;
  --panel: #1d2050;
  --panel2: #282c6b;
  --line: #3b408c;
  --text: #f4f3ff;
  --muted: #a9acd9;
  --gold: #ffd23f;
  --green: #5be36b;
  --blue: #4fc3ff;
  --pink: #ff5d8f;
  --red: #ff4f6d;
  --body: #7d86ff;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font-family: 'Fredoka', system-ui, sans-serif; user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: none; }
#view.panning { cursor: grabbing; }

/* ---------- HUD ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px; pointer-events: none; }
.pill { background: rgba(20, 22, 58, 0.72); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,0.12); border-radius: 999px; padding: 5px 14px; display: flex; gap: 14px; align-items: baseline; box-shadow: 0 4px 14px rgba(0,0,0,0.25); }
.pill b { font-size: 18px; font-weight: 700; }
.pill small { color: var(--muted); font-size: 13px; margin-left: 2px; }
#s-time-wrap b { font-variant-numeric: tabular-nums; }
#s-time-wrap.low b { color: var(--red); animation: blink 1s infinite; }
#s-saved.ok { color: var(--green); }
.hover-info { font-size: 14px; color: #fff; min-height: 0; }
.hover-info:empty { display: none; }
#btn-menu { margin-left: auto; pointer-events: auto; }
.round { width: 42px; height: 42px; border-radius: 50%; background: rgba(20, 22, 58, 0.75); border: 1px solid rgba(255,255,255,0.15); font-size: 20px; display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,0.25); }
.round:hover { background: var(--panel2); }
#paused-tag { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); background: var(--gold); color: #3a2a00; font-weight: 700; padding: 4px 16px; border-radius: 999px; letter-spacing: 2px; pointer-events: none; animation: blink 1.4s infinite; }
#demo-tag { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); background: rgba(20,22,58,0.8); padding: 6px 16px; border-radius: 999px; font-size: 14px; pointer-events: none; }
@keyframes blink { 50% { opacity: 0.55; } }

/* ---------- Panneau ---------- */
#panel { background: linear-gradient(#232661, #181a45); border-top: 2px solid #3d4296; padding: 6px 8px calc(6px + var(--safe-b)); display: flex; gap: 8px; align-items: stretch; }
#panel .row { display: flex; gap: 6px; align-items: stretch; }
#panel .skills { flex: 0 1 auto; }
#panel .controls { flex: 1 1 auto; min-width: 0; }
.skill { position: relative; width: 62px; height: 66px; border-radius: 14px; background: linear-gradient(#343a8a, #262a6a); border: 2px solid #464db0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding: 0 0 3px; transition: transform .08s, background .15s; flex: 0 0 auto; }
.skill canvas { width: 44px; height: 44px; pointer-events: none; }
.skill .n { position: absolute; top: -6px; right: -6px; min-width: 24px; height: 24px; padding: 0 5px; border-radius: 12px; background: var(--gold); color: #3a2a00; font-weight: 700; font-size: 15px; display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0,0,0,0.35); }
.skill .k { position: absolute; top: 2px; left: 6px; font-size: 11px; color: var(--muted); }
.skill .lbl { font-size: 11px; line-height: 1; color: #dfe1ff; white-space: nowrap; }
.skill.sel { background: linear-gradient(#5b63e8, #3c43c0); border-color: #fff; transform: translateY(-3px); box-shadow: 0 0 0 3px rgba(255,255,255,0.25), 0 6px 16px rgba(0,0,0,0.35); }
.skill.empty { opacity: 0.38; }
.skill.empty .n { background: #6b6f9e; color: #fff; }
.skill.flash { animation: flash .35s; }
@keyframes flash { 30% { background: #ff6b6b; } }
.ctl { min-width: 50px; height: 66px; border-radius: 14px; background: linear-gradient(#343a8a, #262a6a); border: 2px solid #464db0; font-size: 24px; display: grid; place-items: center; flex: 0 0 auto; }
.ctl:active, .skill:active { transform: scale(0.95); }
.ctl.on { background: linear-gradient(#ffd23f, #f0a500); border-color: #fff3c0; color: #3a2a00; }
.ctl.danger.armed { background: linear-gradient(#ff6b6b, #d6304f); border-color: #ffd0d0; animation: blink .5s infinite; }
.rr { display: flex; gap: 4px; align-items: stretch; }
.rr .ctl { min-width: 40px; font-size: 26px; font-weight: 700; }
.rr-val { width: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #15173d; border-radius: 12px; border: 2px solid #33377a; }
.rr-val small { font-size: 11px; color: var(--muted); }
.rr-val b { font-size: 22px; font-variant-numeric: tabular-nums; }
#minimap { flex: 1 1 140px; min-width: 100px; height: 66px; border-radius: 12px; background: #0d0f2b; border: 2px solid #33377a; cursor: pointer; touch-action: none; }

@media (max-width: 980px) {
  #panel { flex-direction: column; gap: 6px; }
  #panel .skills { justify-content: space-between; }
  .skill { flex: 1 1 0; width: auto; min-width: 0; }
}
@media (max-width: 560px) {
  .skill { height: 56px; border-radius: 12px; }
  .skill canvas { width: 36px; height: 36px; }
  .skill .lbl, .skill .k { display: none; }
  .skill .n { min-width: 20px; height: 20px; font-size: 13px; top: -5px; right: -4px; }
  .ctl { height: 50px; min-width: 42px; font-size: 20px; border-radius: 12px; }
  .rr .ctl { min-width: 34px; }
  .rr-val { width: 40px; }
  #minimap { height: 50px; }
  .pill { padding: 4px 10px; gap: 10px; }
  .pill b { font-size: 15px; }
  .pill small { font-size: 11px; }
  .round { width: 36px; height: 36px; font-size: 17px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  #panel { flex-direction: row; padding-top: 4px; padding-bottom: calc(4px + var(--safe-b)); }
  .skill { height: 50px; width: 48px; flex: 0 0 auto; }
  .skill canvas { width: 32px; height: 32px; }
  .skill .lbl, .skill .k { display: none; }
  .ctl { height: 50px; min-width: 40px; font-size: 20px; }
  .rr .ctl { min-width: 30px; }
  .rr-val { width: 38px; }
  #minimap { height: 50px; }
}

/* ---------- Écrans ---------- */
#screens > .screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; z-index: 10; }
.screen.dim { background: rgba(10, 11, 34, 0.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.card { background: linear-gradient(160deg, rgba(43, 47, 112, 0.97), rgba(26, 28, 74, 0.97)); border: 2px solid #4a51b8; border-radius: 22px; padding: 22px; width: min(560px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,0.45); max-height: calc(100% - 8px); overflow: auto; animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(0.92); opacity: 0; } }
.card h2 { margin: 0 0 6px; font-size: 28px; line-height: 1.1; }
.card .sub { color: var(--muted); margin: 0 0 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 22px; border-radius: 14px; font-size: 18px; font-weight: 600; background: linear-gradient(#4c54d6, #353cb0); border: 2px solid #6c74f0; box-shadow: 0 4px 0 #23277a; transition: transform .08s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #23277a; }
.btn.go { background: linear-gradient(#6df07c, #34b947); border-color: #b5ffbe; color: #0d3a14; box-shadow: 0 4px 0 #1e7a2c; }
.btn.gold { background: linear-gradient(#ffe066, #f5b400); border-color: #fff3c0; color: #4a3300; box-shadow: 0 4px 0 #a87a00; }
.btn.ghost { background: transparent; border-color: #4a51b8; box-shadow: none; }
.btn.small { padding: 8px 14px; font-size: 15px; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }

/* titre */
#title-screen { flex-direction: column; gap: 10px; text-align: center; background: radial-gradient(ellipse at center, rgba(10,11,34,0.15), rgba(10,11,34,0.6)); }
.logo { font-size: clamp(48px, 12vw, 110px); font-weight: 700; line-height: 0.95; margin: 0; letter-spacing: 1px; color: #fff;
  text-shadow: 0 4px 0 #3c43c0, 0 8px 0 #23277a, 0 14px 30px rgba(0,0,0,0.5); }
.logo span { display: inline-block; animation: hop 2.4s infinite ease-in-out; }
.logo .accent { color: var(--green); }
@keyframes hop { 0%, 70%, 100% { transform: translateY(0); } 80% { transform: translateY(-14px) rotate(-3deg); } 90% { transform: translateY(0); } }
.tagline { font-size: clamp(16px, 3.4vw, 22px); color: #e8e9ff; margin: 6px 0 14px; text-shadow: 0 2px 8px rgba(0,0,0,0.6); }
.menu { display: flex; flex-direction: column; gap: 10px; width: min(320px, 90vw); }
.menu .btn { width: 100%; font-size: 20px; }
.account { font-size: 14px; color: #dfe1ff; margin-top: 8px; text-shadow: 0 1px 4px rgba(0,0,0,0.6); }
.account button { background: none; text-decoration: underline; color: var(--gold); }

/* sélection des niveaux */
.select { width: min(980px, 100%); }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { flex: 1 1 120px; padding: 10px 12px; border-radius: 14px; background: #20235a; border: 2px solid #3b408c; text-align: left; }
.tab b { display: block; font-size: 18px; }
.tab small { color: var(--muted); }
.tab.sel { border-color: var(--c); background: color-mix(in srgb, var(--c) 22%, #20235a); }
.tab.locked { opacity: 0.5; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.lvl { position: relative; text-align: left; padding: 10px 12px 12px; border-radius: 16px; background: #262a6a; border: 2px solid #3b408c; min-height: 92px; display: flex; flex-direction: column; gap: 4px; }
.lvl:hover:not(.locked) { border-color: var(--c); transform: translateY(-2px); }
.lvl .num { font-size: 13px; color: var(--muted); }
.lvl .name { font-weight: 600; font-size: 16px; line-height: 1.15; }
.lvl .stars { margin-top: auto; font-size: 16px; letter-spacing: 2px; color: #4a4f8f; }
.lvl .stars .on { color: var(--gold); }
.lvl.locked { opacity: 0.45; cursor: default; }
.lvl.locked .name::before { content: '🔒 '; }
.lvl.done { background: linear-gradient(160deg, #2d3380, #262a6a); }
.total { display: flex; justify-content: space-between; align-items: center; margin: 0 0 12px; gap: 10px; flex-wrap: wrap; }
.total .score { font-size: 18px; }
.total .score b { color: var(--gold); }

/* briefing */
.brief .facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 12px 0; }
.fact { background: #1b1e4e; border-radius: 12px; padding: 8px 10px; }
.fact small { display: block; color: var(--muted); font-size: 12px; }
.fact b { font-size: 20px; }
.brief .skills-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { display: flex; align-items: center; gap: 4px; background: #1b1e4e; border-radius: 999px; padding: 2px 10px 2px 2px; font-size: 14px; }
.chip canvas { width: 30px; height: 30px; }
.chip b { color: var(--gold); }
.hint { background: rgba(255, 210, 63, 0.12); border-left: 4px solid var(--gold); border-radius: 8px; padding: 8px 12px; margin: 10px 0 0; color: #fff3c0; }
.badge { display: inline-block; font-size: 13px; padding: 2px 10px; border-radius: 999px; background: var(--c); color: #111; font-weight: 600; margin-bottom: 6px; }

/* résultats */
.result { text-align: center; }
.result .big { font-size: 56px; font-weight: 700; line-height: 1; margin: 8px 0; }
.result .big small { font-size: 22px; color: var(--muted); }
.result .stars-big { font-size: 44px; letter-spacing: 6px; color: #4a4f8f; }
.result .stars-big .on { color: var(--gold); text-shadow: 0 0 18px rgba(255,210,63,0.6); display: inline-block; animation: star .5s backwards; }
@keyframes star { from { transform: scale(2.5) rotate(-30deg); opacity: 0; } }
.result .msg { font-size: 18px; margin: 8px 0; }
.result .pts { color: var(--gold); font-size: 18px; }
.pseudo-row { display: flex; gap: 8px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
input[type=text] { font: inherit; font-size: 17px; padding: 10px 12px; border-radius: 12px; border: 2px solid #4a51b8; background: #12143a; color: #fff; min-width: 0; width: 200px; user-select: text; -webkit-user-select: text; }
.err { color: #ff8b9b; min-height: 1.2em; font-size: 14px; margin-top: 6px; }
.ok-msg { color: var(--green); font-size: 15px; margin-top: 6px; }

/* classement */
.board ol { list-style: none; padding: 0; margin: 10px 0 0; }
.board li { display: flex; gap: 12px; padding: 8px 12px; border-radius: 10px; background: #1b1e4e; margin-bottom: 6px; align-items: center; }
.board li .r { width: 32px; font-weight: 700; color: var(--muted); }
.board li:nth-child(1) .r { color: var(--gold); }
.board li:nth-child(2) .r { color: #dfe6f0; }
.board li:nth-child(3) .r { color: #e8a15a; }
.board li .p { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li .s { font-weight: 700; }
.board li.me { outline: 2px solid var(--green); }

/* aide */
.help-list { display: grid; gap: 8px; margin-top: 8px; }
.help-item { display: flex; gap: 10px; align-items: center; background: #1b1e4e; border-radius: 12px; padding: 6px 10px; }
.help-item canvas { width: 46px; height: 46px; flex: 0 0 auto; }
.help-item b { display: block; }
.help-item span { color: var(--muted); font-size: 14px; }
.keys { color: var(--muted); font-size: 14px; line-height: 1.6; margin-top: 12px; }
kbd { background: #12143a; border: 1px solid #4a51b8; border-radius: 6px; padding: 0 6px; font-family: inherit; color: #fff; }

.toggle { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid #343a8a; font-size: 18px; }
.switch { width: 58px; height: 32px; border-radius: 16px; background: #3a3f80; position: relative; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch.on { background: var(--green); }
.switch.on::after { transform: translateX(26px); }

#toast { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); background: rgba(20,22,58,0.92); border: 1px solid #4a51b8; padding: 10px 18px; border-radius: 14px; z-index: 50; font-size: 16px; text-align: center; max-width: 90vw; animation: pop .2s; }
#rotate-hint { font-size: 14px; color: var(--muted); }
