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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f4f8;
  color: #2d3748;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Screen management */
.screen {
  display: none;
  width: 100%;
  max-width: 500px;
  padding: 24px;
  text-align: center;
}

.screen.active {
  display: block;
}

/* Landing */
#landing h1 {
  font-size: 2rem;
  margin-bottom: 8px;
  color: #1a365d;
}

#landing p {
  color: #718096;
  margin-bottom: 32px;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Buttons */
button {
  padding: 14px 24px;
  font-size: 1.1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: #3182ce;
  color: white;
  transition: background 0.15s;
}

button:hover {
  background: #2b6cb0;
}

button:disabled {
  background: #cbd5e0;
  color: #a0aec0;
  cursor: not-allowed;
}

/* Game header */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.game-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  font-size: 0.95rem;
  color: #4a5568;
}

#timer {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #1a365d;
}

/* Question */
.question {
  font-size: 1.8rem;
  font-weight: 600;
  margin-bottom: 24px;
  color: #1a365d;
}

/* Answer grid */
.answer-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.answer-cell {
  padding: 18px 12px;
  border: 2px solid #3182ce;
  border-radius: 8px;
  background: #ebf8ff;
  cursor: pointer;
  text-align: center;
  font-size: 1.3rem;
  color: #1a365d;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
}

.answer-cell:hover {
  background: #bee3f8;
  border-color: #2b6cb0;
}

.answer-cell.correct {
  background: #c6f6d5;
  border-color: #38a169;
}

.answer-cell.wrong {
  background: #fed7d7;
  border-color: #e53e3e;
}

.answer-cell.disabled {
  pointer-events: none;
  opacity: 0.7;
}

/* Game controls */
.game-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.btn-secondary {
  padding: 8px 20px;
  font-size: 0.9rem;
  background: #e2e8f0;
  color: #4a5568;
  border: 1px solid #cbd5e0;
}

.btn-secondary:hover {
  background: #cbd5e0;
}

/* Feedback */
.feedback {
  height: 24px;
  font-size: 1rem;
  color: #718096;
}

/* Fraction rendering */
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  font-size: 0.9em;
  line-height: 1.2;
}

.frac .num {
  border-bottom: 2px solid currentColor;
  padding: 0 4px 2px;
}

.frac .den {
  padding: 2px 4px 0;
}

/* Results */
.results-box {
  background: white;
  border-radius: 12px;
  padding: 24px;
  margin: 24px 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.results-box p {
  font-size: 1.2rem;
  margin: 12px 0;
}

#results h1 {
  font-size: 2rem;
  color: #1a365d;
}

#results button {
  margin: 6px;
}

/* Party mode headings */
#party-menu h1,
#party-create h1,
#party-join h1,
#party-lobby h1,
#party-results h1 {
  font-size: 2rem;
  color: #1a365d;
  margin-bottom: 8px;
}

#party-menu p {
  color: #718096;
  margin-bottom: 24px;
}

/* Form inputs */
.form-group {
  margin-bottom: 16px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  color: #4a5568;
  margin-bottom: 4px;
  font-weight: 500;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1.1rem;
  border: 2px solid #cbd5e0;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus {
  border-color: #3182ce;
}

.room-code-input {
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-family: monospace;
  font-size: 1.3rem !important;
}

.lobby-status {
  color: #e53e3e;
  font-size: 0.9rem;
  min-height: 20px;
  margin: 8px 0;
}

.error-msg {
  color: #e53e3e;
  font-size: 0.9rem;
  min-height: 20px;
  margin-bottom: 12px;
}

#party-create button,
#party-join button {
  margin: 4px;
}

/* Room code display in lobby */
.room-code-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 20px 0;
}

.room-code-label {
  font-size: 0.85rem;
  color: #718096;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}

.room-code {
  font-size: 2.5rem;
  font-weight: 700;
  font-family: monospace;
  letter-spacing: 0.3em;
  color: #1a365d;
  background: white;
  padding: 12px 24px;
  border-radius: 8px;
  border: 2px solid #3182ce;
}

/* QR code in lobby */
.qr-container {
  display: flex;
  justify-content: center;
  margin: 16px 0;
}

.qr-container svg {
  background: white;
  padding: 8px;
  border-radius: 8px;
}

/* Player list in lobby */
.player-list {
  margin: 20px 0;
  text-align: left;
}

.player-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: white;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 1.05rem;
}

.player-item .host-badge {
  font-size: 0.75rem;
  background: #3182ce;
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
}

#party-lobby button {
  margin: 4px;
}

/* Countdown */
.countdown {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #1a365d;
}

.countdown.urgent {
  color: #e53e3e;
}

/* Status message during party game */
.status-msg {
  min-height: 32px;
  font-size: 1.1rem;
  font-weight: 500;
  margin: 8px 0;
  color: #718096;
}

.status-msg.won {
  color: #38a169;
}

.status-msg.lost {
  color: #e53e3e;
}

/* Live scores */
.live-scores {
  margin-top: 16px;
  text-align: left;
}

.live-scores h3 {
  font-size: 0.85rem;
  color: #718096;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.score-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 12px;
  font-size: 0.95rem;
  border-radius: 4px;
}

.score-row:nth-child(even) {
  background: rgba(0, 0, 0, 0.03);
}

.score-row .score-points {
  font-weight: 600;
  color: #3182ce;
}

/* Rankings table on results */
.rankings-table {
  margin: 20px 0;
  text-align: left;
}

.rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: white;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 1.05rem;
}

.rank-row.winner {
  background: #fefcbf;
  border: 2px solid #d69e2e;
}

.rank-number {
  font-weight: 700;
  font-size: 1.2rem;
  color: #1a365d;
  min-width: 28px;
}

.rank-name {
  flex: 1;
}

.rank-points {
  font-weight: 600;
  color: #3182ce;
}

.rank-time {
  font-size: 0.85rem;
  color: #718096;
}

#party-results button {
  margin: 4px;
}

/* Mobile */
@media (max-width: 400px) {
  .answer-cell {
    padding: 14px 8px;
    font-size: 1.1rem;
  }

  .question {
    font-size: 1.5rem;
  }
}
