/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #0a0a1a;
  --bg-card: #141428;
  --bg-card-alt: #1c1c3a;
  --bg-input: #0e0e24;
  --text-primary: #e8e8f0;
  --text-secondary: #9898b0;
  --text-dim: #606078;
  --accent: #f0c040;
  --accent-dim: #b89020;
  --teal: #00b4d8;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f97316;
  --purple: #a78bfa;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
  padding-bottom: 32px;
}

.hidden { display: none !important; }

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 26, 0.92);
  backdrop-filter: blur(12px);
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  margin: 0 -16px;
  padding-left: 16px;
  padding-right: 16px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#header-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

.room-badge {
  background: var(--bg-card-alt);
  color: var(--accent);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 2px;
}

/* ── Pages ── */
.page {
  padding-top: 24px;
  animation: fadeIn 0.3s ease;
}

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

/* ── Hero ── */
.hero {
  text-align: center;
  padding: 60px 0 40px;
}

.hero h1 {
  font-size: 2.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--orange));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.hero p {
  color: var(--text-secondary);
  font-size: 1rem;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--orange));
  color: #000;
}
.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
  background: var(--bg-card-alt);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  width: 100%;
  margin-top: 8px;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.85rem;
  border-radius: 6px;
  background: var(--bg-card-alt);
  color: var(--accent);
  border: 1px solid rgba(240, 192, 64, 0.3);
}

.btn-lg {
  width: 100%;
  padding: 16px;
  font-size: 1.1rem;
}

.btn-block { width: 100%; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ── Card ── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.card h2 {
  font-size: 1.3rem;
  margin-bottom: 20px;
  color: var(--text-primary);
}

.card h3 {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* ── Home Actions ── */
.home-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Form ── */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

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

input[type="text"]::placeholder {
  color: var(--text-dim);
}

/* ── Counter ── */
.counter {
  display: flex;
  align-items: center;
  gap: 20px;
  justify-content: center;
}

.counter-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--accent-dim);
  background: transparent;
  color: var(--accent);
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.counter-btn:hover {
  background: rgba(240, 192, 64, 0.1);
}

.counter span {
  font-size: 2rem;
  font-weight: 700;
  min-width: 48px;
  text-align: center;
}

.hint {
  display: block;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 4px;
}

/* ── Difficulty ── */
.difficulty-selector {
  display: flex;
  gap: 8px;
}

.diff-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
}

.diff-btn.active {
  background: rgba(240, 192, 64, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Room Info ── */
.room-info {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-input);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}

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

.room-id-display {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--accent);
  flex: 1;
}

/* ── Player List ── */
.player-list-section {
  margin-bottom: 20px;
}

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

.player-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  background: var(--bg-input);
}

.player-list li.disconnected {
  opacity: 0.4;
}

.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal), var(--purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.player-name {
  flex: 1;
  font-size: 0.95rem;
}

.player-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(240, 192, 64, 0.15);
  color: var(--accent);
}

.hint-text {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* ── Generating ── */
.center-content {
  text-align: center;
  padding: 60px 20px;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--bg-card-alt);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 24px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Script Reading ── */
.script-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.script-header h2 {
  margin: 0;
}

.script-label {
  font-size: 0.8rem;
  padding: 2px 10px;
  border-radius: 10px;
  background: rgba(0, 180, 216, 0.15);
  color: var(--teal);
}

.script-story {
  font-size: 1rem;
  line-height: 1.8;
  white-space: pre-wrap;
  color: var(--text-primary);
  padding: 16px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  border-left: 3px solid var(--accent-dim);
}

.public-background {
  background: var(--bg-card-alt);
  padding: 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.public-background h3 {
  color: var(--accent);
  margin-bottom: 8px;
}

.public-background p {
  font-size: 0.95rem;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* ── Clues ── */
.clues-section {
  margin-bottom: 20px;
}

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

.clues-list li {
  padding: 10px 14px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  border-left: 3px solid var(--teal);
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ── Progress Bar ── */
.progress-bar {
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--orange));
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 0%;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.read-progress-bar,
.answer-progress-bar {
  margin: 16px 0;
}

/* ── Questions ── */
.questions-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.question-card {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 16px;
}

.question-card .q-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.question-card .q-text {
  font-size: 0.95rem;
  line-height: 1.5;
  flex: 1;
}

.question-card .q-points {
  font-size: 0.8rem;
  color: var(--accent);
  white-space: nowrap;
  margin-left: 8px;
}

.question-card .q-type {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.option-btn {
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.option-btn:hover {
  border-color: var(--accent-dim);
}

.option-btn.selected {
  background: rgba(240, 192, 64, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Results ── */
.result-section {
  margin-bottom: 24px;
}

.result-section h3 {
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.score-highlight {
  font-size: 1.5rem;
  color: var(--accent);
  font-weight: 800;
}

.score-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.score-tag {
  padding: 6px 12px;
  background: var(--bg-input);
  border-radius: 20px;
  font-size: 0.8rem;
}

.score-tag .tag-label {
  color: var(--text-dim);
}

.score-tag .tag-value {
  color: var(--text-primary);
  font-weight: 600;
}

/* ── Leaderboard ── */
.leaderboard {
  list-style: none;
}

.leaderboard li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  background: var(--bg-input);
}

.leaderboard li:first-child {
  background: rgba(240, 192, 64, 0.1);
  border: 1px solid rgba(240, 192, 64, 0.2);
}

.lb-rank {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-card-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.leaderboard li:first-child .lb-rank {
  background: var(--accent);
  color: #000;
}

.lb-name {
  flex: 1;
  font-size: 0.95rem;
}

.lb-score {
  font-weight: 700;
  color: var(--accent);
}

/* ── Awards ── */
.awards-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.award-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
}

.award-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--orange));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.award-info {
  flex: 1;
}

.award-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.award-winner {
  font-size: 0.8rem;
  color: var(--accent);
}

.award-desc {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ── Answer Review ── */
.answer-review {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.review-item {
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--text-dim);
}

.review-item.correct {
  border-left-color: var(--green);
}

.review-item.wrong {
  border-left-color: var(--red);
}

.review-item.partial {
  border-left-color: var(--orange);
}

.review-q {
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.review-answer {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.review-answer .correct-mark {
  color: var(--green);
  font-weight: 600;
}

.review-answer .wrong-mark {
  color: var(--red);
}

/* ── Truth ── */
.truth-text {
  font-size: 0.95rem;
  line-height: 1.8;
  white-space: pre-wrap;
  padding: 16px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--purple);
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 0.9rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 999;
  animation: toastIn 0.3s ease;
}

.toast.error {
  border-color: var(--red);
  color: var(--red);
}

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

/* ── Responsive ── */
@media (min-width: 481px) {
  #app {
    padding-top: 20px;
  }
}
