/* CSS Variables */
:root {
  --color-bg: #f8f6f1;
  --color-surface: #ffffff;
  --color-primary: #1a365d;
  --color-primary-light: #2c5282;
  --color-accent: #d69e2e;
  --color-success: #38a169;
  --color-error: #e53e3e;
  --color-text: #2d3748;
  --color-text-muted: #718096;
  --color-border: #e2e8f0;
  
  --font-display: 'Libre Baskerville', Georgia, serif;
  --font-body: 'Source Sans 3', -apple-system, BlinkMacSystemFont, sans-serif;
  
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  
  --transition: 0.2s ease;
}

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

html {
  font-size: 16px;
}

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 500px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--color-bg);
}

/* Screens */
.screen {
  display: none;
  padding: 1rem;
  min-height: 100vh;
  animation: fadeIn 0.3s ease;
}

.screen.active {
  display: block;
}

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

/* Header */
header {
  text-align: center;
  padding: 2rem 0 1.5rem;
}

header h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  color: var(--color-primary);
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

/* Buttons */
.btn {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.875rem 1.5rem;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--color-primary-light);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 2px solid var(--color-border);
}

.btn-secondary:hover {
  border-color: var(--color-primary);
}

.btn-back {
  background: none;
  border: none;
  color: var(--color-primary);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.5rem;
  position: absolute;
  left: 1rem;
  top: 1rem;
}

/* Menu Section */
.menu-section {
  margin-bottom: 2rem;
}

.menu-section h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--color-primary);
  margin-bottom: 1rem;
  padding-left: 0.25rem;
}

/* Topic Grid */
.topic-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.topic-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all var(--transition);
  border: 2px solid transparent;
}

.topic-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-accent);
  transform: translateY(-2px);
}

.topic-card h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--color-primary);
  margin-bottom: 0.25rem;
}

.topic-card .topic-meta {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* Mode Selection */
.mode-selection {
  margin: 1.5rem 0;
}

.mode-selection h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--color-primary);
  margin-bottom: 1rem;
}

.mode-buttons {
  display: flex;
  gap: 1rem;
}

.btn-mode {
  flex: 1;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-mode:hover {
  border-color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.mode-icon {
  font-size: 2rem;
}

.mode-label {
  font-weight: 600;
  color: var(--color-primary);
}

.mode-desc {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* Sporcle Section */
.sporcle-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

.sporcle-section h2 {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--color-primary);
  margin-bottom: 1rem;
}

.sporcle-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sporcle-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--color-text);
  transition: all var(--transition);
}

.sporcle-link:hover {
  background: var(--color-primary);
  color: white;
}

.sporcle-link::before {
  content: '→';
  color: var(--color-accent);
}

.sporcle-link:hover::before {
  color: white;
}

/* Quiz Screen */
#quiz-screen {
  display: none;
  flex-direction: column;
  padding: 0;
}

#quiz-screen.active {
  display: flex;
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: relative;
}

.quiz-header .btn-back {
  position: static;
}

.quiz-stats {
  display: flex;
  gap: 1rem;
  font-weight: 600;
  color: var(--color-primary);
}

#round-indicator {
  color: var(--color-text-muted);
}

/* Clue Card */
.quiz-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  gap: 1.5rem;
  position: relative;
}

.clue-card {
  width: 100%;
  max-width: 400px;
  height: 280px;
  perspective: 1000px;
  cursor: pointer;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}

.clue-card.no-transition .card-inner {
  transition: none;
}

.clue-card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card-front, .card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.card-front {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
  color: white;
}

.card-front p {
  font-family: var(--font-display);
  font-size: 1.2rem;
  line-height: 1.7;
}

.card-back {
  background: var(--color-surface);
  border: 3px solid var(--color-accent);
  transform: rotateY(180deg);
}

.card-back p {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
}

/* Answer Buttons */
.answer-buttons {
  display: flex;
  gap: 1rem;
  width: 100%;
  max-width: 400px;
}

.answer-buttons.hidden {
  display: none;
}

.btn-missed, .btn-got-it {
  flex: 1;
  padding: 1rem;
  font-size: 1.1rem;
  font-weight: 700;
}

.btn-missed {
  background: var(--color-error);
  color: white;
}

.btn-missed:hover {
  background: #c53030;
}

.btn-got-it {
  background: var(--color-success);
  color: white;
}

.btn-got-it:hover {
  background: #2f855a;
}

.btn-reveal {
  background: var(--color-accent);
  color: var(--color-primary);
  font-weight: 700;
  width: 100%;
  max-width: 400px;
}

.btn-reveal:hover {
  background: #b7791f;
  color: white;
}

.btn-reveal.hidden {
  display: none;
}

/* Star Button */
.btn-star {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.75rem;
  cursor: pointer;
  padding: 0.5rem;
  color: var(--color-text-muted);
  transition: all var(--transition);
}

.btn-star:hover {
  color: var(--color-accent);
  transform: scale(1.1);
}

.btn-star.starred {
  color: var(--color-accent);
}

/* Audio Button */
.btn-audio {
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: var(--color-primary);
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  color: white;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.btn-audio:hover {
  background: var(--color-primary-light);
  transform: scale(1.05);
}

.btn-audio.playing {
  background: var(--color-accent);
  animation: pulse 1s infinite;
}

.btn-audio.hidden {
  display: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Progress Bar */
.progress-bar {
  height: 4px;
  background: var(--color-border);
  width: 100%;
}

.progress-fill {
  height: 100%;
  background: var(--color-accent);
  width: 0%;
  transition: width 0.3s ease;
}

/* Round Complete */
#round-complete {
  display: none;
  align-items: center;
  justify-content: center;
}

#round-complete.active {
  display: flex;
}

.round-summary {
  text-align: center;
  background: var(--color-surface);
  padding: 2.5rem 2rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 350px;
  width: 100%;
}

.round-summary h2 {
  font-family: var(--font-display);
  color: var(--color-primary);
  margin-bottom: 1rem;
}

.score-big {
  font-size: 4rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1;
  margin-bottom: 0.5rem;
}

.running-total {
  color: var(--color-text-muted);
  margin-bottom: 2rem;
}

.round-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Starred Screen */
.starred-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.starred-item {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
}

.starred-item .clue {
  font-size: 0.95rem;
  color: var(--color-text);
  margin-bottom: 0.5rem;
}

.starred-item .answer {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--color-primary);
}

.starred-item .topic-tag {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 0.5rem;
}

.starred-item .unstar-btn {
  background: none;
  border: none;
  color: var(--color-accent);
  cursor: pointer;
  float: right;
  font-size: 1.25rem;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
}

.empty-state .hint {
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* Responsive */
@media (max-width: 380px) {
  .mode-buttons {
    flex-direction: column;
  }
  
  .card-front p {
    font-size: 1.1rem;
  }
}