:root {
  --bg: #ffffff;
  --bg-alt: #f5f5f7;
  --text: #1a1a1e;
  --text-muted: #6b6b70;
  --border: #e2e2e5;
  --accent: #3d5afe;
  --accent-text: #ffffff;
  --success: #2e7d32;
  --danger: #c62828;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --page-max: 960px;
  --page-backdrop: linear-gradient(180deg, #eaeeff 0%, #f6f7fb 60%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #121214;
    --bg-alt: #1c1c1f;
    --text: #f2f2f3;
    --text-muted: #9a9aa0;
    --border: #2c2c30;
    --accent: #6d87ff;
    --accent-text: #0b0b0d;
    --success: #66bb6a;
    --danger: #ef5350;
    --shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    --page-backdrop: linear-gradient(180deg, #1b1b26 0%, #0c0c0e 60%);
  }
}

:root[data-theme='dark'] {
  --bg: #121214;
  --bg-alt: #1c1c1f;
  --text: #f2f2f3;
  --text-muted: #9a9aa0;
  --border: #2c2c30;
  --accent: #6d87ff;
  --accent-text: #0b0b0d;
  --success: #66bb6a;
  --danger: #ef5350;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  --page-backdrop: linear-gradient(180deg, #1b1b26 0%, #0c0c0e 60%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0 16px;
  background: var(--page-backdrop);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  max-width: var(--page-max);
  margin: 32px auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

@media (max-width: 480px) {
  .app-shell {
    margin: 16px auto;
    border-radius: 14px;
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 800;
  font-size: 1.6rem;
  letter-spacing: -0.03em;
}

.room-code {
  font-family: 'SFMono-Regular', Consolas, Menlo, monospace;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 36px;
  height: 36px;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text);
}

.icon-btn:hover {
  background: var(--bg-alt);
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.center-page {
  text-align: center;
  padding-top: 60px;
}

h1 {
  font-size: 2rem;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

@media (max-width: 480px) {
  .center-page {
    padding-top: 32px;
  }

  h1 {
    font-size: 1.5rem;
  }
}

.subtitle {
  color: var(--text-muted);
  margin-bottom: 36px;
}

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

.card-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.card {
  flex: 1 1 260px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: left;
}

.card h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

button {
  font-family: inherit;
}

.btn-primary {
  width: 100%;
  padding: 11px 16px;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

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

.btn-secondary {
  width: 100%;
  padding: 11px 16px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  margin-top: 10px;
}

.btn-secondary:hover {
  background: var(--bg-alt);
}

.error-msg {
  color: var(--danger);
  margin-top: 20px;
}

.join-prompt {
  max-width: 280px;
  margin: 16px auto 0;
}

/* Room layout */
.room-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 20px;
  padding: 24px;
}

.room-layout.room-layout--with-rules {
  grid-template-columns: 200px minmax(0, 1fr) 220px;
}

@media (max-width: 700px) {
  .room-layout,
  .room-layout.room-layout--with-rules {
    grid-template-columns: minmax(0, 1fr);
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .room-layout,
  .room-layout.room-layout--with-rules {
    padding: 12px;
    gap: 14px;
  }

  .game-area {
    padding: 18px 14px;
  }

  .topbar {
    padding: 12px 14px;
  }

  .number-display {
    font-size: 2rem;
  }
}

.rules-panel {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  align-self: start;
}

.rules-panel h3 {
  margin-top: 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.rules-panel ul {
  margin: 0;
  padding-left: 18px;
  font-size: 0.85rem;
  line-height: 1.5;
}

.rules-panel li {
  margin-bottom: 8px;
}

.rules-panel li:last-child {
  margin-bottom: 0;
}

.sidebar h3 {
  margin-top: 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.player-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.player-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-alt);
  border-radius: 8px;
  font-size: 0.9rem;
}

.player-item.is-host::before {
  content: '★ ';
  color: var(--accent);
}

.player-score {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.game-area {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  min-height: 320px;
  text-align: center;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 14px;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.15s ease;
}

.game-card:hover:not(:disabled) {
  border-color: var(--accent);
}

.game-card:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}


.game-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 1.6rem;
  background: var(--bg-alt);
}

.game-icon.large {
  width: 72px;
  height: 72px;
  font-size: 2.2rem;
  margin: 0 auto;
}

.game-icon--reaction {
  background: rgba(251, 146, 60, 0.2);
}

.game-icon--quiz {
  background: rgba(167, 139, 250, 0.2);
}

.game-icon--sequence {
  background: rgba(45, 212, 191, 0.2);
}

.game-icon--numbers {
  background: rgba(96, 165, 250, 0.2);
}

.game-icon--typing {
  background: rgba(74, 222, 128, 0.2);
}

.game-icon--unique45 {
  background: rgba(253, 224, 71, 0.28);
}

.game-icon--flags {
  background: rgba(56, 189, 248, 0.22);
}

.game-icon--scramble {
  background: rgba(244, 114, 182, 0.2);
}

.game-icon--emoji {
  background: rgba(251, 191, 36, 0.24);
}

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

.selected-box {
  max-width: 420px;
  margin: 0 auto 16px;
}

/* Quiz category picker */
.quiz-picker-back {
  width: auto;
  display: inline-block;
  margin: 0 0 16px;
  padding: 8px 14px;
  font-size: 0.85rem;
}

.quiz-category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.quiz-category-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: left;
  transition: border-color 0.15s ease;
}

.quiz-category-card:hover,
.quiz-category-card:focus-within {
  border-color: var(--accent);
}

.quiz-category-card h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.quiz-preview {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.2s ease, opacity 0.2s ease;
}

.quiz-category-card:hover .quiz-preview,
.quiz-category-card:focus-within .quiz-preview {
  max-height: 200px;
  opacity: 1;
}

.quiz-preview-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 6px;
}

.quiz-preview ul {
  margin: 0;
  padding-left: 18px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.quiz-select-btn {
  margin-top: 14px;
}

@media (max-width: 480px) {
  .quiz-preview {
    max-height: 200px;
    opacity: 1;
    transition: none;
  }
}

.results-list {
  max-width: 400px;
  margin: 16px auto;
  padding-left: 0;
  list-style: none;
  counter-reset: rank;
  text-align: left;
}

.results-list li {
  counter-increment: rank;
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}

.results-list li::before {
  content: counter(rank) '. ';
  color: var(--text-muted);
  margin-right: 6px;
}

/* Reaction Time */
.reaction-box {
  width: 100%;
  max-width: 360px;
  height: 200px;
  margin: 16px auto;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  user-select: none;
}

.reaction-box.waiting {
  background: #b0413e;
}

.reaction-box.go {
  background: #2e7d32;
}

/* Sequence Memory */
.simon-grid {
  display: grid;
  grid-template-columns: repeat(2, 100px);
  gap: 10px;
  justify-content: center;
  margin: 20px auto;
}

.simon-tile {
  width: 100px;
  height: 100px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.1s ease;
}

.simon-tile.lit {
  opacity: 1;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.4) inset;
}

.simon-red {
  background: #e53935;
}

.simon-blue {
  background: #1e88e5;
}

.simon-green {
  background: #43a047;
}

.simon-yellow {
  background: #fdd835;
}

/* Number Memory */
.number-display {
  font-size: 2.6rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 24px 0;
  font-variant-numeric: tabular-nums;
}

.number-input {
  max-width: 220px;
  margin: 0 auto 10px;
  text-align: center;
  font-size: 1.2rem;
}

/* Typing Speed */
.typing-target {
  font-size: 1.15rem;
  line-height: 1.6;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  text-align: left;
}

.typing-target .ok {
  color: var(--success);
}

.typing-target .bad {
  color: var(--danger);
  text-decoration: underline;
}

.typing-input {
  width: 100%;
  max-width: 100%;
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  resize: none;
}

/* Flag Frenzy */
.flag-image {
  display: block;
  width: 220px;
  max-width: 80%;
  height: auto;
  margin: 16px auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

/* Word Scramble / Emoji Riddle */
.scramble-prompt {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  margin: 20px 0;
  font-family: 'SFMono-Regular', Consolas, Menlo, monospace;
}

.emoji-prompt {
  font-size: 3.2rem;
  margin: 20px 0;
  line-height: 1.2;
}

.race-guess {
  display: flex;
  gap: 8px;
  max-width: 360px;
  margin: 0 auto;
}

.race-guess input {
  margin-bottom: 0;
  text-align: center;
}

.race-guess .btn-primary {
  width: auto;
  white-space: nowrap;
  margin-top: 0;
  padding: 11px 20px;
}

.race-guess input.shake {
  animation: race-shake 0.4s ease;
  border-color: var(--danger);
}

@keyframes race-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

/* Quiz */
.quiz-question {
  margin: 8px 0 18px;
}

.quiz-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
}

.quiz-option {
  padding: 14px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
}

.quiz-option:hover:not(:disabled) {
  border-color: var(--accent);
}

.quiz-option.selected {
  border-color: var(--accent);
  border-width: 2px;
}

.quiz-option.correct {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.quiz-option.incorrect {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.quiz-timer,
.round-timer {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  max-width: 560px;
  margin: 18px auto 0;
  overflow: hidden;
}

.quiz-timer-bar,
.round-timer-bar {
  height: 100%;
  width: 100%;
  background: var(--accent);
}

/* Unique45 */
.unique45-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 8px;
  max-width: 560px;
  margin: 16px auto 0;
}

.unique45-number {
  padding: 10px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.unique45-number:hover:not(:disabled) {
  border-color: var(--accent);
}

.unique45-number:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.unique45-number.selected {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  opacity: 1;
}

.unique45-results {
  max-width: 380px;
  margin: 16px auto 0;
  padding-left: 0;
  list-style: none;
  text-align: left;
}

.unique45-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.unique45-row--winner {
  border-color: var(--success);
  background: rgba(46, 125, 50, 0.12);
  font-weight: 600;
}
