/* ═══════════════════════════════════════════════════════════════════════
   Chasse au code couleur — feuille de style mobile-first
   Breakpoint desktop : 900px. Cibles tactiles ≥ 44px.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  --bg:        #0b1020;
  --bg-panel:  #151b30;
  --panel:     #1e2541;
  --border:    #2a3356;
  --text:      #e7ecff;
  --text-dim:  #8892b8;
  --accent:    #4f7cff;
  --accent-2:  #7c5cff;
  --ok:        #34d399;
  --bad:       #f87171;
  --gold:      #fbbf24;
  --r:         #ef4444;
  --g:         #22c55e;
  --b:         #3b82f6;
  --radius:    14px;
  --radius-sm: 8px;
  --tap:       44px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(ellipse at top, #1a2040 0%, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
  overscroll-behavior-y: contain;
  padding-bottom: env(safe-area-inset-bottom);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
}

input {
  font-family: inherit;
}

h1, h2, h3 { margin: 0 0 .3em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }

/* ── Layout principal ─────────────────────────────────────────────────── */

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.screen { display: none; flex-direction: column; gap: 14px; flex: 1; }
.screen.active { display: flex; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.panel-tight { padding: 12px; }

.row { display: flex; gap: 10px; align-items: center; }
.row-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

.muted     { color: var(--text-dim); }
.small     { font-size: .85rem; }
.tiny      { font-size: .75rem; }
.mono      { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.center    { text-align: center; }
.bold      { font-weight: 700; }

/* ── Boutons ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  border-radius: var(--radius-sm);
  transition: transform .08s ease, filter .15s ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.1); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-full  { width: 100%; }
.btn-ghost { background: var(--bg-panel); border: 1px solid var(--border); color: var(--text); }
.btn-ok    { background: var(--ok); color: #0b2e1a; }
.btn-bad   { background: var(--bad); color: #1a0b0b; }
.btn-gold  { background: var(--gold); color: #2a1d00; }
.btn-sm    { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn-xs    { min-height: 28px; padding: 4px 10px; font-size: .8rem; }

.btn-pinned {
  position: sticky;
  bottom: 10px;
  z-index: 5;
}

/* ── Formulaires ──────────────────────────────────────────────────────── */

label {
  display: block;
  font-size: .85rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 1rem;
}
input[type="text"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 124, 255, .25);
}

/* ── Accueil ──────────────────────────────────────────────────────────── */

.hero {
  text-align: center;
  padding: 28px 20px;
}
.hero h1 {
  font-size: 2rem;
  background: linear-gradient(135deg, #ffd166, #ef476f, #06d6a0, #118ab2);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 6px;
}
.hero p { color: var(--text-dim); margin: 6px 0 0; }

.room-code-input {
  text-transform: uppercase;
  letter-spacing: .3em;
  text-align: center;
  font-weight: 700;
  font-size: 1.4rem;
}

/* ── Lobby ────────────────────────────────────────────────────────────── */

.room-code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: .35em;
  text-align: center;
  padding: 18px;
  background: linear-gradient(135deg, rgba(79,124,255,.15), rgba(124,92,255,.15));
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  color: var(--gold);
}

.players-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-panel);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.player-row.you { border-color: var(--accent); }
.player-row.offline { opacity: .55; }

.player-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
  flex-shrink: 0;
}
.player-row.offline .player-dot { background: var(--text-dim); box-shadow: none; }

.player-name { flex: 1; font-weight: 600; }
.player-score {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 700;
  color: var(--gold);
  min-width: 2.5em;
  text-align: right;
}

