:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-alt: #f0f2f5;
  --border: #dfe3e8;
  --text: #16181d;
  --text-muted: #6b7280;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-text: #ffffff;
  --success: #10a37f;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-alt: #1f232c;
    --border: #2c313c;
    --text: #e7e9ee;
    --text-muted: #9aa1ae;
    --accent: #7c74f0;
    --accent-soft: #23213c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }
button { font: inherit; cursor: pointer; }
a { color: var(--accent); }

.muted { color: var(--text-muted); }
.small { font-size: 0.82rem; }
.hidden { display: none !important; }

/* ------------------------------------------------------------- contrôles */

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 9px;
  padding: 0.55rem 0.95rem;
  font-weight: 550;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
}
.btn:hover:not(:disabled) { background: var(--surface-alt); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-alt); color: var(--text); }
.btn.small { padding: 0.32rem 0.6rem; font-size: 0.8rem; }
.btn.danger { color: var(--danger); }

input[type='text'], select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input[type='text']:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

label.field { display: block; margin-bottom: 0.9rem; }
label.field > span { display: block; font-size: 0.82rem; font-weight: 550; margin-bottom: 0.3rem; color: var(--text-muted); }

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.6rem;
  min-height: 1.1em;
}

/* --------------------------------------------------------------- accueil */

.landing {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}
.landing-inner { width: 100%; max-width: 440px; }
.landing header { text-align: center; margin-bottom: 1.8rem; }
.landing header h1 { font-size: 1.7rem; }
.landing header p { margin-top: 0.4rem; color: var(--text-muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.4rem;
}
.card + .card { margin-top: 1rem; }
.card h2 { font-size: 1rem; margin-bottom: 1rem; }

.deck-preview {
  display: flex;
  gap: 0.35rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1.6rem;
}
.deck-preview span {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* --------------------------------------------------------------- session */

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1.1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.topbar .brand { font-weight: 650; }
.topbar .code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 7px;
  padding: 0.2rem 0.5rem;
  font-weight: 650;
  letter-spacing: 0.08em;
}
.topbar .spacer { flex: 1; }

.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head {
  padding: 0.9rem 1rem 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.sidebar-head h2 { font-size: 0.9rem; flex: 1; }

.topic-list { overflow-y: auto; padding: 0 0.6rem 1rem; flex: 1; }
.topic-empty { padding: 1rem; color: var(--text-muted); font-size: 0.85rem; }

.topic {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 0.55rem 0.65rem;
  cursor: pointer;
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}
.topic:hover { background: var(--surface-alt); }
.topic.active { background: var(--accent-soft); border-color: var(--accent); }
.topic .title { flex: 1; font-size: 0.86rem; line-height: 1.35; }
.topic .badge {
  font-size: 0.72rem;
  font-weight: 650;
  border-radius: 6px;
  padding: 0.1rem 0.4rem;
  background: var(--success);
  color: #fff;
  flex-shrink: 0;
}
.topic .badge.pending { background: var(--surface-alt); color: var(--text-muted); }
.topic .remove { opacity: 0; }
.topic:hover .remove { opacity: 1; }

.main {
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  min-width: 0;
  overflow-y: auto;
}

.current-topic { }
.current-topic .eyebrow { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.current-topic h1 { font-size: 1.35rem; margin: 0.3rem 0; line-height: 1.3; }
.current-topic .meta { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; font-size: 0.82rem; color: var(--text-muted); }
.current-topic .excerpt { margin-top: 0.6rem; color: var(--text-muted); font-size: 0.88rem; line-height: 1.5; max-width: 70ch; }

.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.75rem;
}

/* table des participants */
.table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
}
.seat { width: 76px; text-align: center; }
.seat .card-face {
  height: 88px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--surface-alt);
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  font-weight: 700;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}
.seat .card-face.voted {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.seat .card-face.revealed { background: var(--surface); border-color: var(--accent); color: var(--text); }
.seat .card-face.spectator { font-size: 1rem; color: var(--text-muted); border-style: dashed; background: transparent; }
.seat .name {
  margin-top: 0.4rem;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seat .name.offline { opacity: 0.4; }
.seat .role { font-size: 0.68rem; color: var(--text-muted); }

/* résultats */
.results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}
.stat-row { display: flex; gap: 1.6rem; flex-wrap: wrap; }
.stat .label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat .value { font-size: 1.5rem; font-weight: 700; }
.stat .value.consensus { color: var(--success); }

.histogram { display: flex; gap: 0.5rem; align-items: flex-end; margin-top: 1rem; min-height: 70px; }
.bar { text-align: center; width: 42px; }
.bar .fill { background: var(--accent); border-radius: 5px 5px 0 0; min-height: 6px; }
.bar .cap { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.bar .val { font-size: 0.8rem; font-weight: 600; margin-top: 0.3rem; }

.accept-row { display: flex; align-items: center; gap: 0.55rem; flex-wrap: wrap; margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.accept-row .label { font-size: 0.82rem; color: var(--text-muted); }
.accept-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 0.3rem 0.65rem;
  font-weight: 650;
  font-size: 0.85rem;
}
.accept-chip.selected { background: var(--success); border-color: var(--success); color: #fff; }

/* deck */
.deck-bar {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.9rem 1.1rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
}
.deck-bar .hint { width: 100%; text-align: center; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.2rem; }

.play-card {
  width: 56px;
  height: 80px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 700;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.play-card:hover:not(:disabled) { transform: translateY(-6px); border-color: var(--accent); }
.play-card.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  transform: translateY(-6px);
}
.play-card:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ---------------------------------------------------------------- modale */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 12, 0.55);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(720px, 100%);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
}
.modal header {
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.modal header h2 { font-size: 1rem; flex: 1; }
.modal .body { padding: 1.2rem; overflow-y: auto; }
.modal footer {
  padding: 0.9rem 1.2rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.6rem;
  align-items: center;
  justify-content: flex-end;
}
.modal footer .spacer { flex: 1; }

.filters { display: flex; gap: 0.7rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters label.field { margin-bottom: 0; flex: 1; min-width: 150px; }

.status-toggles { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.status-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font-size: 0.8rem;
}
.status-toggle.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.post-list { display: flex; flex-direction: column; gap: 0.35rem; }
.post {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
}
.post:hover { background: var(--surface-alt); }
.post.selected { border-color: var(--accent); background: var(--accent-soft); }
.post input { margin-top: 0.25rem; }
.post .title { font-size: 0.88rem; font-weight: 550; }
.post .sub { font-size: 0.76rem; color: var(--text-muted); margin-top: 0.15rem; }
.post .already { font-size: 0.72rem; color: var(--warning); }

.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: 9px;
  font-size: 0.85rem;
  z-index: 100;
  box-shadow: var(--shadow);
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 34vh;
  }
  .main { padding: 1rem; }
  .seat { width: 62px; }
  .seat .card-face { height: 72px; font-size: 1.1rem; }
  .play-card { width: 48px; height: 68px; font-size: 1rem; }
}
