/* Light theme is the base; dark is applied via [data-theme="dark"]. */
:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --ready: #16a34a;
  --danger: #ef4444;
  --btn-hover-bg: #cbd5e1;
  --backdrop: rgba(15, 23, 42, 0.5);
  --radius: 12px;
}

[data-theme='dark'] {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --ready: #22c55e;
  --btn-hover-bg: #3f4d63;
  --backdrop: rgba(15, 23, 42, 0.8);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--panel-2);
}

header h1 { margin: 0; font-size: 1.5rem; }
header h1 .home-link { color: inherit; text-decoration: none; }
header h1 .home-link:hover { text-decoration: underline; }

.name-field {
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
  color: var(--muted);
  gap: 0.25rem;
}

input[type='text'] {
  background: var(--panel);
  border: 1px solid var(--panel-2);
  color: var(--text);
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  font-size: 1rem;
  min-width: 180px;
}
input[type='text']:focus { outline: 2px solid var(--accent); }

.view { max-width: 820px; margin: 0 auto; padding: 1.5rem; }

/* Buttons */
button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--panel-2);
  background: var(--panel-2);
  color: var(--text);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  transition: background 0.15s, transform 0.05s;
}
button:hover { background: var(--btn-hover-bg); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: default; }

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-hover); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { background: var(--panel); }
.header-controls { display: flex; align-items: flex-end; gap: 0.75rem; }
.theme-toggle { font-size: 1.1rem; line-height: 1; padding: 0.45rem 0.6rem; }

/* Connection status banner */
.conn-status {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 0.45rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 20;
}
.conn-status.lost { background: var(--danger); color: #fff; }
.conn-status.ok { background: var(--ready); color: #06270f; }

/* Name prompt modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 10;
}
/* An author `display` rule overrides the UA `[hidden]{display:none}`, so
   restore it explicitly for the modal. */
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.modal h2 { margin: 0; }
.modal p { margin: 0; color: var(--muted); }
.modal input { width: 100%; }
.modal .primary { margin-top: 0.5rem; }

/* Landing */
.card-panel {
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
}
.card-panel h2 { margin-top: 0; }
.card-panel .primary { font-size: 1.05rem; padding: 0.7rem 1.5rem; }

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  margin: 1.5rem 0;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--panel-2);
}

.join-form { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }

/* Recent rooms */
.card-panel.recent { margin-top: 1rem; text-align: left; }
.card-panel.recent h2 { margin: 0 0 0.75rem; font-size: 1rem; color: var(--muted); }
ul#recent-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.recent-link {
  display: block;
  background: var(--panel-2);
  border: 1px solid var(--panel-2);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.1em;
}
.recent-link:hover { border-color: var(--accent); background: var(--btn-hover-bg); }

/* Room head */
.room-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.room-code { font-size: 1.1rem; color: var(--muted); }
.room-code strong { color: var(--text); letter-spacing: 0.1em; }
.room-code .ghost { margin-left: 0.5rem; font-size: 0.85rem; }

/* Deck */
.deck {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.card {
  width: 64px;
  height: 92px;
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 2px solid var(--panel-2);
}
.card:hover:not(:disabled) { border-color: var(--accent); }
.card.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.35);
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
}
.summary { margin-left: 0.5rem; font-weight: 600; color: var(--ready); }

/* Results panel (shown after reveal) */
.results {
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.75rem;
}
.stat-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  background: var(--panel-2);
  border-radius: 8px;
  padding: 0.7rem 0.5rem;
}
.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.stat-value { font-size: 1.4rem; font-weight: 700; }

.distribution { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.dist-row { display: flex; align-items: center; gap: 0.75rem; }
.dist-label {
  min-width: 2.5rem;
  font-weight: 700;
  text-align: center;
}
.dist-track {
  flex: 1;
  height: 0.85rem;
  background: var(--panel-2);
  border-radius: 99px;
  overflow: hidden;
}
.dist-bar {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.2s;
}
.dist-count {
  min-width: 4.5rem;
  text-align: right;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Participants */
.participants h2 { font-size: 1rem; color: var(--muted); }
ul#participants { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.participant {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
}
.participant.offline { opacity: 0.55; }
.p-name { flex: 1; }
.p-status { color: var(--muted); font-size: 1.1rem; min-width: 1.5rem; text-align: center; }
.p-status.ready { color: var(--ready); }
.p-vote {
  font-weight: 700;
  color: var(--text);
  background: var(--panel-2);
  border-radius: 6px;
  padding: 0.1rem 0.55rem;
}
.offline-badge {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border: 1px solid var(--panel-2);
  border-radius: 99px;
  padding: 0.1rem 0.5rem;
}
button.remove {
  background: transparent;
  border-color: transparent;
  color: var(--danger);
  padding: 0.2rem 0.5rem;
  font-size: 0.9rem;
}
button.remove:hover { background: rgba(239, 68, 68, 0.15); }

@media (max-width: 520px) {
  header { flex-direction: column; align-items: stretch; }
  .name-field input { min-width: 0; width: 100%; }
  .stat-tiles { grid-template-columns: repeat(2, 1fr); }
}
