:root {
  color-scheme: light;
  --bg: #f3f4f1;
  --surface: #ffffff;
  --tint: #f7f8f5;
  --line: #e2e5df;
  --line-soft: #eef0ec;
  --field-line: #cbd1ca;
  --ink: #15201b;
  --ink-soft: #3f4a44;
  --muted: #5b6660;
  --accent: #1e6b4f;
  --accent-dark: #155239;
  --accent-soft: #e6f1ec;
  --ring: #d3e8de;
  --danger: #8e2a1f;
  --danger-soft: #fbeae7;
  --ok: #2f9e6e;
  --ok-soft: #e6f1ec;
  --warning: #d9a400;
  --warning-soft: #fdf5d9;
  --warning-ink: #6b5200;
  --alert: #d33a2c;
  --alert-soft: #fbeae7;
  font-family: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

h1,
h2,
p {
  margin: 0;
}

[v-cloak] {
  display: none;
}

/* Header */

.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1160px;
  min-height: 72px;
  margin: 0 auto;
  padding: 0 32px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
}

.brand-tagline {
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
}

.timer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--tint);
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.timer svg,
.round-bar-timer svg {
  color: var(--accent);
}

.timer.urgent,
.round-bar-timer.urgent,
.timer.urgent svg,
.round-bar-timer.urgent svg {
  color: var(--danger);
}

.timer.paused,
.round-bar-timer.paused,
.timer.paused svg,
.round-bar-timer.paused svg {
  color: var(--muted);
}

.timer.urgent {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.avatar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
}

.ghost-action {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.ghost-action:hover {
  background: var(--tint);
  color: var(--ink);
}

/* Phone-only bar shown during a round */

.round-bar {
  display: none;
}

/* Layout */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
  max-width: 1160px;
  margin: 0 auto;
  padding: 32px;
}

.main-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.hero {
  display: none;
}

.card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

/* Fields */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
}

