:root {
  --bg: #0b0d17;
  --panel: #151a2e;
  --panel-2: #1d2440;
  --text: #eef1ff;
  --muted: #8b93b8;
  --cell: #1a2038;
  --cell-edge: #262f52;
  --lit: #39ff9f;
  --lit-glow: rgba(57, 255, 159, 0.55);
  --team-a: #4cc9ff;
  --team-b: #ff5c8a;
  --miss: #ff4757;
  --accent: #39ff9f;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

input { -webkit-user-select: text; user-select: text; }

#app {
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen {
  display: none;
  flex-direction: column;
  gap: 16px;
  height: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px;
  overflow-y: auto;
  position: relative;
}
.screen[data-active] { display: flex; }

h1, h2 { margin: 0; }
h2 { text-align: center; font-size: 1.5rem; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  border-radius: var(--radius);
  padding: 14px 18px;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { opacity: 0.4; cursor: default; }
.primary { background: var(--accent); color: #04140c; font-weight: 700; font-size: 1.1rem; }
.ghost { background: var(--panel-2); }
.small { padding: 6px 12px; font-size: 0.85rem; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.back {
  position: absolute;
  top: 14px;
  left: 12px;
  background: transparent;
  font-size: 1.4rem;
  padding: 6px 12px;
}

.hint { color: var(--muted); text-align: center; font-size: 0.9rem; min-height: 1.2em; margin: 0; }

/* Accueil */
.brand { text-align: center; padding-top: 12px; }
.brand h1 { font-size: 2.4rem; letter-spacing: 0.04em; }
.tagline { color: var(--muted); margin: 4px 0 0; }
.logo {
  display: grid;
  grid-template-columns: repeat(2, 26px);
  gap: 5px;
  justify-content: center;
  margin-bottom: 10px;
}
.logo i { height: 26px; border-radius: 6px; background: var(--cell-edge); }
.logo i.on { background: var(--lit); box-shadow: 0 0 16px var(--lit-glow); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { color: var(--muted); font-size: 0.85rem; }
.field input {
  font: inherit;
  font-size: 1.1rem;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--cell-edge);
  background: var(--panel);
  color: var(--text);
}
.code-input { text-transform: uppercase; letter-spacing: 0.4em; text-align: center; font-size: 1.8rem !important; }

.modes { display: flex; flex-direction: column; gap: 10px; }
.mode {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--cell-edge);
}
.mode strong { font-size: 1.15rem; }
.mode small { color: var(--muted); }
.mode:active { border-color: var(--accent); }

/* Salon */
.room-code {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px;
}
.room-code span { color: var(--muted); }
.room-code strong { font-size: 2rem; letter-spacing: 0.3em; font-family: ui-monospace, monospace; }

.seats { display: grid; gap: 12px; }
.team {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px;
  border-top: 4px solid var(--team-color);
}
.team h3 { margin: 0 0 8px; font-size: 1rem; color: var(--team-color); }
.team[data-team="A"] { --team-color: var(--team-a); }
.team[data-team="B"] { --team-color: var(--team-b); }
.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.slots.single { grid-template-columns: 1fr; }
.slot {
  background: var(--panel-2);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 62px;
  border: 2px solid transparent;
}
.slot small { color: var(--muted); font-size: 0.75rem; }
.slot.me { border-color: var(--team-color); }
.slot.empty { color: var(--muted); font-style: italic; }

/* Jeu */
#screen-game { max-width: none; padding: 10px 12px; gap: 10px; }
.hud { display: flex; align-items: center; gap: 10px; min-height: 52px; }
.hud .back { position: static; }
.hud-main { display: flex; gap: 18px; }
.stat { display: flex; flex-direction: column; line-height: 1.1; }
.stat span { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.timer strong { min-width: 3.2ch; }
.timer.low strong { color: var(--miss); }
.hud-others { margin-left: auto; display: flex; gap: 12px; }
.hud-others .stat strong { font-size: 1.2rem; }
.hud-others .stat[data-team="A"] strong { color: var(--team-a); }
.hud-others .stat[data-team="B"] strong { color: var(--team-b); }

.minimap {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  width: min(180px, 50%);
  margin: 0 auto;
  padding: 3px;
  border-radius: 6px;
  background: var(--panel);
}
.minimap i { aspect-ratio: 1; border-radius: 2px; background: var(--cell); }
.minimap i.mine { background: var(--cell-edge); }
.minimap i.lit { background: var(--lit); }
.minimap i.split { margin-right: 3px; }

.grid-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
}
.grid {
  --size: min(100%, calc(100dvh - 140px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  width: var(--size);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: clamp(6px, 2vmin, 14px);
  touch-action: none;
}
.cell {
  border-radius: clamp(8px, 2.5vmin, 18px);
  background: var(--cell);
  border: 2px solid var(--cell-edge);
  transition: background 60ms, box-shadow 60ms, transform 60ms;
}
.cell.lit {
  background: var(--lit);
  border-color: #b6ffdc;
  box-shadow: 0 0 28px var(--lit-glow), inset 0 0 18px rgba(255, 255, 255, 0.45);
}
.cell.hit { transform: scale(0.92); }
.cell.miss { background: var(--miss); border-color: var(--miss); }
.team-b .cell.lit { --lit: var(--team-b); --lit-glow: rgba(255, 92, 138, 0.55); border-color: #ffc2d3; }
.team-a.coop .cell.lit, .team-a.duo .cell.lit { --lit: var(--team-a); --lit-glow: rgba(76, 201, 255, 0.55); border-color: #c4ecff; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(4rem, 25vmin, 10rem);
  font-weight: 800;
  background: rgba(11, 13, 23, 0.6);
  border-radius: var(--radius);
  pointer-events: none;
}
.overlay[hidden] { display: none; }

/* Résultats */
.result-body { display: flex; flex-direction: column; gap: 10px; }
.result-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  border-left: 5px solid var(--team-color, var(--accent));
}
.result-card[data-team="A"] { --team-color: var(--team-a); }
.result-card[data-team="B"] { --team-color: var(--team-b); }
.result-card .big { font-size: 2.2rem; font-weight: 800; grid-row: span 2; align-self: center; }
.result-card small { color: var(--muted); }
.result-card.winner { box-shadow: 0 0 0 2px var(--team-color, var(--accent)); }

/* Classement */
.tabs { display: flex; background: var(--panel); border-radius: var(--radius); padding: 4px; }
.tabs button { flex: 1; background: transparent; padding: 10px; }
.tabs button[aria-selected="true"] { background: var(--panel-2); font-weight: 700; }
.lb { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lb li {
  display: grid;
  grid-template-columns: 2.2em 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
  border-radius: 10px;
}
.lb .pos { color: var(--muted); font-weight: 700; }
.lb li:nth-child(1) .pos { color: #ffd166; }
.lb li:nth-child(2) .pos { color: #d9dde8; }
.lb li:nth-child(3) .pos { color: #e09f6b; }
.lb .who small { display: block; color: var(--muted); font-size: 0.75rem; }
.lb .pts { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.lb li.mine { outline: 2px solid var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--panel-2);
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (orientation: landscape) and (max-height: 520px) {
  #screen-game { flex-direction: row; flex-wrap: wrap; }
  .hud { flex-direction: column; align-items: flex-start; width: 110px; }
  .hud-main { flex-direction: column; gap: 8px; }
  .hud-others { margin-left: 0; flex-direction: column; }
  .minimap { position: absolute; bottom: 10px; left: 12px; width: 100px; margin: 0; }
  .grid { --size: min(100%, calc(100dvh - 24px)); }
}

.minimap[hidden] { display: none; }
.minimap.team-a i.lit { background: var(--team-a); }
.minimap.team-b i.lit { background: var(--team-b); }
.slot:disabled { opacity: 1; }

.profile-stats { margin: -6px 0 0; color: var(--muted); font-size: 0.85rem; min-height: 1.2em; }
.field input.invalid { border-color: var(--miss); }
