:root {
  --bg: #0c0d0f;
  --panel: #15171a;
  --panel-2: #1c1f23;
  --line: #2b2f35;
  --text: #d9d4c7;
  --muted: #8a8578;
  --amber: #ffb547;
  --amber-dim: #6b4a17;
  --green: #7ee08a;
  --red: #ff6b5b;
  --lcd: #1f2a1c;
  --lcd-text: #b7f07a;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 14px;
  overflow: hidden;
}
[hidden] { display: none !important; }

.screen-bg {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 181, 71, .08), transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 39px, rgba(255,255,255,.025) 39px 40px),
    repeating-linear-gradient(90deg, transparent 0 39px, rgba(255,255,255,.025) 39px 40px),
    var(--bg);
}

h1, h2, h3, .logo, .big-code, .timer, .partner-name, .ptt {
  font-family: 'Chakra Petch', sans-serif;
}
h2 { font-size: 18px; margin: 0 0 14px; color: var(--amber); }
h3 { font-size: 15px; margin: 0 0 10px; color: var(--amber); }

.logo { font-size: 46px; letter-spacing: .06em; margin: 0; }
.logo span { color: var(--amber); }
.logo.small { font-size: 24px; }

/* ---------- Composants ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
label { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
input, select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  font-size: 15px;
  text-transform: none;
  letter-spacing: normal;
}
input:focus, select:focus { outline: 2px solid var(--amber-dim); border-color: var(--amber); }
.code-input { text-transform: uppercase; letter-spacing: .4em; font-size: 22px; text-align: center; font-family: 'Chakra Petch', sans-serif; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 6px;
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--amber-dim); }
.btn.primary { background: var(--amber); color: #1a1205; border-color: var(--amber); font-weight: 500; }
.btn.primary:hover { background: #ffc46b; }
.btn.ghost { background: transparent; }
.btn.icon { padding: 7px 9px; }

.error { color: var(--red); margin: 0 0 12px; }
.center { text-align: center; }
.muted { color: var(--muted); }
kbd {
  background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 6px; font-size: 12px; color: var(--text);
}

/* ---------- Login ---------- */
.login { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; text-align: center; }
.login .tagline { color: var(--muted); margin: 8px 0 28px; }
.login form { text-align: left; }
.login .btn { width: 100%; }

/* ---------- Lobby ---------- */
.screen { position: fixed; inset: 0; overflow-y: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; border-bottom: 1px solid var(--line); }
.user { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.lobby-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; max-width: 900px; margin: 40px auto 0; padding: 0 16px; }
.lobby-grid .card { display: flex; flex-direction: column; }
.lobby-grid .btn { width: 100%; margin-top: auto; }
.lobby-grid .solo-desc { font-size: 12px; margin: 0 0 12px; }
.waiting { max-width: 420px; margin: 40px auto 0; text-align: center; }
.big-code { font-size: 64px; letter-spacing: .25em; color: var(--amber); margin: 10px 0; text-shadow: 0 0 24px rgba(255,181,71,.35); }
.rules { max-width: 760px; margin: 24px auto 40px; }
.rules ul { margin: 0 0 14px; padding-left: 20px; line-height: 1.7; }
.rules .keys { color: var(--muted); line-height: 2; margin: 0; }

/* ---------- Jeu ---------- */
#game { display: flex; overflow: hidden; }
#view { position: relative; flex: 1; min-width: 0; background: #000; cursor: crosshair; }
#view canvas { display: block; width: 100%; height: 100%; }

.lock-hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(12,13,15,.8); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 22px; text-align: center; pointer-events: none; font-size: 16px;
}
.lock-hint small { display: block; color: var(--muted); margin-top: 6px; font-size: 12px; }
.banner {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
  background: rgba(12,13,15,.85); border: 1px solid var(--amber-dim); color: var(--amber);
  padding: 10px 18px; border-radius: 6px; font-size: 15px; pointer-events: none; white-space: nowrap;
}
.tx-indicator {
  position: absolute; bottom: 18px; left: 18px;
  background: var(--red); color: #fff; padding: 6px 12px; border-radius: 4px;
  font-family: 'Chakra Petch', sans-serif; letter-spacing: .1em;
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: .55; } }