.badge {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  padding: 3px 7px;
  border-radius: 4px;
  background: var(--border);
  color: var(--text);
}
.badge.creator { background: var(--accent); color: #fff; }
.badge.master  { background: var(--gold); color: #2a1d00; }
.badge.you     { background: var(--ok); color: #0b2e1a; }

/* ── Grille de couleurs (écran maître) ────────────────────────────────── */

.color-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.swatch {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 3px solid transparent;
  cursor: pointer;
  position: relative;
  transition: transform .1s, border-color .15s;
  min-height: 64px;
}
.swatch:active { transform: scale(.95); }
.swatch.selected {
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(251, 191, 36, .6);
}
.swatch-label {
  position: absolute;
  bottom: -1px; left: 0; right: 0;
  padding: 2px 4px;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: .65rem;
  text-align: center;
  border-bottom-left-radius: calc(var(--radius-sm) - 2px);
  border-bottom-right-radius: calc(var(--radius-sm) - 2px);
  pointer-events: none;
}

/* ── LED target / preview ─────────────────────────────────────────────── */

.led-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  padding: 20px 10px;
}

.led {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: var(--led-color, #444);
  box-shadow:
    0 0 40px var(--led-glow, rgba(100,100,100,.6)),
    0 0 80px var(--led-glow, rgba(100,100,100,.3)),
    inset 0 0 18px rgba(255, 255, 255, .18);
  transition: background .2s, box-shadow .2s;
  flex-shrink: 0;
}
.led-lg { width: 180px; height: 180px; }
.led-sm { width: 80px; height: 80px; box-shadow: 0 0 24px var(--led-glow, rgba(100,100,100,.6)), inset 0 0 10px rgba(255,255,255,.18); }

.led-label {
  text-align: center;
  font-size: .75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .1em;
  margin-top: 6px;
}

/* ── Bandeau format / timer ───────────────────────────────────────────── */

.format-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: linear-gradient(90deg, rgba(79,124,255,.2), rgba(124,92,255,.2));
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-weight: 700;
}
.format-banner .format-name {
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: .15em;
}
.timer {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 1.1rem;
  font-weight: 700;
}
.timer.low { color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* ── Code cible dans une autre base (à convertir) ─────────────────────── */

.target-code-panel {
  background: linear-gradient(135deg, rgba(251,191,36,.1), rgba(124,92,255,.12));
  border: 1.5px dashed var(--gold);
}
.target-code-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.target-code-label > span:first-child { color: var(--gold); font-weight: 700; }
.target-code-from {
  margin-left: auto;
  padding: 2px 10px;
  background: var(--gold);
  color: #2a1d00;
  border-radius: 999px;
  font-weight: 800;
  font-size: .72rem;
  letter-spacing: .1em;
}
.target-code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 800;
  font-size: 1.05rem;
  line-height: 1.7;
  letter-spacing: .08em;
  color: var(--text);
  text-align: center;
  padding: 10px 4px;
  background: rgba(0, 0, 0, .18);
  border-radius: 8px;
}
.target-code .ch {
  display: inline-block;
  width: 14px;
  font-weight: 800;
  margin-right: 8px;
}
.target-code .ch-r { color: var(--r); }
.target-code .ch-g { color: var(--g); }
.target-code .ch-b { color: var(--b); }
.target-code .hex-line { font-size: 1.4rem; letter-spacing: .18em; color: var(--gold); }
.target-code .dec-val, .target-code .bin-val { color: #fff; }

/* ── Saisie HEX ───────────────────────────────────────────────────────── */

.hex-input-box {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.hex-input-box:focus-within { border-color: var(--accent); }
.hex-prefix {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-dim);
}
.hex-input-box input {
  flex: 1;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: .15em;
  text-transform: uppercase;
  text-align: center;
  background: transparent;
  border: none;
  min-height: auto;
  padding: 4px 0;
  color: var(--text);
}
.hex-input-box input:focus { box-shadow: none; border: none; }

.hex-breakdown {
  display: flex;
  justify-content: space-around;
  margin-top: 8px;
  font-family: ui-monospace, monospace;
  font-size: .85rem;
}
.hex-breakdown .r { color: var(--r); }
.hex-breakdown .g { color: var(--g); }
.hex-breakdown .b { color: var(--b); }

/* ── Saisie BIN ───────────────────────────────────────────────────────── */

.bit-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.bit-channel {
  width: 24px;
  font-weight: 800;
  text-align: center;
  font-size: .95rem;
}
.bit-channel.r { color: var(--r); }
.bit-channel.g { color: var(--g); }
.bit-channel.b { color: var(--b); }

.bit-cells {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  flex: 1;
}
.bit {
  aspect-ratio: 1;
  min-height: var(--tap);
  min-width: 32px;
  background: #2a2f4a;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: ui-monospace, monospace;
  font-weight: 800;
  font-size: 1rem;
  border-radius: 6px;
  transition: background .1s, transform .05s;
}
.bit:active { transform: scale(.9); }
.bit.on { color: #fff; }
.bit-row.r .bit.on { background: var(--r); border-color: #ff6b6b; }
.bit-row.g .bit.on { background: var(--g); border-color: #4ade80; }
.bit-row.b .bit.on { background: var(--b); border-color: #60a5fa; }

.bit-value {
  min-width: 3em;
  text-align: right;
  font-family: ui-monospace, monospace;
  font-weight: 700;
  color: var(--text-dim);
  font-size: .9rem;
}

.bit-weights {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin-left: 30px;
  font-family: ui-monospace, monospace;
  font-size: .65rem;
  color: var(--text-dim);
  text-align: center;
  margin-top: -4px;
  padding: 0 4em 8px 0;
}

/* ── Saisie DEC ───────────────────────────────────────────────────────── */

.dec-row {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}
.dec-row .ch-label {
  font-weight: 800;
  text-align: center;
}
.dec-row.r .ch-label { color: var(--r); }
.dec-row.g .ch-label { color: var(--g); }
.dec-row.b .ch-label { color: var(--b); }

.dec-row input {
  font-family: ui-monospace, monospace;
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
}

/* ── Résultat de manche ───────────────────────────────────────────────── */

.round-result { text-align: center; padding: 14px; }
.round-result .verdict {
  font-size: 1.8rem;
  font-weight: 900;
  margin-bottom: 8px;
}
.round-result .verdict.ok  { color: var(--ok); }
.round-result .verdict.ko  { color: var(--bad); }

.winners-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.winner-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-panel);
  border-radius: var(--radius-sm);
}
.winner-rank {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: .9rem;
}
.winner-rank.r1 { background: var(--gold); color: #2a1d00; }
.winner-rank.r2 { background: #cbd5e1; color: #1e293b; }
.winner-rank.r3 { background: #d97706; color: #fff; }

/* ── Classement flottant ──────────────────────────────────────────────── */

.leaderboard-pill {
  position: fixed;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: .85rem;
  font-weight: 700;
  color: var(--gold);
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 50;
  display: none;
}
.sheet-backdrop.open { display: block; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 80vh;
  background: var(--panel);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  z-index: 51;
  transform: translateY(100%);
  transition: transform .25s ease;
  overflow-y: auto;
}
.sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 50px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: -4px auto 12px;
}

/* ── Barre de session persistante ─────────────────────────────────────── */

.session-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px calc(8px + env(safe-area-inset-top)) 14px;
  background: rgba(21, 27, 48, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
}
.session-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 8px;
  background: linear-gradient(135deg, rgba(79,124,255,.2), rgba(124,92,255,.2));
  border: 1px solid var(--accent);
  border-radius: 999px;
}
.session-label {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--text-dim);
}
.session-code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 900;
  letter-spacing: .2em;
  color: var(--gold);
  font-size: 1rem;
}
.session-you {
  color: var(--text);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 10em;
}

/* ── Liste des parties (accueil) ──────────────────────────────────────── */

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.room-card {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: border-color .12s, transform .08s;
}
.room-card:hover  { border-color: var(--accent); }
.room-card:active { transform: scale(.99); }
.room-card .room-phase-icon {
  font-size: 1.5rem;
  text-align: center;
}
.room-card .room-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.room-card .room-line1 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}
.room-card .room-code-sm {
  font-family: ui-monospace, monospace;
  letter-spacing: .18em;
  color: var(--gold);
  font-size: 1rem;
}
.room-card .room-line2 {
  font-size: .75rem;
  color: var(--text-dim);
}
.room-card .room-cta {
  font-size: .8rem;
  color: var(--accent);
  font-weight: 700;
}
.room-card.in-progress .room-phase-icon { filter: hue-rotate(40deg); }

/* ── Toasts ───────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  top: 20px; left: 50%;
  transform: translateX(-50%) translateY(-120%);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 600;
  z-index: 100;
  transition: transform .3s ease;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
  max-width: 88vw;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.err  { border-color: var(--bad); color: var(--bad); }
.toast.ok   { border-color: var(--ok);  color: var(--ok); }

/* ── Divider ──────────────────────────────────────────────────────────── */

.divider {
  text-align: center;
  color: var(--text-dim);
  font-size: .8rem;
  margin: 6px 0;
  position: relative;
}
.divider::before, .divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 35%;
  height: 1px;
  background: var(--border);
}
.divider::before { left: 0; }
.divider::after  { right: 0; }

/* ── Desktop ≥ 900px ──────────────────────────────────────────────────── */

@media (min-width: 900px) {
  .app { max-width: 1100px; }
  .layout-with-sidebar {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 16px;
    align-items: start;
  }
  .layout-with-sidebar .main-col { display: flex; flex-direction: column; gap: 14px; }
  .layout-with-sidebar .side-col { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 16px; }
  .leaderboard-pill { display: none; }

  .bit { min-height: 48px; }
  .led     { width: 180px; height: 180px; }
  .led-lg  { width: 220px; height: 220px; }
  .color-grid { gap: 12px; }
  .swatch { min-height: 88px; }
}

/* ── Animations d'entrée ──────────────────────────────────────────────── */

.screen.active { animation: fadeIn .25s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
