/* ============================
   CSS Variables & Reset
   ============================ */

:root {
  --yellow: #facc15;
  --yellow-dark: #eab308;
  --yellow-light: #fde68a;
  --yellow-bg: #fefce8;
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --blue-light: #bfdbfe;
  --blue-bg: #eff6ff;
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --border: #334155;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --transition: 0.2s ease;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

html {
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 600px;
  padding: 1rem;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================
   Screens
   ============================ */

.screen {
  display: none;
  width: 100%;
}

.screen.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.container {
  width: 100%;
}

/* ============================
   Typography
   ============================ */

.logo {
  font-size: 2rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 0.25rem;
  letter-spacing: -0.02em;
}

.yellow {
  color: var(--yellow);
}

.blue {
  color: var(--blue);
}

.subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

/* ============================
   Buttons
   ============================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  width: 100%;
  text-align: center;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-yellow {
  background: var(--yellow);
  color: #111827;
  border-color: var(--yellow);
}

.btn-yellow:hover:not(:disabled) {
  background: var(--yellow-dark);
  border-color: var(--yellow-dark);
}

.btn-blue {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.btn-blue:hover:not(:disabled) {
  background: var(--blue-dark);
  border-color: var(--blue-dark);
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--text-muted);
  background: var(--bg-card);
}

.btn-small {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  width: auto;
}

.btn-large {
  padding: 1rem 2rem;
  font-size: 1.15rem;
}

.btn-key-hint {
  margin-left: 0.65rem;
  padding: 0.12rem 0.45rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.2;
  opacity: 0.85;
}

/* ============================
   Forms
   ============================ */

input[type="text"],
select {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color var(--transition);
}

input[type="text"]:focus {
  border-color: var(--yellow);
}

select {
  cursor: pointer;
  appearance: auto;
}

/* ============================
   Join Screen
   ============================ */

.join-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ============================
   Lobby Screen
   ============================ */

.share-link-box {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.share-link-box p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.share-link-row {
  display: flex;
  gap: 0.5rem;
}

.share-link-row input {
  flex: 1;
  font-size: 0.85rem;
}

.copy-feedback {
  font-size: 0.8rem;
  color: var(--yellow);
  margin-top: 0.25rem;
  display: inline-block;
}

.lobby-players {
  margin-bottom: 1.5rem;
}

.lobby-players h2 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
}

#player-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

#player-list li {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
}

#player-list li.host::after {
  content: " (host)";
  color: var(--text-muted);
  font-size: 0.8rem;
}

#player-list li.disconnected {
  opacity: 0.4;
  text-decoration: line-through;
}

.host-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.round-select {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.round-select label {
  font-weight: 600;
  white-space: nowrap;
}

.round-select select {
  width: auto;
  min-width: 80px;
}

.waiting-text {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 1rem;
}

/* ============================
   Question Screen
   ============================ */

.round-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.round-indicator {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
}

.team-badge {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.team-badge.yellow-team {
  background: var(--yellow);
  color: #111827;
}

.team-badge.blue-team {
  background: var(--blue);
  color: #fff;
}

.question-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  position: relative;
}

.question-type-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  background: var(--bg);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  margin-bottom: 0.75rem;
}

.question-text {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
}

.answer-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.answer-option-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.9rem;
  padding: 1rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.answer-option-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.8rem;
  height: 1.8rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.answer-option-label {
  flex: 1;
  text-align: left;
}

.answer-option-btn:hover {
  border-color: var(--yellow);
  background: rgba(250, 204, 21, 0.12);
}

.answer-option-btn:hover .answer-option-key,
.answer-option-btn.selected .answer-option-key {
  border-color: currentColor;
  color: inherit;
}

.answer-option-btn.selected {
  border-color: var(--yellow);
  background: var(--yellow);
  color: #111827;
}

.fill-blank-input {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.answer-submitted {
  text-align: center;
  padding: 1rem;
  background: rgba(250, 204, 21, 0.12);
  border: 2px solid var(--yellow);
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}

.answer-submitted p {
  color: var(--yellow);
  font-weight: 600;
}

.submission-tracker {
  text-align: center;
  margin-bottom: 1rem;
}

#submission-status {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.submission-dots {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.sub-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background var(--transition);
}

.sub-dot.answered {
  background: var(--yellow);
}

/* ============================
   Reveal Screen
   ============================ */

.reveal-question-card {
  margin-bottom: 1rem;
}

