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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --text: #e8eaf0;
  --text-muted: #9aa0b4;
  --primary: #4f8cff;
  --secondary: #6c5ce7;
  --success: #2ecc71;
  --warning: #f39c12;
  --danger: #e74c3c;
  --lobby: #4f8cff;
  --writing: #2ecc71;
  --generating: #f39c12;
  --guessing: #a855f7;
  --reveal: #f1c40f;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

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

.hidden { display: none !important; }

/* Landing */
.page-landing {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.landing {
  width: 100%;
  max-width: 420px;
}

.landing h1 {
  font-size: 2rem;
  text-align: center;
  margin-bottom: 0.25rem;
}

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

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

.card h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--text-muted);
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  margin-top: 0.75rem;
}

input, textarea, select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--surface2);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

textarea {
  resize: vertical;
  min-height: 60px;
}

.btn {
  display: inline-block;
  width: 100%;
  padding: 0.85rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 1rem;
  transition: opacity 0.2s, transform 0.1s;
}

.btn:hover:not(:disabled) { opacity: 0.9; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }

.error-msg {
  color: var(--danger);
  text-align: center;
  margin-top: 1rem;
  font-size: 0.9rem;
}

/* Game layout */
.game-header {
  background: var(--surface);
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--surface2);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.room-code {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.phase-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.phase-badge.lobby { background: var(--lobby); color: #fff; }
.phase-badge.writing { background: var(--writing); color: #fff; }
.phase-badge.generating { background: var(--generating); color: #fff; }
.phase-badge.guessing { background: var(--guessing); color: #fff; }
.phase-badge.reveal { background: var(--reveal); color: #111; }

.player-title {
  font-size: 1.4rem;
}

.game-container {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.5rem;
}

body.submission-active .game-container {
  padding-bottom: 10rem;
}

body.submission-active .phase form .btn[type="submit"] {
  margin-bottom: 0.5rem;
}

.phase h2 {
  margin-bottom: 0.5rem;
}

.phase-desc {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

/* Lobby */
.player-list {
  list-style: none;
  margin-bottom: 1.5rem;
}

.player-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

.player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.player-dot.offline { background: var(--text-muted); }

.player-list .host-tag {
  font-size: 0.7rem;
  background: var(--primary);
  color: #fff;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  margin-left: auto;
}

.lobby-hint {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  margin-top: 1rem;
}

.countdown-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  margin: 1.5rem 0;
  border: 1px solid var(--primary);
}

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

.countdown-timer {
  font-size: 2.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

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

.btn-leave {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--surface2);
  margin-top: 0.75rem;
}

.btn-leave:hover:not(:disabled) {
  color: var(--danger);
  border-color: var(--danger);
}

/* Writing */
.writing-field {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.writing-field label {
  font-size: 1rem;
  color: var(--text);
  font-weight: 600;
  margin-top: 0;
}

.writing-field textarea:disabled,
.writing-field input:disabled {
  opacity: 0.6;
}

/* Generating */
.generating-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}

.cooking-phrase {
  font-size: 1.3rem;
  font-style: italic;
  color: var(--text);
  opacity: 0;
  transition: opacity 1s ease;
  max-width: 400px;
}

.cooking-phrase.visible { opacity: 1; }

.generating-progress {
  margin-top: 2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  margin-top: 0.75rem;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--generating);
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* Guessing */
.guess-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.guess-card .text-content {
  font-size: 1.05rem;
  margin-bottom: 1rem;
  line-height: 1.6;
  border-left: 3px solid var(--guessing);
  padding-left: 1rem;
}

.guess-card select:disabled { opacity: 0.6; }

/* Reveal */
.reveal-score {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: var(--reveal);
}

.reveal-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.reveal-card .text-content {
  font-size: 1.05rem;
  margin-bottom: 1rem;
  line-height: 1.6;
}

.reveal-answer {
  background: rgba(46, 204, 113, 0.15);
  border: 1px solid var(--success);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

.reveal-choices {
  list-style: none;
}

.reveal-choices li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  font-size: 0.95rem;
}

.reveal-choices .correct { color: var(--success); }
.reveal-choices .wrong { color: var(--text-muted); }

.choice-icon { font-size: 1rem; }

/* Submission panel */
.submission-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--surface2);
  padding: 0.75rem 1rem 1rem;
  z-index: 20;
  max-height: 38vh;
  overflow-y: auto;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
}

.submission-panel h3 {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

#submission-count {
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.submission-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.submission-list li {
  font-size: 0.85rem;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  background: var(--surface2);
}

.submission-list li.done { background: rgba(46, 204, 113, 0.2); color: var(--success); }
.submission-list li.pending { color: var(--text-muted); }

/* Toast */
.toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 100;
  box-shadow: var(--shadow);
}

body.submission-active .toast {
  bottom: calc(38vh + 1rem);
}

/* Leaderboard */
.leaderboard {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.leaderboard h3 {
  margin-bottom: 1rem;
  text-align: center;
}

.leaderboard-list {
  list-style: none;
}

.leaderboard-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  margin-bottom: 0.35rem;
  background: var(--surface2);
}

.leaderboard-list li.winner {
  background: rgba(241, 196, 15, 0.15);
  border: 1px solid var(--reveal);
}

.leaderboard-list li.viewer {
  outline: 2px solid var(--primary);
}

.leaderboard-list .rank {
  font-weight: 700;
  min-width: 2rem;
  color: var(--text-muted);
}

.leaderboard-list .name {
  flex: 1;
  margin: 0 0.5rem;
}

.leaderboard-list .points {
  font-weight: 700;
  color: var(--reveal);
}

.winners-banner {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--reveal);
  margin-bottom: 1rem;
  padding: 1rem;
  background: rgba(241, 196, 15, 0.1);
  border-radius: var(--radius);
}

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

.reveal-actions {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--surface2);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.reveal-actions .btn {
  margin-top: 0;
}

@media (min-width: 768px) {
  body.submission-active .game-container {
    padding-bottom: 1.5rem;
  }

  .submission-panel {
    position: fixed;
    bottom: auto;
    top: 50%;
    right: 1.5rem;
    left: auto;
    transform: translateY(-50%);
    width: 220px;
    border-radius: var(--radius);
    border: 1px solid var(--surface2);
  }

  .game-container {
    margin-right: 260px;
  }
}
