:root {
  --ink: #1d2342; --dusk: #2b3566; --panel: #f3f6fb; --line: #3b4a86; --inner: #9db7e6;
  --text: #1e2747; --muted: #56618c; --violet: #6b4fd6; --violet-d: #4d36ad; --gold: #f2b630;
  --danger: #c93a4e; --mint: #2f9d78;
  --px: "Pixelify Sans", "Trebuchet MS", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--text); font: 16px/1.5 var(--body); }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
button, input, select { font: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- Écrans de connexion ---------- */
.auth {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 1px 1px, rgba(157,183,230,.18) 1px, transparent 1.5px) 0 0 / 24px 24px,
    linear-gradient(180deg, #1d2342 0%, #2b3566 70%, #3d4a86 100%);
}
.logo {
  font: 700 clamp(2.6rem, 9vw, 4.2rem)/1 var(--px); color: var(--panel); margin: 0; letter-spacing: .02em;
  text-shadow: 0 4px 0 var(--violet-d), 0 8px 0 rgba(0,0,0,.35);
}
.tagline { color: var(--inner); margin: 10px 0 26px; font-family: var(--px); font-size: 1.1rem; }

.box {
  background: var(--panel); border: 3px solid var(--line); border-radius: 8px;
  box-shadow: inset 0 0 0 3px var(--panel), inset 0 0 0 5px var(--inner), 0 6px 0 rgba(0,0,0,.3);
  padding: 22px 22px 20px; width: min(100%, 400px);
}
.box.wide { width: min(100%, 760px); }
.box h2 { font: 600 1.45rem/1.2 var(--px); margin: 0 0 12px; }
.box h3 { font: 600 1.1rem/1.2 var(--px); margin: 14px 0 8px; }
.box p { margin: 0 0 12px; }
.small, .hint { font-size: .88rem; color: var(--muted); }
.hint { margin: 14px 0 0 !important; }
label { display: block; margin: 0 0 12px; font-weight: 700; font-size: .92rem; }
input:not([type=radio]):not([type=checkbox]):not([type=range]), select {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; border: 2px solid var(--line);
  border-radius: 6px; background: #fff; color: var(--text); font-weight: 400;
}
input[type=range] { width: 100%; accent-color: var(--violet); }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.err { color: var(--danger); font-weight: 700; min-height: 0; }
.err:empty { display: none; }

.btn {
  display: inline-block; font: 600 1rem/1 var(--px); padding: 11px 16px; border-radius: 6px; cursor: pointer;
  border: 2px solid var(--line); background: #fff; color: var(--text); box-shadow: 0 3px 0 var(--line);
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.btn.primary { background: var(--violet); color: #fff; border-color: var(--violet-d); box-shadow: 0 3px 0 var(--violet-d); width: 100%; }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--muted); }
.btn.small { padding: 8px 11px; font-size: .9rem; width: auto; }
.btn.on { background: var(--gold); border-color: #b88412; }
.btn + .btn { margin-top: 8px; }
.row .btn + .btn, .wrap .btn + .btn { margin-top: 0; }
.row { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 8px; }
.row.wrap { flex-wrap: wrap; justify-content: flex-start; margin-bottom: 10px; }
.row .btn.primary { width: auto; }

.qr { display: flex; justify-content: center; margin: 4px 0 10px; }
.qr img { width: 200px; height: 200px; image-rendering: pixelated; border: 2px solid var(--line); border-radius: 6px; background: #fff; }
.qr img:not([src]) { display: none; }
.secret { font: 600 1.05rem/1.4 var(--px); letter-spacing: .08em; background: #e6ecf8; border-radius: 6px; padding: 8px; text-align: center; word-break: break-all; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0; margin: 0 0 14px; list-style: none; }
.codes li { font: 600 1.05rem var(--px); background: #e6ecf8; border-radius: 6px; padding: 6px; text-align: center; letter-spacing: .06em; }

/* Création de personnage */
.char-grid { display: grid; grid-template-columns: 200px 1fr; gap: 20px; }
.char-preview { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#preview {
  width: 192px; height: 192px; image-rendering: pixelated; border-radius: 8px; border: 3px solid var(--line);
  background: repeating-conic-gradient(#86c96b 0 25%, #7bbd60 0 50%) 0 0 / 48px 48px;
}
.turn { display: flex; gap: 6px; }
.turn .btn + .btn { margin-top: 0; }
.classes { border: 0; padding: 0; margin: 0 0 12px; }
.classes legend { font-weight: 700; font-size: .92rem; margin-bottom: 4px; }
.cls { display: block; margin: 0 0 6px; font-weight: 400; }
.cls input { position: absolute; opacity: 0; }
.cls span { display: block; padding: 8px 10px; border: 2px solid var(--inner); border-radius: 6px; cursor: pointer; font-size: .9rem; }
.cls b { display: block; font: 600 1.05rem var(--px); }
.cls input:checked + span { border-color: var(--violet); background: #ece8fb; }
.cls input:focus-visible + span { outline: 3px solid var(--gold); }
.swatches { display: grid; grid-template-columns: 78px 1fr; align-items: center; margin-bottom: 8px; font-size: .9rem; font-weight: 700; }
.swatches > div { display: flex; flex-wrap: wrap; gap: 5px; }
.sw { width: 28px; height: 28px; border-radius: 6px; border: 2px solid var(--line); cursor: pointer; padding: 0; font: 600 .8rem var(--px); background: #fff; color: var(--text); }
.sw.on { outline: 3px solid var(--violet); outline-offset: 1px; }

/* ---------- Jeu ---------- */
.game { position: fixed; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; background: #000; }

.hud {
  position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 0; pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-me {
  background: rgba(243,246,251,.94); border: 2px solid var(--line); border-radius: 8px; padding: 6px 10px;
  display: grid; grid-template-columns: auto auto; gap: 2px 10px; align-items: center; min-width: 170px;
}
.hud-name { font: 600 1rem var(--px); }
.hud-level { font: 600 .9rem var(--px); color: var(--violet-d); justify-self: end; }
.hud-gold { font: 600 .85rem var(--px); color: #8a6100; grid-column: 1 / -1; }
.xpbar { grid-column: 1 / -1; height: 6px; background: #d4dcef; border-radius: 3px; overflow: hidden; }
.xpbar i { display: block; height: 100%; width: 0; background: var(--gold); }
.hud-menu { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.hud-menu .btn + .btn { margin-top: 0; }

.chat {
  position: absolute; left: 10px; bottom: calc(env(safe-area-inset-bottom) + 10px); width: min(380px, calc(100% - 20px));
  background: rgba(29,35,66,.78); border-radius: 8px; padding: 6px; color: #eef2fb; font-size: .9rem;
}
.chat-log { list-style: none; margin: 0; padding: 0 4px; max-height: 26vh; overflow-y: auto; overflow-wrap: anywhere; }
.chat-log li { margin: 2px 0; }
.chat-log .who { font-weight: 700; color: #bcd0ff; }
.chat-log .staff .who { color: var(--gold); }
.chat-log .system { color: #9fe0c8; }
.chat-log .announce { color: #ffd76a; font-weight: 700; }
.chat-log .whisper { color: #e2b6ff; }
.chat-form { display: flex; gap: 6px; margin-top: 6px; }
.chat-form input { margin: 0 !important; padding: 7px 9px !important; font-size: .9rem; }
.chat-form .btn { margin: 0; }
.chat-toggle { display: none; }

.touch { position: absolute; inset: auto 0 0 0; height: 0; }
.stick {
  position: absolute; left: 22px; bottom: calc(env(safe-area-inset-bottom) + 26px); width: 132px; height: 132px; border-radius: 50%;
  background: rgba(243,246,251,.22); border: 3px solid rgba(243,246,251,.6); touch-action: none;
}
.stick i { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; background: rgba(243,246,251,.85); border: 3px solid var(--line); }
.skills { position: absolute; right: 18px; bottom: calc(env(safe-area-inset-bottom) + 26px); display: grid; grid-template-columns: 62px 62px; gap: 10px; }
.skill { width: 62px; height: 62px; border-radius: 50%; border: 3px solid var(--line); background: rgba(243,246,251,.85); font: 700 1.2rem var(--px); color: var(--text); }
.skill:disabled { opacity: .45; }
.touch.left .stick { left: auto; right: 22px; }
.touch.left .skills { right: auto; left: 18px; }

.modal { position: absolute; inset: 0; background: rgba(15,18,38,.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.dialog { max-height: calc(100% - 20px); overflow-y: auto; }
.credits { margin: 6px 0 4px; font-size: .88rem; }
.credits summary { cursor: pointer; font-weight: 700; }
.credits p { margin: 6px 0 0; }
.tuto-steps { display: flex; gap: 6px; margin-bottom: 6px; }
.tuto-steps i { width: 10px; height: 10px; border-radius: 2px; background: var(--inner); }
.tuto-steps i.on { background: var(--violet); }

.admin-box { width: min(100%, 640px); }
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.admin-head h2 { margin: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 12px 0; border-bottom: 2px solid var(--inner); }
.tabs button { font: 600 .95rem var(--px); border: 0; background: none; padding: 8px 10px; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--violet); }
.admin-msg { font-weight: 700; }
.admin-msg.bad { color: var(--danger); }
.admin-msg.good { color: var(--mint); }
.list { list-style: none; padding: 0; margin: 10px 0; max-height: 240px; overflow-y: auto; border: 2px solid var(--inner); border-radius: 6px; }
.list:empty { display: none; }
.list li { padding: 7px 10px; border-bottom: 1px solid #dfe6f4; font-size: .9rem; }
.list li:last-child { border-bottom: 0; }
.player-list li { cursor: pointer; }
.player-list li.on { background: #ece8fb; }
.list .meta { color: var(--muted); font-size: .82rem; }
.temp-pass { background: #fff5d6; border: 2px solid var(--gold); border-radius: 6px; padding: 10px; font-weight: 700; overflow-wrap: anywhere; }
.temp-pass code { font: 600 1.15rem var(--px); letter-spacing: .05em; }
.target-box { border-top: 2px solid var(--inner); margin-top: 8px; }

.toast {
  position: absolute; left: 50%; top: calc(env(safe-area-inset-top) + 74px); transform: translateX(-50%);
  background: var(--panel); border: 2px solid var(--line); border-radius: 8px; padding: 8px 14px; font: 600 .95rem var(--px); z-index: 20; max-width: 90%;
}

.minimap-wrap { position: absolute; right: 10px; top: calc(env(safe-area-inset-top) + 56px); display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.minimap-btn { padding: 0; border: 2px solid var(--line); border-radius: 8px; background: rgba(29,35,66,.85); cursor: pointer; line-height: 0; }
#minimap { width: 150px; height: 105px; image-rendering: pixelated; border-radius: 6px; }
.zone-name { font: 600 .85rem var(--px); color: #fff; background: rgba(29,35,66,.78); padding: 2px 8px; border-radius: 6px; }
.map-box { width: min(100%, 1000px); }
#bigmap { width: 100%; height: auto; max-height: 72vh; object-fit: contain; image-rendering: pixelated; background: #1d2342; border-radius: 6px; margin: 10px 0 6px; }
.prompt {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 8px; border-radius: 999px; cursor: pointer;
  background: var(--panel); border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line); font: 600 1rem var(--px); color: var(--text); z-index: 5;
}
.prompt .key { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 6px; background: var(--violet); color: #fff; }
.prompt.passive { cursor: default; opacity: .85; }
.prompt.passive .key { display: none; }
.act-btn { position: absolute; right: 162px; bottom: calc(env(safe-area-inset-bottom) + 46px); width: 72px; height: 72px; border-radius: 50%; border: 3px solid var(--violet-d); background: var(--violet); color: #fff; font: 700 .95rem var(--px); }
.touch.left .act-btn { right: auto; left: 162px; }

.hpbar { grid-column: 1 / -1; height: 12px; background: #3a2230; border-radius: 4px; overflow: hidden; position: relative; }
.hpbar i { display: block; height: 100%; width: 100%; background: linear-gradient(#5fd38a, #2f9d5f); transition: width .15s; }
.hpbar.weak i { background: linear-gradient(#e8a44a, #b8742a); }
.hpbar span { position: absolute; inset: 0; font: 600 .68rem/12px var(--px); color: #fff; text-align: center; text-shadow: 0 1px 0 #1d2342; }
.target { position: absolute; left: 50%; top: calc(env(safe-area-inset-top) + 8px); transform: translateX(-50%); min-width: 180px;
  background: rgba(29,35,66,.88); border: 2px solid var(--line); border-radius: 8px; padding: 5px 10px; color: #fff; text-align: center; }
.target .t-name { font: 600 .95rem var(--px); }
.target .t-lvl { font: 600 .8rem var(--px); margin-left: 6px; }
.t-hp { height: 8px; background: #3a2230; border-radius: 4px; overflow: hidden; margin-top: 4px; }
.t-hp i { display: block; height: 100%; background: #d8485b; }
.skillbar { position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 10px); transform: translateX(-50%); display: flex; gap: 6px; }
.slot { position: relative; width: 74px; height: 58px; border-radius: 8px; border: 2px solid var(--line); background: rgba(243,246,251,.94); cursor: pointer; padding: 4px; overflow: hidden; color: var(--text); }
.slot kbd { position: absolute; left: 4px; top: 2px; font: 700 .75rem var(--px); color: var(--violet-d); }
.slot .sname { display: block; font: 600 .72rem/1.05 var(--px); margin-top: 14px; }
.cd { position: absolute; inset: 0; background: conic-gradient(rgba(29,35,66,.72) var(--cd, 0%), transparent 0); pointer-events: none; }
.skill { position: relative; overflow: hidden; }
.skill .sname { font: 700 .62rem/1.05 var(--px); padding: 0 4px; display: block; }
.castbar { position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 132px); transform: translateX(-50%); width: 220px; height: 16px; background: rgba(29,35,66,.85); border: 2px solid var(--line); border-radius: 8px; overflow: hidden; }
.castbar i { display: block; height: 100%; width: 0; background: #b48cff; }
.castbar span { position: absolute; inset: 0; font: 600 .72rem/12px var(--px); color: #fff; text-align: center; }
.drive { position: absolute; left: 50%; top: calc(env(safe-area-inset-top) + 60px); transform: translateX(-50%); background: rgba(29,35,66,.9); color: #fff; border: 2px solid var(--gold); border-radius: 8px; padding: 6px 12px; font: 600 .9rem var(--px); display: flex; gap: 10px; }
.death { position: absolute; left: 50%; top: calc(env(safe-area-inset-top) + 64px); transform: translateX(-50%); width: min(92%, 360px); background: rgba(29,35,66,.94); color: #fff; border: 2px solid var(--inner); border-radius: 10px; padding: 16px; text-align: center; z-index: 6; }
.death h2 { font: 600 1.3rem var(--px); margin: 0 0 6px; }
.death p { margin: 0 0 12px; font-size: .9rem; }
.death .btn { width: 100%; }
@media (pointer: coarse) { .skillbar { display: none; } }
.game.spirit #world { filter: saturate(.35) brightness(.9) hue-rotate(10deg); }
.prompt { bottom: calc(env(safe-area-inset-bottom) + 82px); }

/* Mobile portrait */
@media (max-width: 640px) {
  .char-grid { grid-template-columns: 1fr; }
  .hud-menu .btn { padding: 7px 8px; font-size: .82rem; }
  .hud-me { min-width: 0; width: max-content; white-space: nowrap; padding: 5px 8px; }
  .hud-name { font-size: .9rem; }
  .chat { top: calc(env(safe-area-inset-top) + 92px); bottom: auto; }
  .chat-log { max-height: 22vh; }
  .chat.collapsed { display: none; }
  .chat-toggle { display: block; position: absolute; left: 10px; top: calc(env(safe-area-inset-top) + 92px); width: auto; }
  .minimap-wrap { top: calc(env(safe-area-inset-top) + 92px); }
  #minimap { width: 110px; height: 77px; }
  .chat { top: calc(env(safe-area-inset-top) + 140px); }
  .prompt { bottom: calc(env(safe-area-inset-bottom) + 190px); }
  .skillbar { display: none; }
  .castbar { bottom: calc(env(safe-area-inset-bottom) + 240px); }
  .target { top: calc(env(safe-area-inset-top) + 92px); min-width: 150px; }
  .drive { top: calc(env(safe-area-inset-top) + 150px); }
  .death { top: auto; bottom: calc(env(safe-area-inset-bottom) + 200px); }
  .act-btn { right: 50%; transform: translateX(50%); bottom: calc(env(safe-area-inset-bottom) + 40px); width: 64px; height: 64px; }
  .touch.left .act-btn { left: auto; right: 50%; }
}
@media (pointer: fine) { .mobile-only { display: none; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