.reveal-banner {
  text-align: center;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

.reveal-banner.winner-banner {
  background: rgba(250, 204, 21, 0.15);
  color: var(--yellow);
  border: 2px solid var(--yellow);
}

.reveal-banner.tie-banner {
  background: rgba(250, 204, 21, 0.15);
  color: var(--yellow);
  border: 2px solid var(--yellow);
}

.reveal-banner.all-different-banner {
  background: rgba(59, 130, 246, 0.15);
  color: var(--blue);
  border: 2px solid var(--blue);
}

.answer-results {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 2px solid var(--border);
}

.result-row.mergeable {
  cursor: pointer;
}

.result-row.mergeable:hover {
  border-color: var(--blue);
  background: rgba(59, 130, 246, 0.08);
}

.result-row.selected {
  border-color: var(--blue);
  background: rgba(59, 130, 246, 0.16);
}

.result-row.winning {
  border-color: var(--yellow);
  background: rgba(250, 204, 21, 0.1);
}

.result-answer {
  font-weight: 600;
  font-size: 1rem;
}

.result-count {
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: 1rem;
}

.result-players {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

.result-variants {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.result-subgroups {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

.split-subgroup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.split-subgroup-btn {
  appearance: none;
  border: 1px solid rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.12);
  color: var(--text);
  border-radius: 999px;
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  cursor: pointer;
}

.split-subgroup-btn:hover {
  background: rgba(59, 130, 246, 0.22);
}

.merge-controls {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: var(--radius-sm);
}

.merge-help {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

.merge-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.team-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.team-column h3 {
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.team-column ul {
  list-style: none;
}

.team-column li {
  font-size: 0.85rem;
  padding: 0.25rem 0;
  display: flex;
  justify-content: space-between;
}

.team-column li .score-change {
  font-weight: 600;
}

.score-change.plus {
  color: var(--yellow);
}

.team-yellow-col {
  background: rgba(250, 204, 21, 0.05);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  border: 1px solid rgba(250, 204, 21, 0.2);
}

.team-blue-col {
  background: rgba(59, 130, 246, 0.05);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.reveal-footer {
  text-align: center;
}

.countdown-text {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

/* ============================
   Finished Screen
   ============================ */

.winner-announce {
  text-align: center;
  padding: 0;
  margin-bottom: 1.5rem;
}

.winner-hero {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.14), rgba(250, 204, 21, 0.06));
  border: 2px solid rgba(250, 204, 21, 0.55);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.winner-hero.blue-team {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.14), rgba(59, 130, 246, 0.06));
  border-color: rgba(59, 130, 246, 0.5);
}

.winner-kicker {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.winner-announce .winner-name {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--yellow);
}

.winner-name-large {
  font-size: 2.4rem !important;
  line-height: 1.05;
  margin-bottom: 0.4rem;
}

.winner-announce .winner-score {
  font-size: 1.1rem;
  color: var(--text-muted);
}

.winner-score-large {
  font-size: 1.35rem !important;
  font-weight: 800;
  color: var(--text) !important;
}

.winner-meta-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.9rem;
}

.winner-meta {
  color: var(--text-muted);
}

.winner-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.winner-pill.yellow-team {
  background: rgba(250, 204, 21, 0.2);
  color: var(--yellow);
  border: 1px solid rgba(250, 204, 21, 0.4);
}

.winner-pill.blue-team {
  background: rgba(59, 130, 246, 0.15);
  color: var(--blue);
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.tie-hero {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.14), rgba(59, 130, 246, 0.08));
}

.winner-tie-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.winner-tie-grid.crowded {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.winner-chip {
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.3);
}

.winner-chip.yellow-team {
  border-color: rgba(250, 204, 21, 0.35);
  background: rgba(250, 204, 21, 0.12);
}

.winner-chip.blue-team {
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.12);
}

.winner-chip-name {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
}

.winner-tie-grid.crowded .winner-chip {
  padding: 0.7rem 0.85rem;
}

.winner-tie-grid.crowded .winner-chip-name {
  font-size: 0.95rem;
}

.winner-chip-team {
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.final-scores {
  margin-bottom: 1.5rem;
}

.final-scores h2 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  text-align: center;
}

#final-score-list {
  list-style: none;
  counter-reset: score-list;
}

#final-score-list li {
  counter-increment: score-list;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

#final-score-list li::before {
  content: counter(score-list) ".";
  font-weight: 700;
  margin-right: 0.75rem;
  min-width: 1.5rem;
  color: var(--text-muted);
}

.final-name {
  flex: 1;
  font-weight: 600;
}

.final-pts {
  font-weight: 700;
  color: var(--yellow);
}

/* ============================
   Spectate Screen
   ============================ */

.spectate-msg {
  text-align: center;
  color: var(--text-muted);
  margin-top: 2rem;
  line-height: 1.8;
}

/* ============================
   Responsive
   ============================ */

@media (max-width: 480px) {
  .logo {
    font-size: 1.6rem;
  }

  .winner-name-large {
    font-size: 1.9rem !important;
  }

  .question-text {
    font-size: 1.1rem;
  }

  .team-summary {
    grid-template-columns: 1fr;
  }
}

/* ============================
   Toast
   ============================ */

.toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: #ef4444;
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 1000;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.3s ease;
  max-width: calc(100vw - 2rem);
  text-align: center;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
