:root {
  color-scheme: light;
  --color-bg: #f4f7fc;
  --color-surface: #ffffff;
  --color-primary: #1d4281;
  --color-primary-dark: #142e5c;
  --color-accent: #f2a341;
  --color-correct: #2e9e5b;
  --color-wrong: #d1495b;
  --color-text: #1b1f27;
  --color-text-muted: #5b6472;
  --radius: 16px;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 640px;
  padding: env(safe-area-inset-top, 1rem) 1rem calc(env(safe-area-inset-bottom, 1rem) + 1rem);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.screen[hidden] {
  display: none;
}

h1, h2 {
  margin: 0.2rem 0;
}

.menu-header {
  text-align: center;
  padding-top: 1rem;
}

.menu-logo {
  border-radius: 20%;
}

.tagline {
  color: var(--color-text-muted);
  margin: 0;
}

.mode-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.mode-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(20, 46, 92, 0.08);
  padding: 0.4rem;
}

.mode-card .btn-mode {
  flex: 1;
  text-align: left;
}

.identity-hint {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  min-height: 1.2em;
}

.menu-footer {
  margin-top: auto;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

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

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

.btn-secondary {
  background: #e4e9f2;
  color: var(--color-primary-dark);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  font-size: 1.3rem;
  padding: 0.4rem 0.7rem;
}

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

.btn-highscore {
  background: var(--color-accent);
  color: var(--color-primary-dark);
  padding: 0.9rem 0.8rem;
}

.top-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.5rem;
}

.timer {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  margin: 0;
}

.feedback-line {
  margin: 0;
  text-align: center;
  font-size: 0.95rem;
  min-height: 1.3em;
}

.feedback-line.correct {
  color: var(--color-correct);
}

.feedback-line.wrong {
  color: var(--color-wrong);
}

.question {
  text-align: center;
  font-size: 2.2rem;
  font-weight: 700;
  margin: 0;
}

.answer-display {
  text-align: center;
  font-size: 2.6rem;
  font-weight: 700;
  min-height: 1.4em;
  color: var(--color-primary);
  background: var(--color-surface);
  border-radius: var(--radius);
  margin: 0;
}

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

.keypad-group {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
}

.keypad-group-remainder {
  grid-template-columns: repeat(5, 1fr);
}

.keypad-group[hidden] {
  display: none;
}

.key {
  background: var(--color-surface);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 0.7rem 0.2rem;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.key.active {
  border-color: var(--color-primary);
  background: #dce6fb;
}

.controls {
  display: flex;
  gap: 0.75rem;
}

.controls-stacked {
  flex-direction: column;
}

.controls .btn {
  flex: 1;
}

.points {
  text-align: center;
  font-weight: 700;
  font-size: 1.2rem;
  margin: 0;
}

.result-points {
  text-align: center;
  font-size: 1.6rem;
  font-weight: 700;
}

.result-sync {
  text-align: center;
  color: var(--color-text-muted);
  min-height: 1.3em;
}

.offline-note {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.highscore-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.highscore-list li {
  display: flex;
  justify-content: space-between;
  background: var(--color-surface);
  border-radius: 12px;
  padding: 0.6rem 0.9rem;
}

.highscore-list li.own-entry {
  border: 2px solid var(--color-accent);
}

.highscore-list .rank {
  color: var(--color-text-muted);
  width: 2em;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --color-bg: #12151c;
    --color-surface: #1c2130;
    --color-text: #eef1f7;
    --color-text-muted: #9aa4b6;
    --color-primary: #5c8fe0;
    --color-primary-dark: #cfe0ff;
  }

  .btn-secondary {
    background: #2a3142;
    color: var(--color-primary-dark);
  }

  .key.active {
    background: #26314a;
  }
}
