:root {
  --bg: #07060c;
  --panel: rgba(14, 11, 26, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4efff;
  --muted: #a49cc0;
  --gold: #ffcc33;
  --pink: #ff3cc8;
  --cyan: #2af0ff;
  --pixel: 'Press Start 2P', monospace;
  --font: 'Rubik', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; user-select: none; -webkit-user-select: none; }
canvas { display: block; }
#app { position: fixed; inset: 0; }
#app > canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- boutons ---------- */
.btn {
  font: 700 15px var(--font); letter-spacing: 0.02em; color: var(--text);
  background: rgba(255, 255, 255, 0.06); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 12px 22px; cursor: pointer; transition: transform 0.12s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.35); transform: translateY(-1px); }
.btn.primary { background: linear-gradient(180deg, #ffd84d, #ff9d2e); color: #1d1206; border-color: transparent; box-shadow: 0 0 24px #ffb13355; }
.btn.primary:hover { box-shadow: 0 0 34px #ffb13399; }
.btn.ghost { background: transparent; }
.btn.danger { background: #ff3b6b; border-color: transparent; color: #fff; }
.btn.disabled { opacity: 0.4; pointer-events: none; }
.menu { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.menu.row { flex-direction: row; justify-content: center; margin-top: 18px; flex-wrap: wrap; }

/* ---------- logo ---------- */
.logo { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.logo .l1 {
  font: 400 clamp(26px, 5.4vw, 64px) var(--pixel); color: #fff; letter-spacing: 0.04em;
  text-shadow: 0 0 6px #fff, 0 0 18px var(--pink), 0 0 42px var(--pink), 4px 4px 0 #5a1060;
}
.logo .l2 { font: 800 clamp(14px, 2vw, 22px) var(--font); color: var(--cyan); letter-spacing: 0.2em; text-transform: uppercase; text-shadow: 0 0 14px #2af0ff99; }
.glitch-logo { display: flex; justify-content: center; }
.glitch-logo canvas { image-rendering: pixelated; animation: hover 2.4s ease-in-out infinite; filter: drop-shadow(0 0 12px #ff3cc8aa); }
@keyframes hover { 50% { transform: translateY(-8px); } }

/* ---------- chargement ---------- */
#loading {
  position: absolute; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  background: radial-gradient(ellipse at center, #1a0f2e 0%, #07060c 70%); transition: opacity 0.8s;
}
#loading.gone { opacity: 0; pointer-events: none; }
#loading .bar { width: min(420px, 80vw); height: 12px; border: 2px solid #ffffff40; border-radius: 4px; overflow: hidden; }
#loading .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--pink), var(--gold)); transition: width 0.2s; }
#loading .ltext { font: 400 10px var(--pixel); color: var(--muted); }

/* ---------- titre ---------- */
#title {
  position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(7, 6, 12, 0.35) 0%, rgba(7, 6, 12, 0.85) 75%);
}
.title-inner { display: flex; flex-direction: column; align-items: center; gap: 26px; padding: 16px; max-width: 640px; text-align: center; }
#title .menu { width: min(300px, 80vw); }
#title .pitch { color: #d8d0ee; line-height: 1.55; font-size: 15px; margin: 0; }
#title .foot { color: var(--muted); font-size: 12px; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
#stats { position: absolute; top: 16px; left: 16px; display: flex; gap: 8px; }
.stat {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line);
  font: 400 13px var(--pixel); backdrop-filter: blur(6px);
}
.stat small { font: 500 12px var(--font); color: var(--muted); }
.stat.star .ico { color: var(--gold); text-shadow: 0 0 10px var(--gold); font-size: 16px; }
.stat.coin.pop { animation: pop 0.35s; }
@keyframes pop { 40% { transform: scale(1.15); } }
.stat.prog { flex-direction: column; align-items: stretch; gap: 5px; padding: 7px 14px; min-width: 96px; }
#h-pbar { height: 5px; border-radius: 3px; background: #ffffff1a; overflow: hidden; }
#h-pbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), #36f5a0); transition: width 0.4s; }

#zone {
  position: absolute; top: 16px; right: 16px; text-align: right; padding: 10px 16px; border-radius: 12px; background: var(--panel);
  border: 1px solid var(--line); border-right: 4px solid var(--acc, var(--gold)); display: flex; flex-direction: column; gap: 6px;
}
#z-name { font: 400 11px var(--pixel); color: var(--acc); text-shadow: 0 0 10px var(--acc); }
#z-info { color: var(--muted); font-size: 12px; }
#z-info:empty { display: none; }
#objective { position: absolute; top: 78px; right: 16px; max-width: 290px; text-align: right; font-size: 13px; color: #d8d0ee; line-height: 1.45; text-shadow: 0 1px 3px #000; }
#objective b { color: var(--gold); }

#cross { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1.5px #0008; transition: all 0.12s; }
#cross.item { width: 22px; height: 22px; margin: -11px 0 0 -11px; background: transparent; border: 2px solid #fff; box-shadow: 0 0 10px #fff8, inset 0 0 0 1px #0006; }
#cross.place { width: 22px; height: 22px; margin: -11px 0 0 -11px; background: transparent; border: 2px dashed var(--cyan); box-shadow: 0 0 10px #2af0ff88; }
#cross.use { width: 18px; height: 18px; margin: -9px 0 0 -9px; background: var(--gold); box-shadow: 0 0 16px var(--gold); }

#tip {
  position: absolute; left: 50%; top: calc(50% + 34px); transform: translateX(-50%); min-width: 220px; max-width: 380px; text-align: center;
  padding: 10px 16px 11px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--acc);
  box-shadow: 0 8px 30px #0008;
}
#tip .chip { display: inline-block; font: 400 8px var(--pixel); padding: 4px 7px; border-radius: 5px; background: var(--acc); color: #0b0812; margin-bottom: 6px; }
#tip .tt { font-weight: 800; font-size: 17px; line-height: 1.2; }
#tip .tm { color: var(--muted); font-size: 13px; margin-top: 3px; }
#tip .ts { font-size: 12px; margin-top: 5px; font-weight: 700; }
#tip .ts.ok { color: #36f5a0; }
#tip .ts.bad { color: #ff9a3a; }
#tip .th { font-size: 11.5px; margin-top: 6px; color: #cfc6ea; }
#tip .th kbd { font: 700 10px var(--font); padding: 1px 5px; border-radius: 4px; background: #ffffff1c; border: 1px solid #ffffff30; }

#bag { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 7px; }
.bag-label { font-size: 13px; text-shadow: 0 1px 4px #000; display: flex; gap: 10px; align-items: baseline; white-space: nowrap; }
.bag-label b { font-size: 15px; }
.slots { display: flex; gap: 5px; padding: 6px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
.slot { position: relative; width: 46px; height: 58px; border-radius: 8px; background: #ffffff0a; border: 1.5px solid #ffffff14; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.slot img { max-width: 92%; max-height: 92%; object-fit: contain; image-rendering: auto; }
.slot .yr { position: absolute; bottom: 0; left: 0; right: 0; font: 400 7px var(--pixel); background: #000b; color: var(--acc); padding: 3px 0 2px; text-align: center; }
.slot.sel { border-color: var(--acc); box-shadow: 0 0 14px var(--acc), inset 0 0 10px #ffffff22; transform: translateY(-5px); }
.slot.empty { opacity: 0.45; }
.bag-count { font: 400 8px var(--pixel); color: var(--muted); }

#powers { position: absolute; left: 16px; bottom: 18px; display: flex; gap: 6px; }
.pw {
  position: relative; width: 62px; height: 70px; border-radius: 12px; background: var(--panel); border: 1.5px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; overflow: hidden;
}
.pw::after { content: ''; position: absolute; inset: 0; background: conic-gradient(#000a calc(var(--cd) * 360deg), transparent 0); pointer-events: none; }
.pw .k { position: absolute; top: 4px; left: 6px; font: 400 8px var(--pixel); color: var(--muted); }
.pw .i { font-size: 22px; }
.pw .n { font-size: 9.5px; font-weight: 700; color: #ddd; text-align: center; line-height: 1.1; padding: 0 3px; }
.pw.locked { opacity: 0.45; }
.pw.active { border-color: var(--cyan); box-shadow: 0 0 16px #2af0ff88; }

#toasts { position: absolute; top: 76px; left: 16px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.toast {
  padding: 9px 14px; border-radius: 10px; background: var(--panel); border-left: 4px solid var(--acc); font-size: 13.5px;
  animation: tin 0.3s ease-out; transition: opacity 0.5s, transform 0.5s; max-width: 360px;
}
.toast b { color: var(--acc); }
.toast.out { opacity: 0; transform: translateX(-20px); }
@keyframes tin { from { opacity: 0; transform: translateX(-24px); } }

#big { position: absolute; left: 0; right: 0; top: 22%; text-align: center; pointer-events: none; }
#big .t { font: 400 clamp(18px, 3vw, 34px) var(--pixel); color: #fff; text-shadow: 0 0 8px #fff, 0 0 24px var(--acc), 0 0 50px var(--acc), 3px 3px 0 #000; }
#big .s { margin-top: 14px; font-weight: 800; font-size: 18px; color: var(--acc); text-shadow: 0 2px 6px #000; }
#big.show { animation: bigin 3s ease-out forwards; }
@keyframes bigin { 0% { opacity: 0; transform: scale(1.6); } 10% { opacity: 1; transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-12px); } }

#dialog {
  position: absolute; left: 50%; bottom: 128px; transform: translateX(-50%); width: min(640px, 92vw); display: flex; gap: 14px; align-items: center;
  padding: 12px 16px; border-radius: 14px; background: var(--panel); border: 1.5px solid #ff3cc866; box-shadow: 0 0 30px #ff3cc833;
}
#dialog .ava { flex: none; width: 64px; height: 64px; border-radius: 10px; background: #1c1030; display: flex; align-items: center; justify-content: center; }
#dialog .ava canvas { image-rendering: pixelated; animation: hover 1.2s ease-in-out infinite; }
#dialog .txt b { font: 400 9px var(--pixel); color: var(--pink); }
#dialog .txt p { margin: 6px 0 0; font-size: 15px; line-height: 1.45; min-height: 2.9em; }
#dialog small { position: absolute; right: 12px; bottom: 6px; color: var(--muted); font-size: 10px; }

#keys-hint { position: absolute; right: 16px; bottom: 18px; max-width: 240px; text-align: right; font-size: 11px; color: #ffffff80; line-height: 1.5; }
#lockmsg {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 16px 26px; border-radius: 12px; background: var(--panel);
  font: 400 11px var(--pixel); border: 1.5px solid var(--gold); pointer-events: auto; cursor: pointer;
}

#fade { position: absolute; inset: 0; pointer-events: none; opacity: 0; z-index: 40; }
#fade.flash { animation: flash 0.6s ease-out; }
@keyframes flash { 0% { opacity: 0.55; } 100% { opacity: 0; } }

/* ---------- fenêtres ---------- */
#modal { position: absolute; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: rgba(5, 4, 10, 0.6); backdrop-filter: blur(4px); padding: 16px; }
.panel {
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 24px 26px; border-radius: 18px; background: var(--panel);
  border: 1.5px solid #ffffff22; box-shadow: 0 30px 80px #000c, 0 0 0 1px #ff3cc822, 0 0 60px #ff3cc818; animation: pin 0.22s ease-out;
}
.panel.narrow { width: min(420px, 100%); }
.panel.wide { width: min(1020px, 100%); padding: 0; display: flex; flex-direction: column; }
.panel.shop { width: min(620px, 100%); border-color: #ffcc3366; }
@keyframes pin { from { opacity: 0; transform: translateY(14px) scale(0.98); } }
.panel h2 { font: 400 18px var(--pixel); margin: 0 0 18px; text-align: center; color: var(--gold); text-shadow: 0 0 14px #ffcc3388; }
.panel h3 { font: 400 11px var(--pixel); color: var(--acc, var(--cyan)); margin: 22px 0 10px; display: flex; align-items: center; gap: 10px; }
.panel h3 .lock { font: 600 12px var(--font); color: var(--muted); }
.panel p.center { text-align: center; color: #d8d0ee; }
.panel .sub { text-align: center; color: var(--muted); font-size: 13px; margin: -8px 0 16px; }
.keys { display: flex; flex-direction: column; gap: 7px; }
.kr { display: flex; gap: 12px; align-items: center; font-size: 14px; }
.kk { flex: none; min-width: 120px; padding: 5px 9px; border-radius: 7px; background: #ffffff10; border: 1px solid #ffffff22; font-weight: 700; font-size: 12px; text-align: center; }
.rule { margin-top: 16px; padding: 12px 14px; border-radius: 10px; background: #ffcc3312; border: 1px solid #ffcc3340; font-size: 14px; line-height: 1.5; }

.opts { display: flex; flex-direction: column; gap: 12px; }
.opt { display: grid; grid-template-columns: 1fr 160px 52px; gap: 12px; align-items: center; font-size: 14px; }
.opt.chk { grid-template-columns: 1fr auto; }
.opt output { font: 400 9px var(--pixel); color: var(--muted); text-align: right; }
input[type=range] { accent-color: var(--gold); width: 100%; }
input[type=checkbox] { accent-color: var(--gold); width: 18px; height: 18px; }

.shop-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.shop-head h2 { margin: 0; }
.purse { font: 400 13px var(--pixel); padding: 8px 12px; border-radius: 10px; background: #ffcc3318; border: 1px solid #ffcc3355; }
.shop-list { display: flex; flex-direction: column; gap: 8px; }
.shop-row { display: flex; align-items: center; gap: 14px; padding: 10px 12px; border-radius: 12px; background: #ffffff08; border: 1px solid #ffffff14; }
.shop-row.max { opacity: 0.55; }
.shop-row .si { font-size: 26px; width: 36px; text-align: center; }
.shop-row .sd { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.shop-row .sd small { color: var(--muted); font-size: 12.5px; }
.shop-row .lv { font-size: 10px; color: var(--gold); letter-spacing: 2px; }
.shop-row .buy { padding: 9px 14px; font-size: 14px; white-space: nowrap; }
.shop-row .done { font: 400 9px var(--pixel); color: #36f5a0; }

.codex-head { display: flex; align-items: center; gap: 18px; padding: 18px 22px 0; flex-wrap: wrap; }
.codex-head h2 { margin: 0; }
.tabs { display: flex; gap: 6px; flex: 1; }
.tab { font: 700 13px var(--font); color: var(--muted); background: transparent; border: 0; padding: 9px 14px; border-radius: 10px; cursor: pointer; }
.tab.on { color: #fff; background: #ffffff14; }
.btn.x { padding: 6px 12px; }
.codex-body { padding: 4px 22px 22px; overflow: auto; }
.cgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.ccard { display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 12px; background: #ffffff08; border: 1px solid #ffffff14; border-left: 3px solid var(--acc); cursor: pointer; transition: background 0.15s; }
.ccard:hover { background: #ffffff12; }
.ccard.done { box-shadow: inset 0 0 24px color-mix(in srgb, var(--acc) 30%, transparent); }
.ccard img { width: 64px; height: 64px; object-fit: contain; flex: none; }
.ccard > div { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ccard small { color: var(--muted); font-size: 11.5px; }
.pb { height: 5px; border-radius: 3px; background: #ffffff18; overflow: hidden; margin-top: 3px; }
.pb i { display: block; height: 100%; background: var(--acc); }
.ggrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.gcard { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px; border-radius: 10px; background: #ffffff08; border: 1px solid #ffffff14; opacity: 0.55; }
.gcard.done { opacity: 1; border-color: var(--acc); }
.gcard img { width: 64px; height: 64px; object-fit: contain; }
.gcard small { font-size: 11.5px; text-align: center; }
.gcard .gq { width: 64px; height: 64px; display: grid; place-items: center; font: 22px "Press Start 2P", monospace; color: #ffffff30; }
.pstats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.pstats div { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border-radius: 12px; background: #ffffff0a; }
.pstats b { font: 400 13px var(--pixel); color: var(--gold); }
.pstats small { color: var(--muted); font-size: 12px; }
.cdetail { display: flex; gap: 18px; align-items: center; margin-top: 18px; padding: 14px; border-radius: 14px; background: #ffffff08; border-left: 4px solid var(--acc); }
.cdetail img { width: 120px; height: 120px; object-fit: contain; }
.cdetail h3 { margin: 0 0 4px; color: var(--acc); }
.cdetail p { margin: 8px 0 0; line-height: 1.5; color: #d8d0ee; font-size: 14px; }
.cdetail small { color: var(--muted); }
.glist { columns: 2; column-gap: 24px; padding-left: 26px; margin: 16px 0 0; font-size: 13.5px; }
.glist li { break-inside: avoid; padding: 4px 0; color: #cfc6ea; }
.glist li.ok { color: #36f5a0; }
.glist li.ok::after { content: ' ✔'; }
.glist .y { font: 400 8px var(--pixel); color: var(--muted); margin-right: 8px; }
.glist .ge { color: #8a82a6; font-size: 11px; margin-left: 6px; }
.end { text-align: center; }
.end p { color: #d8d0ee; line-height: 1.5; }

@media (max-width: 720px) {
  #keys-hint, #objective { display: none; }
  #powers { bottom: 120px; }
  .pstats { grid-template-columns: repeat(2, 1fr); }
  .glist { columns: 1; }
  .opt { grid-template-columns: 1fr 110px 44px; }
}

/* Bornes d'arcade jouables */
.panel.arcade { width: min(620px, 100%); }
.arc-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.arc-head h2 { margin: 0; color: var(--acc); text-shadow: 0 0 14px var(--acc); }
.arc-screen { position: relative; border: 3px solid var(--acc); border-radius: 10px; box-shadow: 0 0 24px color-mix(in srgb, var(--acc) 45%, transparent), inset 0 0 30px #000; overflow: hidden; background: #07060d; }
.arc-screen canvas { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; image-rendering: pixelated; }
.arc-over { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: #07060dd9; text-align: center; padding: 16px; }
.arc-over.hidden { display: none; }
.arc-score { font: 400 20px var(--pixel); color: #fff; margin-bottom: 8px; text-shadow: 0 0 12px var(--acc); }
.arc-l { font-size: 14px; color: #d8d0ee; }
.arc-l.gold { color: var(--gold); font-weight: 700; }
.arc-l.ok { color: #36f5a0; font-weight: 700; }
.arc-l.cyan { color: var(--cyan); }
.arc-over .menu { margin-top: 12px; }
.arc-info { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin: 12px 2px 4px; font-size: 13px; color: #d8d0ee; }
.arc-info i { font-style: normal; color: var(--muted); font-size: 12px; }
.arc-info i.ok { color: #36f5a0; }
.arc-help { margin: 6px 0 0 !important; }