.field-label b {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

select,
input:not([type="checkbox"]):not([type="range"]) {
  width: 100%;
  height: 44px;
  border: 1px solid var(--field-line);
  border-radius: 10px;
  background-color: var(--surface);
  padding: 0 14px;
  font-size: 15px;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235B6660' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

input[type="range"] {
  width: 100%;
  height: 44px;
  margin: 0;
  accent-color: var(--accent);
}

select:focus,
input:not([type="checkbox"]):not([type="range"]):focus {
  border-color: var(--accent);
  outline: 3px solid var(--ring);
  outline-offset: 0;
}

input::placeholder {
  color: #8a948e;
  font-weight: 500;
}

button:focus-visible,
input[type="checkbox"]:focus-visible,
input[type="range"]:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

.primary-action,
.outline-action {
  flex: none;
  min-height: 44px;
  padding: 0 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
}

.primary-action {
  border: 0;
  background: var(--accent);
  color: #fff;
}

.primary-action:hover:not(:disabled) {
  background: var(--accent-dark);
}

.outline-action {
  border: 1px solid var(--field-line);
  background: var(--surface);
}

.outline-action:hover {
  background: var(--tint);
}

/* Settings card */

.settings-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 24px;
}

.settings-fields {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1.2fr;
  gap: 20px;
  align-items: end;
}

.settings-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.quiz-options {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 24px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
}

.checkbox-field input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

/* Quiz card */

.quiz-card {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 32px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.stat-value small {
  color: var(--muted);
  font-size: 0.6em;
  font-weight: 600;
}

.stat-value.accent {
  color: var(--accent);
}

.prompt-row {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 20px;
  border-radius: 14px;
  background: var(--tint);
}

.replay-action {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
}

.replay-action:hover:not(:disabled) {
  background: var(--accent-dark);
}

.replay-action svg {
  width: 26px;
  height: 26px;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid rgb(255 255 255 / 0.35);
  border-top-color: #fff;
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
}

.prompt-reveal.waiting .prompt-text {
  color: var(--muted);
}

.prompt-reveal {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.prompt-text {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.prompt-reveal.revealed .prompt-text {
  color: var(--accent-dark);
}

.prompt-hint {
  color: var(--muted);
  font-size: 14px;
}

.answer-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.answer-row {
  display: flex;
  gap: 12px;
}

.answer-row input:not([type="checkbox"]):not([type="range"]) {
  flex: 1 1 auto;
  min-width: 0;
  height: 56px;
  border-width: 1.5px;
  border-radius: 12px;
  padding: 0 18px;
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.answer-row .primary-action {
  height: 56px;
  padding: 0 32px;
  border-radius: 12px;
  font-size: 16px;
}

/* Time remaining, shown under the answer box during a round. */
.time-status {
  position: relative;
  height: 28px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--ok-soft);
  color: var(--accent-dark);
}

.time-status-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--ok);
  opacity: 0.35;
  transition: width 1s linear, background-color 0.3s;
}

.time-status-text {
  position: relative;
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.time-status.warning {
  background: var(--warning-soft);
  color: var(--warning-ink);
}

.time-status.warning .time-status-fill {
  background: var(--warning);
}

.time-status.danger {
  background: var(--alert-soft);
  color: var(--danger);
}

.time-status.danger .time-status-fill {
  background: var(--alert);
}

.time-status.paused {
  background: var(--line-soft);
  color: var(--ink-soft);
}

.time-status.paused .time-status-fill {
  background: var(--muted);
}

/* The weak spots being drilled, under the score. */
.practice-line {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: baseline;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 13px;
}

.link-action {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

/* Sound loading panel, collapsed by default. */
.sound-queue {
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink-soft);
  font-size: 13px;
}

.sound-queue summary {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
}

.sound-queue summary span {
  color: var(--muted);
  font-weight: 500;
}

.sound-queue ol {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0 14px 12px;
  list-style: none;
}

.sound-queue li {
  display: grid;
  grid-template-columns: 10px 56px 1fr;
  gap: 8px;
  align-items: baseline;
}

.sound-queue-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--field-line);
}

.sound-queue li.loading .sound-queue-dot {
  background: var(--warning);
}

.sound-queue li.ready .sound-queue-dot {
  background: var(--ok);
}

.sound-queue li.failed .sound-queue-dot {
  background: var(--alert);
}

.sound-queue-label {
  color: var(--muted);
  font-weight: 600;
}

.sound-queue-text {
  min-width: 0;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.feedback {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--tint);
  color: var(--ink-soft);
  font-size: 15px;
  overflow-wrap: anywhere;
}

.feedback svg {
  flex: none;
}

.feedback.correct {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.feedback.incorrect {
  background: var(--danger-soft);
  color: var(--danger);
}

.tts-notice {
  color: #7a4b12;
  font-size: 13px;
}

/* Leaderboard */

.leaderboard {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  padding: 24px;
}

.section-heading {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.section-heading h2 {
  font-size: 18px;
  font-weight: 700;
}

.section-heading span,
.empty-state {
  color: var(--muted);
  font-size: 13px;
}

.leaderboard ol {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}

.rank {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--tint);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 800;
}

.rank.first {
  background: #f2e7c9;
  color: #6b4e0e;
}

.leaderboard li strong {
  flex: 1 1 auto;
  font-size: 15px;
  font-weight: 700;
}

.leaderboard li small {
  color: var(--muted);
  font-size: 13px;
}

.entry-score {
  width: 36px;
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Dialogs */

.app-dialog {
  width: min(380px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(21, 32, 27, 0.18);
}

.login-dialog {
  width: min(420px, calc(100vw - 32px));
}

.app-dialog::backdrop {
  background: rgba(21, 32, 27, 0.4);
}

.login-dialog::backdrop {
  background: var(--bg);
}

.app-dialog form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app-dialog h2 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.app-dialog p {
  color: var(--muted);
  font-size: 14px;
}

.app-dialog .dialog-error {
  color: var(--danger);
  font-weight: 600;
}

.app-dialog .primary-action {
  min-height: 48px;
  margin-top: 4px;
  font-size: 16px;
}

/* Leaderboard drops under the quiz on narrower windows. */
@media (max-width: 960px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 720px) {
  .site-header-inner {
    min-height: 60px;
    padding: 0 8px 0 16px;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    font-size: 16px;
  }

  .brand-tagline,
  .site-header .timer {
    display: none;
  }

  .header-actions {
    gap: 4px;
  }

  .avatar {
    width: 34px;
    height: 34px;
    font-size: 13px;
  }

  .ghost-action {
    padding: 0 8px;
  }

  .layout {
    gap: 16px;
    padding: 16px;
  }

  .main-column {
    gap: 16px;
  }

  .hero {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 4px 4px 0;
  }

  .hero h1 {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.02em;
  }

  .hero p {
    color: var(--muted);
    font-size: 14px;
  }

  /* 16px text keeps iOS from zooming into focused fields. */
  select,
  input:not([type="checkbox"]):not([type="range"]) {
    height: 48px;
    font-size: 16px;
  }

  input[type="range"] {
    height: 48px;
  }

  .settings-card {
    gap: 14px;
    padding: 16px;
  }

  .settings-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 12px;
  }

  .field-type {
    grid-column: 1 / -1;
  }

  .settings-footer {
    padding-top: 6px;
  }

  .settings-footer .primary-action,
  .settings-footer .outline-action {
    width: 100%;
    min-height: 52px;
    border-radius: 12px;
    font-size: 17px;
  }

  .quiz-card {
    gap: 12px;
    padding: 14px;
  }

  /* Before the first round there is nothing to show in the quiz card. */
  .quiz-card.no-round,
  .app-shell:not(.in-round) .prompt-row,
  .app-shell:not(.in-round) .answer-form {
    display: none;
  }

  .stats {
    gap: 24px;
  }

  .stat-value {
    font-size: 22px;
  }

  .leaderboard {
    gap: 8px;
    padding: 16px;
  }

  .section-heading {
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
  }

  .section-heading h2 {
    font-size: 16px;
  }

  .leaderboard li {
    padding: 10px 0;
  }

  /* During a round: only the round bar and a compact quiz card, so the
     keyboard fits underneath. */
  .in-round .site-header,
  .in-round .hero,
  .in-round .settings-card,
  .in-round .leaderboard,
  .in-round .stats,
  .in-round .practice-line,
  .in-round .answer-form > .field-label {
    display: none;
  }

  .in-round .round-bar {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 8px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }

  .round-bar-end {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--ink-soft);
  }

  .round-bar-timer {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 18px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
  }

  .round-bar-score {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 44px;
    padding: 0 8px;
    font-variant-numeric: tabular-nums;
  }

  .round-bar-count {
    font-size: 16px;
    font-weight: 800;
    line-height: 1.2;
  }

  .round-bar-accuracy {
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
  }

  .in-round .layout {
    padding: 12px 12px 0;
  }

  .prompt-row {
    gap: 12px;
    padding: 0;
    background: transparent;
  }

  .replay-action {
    width: 48px;
    height: 48px;
  }

  .replay-action svg {
    width: 22px;
    height: 22px;
  }

  .prompt-reveal {
    gap: 1px;
  }

  .prompt-text {
    font-size: 17px;
  }

  .prompt-hint {
    font-size: 13px;
  }

  .answer-row {
    gap: 8px;
  }

  .answer-row input:not([type="checkbox"]):not([type="range"]) {
    height: 52px;
    padding: 0 14px;
    font-size: 22px;
  }

  .answer-row .primary-action {
    height: 52px;
    padding: 0 20px;
  }

  .feedback {
    gap: 8px;
    font-size: 14px;
  }

  .in-round .feedback {
    padding: 0;
    background: transparent;
  }
}
