:root {
  --bg: #0b0e1a;
  --panel: #151a33;
  --line: #39427a;
  --text: #eef1ff;
  --muted: #a3acd9;
  --p1: #ff6a3d;
  --p2: #4fd8ff;
  --gold: #ffd23f;
  --font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; }
body { overscroll-behavior: none; user-select: none; -webkit-user-select: none; }

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; visibility: hidden; cursor: crosshair; }
.playing #game { visibility: visible; }

.screen {
  position: fixed; inset: 0; z-index: 2;
  display: flex; align-items: safe center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-y: auto;
  background-color: var(--bg);
  background-image: linear-gradient(rgba(120,140,220,.06) 2px, transparent 2px), linear-gradient(90deg, rgba(120,140,220,.06) 2px, transparent 2px);
  background-size: 48px 48px;
}
.screen.dim { background: rgba(7, 9, 18, .78); }

.panel {
  width: min(430px, 100%);
  display: flex; flex-direction: column; gap: 12px;
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: 8px 8px 0 rgba(0,0,0,.45);
  padding: 22px;
}

h1 { font-size: clamp(44px, 10vw, 68px); line-height: .9; margin: 4px 0 0; font-weight: 900; letter-spacing: -1px; text-transform: uppercase; }
h2 { margin: 0; font-size: 26px; font-weight: 900; }
.lede { margin: 0; color: var(--muted); }
.hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.hint:empty, .status:empty { display: none; }
.status { color: var(--muted); font-size: 14px; }
.status.err { color: #ff8aa2; }

.duo { display: flex; align-items: center; gap: 12px; }
.duo i { width: 44px; height: 44px; position: relative; display: block; animation: bob 1.1s ease-in-out infinite alternate; }
.duo i.a { background: var(--p1); }
.duo i.z { background: var(--p2); animation-delay: -.55s; }
.duo i::before, .duo i::after { content: ""; position: absolute; top: 11px; width: 9px; height: 12px; background: #fff; box-shadow: inset 3px 0 0 #10142a; }
.duo i.z::before, .duo i.z::after { box-shadow: inset -3px 0 0 #10142a; }
.duo i.a::before { left: 13px; box-shadow: inset -4px 0 0 #10142a; } .duo i.a::after { left: 26px; box-shadow: inset -4px 0 0 #10142a; }
.duo i.z::before { left: 9px; box-shadow: inset 4px 0 0 #10142a; } .duo i.z::after { left: 22px; box-shadow: inset 4px 0 0 #10142a; }
.duo b { color: var(--gold); font-weight: 900; }
@keyframes bob { from { transform: translateY(-3px); } to { transform: translateY(4px) rotate(4deg); } }

.actions { display: flex; flex-direction: column; gap: 9px; }
.btn {
  font: 800 17px var(--font); color: var(--text);
  background: #232a52; border: 3px solid var(--line);
  padding: 12px 16px; min-height: 48px; cursor: pointer;
  box-shadow: 4px 4px 0 rgba(0,0,0,.45);
  transition: transform .06s, box-shadow .06s, background .12s;
}
.btn:hover:not(:disabled) { background: #2e3768; }
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 1px 1px 0 rgba(0,0,0,.45); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--gold); border-color: #fff0b0; color: #1a1500; }
.btn.primary:hover { background: #ffdd66; }
.btn.small { min-height: 40px; padding: 7px 12px; font-size: 15px; width: 100%; }
:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.levels { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.levels span { margin-right: 4px; }
.chip {
  font: 700 14px var(--font); color: var(--text);
  background: transparent; border: 2px solid var(--line);
  padding: 7px 11px; min-height: 36px; cursor: pointer; align-self: flex-start;
}
.chip:hover { background: #232a52; }
.chip.on { background: var(--text); color: #10142a; border-color: var(--text); }

details { font-size: 14px; color: var(--muted); }
summary { cursor: pointer; font-weight: 700; color: var(--text); padding: 4px 0; }
table { width: 100%; border-collapse: collapse; margin: 6px 0 8px; font-size: 13px; }
th { text-align: left; color: var(--text); }
td, th { padding: 4px 6px 4px 0; border-bottom: 1px solid #2a3159; }
details .hint { margin-top: 6px; }

#roomBox { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.code { font: 900 46px/1.1 Consolas, "Courier New", monospace; letter-spacing: 8px; color: var(--gold); text-align: center; padding-left: 8px; }
.sep { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.sep::before, .sep::after { content: ""; flex: 1; height: 2px; background: #2a3159; }
#joinForm { display: flex; gap: 8px; }
#joinForm .btn { flex: 1; min-width: 0; }
#joinCode {
  width: 124px; min-width: 0; min-height: 48px; text-align: center; text-transform: uppercase;
  font: 800 22px Consolas, monospace; letter-spacing: 4px; color: var(--text);
  background: #0c1024; border: 3px solid var(--line); padding: 4px;
  user-select: text; -webkit-user-select: text;
}

/* Sélection */
#select { flex-direction: column; justify-content: safe center; align-items: stretch; gap: 12px; }
.selectHead { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; max-width: 1180px; width: 100%; margin: 0 auto; flex: none; }
.selectHead .chip { align-self: center; }
#cards { display: flex; gap: 12px; overflow-x: auto; max-width: 1180px; width: 100%; margin: 0 auto; padding: 4px 8px 12px 2px; flex: none; scroll-snap-type: x proximity; }
.card {
  --c: #fff;
  flex: 1 0 196px; scroll-snap-align: start;
  display: flex; flex-direction: column; gap: 4px; text-align: left;
  font-family: var(--font); color: var(--text);
  background: var(--panel); border: 3px solid var(--line); padding: 13px; cursor: pointer;
  box-shadow: 5px 5px 0 rgba(0,0,0,.4);
  transition: transform .1s, border-color .1s;
}
.card:hover { border-color: var(--c); transform: translateY(-3px); }
.card.chosen { border-color: var(--c); background: #20274a; }
.card strong { font-size: 20px; font-weight: 900; color: var(--c); margin-top: 3px; }
.card em { font-style: normal; font-size: 13px; color: var(--text); }
.card .stats { font-size: 12px; color: var(--muted); }
.card ul { list-style: none; margin: 5px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 12px; line-height: 1.3; color: var(--muted); }
.card li b { display: block; color: var(--text); font-size: 13px; }
.card li.ult b { color: var(--gold); }
.mini { width: 40px; height: 40px; background: var(--c); position: relative; display: block; flex: none; }
.mini i { position: absolute; top: 10px; width: 9px; height: 11px; background: #fff; box-shadow: inset -4px 0 0 #10142a; }
.mini i:first-child { left: 9px; } .mini i:last-child { left: 23px; }

.endTitle { font-size: 44px; text-align: center; }
#end .panel, #pause .panel { text-align: center; }

#pauseBtn {
  position: fixed; z-index: 1; top: 4px; right: max(4px, env(safe-area-inset-right));
  width: 42px; height: 42px; background: transparent; border: 2px solid var(--line); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
}
#pauseBtn span { width: 18px; height: 3px; background: var(--text); }

#toast {
  position: fixed; z-index: 5; top: 14px; left: 50%; transform: translateX(-50%);
  max-width: calc(100vw - 32px); background: var(--text); color: #10142a; font-weight: 800; padding: 10px 16px;
  box-shadow: 4px 4px 0 rgba(0,0,0,.5);
}

#rotate { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  .playing #rotate {
    display: flex; position: fixed; inset: 0; z-index: 4; background: var(--bg);
    flex-direction: column; align-items: center; justify-content: center; gap: 22px; text-align: center; padding: 24px; font-weight: 800; font-size: 18px;
  }
  #rotate i { width: 44px; height: 76px; border: 4px solid var(--gold); display: block; animation: turn 1.8s ease-in-out infinite; }
  #rotate p { margin: 0; }
}
@keyframes turn { 0%, 25% { transform: rotate(0); } 70%, 100% { transform: rotate(90deg); } }

/* Téléphone à l'horizontale : tout doit tenir sur très peu de hauteur */
@media (max-height: 520px) {
  .screen { align-items: flex-start; }
  .panel { width: min(640px, 100%); margin: auto; padding: 14px; gap: 8px; }
  .hero h1 { font-size: 36px; }
  .hero h1 br { display: none; }
  .duo { display: none; }
  .actions { flex-direction: row; }
  .actions .btn { flex: 1; min-width: 0; font-size: 15px; padding: 8px; }
  #select { justify-content: flex-start; gap: 6px; padding-top: 8px; padding-bottom: 6px; }
  .card { flex-basis: 190px; padding: 9px; }
  .mini { display: none; }
  .card strong { margin-top: 0; font-size: 17px; }
  .endTitle { font-size: 32px; }
  .code { font-size: 32px; }
}
@media (prefers-reduced-motion: reduce) { .duo i, #rotate i { animation: none; } }
