:root {
  --bg: #1a1330;
  --bg-alt: #241b3f;
  --card: #2c2150;
  --text: #f4f0ff;
  --text-dim: #b7aed6;
  --accent: #ff5da2;
  --accent-2: #7c5cff;
  --good: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
}

* { box-sizing: border-box; }

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes popIn {
  0% { opacity: 0; transform: scale(0.85); }
  60% { opacity: 1; transform: scale(1.04); }
  100% { transform: scale(1); }
}
@keyframes bounceBadge {
  0% { transform: scale(0.6) rotate(-6deg); opacity: 0; }
  55% { transform: scale(1.12) rotate(3deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 93, 162, 0.45); }
  50% { box-shadow: 0 0 0 14px rgba(255, 93, 162, 0); }
}
@keyframes dangerGlowPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.55); }
  50% { box-shadow: 0 0 0 10px rgba(248, 113, 113, 0); }
}
@keyframes timerPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}
@keyframes shimmerText {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes confettiFall {
  0% { transform: translateY(-10vh) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(540deg); opacity: 0.9; }
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: radial-gradient(circle at top, var(--bg-alt), var(--bg));
  color: var(--text);
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { margin: 0 0 0.5em; }

.btn {
  display: inline-block;
  padding: 0.9em 1.6em;
  border-radius: 999px;
  border: none;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
@media (hover: hover) {
  .btn:not(:disabled):hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25); }
}

.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; }
.btn-secondary { background: var(--card); color: var(--text); border: 2px solid var(--accent-2); }
.btn-block { display: block; width: 100%; }

input[type="text"], textarea {
  width: 100%;
  padding: 0.8em 1em;
  font-size: 1.1rem;
  border-radius: 12px;
  border: 2px solid var(--accent-2);
  background: var(--bg-alt);
  color: var(--text);
  font-family: inherit;
}
input[type="text"]:focus, textarea:focus { outline: 2px solid var(--accent); }

/* Landing */
.landing { align-items: center; justify-content: center; text-align: center; padding: 1.5em; }
.landing-card { max-width: 420px; animation: popIn 0.5s ease both; }
.landing h1 {
  font-size: 2.6rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2), var(--accent));
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmerText 4s linear infinite;
}
.subtitle { color: var(--text-dim); margin-bottom: 2em; }
.landing-actions { display: flex; flex-direction: column; gap: 1em; }
.landing-hint { color: var(--text-dim); font-size: 0.85rem; margin-top: 2em; }

/* Generic screen container */
.screen {
  flex: 1;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5em;
  text-align: center;
  gap: 1em;
}
.screen.active { display: flex; animation: fadeSlideUp 0.4s ease both; }

.card {
  background: var(--card);
  border-radius: 20px;
  padding: 1.5em;
  width: 100%;
  max-width: 480px;
  animation: popIn 0.4s ease both;
}

.lobby-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 2em;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
}
.lobby-main {
  flex: 1 1 380px;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1em;
}
.lobby-tips {
  flex: 1 1 340px;
  max-width: 420px;
  text-align: left;
}
.lobby-tips h3 { text-align: center; }
.lobby-tips ol {
  margin: 0;
  padding-left: 1.3em;
  display: flex;
  flex-direction: column;
  gap: 0.6em;
}
.lobby-tips li { line-height: 1.4; }
.lobby-tips .progress-text { text-align: center; margin: 1em 0 0; }

/* Host: room code */
.room-code {
  font-size: 4rem;
  font-weight: 800;
  letter-spacing: 0.25em;
  padding: 0.3em 0.4em 0.3em 0.55em;
  background: var(--bg-alt);
  border-radius: 16px;
  border: 3px dashed var(--accent);
  animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both, glowPulse 2.5s ease-in-out infinite 0.5s;
}