#side {
  width: 380px; flex-shrink: 0; background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 12px; padding: 14px; overflow-y: auto;
}
.side-head { display: flex; justify-content: space-between; align-items: flex-end; }
.label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }
.partner-name { font-size: 20px; color: var(--amber); }
.head-right { display: flex; align-items: center; gap: 10px; }
.timer { font-size: 26px; font-variant-numeric: tabular-nums; }

.guide-line { margin-top: 2px; text-transform: none; letter-spacing: 0; }
.guide-line span { color: var(--text); }
.team { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.team li { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; min-width: 0; }
.team li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team li .role { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.team li .fa-key { color: var(--line); }
.team li.got .fa-key { color: #ffc23a; }
.team li .fa-door-open { color: var(--green); }
.team li.talking { border-color: var(--lcd-text); box-shadow: 0 0 8px rgba(183,240,122,.35); }
.team li.me { background: var(--panel-2); }
.player-list { list-style: none; padding: 0; margin: 14px auto; max-width: 260px; text-align: left; }
.player-list li { padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.player-list li.empty { border-style: dashed; color: var(--muted); }
.waiting .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.map-wrap { position: relative; aspect-ratio: 1; background: #0e0f0c; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
#map { width: 100%; height: 100%; display: block; cursor: crosshair; }
.map-tools { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; }
.map-tools .btn { background: rgba(21,23,26,.85); }
.map-wrap.big {
  position: fixed; inset: 0; right: 380px; margin: auto; z-index: 5;
  width: min(calc(100vw - 380px - 32px), calc(100vh - 32px)); height: auto;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.65);
}
.map-wrap.big .map-tools .btn { padding: 10px 12px; font-size: 16px; }
.hint { margin: -4px 0 0; color: var(--muted); font-size: 11px; }

.legend summary { cursor: pointer; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
#legend { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin-top: 8px; font-size: 12px; }
#legend .item { display: flex; align-items: center; gap: 6px; }
#legend canvas { flex-shrink: 0; }

.radio { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.radio-screen { background: var(--lcd); color: var(--lcd-text); border-radius: 6px; padding: 8px 10px; font-size: 12px; box-shadow: inset 0 0 12px rgba(0,0,0,.6); }
.radio-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.radio-row + .radio-row { margin-top: 6px; }
.state.off { opacity: .5; }
.state.ok { color: var(--lcd-text); }
.state.bad { color: var(--red); }
.rx.on { color: #fff; text-shadow: 0 0 8px var(--lcd-text); }
.ptt {
  border: none; border-radius: 8px; padding: 14px; font-size: 15px; letter-spacing: .06em;
  background: linear-gradient(#3a2f1c, #2a2214); color: var(--amber); cursor: pointer;
  box-shadow: 0 3px 0 #120e08, inset 0 1px 0 rgba(255,255,255,.08);
  user-select: none;
}
.ptt small { opacity: .6; font-size: 11px; }
.ptt.active { background: var(--red); color: #fff; transform: translateY(2px); box-shadow: 0 1px 0 #120e08; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 16px; }
.end-card { text-align: center; min-width: 320px; }
.end-card .row { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }

@media (max-width: 900px) {
  #game { flex-direction: column; }
  #view { flex: none; height: 55vh; }
  #side { width: 100%; border-left: none; border-top: 1px solid var(--line); flex: 1; }
  .map-wrap { max-width: 420px; width: 100%; margin: 0 auto; }
  .map-wrap.big { right: 0; max-width: none; width: min(calc(100vw - 32px), calc(100vh - 32px)); margin: auto; }
}
