/*
 * Feuille de style commune aux parties partagées Pokémon (Rouge, Cristal,
 * Rouge FR, Émeraude). Simple : deux colonnes (jeu | partie + discussion),
 * thème clair ou sombre selon le système, couleur d'accent par jeu.
 */

:root {
  color-scheme: light dark;
  --accent: #e3350d;
  --accent-text: #fff;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e2e4e9;
  --text: #16181d;
  --text-2: #4b5160;
  --text-3: #7c8291;
  --ok: #16a34a;
  --wait: #d97706;
  --info: #2563eb;
  --danger: #dc2626;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

body { --screen-ratio: 1.1111; }   /* Game Boy : 160 × 144 */
body[data-game="cristal"] { --accent: #2f6fdb; }
body[data-game="emeraude"] { --accent: #0e9f6e; --screen-ratio: 1.5; }   /* GBA : 240 × 160 */
body[data-game="rocket"] { --accent: #c0392b; --screen-ratio: 1.5; }   /* GBA : 240 × 160 */

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #171a20;
    --surface-2: #1f232b;
    --border: #2a2f39;
    --text: #eceef2;
    --text-2: #b4b9c4;
    --text-3: #838a98;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
[hidden] { display: none !important; }

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0.05em 0.45em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 0.85em;
  text-align: center;
}

.app {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

/* ── En-tête ─────────────────────────────────────────────── */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  flex: none;
  color: var(--accent);
}

.brand h1 {
  margin: 0;
  font-size: 1.6rem;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.tagline {
  margin: 2px 0 0;
  color: var(--text-2);
  font-size: 0.95rem;
}

.top-status {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.82rem;
  white-space: nowrap;
}

.chip.subtle { color: var(--text-3); font-family: var(--mono); font-size: 0.75rem; }
.chip.state-playable { border-color: transparent; background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); font-weight: 600; }
.chip.state-queued { border-color: transparent; background: color-mix(in srgb, var(--info) 14%, transparent); color: var(--info); font-weight: 600; }
.chip.state-spectating { border-color: transparent; background: color-mix(in srgb, var(--wait) 14%, transparent); color: var(--wait); font-weight: 600; }

/* ── Mise en page ────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.stage, .side {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* ── Écran ───────────────────────────────────────────────── */

.screen-frame {
  position: relative;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #111318;
  box-shadow: var(--shadow);
  outline: none;
}

.screen-frame:focus-visible { box-shadow: var(--shadow), 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); }
.screen-frame.is-playing { border-color: color-mix(in srgb, var(--ok) 70%, transparent); }

.screen {
  display: block;
  /* Toute la largeur, sans dépasser la hauteur de la fenêtre (commandes visibles). */
  width: min(100%, calc((100vh - 230px) * var(--screen-ratio))) !important;
  min-width: min(100%, 320px);
  height: auto !important;
  margin: 0 auto;
  border-radius: 8px;
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.screen-badge {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  pointer-events: none;
}

.screen-frame:not(.is-playing):not(.is-spectating) .screen-badge { display: none; }
.screen-frame.is-spectating .screen-badge::before { content: "● EN DIRECT"; color: #fbbf24; }
.screen-frame.is-playing .screen-badge::before { content: "● À TOI"; color: #4ade80; }
.screen-frame.is-paused .screen-badge::after { content: " · PAUSE"; color: #e5e7eb; }

.overlay-message {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 48px);
  margin: 0;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 0.82rem;
  text-align: center;
  pointer-events: none;
}

/* ── Barre de commandes sous l'écran ─────────────────────── */

.player-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px;
}

.bar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bar-spacer { flex: 1; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.is-on { color: var(--accent); }

.volume {
  display: flex;
  align-items: center;
  gap: 4px;
}

.volume input[type="range"] {
  width: 110px;
  accent-color: var(--accent);
}

.volume-value {
  min-width: 3ch;
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 0.75rem;
}

.speed-control {
  display: flex;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.speed-btn {
  height: 30px;
  min-width: 38px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-size: 0.82rem;
  font-weight: 600;
}

.speed-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.meta-line {
  margin: 0 4px;
  color: var(--text-3);
  font-size: 0.85rem;
}

#sync-label { color: var(--text-2); }

/* ── Panneaux repliables ─────────────────────────────────── */

.panel {
  padding: 0;
  overflow: hidden;
}

.panel > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 16px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::after { content: "›"; margin-left: auto; color: var(--text-3); font-size: 1.2rem; transition: transform 0.15s; }
.panel[open] > summary::after { transform: rotate(90deg); }

.panel-body {
  padding: 0 16px 16px;
  color: var(--text-2);
  font-size: 0.92rem;
}

.panel-body p { margin: 0 0 10px; }

.steps {
  margin: 0 0 10px;
  padding-left: 1.3em;
}

.steps li { margin: 4px 0; }

.control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn.primary { border-color: transparent; background: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 85%, #000); }
.btn.primary.joined { border-color: var(--border); background: var(--surface-2); color: var(--text); }
.btn.block { width: 100%; }

/* ── Carte « Partie » ────────────────────────────────────── */

.turn-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  margin: 0;
  color: var(--text-3);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.counters {
  display: flex;
  gap: 6px;
}

.counter {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 0.78rem;
  white-space: nowrap;
}

.turn-now {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 1rem;
}

.mp-dot {
  width: 10px;
  height: 10px;
  margin-top: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--text-3);
}

.mp-dot.playing { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 20%, transparent); }
.mp-dot.watching { background: var(--wait); }
.mp-dot.waiting { background: var(--info); }
.mp-dot.syncing { animation: blink 1.2s ease-in-out infinite; }

@keyframes blink { 50% { opacity: 0.3; } }

.turn-times {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.turn-times:not(:has(> :not([hidden]))) { display: none; }

.time-chip {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.time-chip.urgent { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); font-weight: 600; }

.queue-list {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: queue;
}

.queue-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  counter-increment: queue;
}

.queue-list li::before {
  content: counter(queue);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 0.75rem;
  font-weight: 700;
}

.queue-list li.is-active::before { content: "▶"; background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.queue-list li.is-me { font-weight: 600; }
.queue-empty { color: var(--text-3); font-size: 0.88rem; }

.join-row {
  display: flex;
  gap: 8px;
}

.mp-nick-input,
.chat-input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  outline: none;
}

.mp-nick-input:focus,
.chat-input:focus { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); }

.hint {
  margin: 0;
  color: var(--text-3);
  font-size: 0.82rem;
}

/* ── Discussion ──────────────────────────────────────────── */

.chat-panel {
  display: flex;
  flex-direction: column;
  height: min(560px, 70vh);
  min-height: 320px;
  overflow: hidden;
}

.chat-panel .card-head { padding: 12px 16px 8px; }

.users-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--border);
  list-style: none;
}

.user {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.8rem;
}

.user::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.user--joue::before { background: var(--ok); }
.user--file::before { background: var(--info); }
.user__role { display: none; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 16px;
}

.chat-empty {
  margin: 24px 0;
  color: var(--text-3);
  text-align: center;
  font-size: 0.88rem;
}

.chat-msg {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 6px;
  padding: 3px 0;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.chat-msg__nick { font-weight: 700; }
.chat-msg__nick.is-me { color: var(--accent); }
.chat-msg__text { flex: 1 1 auto; color: var(--text); }
.chat-msg__time { color: var(--text-3); font-size: 0.72rem; }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

/* ── Historique ──────────────────────────────────────────── */

.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid var(--border);
}

.history-reason { color: var(--text-3); }
.history-empty { color: var(--text-3); }

/* ── Touches ─────────────────────────────────────────────── */

.keys-head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.keys-table {
  display: grid;
  gap: 4px;
}

.keys-row {
  display: grid;
  grid-template-columns: 90px repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 6px;
}

.keys-row--head { color: var(--text-3); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.keys-name { font-weight: 600; color: var(--text); }

.keys-row [role="cell"] {
  display: flex;
  align-items: center;
  gap: 4px;
}

.key-slot {
  flex: 1;
  height: 34px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-3);
  font-size: 0.85rem;
}

.key-slot:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.key-slot.is-capturing { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.key-clear {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-3);
}

.key-clear:hover { background: var(--surface-2); color: var(--danger); }

/* ── Divers ──────────────────────────────────────────────── */

.error-banner {
  margin: 0;
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--danger);
  font-size: 0.9rem;
}

.site-notice {
  margin: 24px 0 0;
  color: var(--text-3);
  font-size: 0.8rem;
  text-align: center;
}

.site-notice a { color: inherit; }

/* Commandes tactiles (Pokémon Rouge sur téléphone uniquement) */
.touch-controls { display: none; }

@media (hover: none) and (pointer: coarse) {
  .touch-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 8px 4px;
  }

  .dpad {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 52px);
    grid-template-areas: ". up ." "left . right" ". down .";
  }

  .touch-button {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-2);
    font-size: 0.8rem;
    font-weight: 700;
    touch-action: none;
    user-select: none;
  }

  .touch-button.is-active { background: var(--accent); color: var(--accent-text); }
  .touch-button.up { grid-area: up; }
  .touch-button.down { grid-area: down; }
  .touch-button.left { grid-area: left; }
  .touch-button.right { grid-area: right; }

  .touch-actions {
    display: grid;
    grid-template-columns: repeat(2, 64px);
    gap: 10px;
  }

  .touch-button.round { height: 64px; border-radius: 50%; }
  .touch-button.capsule { height: 36px; border-radius: 999px; }
}