.player-list {
  list-style: none;
  padding: 0;
  margin: 1em 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  justify-content: center;
}
.player-list li {
  background: var(--bg-alt);
  padding: 0.5em 1em;
  border-radius: 999px;
  border: 2px solid var(--accent-2);
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.player-list li:nth-child(1) { animation-delay: 0.03s; }
.player-list li:nth-child(2) { animation-delay: 0.06s; }
.player-list li:nth-child(3) { animation-delay: 0.09s; }
.player-list li:nth-child(4) { animation-delay: 0.12s; }
.player-list li:nth-child(5) { animation-delay: 0.15s; }
.player-list li:nth-child(6) { animation-delay: 0.18s; }
.player-list li:nth-child(7) { animation-delay: 0.21s; }
.player-list li:nth-child(8) { animation-delay: 0.24s; }

.after-dark-toggle {
  display: flex;
  align-items: center;
  gap: 0.5em;
  justify-content: center;
  background: var(--bg-alt);
  border: 2px solid var(--danger);
  border-radius: 999px;
  padding: 0.6em 1.2em;
  margin: 0.5em 0 1em;
  cursor: pointer;
  font-weight: 600;
}
.after-dark-toggle input { width: 1.2em; height: 1.2em; }

.sound-toggle {
  position: fixed;
  top: 0.6em;
  left: 0.6em;
  width: 2.6em;
  height: 2.6em;
  border-radius: 50%;
  border: 2px solid var(--accent-2);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  z-index: 15;
  transition: transform 0.15s ease;
}
.sound-toggle:active { transform: scale(0.9); }

.after-dark-badge {
  position: fixed;
  top: 0;
  right: 0;
  background: var(--danger);
  color: white;
  font-weight: 700;
  padding: 0.4em 1em;
  border-bottom-left-radius: 12px;
  z-index: 10;
  animation: bounceBadge 0.4s ease both, dangerGlowPulse 2s ease-in-out infinite 0.4s;
}

.round-indicator {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0.03em;
  margin-bottom: 0.25em;
}

.round-type-badge {
  display: inline-block;
  padding: 0.3em 1em;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--accent-2);
  color: white;
  margin-bottom: 0.5em;
  animation: bounceBadge 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.timer {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--warn);
  display: inline-block;
}
.timer.low { color: var(--danger); animation: timerPulse 0.8s ease-in-out infinite; }

.progress-text { color: var(--text-dim); }

/* Write-round suggestion chips */
#text-suggestions { display: flex; flex-wrap: wrap; gap: 0.5em; justify-content: center; margin-top: 1em; }
#text-suggestions .suggestions-label { width: 100%; color: var(--text-dim); font-size: 0.85rem; margin: 0; }
.suggestion-chip {
  border-radius: 999px;
  border: 2px solid var(--accent-2);
  background: var(--bg-alt);
  color: var(--text);
  padding: 0.5em 1em;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
}
.suggestion-chip:active { background: var(--accent-2); }
.suggestion-chip.selected { background: var(--accent-2); color: white; }

/* Reveal */
#round-title { animation: popIn 0.35s ease both; }
.reveal-content { min-height: 220px; display: flex; align-items: center; justify-content: center; }
.reveal-content img { max-width: 100%; max-height: 50vh; border-radius: 12px; background: white; animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.reveal-content p { font-size: 1.8rem; font-weight: 700; animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.reveal-author { color: var(--text-dim); margin-top: 0.5em; display: inline-block; animation: fadeSlideUp 0.35s ease both; }
.reveal-progress { color: var(--text-dim); font-size: 0.9rem; }

/* Confetti */
.confetti-container {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 20;
}
.confetti-piece {
  position: absolute;
  top: 0;
  width: 10px;
  height: 16px;
  opacity: 0.9;
  animation-name: confettiFall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}

/* Connecting spinner */
.spinner {
  width: 3em;
  height: 3em;
  border-radius: 50%;
  border: 5px solid var(--bg-alt);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

/* Player drawing canvas */
.canvas-wrap {
  width: 100%;
  max-width: 480px;
  touch-action: none;
}
canvas.drawing {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: white;
  border-radius: 12px;
  display: block;
  touch-action: none;
}
.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  margin: 0.8em 0;
  flex-wrap: wrap;
}
.swatch {
  width: 2em;
  height: 2em;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  padding: 0;
}
.swatch.selected { border-color: var(--text); }
.brush-btn {
  border-radius: 999px;
  border: 2px solid var(--accent-2);
  background: var(--bg-alt);
  color: var(--text);
  padding: 0.4em 0.8em;
  cursor: pointer;
}
.brush-btn.selected { background: var(--accent-2); }

.error-msg { color: var(--danger); min-height: 1.2em; }

.big-message { font-size: 1.6rem; font-weight: 700; animation: popIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both; }

@media (min-width: 700px) {
  .room-code { font-size: 6rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
