:root {
  color-scheme: light;
  --bg: #f6f9fc;
  --bg-elevated: #ffffff;
  --bg-soft: #eef2f7;
  --border: #e3e8ee;
  --border-strong: #c3cbd8;
  --text: #0a2540;
  --muted: #5b6b84;
  --accent: #635bff;
  --accent-strong: #4f46e5;
  --accent-dim: rgba(99, 91, 255, 0.12);
  --accent-ring: rgba(99, 91, 255, 0.22);
  --good: #0a7a52;
  --good-dim: rgba(10, 122, 82, 0.1);
  --bad: #df1b41;
  --bad-dim: rgba(223, 27, 65, 0.1);
  --playing: #0570de;
  --playing-dim: rgba(5, 112, 222, 0.12);
  --key-bg: #d3d6da;
  --key-bg-active: #c3c7cd;
  --key-text: #1a1a1b;
  --radius: 14px;
  --shadow: 0 15px 35px rgba(60, 66, 87, 0.08), 0 5px 15px rgba(10, 37, 64, 0.05);
  --shadow-sm: 0 1px 2px rgba(10, 37, 64, 0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  background: #ffffff radial-gradient(1200px 600px at 50% -10%, #f1efff 0%, var(--bg) 55%);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overflow-x: clip;
}

body {
  /* env() is read directly here: older WebKit resolves it unreliably via var(). */
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  padding-right: calc(14px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(14px + env(safe-area-inset-left, 0px));
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.hidden {
  display: none !important;
}

.app {
  max-width: 720px;
  width: 100%;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  width: 100%;
}

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

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-dim), 0 0 12px rgba(99, 91, 255, 0.45);
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  /* The wordmark has no break opportunity, so it is the only part of the
     topbar allowed to give way rather than push the actions off-screen. */
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-tld {
  color: var(--accent);
  font-weight: 500;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  min-width: 0;
}

.signal-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 11px 0 9px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  user-select: none;
}

.station-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 11px 0 9px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.station-badge:hover {
  border-color: rgba(99, 91, 255, 0.35);
  background: var(--bg-soft);
}

.station-badge:active {
  background: var(--accent-dim);
  border-color: rgba(99, 91, 255, 0.45);
}

.station-glyph {
  color: var(--accent);
  flex-shrink: 0;
}

.station-badge.is-complete {
  border-color: rgba(10, 122, 82, 0.35);
  background: var(--good-dim);
}

.station-badge.is-complete .station-glyph {
  color: var(--good);
}

.signal-glyph {
  color: var(--accent);
  flex-shrink: 0;
}

.signal-glyph.empty {
  opacity: 0.35;
}

.signal-unit {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: -0.01em;
}

.lock-icon {
  flex-shrink: 0;
  display: inline-block;
  vertical-align: -2px;
}

.seek-lock {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
}

.seek-row:not(.locked) .seek-lock {
  color: var(--accent);
}

.icon-btn,
.ghost-btn,
.primary-btn,
.play-btn,
.pad-key {
  font: inherit;
  color: inherit;
  border: none;
  background: transparent;
  cursor: pointer;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--muted);
  box-shadow: var(--shadow-sm);
}

.icon-btn:active,
.ghost-btn:active:not(:disabled) {
  background: var(--bg-soft);
}

.ghost-btn {
  height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 560;
  box-shadow: var(--shadow-sm);
}

.ghost-btn.compact,
.primary-btn.compact {
  height: 34px;
  padding: 0 12px;
  font-size: 0.9rem;
  border-radius: 10px;
}

.ghost-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.primary-btn {
  height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(99, 91, 255, 0.3);
}

.primary-btn:active {
  background: var(--accent-strong);
}

.mode-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.mode-picker-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.mode-select-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 280px;
}

.mode-select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-60%) rotate(45deg);
  pointer-events: none;
}

.mode-select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 42px;
  padding: 0 40px 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  font-size: 0.98rem;
  letter-spacing: -0.01em;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

.mode-select:hover {
  border-color: var(--border-strong);
}

.mode-select:focus {
  outline: none;
}

.mode-select:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.koch-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.koch-panel.hidden {
  display: none;
}

.koch-meter {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.koch-meter-labels {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  gap: 8px;
  min-width: 0;
}

.koch-meter-learned-label {
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.koch-meter-count {
  flex: 0 0 auto;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.koch-meter-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.koch-meter-track {
  display: flex;
  flex: 1;
  min-width: 0;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.koch-meter-seg {
  height: 100%;
  flex: 0 0 auto;
  min-width: 0;
  transition: width 0.22s ease;
}

@media (prefers-reduced-motion: reduce) {
  .koch-meter-seg {
    transition: none;
  }
}

.koch-meter-learned {
  background: var(--good);
}

.koch-meter-next {
  background: var(--accent);
}

.koch-meter-next.hidden {
  display: none;
}

.koch-meter-next-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.koch-meter-next-badge[hidden] {
  display: none !important;
}

.koch-meter-next-caption {
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.koch-meter-next-glyph {
  display: inline-grid;
  place-items: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 8px;
  border: 1.5px solid rgba(99, 91, 255, 0.45);
  background: var(--accent-dim);
  color: var(--accent-strong);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1;
}

/* Stats dialog still uses the older foot layout. */
.koch-meter-foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.koch-progress {
  font-size: 0.85rem;
  font-weight: 650;
  color: var(--text);
  letter-spacing: -0.01em;
  min-width: 0;
}

.koch-next {
  flex: 0 0 auto;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.koch-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.koch-lesson-label {
  flex: 1;
  min-width: 0;
  margin: 0;
}

.koch-lesson-select {
  width: 100%;
  height: 34px;
  padding: 0 28px 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7280' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}

.koch-lesson-select:focus {
  outline: none;
  border-color: rgba(99, 91, 255, 0.55);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.koch-nav .ghost-btn.compact {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
  flex: 0 0 auto;
}

.koch-learned {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--muted);
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.koch-flash {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 168px;
  padding: 12px 8px 4px;
  cursor: text;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.koch-flash.hidden {
  display: none;
}

.koch-flash-glyph {
  margin: 0;
  width: min(220px, 72vw);
  height: min(220px, 42vw, 220px);
  min-height: 140px;
  border-radius: 22px;
  border: 2px solid var(--border-strong);
  background: var(--bg-soft);
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: clamp(3.6rem, 14vw, 5.5rem);
  font-weight: 700;
  line-height: 1;
  display: grid;
  place-items: center;
  pointer-events: none;
  user-select: none;
  transition:
    background 0.12s ease,
    border-color 0.12s ease,
    color 0.12s ease,
    box-shadow 0.12s ease,
    transform 0.12s ease;
}

.koch-flash-glyph.is-empty {
  color: var(--muted);
  font-weight: 500;
}

.koch-flash-glyph.is-listening {
  border-color: rgba(5, 112, 222, 0.4);
  background: var(--playing-dim);
  color: var(--playing);
  box-shadow: 0 0 0 3px var(--playing-dim);
}

.koch-flash-glyph.is-awaiting {
  border-color: rgba(99, 91, 255, 0.45);
  box-shadow: 0 0 0 3px var(--accent-dim);
  color: var(--muted);
}

.koch-flash-glyph.is-correct {
  background: var(--good-dim);
  border-color: rgba(10, 122, 82, 0.45);
  color: var(--good);
  box-shadow: 0 0 0 3px var(--good-dim);
}

.koch-flash-glyph.is-wrong {
  background: var(--bad-dim);
  border-color: rgba(223, 27, 65, 0.4);
  color: var(--bad);
  box-shadow: 0 0 0 3px var(--bad-dim);
}

.koch-flash-glyph.is-miss {
  background: var(--bad-dim);
  border-color: rgba(223, 27, 65, 0.28);
  color: rgba(223, 27, 65, 0.55);
  box-shadow: none;
}

.koch-flash-hint {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  line-height: 1.35;
}

.stage.is-koch .slots,
.stage.is-koch .slots-hint,
.stage.is-koch .seek-block,
.stage.is-koch #btn-reveal,
.stage.is-koch #enter-hint {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .koch-flash-glyph {
    transition: none;
  }
}

.custom-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.custom-panel label {
  font-size: 0.85rem;
  color: var(--muted);
}

.custom-panel textarea {
  width: 100%;
  resize: vertical;
  min-height: 90px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 12px;
  font: inherit;
  line-height: 1.45;
  outline: none;
}

.custom-panel textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.stage {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.play-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.play-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(160deg, #8b85ff, var(--accent));
  color: #ffffff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 8px 24px rgba(99, 91, 255, 0.32);
}

.play-btn:active {
  transform: scale(0.96);
}

.play-meta {
  flex: 1;
  min-width: 0;
}

.stage-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  max-width: 100%;
  box-shadow: none;
}

.status-chip.warn {
  color: #9a6700;
  border-color: rgba(154, 103, 0, 0.28);
  background: rgba(154, 103, 0, 0.08);
}

.status-chip.locked {
  color: var(--accent);
  border-color: rgba(99, 91, 255, 0.28);
  background: var(--accent-dim);
}

.status-chip .lock-icon {
  color: var(--accent);
}

.session-btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: normal;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.session-btn:hover {
  background: #e4eaf1;
  border-color: var(--border);
  color: var(--text);
}

.session-btn:active {
  background: #e4eaf1;
}

.status-line {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.round-stars {
  margin-top: 4px;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.round-stars.good {
  color: var(--good);
}

.round-stars.muted {
  color: var(--muted);
  font-weight: 560;
}

.seek-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.seek-row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 0;
}

.seek-row.locked {
  opacity: 0.72;
}

.seek-row.locked .seek-time,
.seek-row.locked .seek-lock {
  opacity: 0.55;
}

.seek-row.locked .seek-slider {
  cursor: default;
  pointer-events: none;
  height: 0.55rem;
  accent-color: var(--border-strong);
  opacity: 0.85;
}

.seek-row:not(.locked) .seek-slider {
  height: 1.4rem;
  cursor: pointer;
}

.scrub-unlock-btn {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  font-size: 0.8rem;
  border-style: dashed;
  color: var(--accent);
  border-color: rgba(99, 91, 255, 0.35);
  background: var(--accent-dim);
}

.scrub-unlock-btn.hidden {
  display: none !important;
}

.settings-section-label {
  margin: 10px 0 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.seek-time {
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 2.6rem;
}

.seek-time:last-child {
  text-align: right;
}

.seek-slider {
  width: 100%;
  accent-color: var(--accent);
}

.chaos-control {
  position: relative;
  z-index: 5;
}

.chaos-chip,
.chaos-pill {
  font: inherit;
  cursor: pointer;
  border: none;
  background: transparent;
  color: inherit;
}

.chaos-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chaos-chip:hover:not(:disabled) {
  border-color: var(--border);
  color: var(--text);
  background: #e4eaf1;
}

.chaos-chip:active:not(:disabled) {
  background: #e4eaf1;
  border-color: var(--border);
  color: var(--text);
}

.chaos-chip.is-on,
.chaos-chip[aria-pressed="true"] {
  color: #ffffff;
  background: linear-gradient(160deg, #8b85ff, var(--accent));
  border-color: transparent;
}

.chaos-chip.is-on:hover:not(:disabled),
.chaos-chip[aria-pressed="true"]:hover:not(:disabled) {
  color: #ffffff;
  background: linear-gradient(160deg, #9a95ff, #736bff);
  border-color: transparent;
}

.chaos-chip.is-on:active:not(:disabled),
.chaos-chip[aria-pressed="true"]:active:not(:disabled) {
  color: #ffffff;
  background: linear-gradient(160deg, #7a74e8, #5850d4);
  border-color: transparent;
}

.chaos-chip:disabled,
.chaos-chip:disabled:hover,
.chaos-chip:disabled:active {
  cursor: default;
  opacity: 0.85;
}

.chaos-chip-label {
  font-weight: 600;
  letter-spacing: -0.01em;
}

.chaos-bonus {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(99, 91, 255, 0.28);
}

.chaos-chip.is-on .chaos-bonus,
.chaos-chip[aria-pressed="true"] .chaos-bonus {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.35);
}

.chaos-locked-note {
  display: inline-flex;
  align-items: center;
  color: inherit;
  opacity: 0.85;
}

.chaos-menu {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100vw - 40px - var(--safe-left) - var(--safe-right)));
  width: min(360px, calc(100dvw - 40px - var(--safe-left) - var(--safe-right)));
  max-height: min(78vh, 480px, calc(100dvh - 24px - var(--safe-top) - var(--safe-bottom)));
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  border-radius: 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 50;
}

#chaos-backdrop {
  z-index: 45;
}

.chaos-multiplier {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chaos-multiplier-value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--text);
}

.chaos-multiplier-unit {
  font-size: 0.78rem;
  font-weight: 600;
}

.chaos-multiplier.is-boosted {
  border-color: rgba(99, 91, 255, 0.45);
  background: var(--accent-dim);
  color: var(--accent);
}

.chaos-multiplier.is-boosted .chaos-multiplier-value {
  color: var(--accent);
}

.chaos-multiplier.is-locked {
  opacity: 0.8;
}

.chaos-effects {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.chaos-pill {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  font-weight: 650;
  font-size: 0.88rem;
  text-align: left;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.chaos-pill:disabled {
  cursor: default;
  opacity: 0.72;
}

.chaos-pill span {
  line-height: 1.2;
}

.chaos-pill em {
  font-style: normal;
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.25;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.chaos-pill[aria-pressed="true"] {
  border-color: rgba(99, 91, 255, 0.45);
  background: var(--accent-dim);
  color: var(--accent);
}

.chaos-pill[aria-pressed="true"] em {
  color: rgba(99, 91, 255, 0.75);
}

.chaos-pill:hover:not(:disabled) {
  border-color: rgba(99, 91, 255, 0.35);
}

.chaos-control.locked-round .chaos-chip,
.chaos-control.locked-round .chaos-chip:hover,
.chaos-control.locked-round .chaos-chip:active {
  cursor: default;
  opacity: 0.85;
}

@media (max-width: 420px) {
  .signal-unit {
    display: none;
  }

  /* Phone-width chrome needs more clearance under the iOS status bar. */
  body {
    padding-top: calc(20px + env(safe-area-inset-top, 0px));
  }

  .topbar {
    gap: 8px;
  }

  /* Brand + 4 actions overflow past the right edge at 390px without this. */
  .topbar-actions {
    gap: 5px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .station-badge,
  .signal-badge {
    height: 36px;
    padding: 0 8px 0 7px;
    border-radius: 10px;
    font-size: 0.78rem;
    gap: 4px;
  }

  .brand h1 {
    font-size: 1.05rem;
  }

  .chaos-effects {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .play-btn:active,
  .pad-key:active:not(:disabled),
  .slot {
    transition: none;
    transform: none;
  }

  .chaos-menu,
  .chaos-chip,
  .chaos-pill,
  .session-btn,
  .slot.cursor-pulse {
    transition: none;
    animation: none;
  }
}

.slots {
  position: relative;
  min-height: 96px;
  max-height: min(38vh, 280px);
  overflow: auto;
  padding: 10px 4px 12px;
  display: flex;
  flex-wrap: wrap;
  /* Row gap only — horizontal word separation comes from .slot.space */
  gap: 10px 0;
  align-content: flex-start;
  -webkit-overflow-scrolling: touch;
}

.slots-hint {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 560;
  color: var(--muted);
}

.almost-banner {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(154, 103, 0, 0.08);
  border: 1px solid rgba(154, 103, 0, 0.28);
  color: #7a5300;
  font-size: 0.88rem;
  font-weight: 560;
  line-height: 1.35;
}

.custom-empty {
  padding: 28px 16px;
  text-align: center;
  border-radius: 14px;
  border: 1.5px dashed var(--border-strong);
  background: var(--bg);
}

.custom-empty-title {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 700;
}

.custom-empty-body {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.custom-empty-body strong {
  color: var(--accent);
}

.stage.is-custom-empty .slots,
.stage.is-custom-empty .slots-hint,
.stage.is-custom-empty .almost-banner,
.stage.is-custom-empty .stats-row,
.stage.is-custom-empty .seek-block {
  display: none !important;
}

.word {
  display: flex;
  gap: 2px;
  flex-wrap: nowrap;
}

.slot {
  appearance: none;
  -webkit-appearance: none;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  width: 1.7rem;
  height: 2.45rem;
  min-height: 2.45rem;
  border: 1.5px solid var(--border-strong);
  border-bottom-width: 2.5px;
  background: var(--bg-soft);
  display: grid;
  place-items: center;
  font: inherit;
  font-weight: 700;
  font-size: 1.08rem;
  line-height: 1;
  text-transform: uppercase;
  color: var(--text);
  transition:
    background 0.12s ease,
    border-color 0.12s ease,
    color 0.12s ease,
    box-shadow 0.12s ease;
  border-radius: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.slot.space {
  width: 0.85rem;
  min-width: 0.85rem;
  border-color: transparent;
  background: transparent;
}

.slot.space.cursor {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-ring);
  background: var(--accent-ring);
}

.slot.punct {
  width: auto;
  min-width: 1.25rem;
  padding: 0 3px;
  border-color: #d5dbe4;
  color: var(--muted);
}

.slot.filled {
  border-color: #8792a2;
  background: var(--bg);
}

.slot.correct {
  color: var(--good);
  background: var(--good-dim);
  border-color: var(--good);
}

.slot.wrong {
  color: var(--bad);
  background: var(--bad-dim);
  border-color: var(--bad);
}

.slot.playing {
  background: var(--playing-dim);
  border-color: var(--playing);
  box-shadow: 0 0 0 1px rgba(5, 112, 222, 0.3);
}

.slot.cursor {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.slot.cursor-pulse {
  animation: cursor-pulse 0.85s ease-out 1;
}

@keyframes cursor-pulse {
  0% {
    box-shadow: 0 0 0 2px var(--accent-ring);
  }
  45% {
    box-shadow: 0 0 0 7px rgba(99, 91, 255, 0.28);
  }
  100% {
    box-shadow: 0 0 0 3px var(--accent-ring);
  }
}

.slot.miss {
  border-color: var(--bad);
  background: var(--bad-dim);
  box-shadow: 0 0 0 1px rgba(223, 27, 65, 0.2);
}

.slot.revealed {
  color: var(--muted);
}

/* Keeps a real <input> for mobile soft keyboards without taking layout space. */
.copy-input-form {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.copy-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  caret-color: transparent;
  font-size: 16px; /* avoid iOS focus zoom */
}

.stats-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  justify-content: flex-start;
  min-width: 0;
}

.stats-row > * {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* Footer actions share the soft pill treatment. */
.stats-row .ghost-btn.compact {
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  box-shadow: none;
}

.stats-row .ghost-btn.compact:active:not(:disabled) {
  background: #e4eaf1;
  box-shadow: none;
}

.enter-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: none;
  animation: none;
}

.enter-hint:hover {
  background: #e4eaf1;
}

.enter-hint:active {
  background: #e4eaf1;
}

.enter-hint.is-ready {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent-strong);
  font-weight: 700;
  animation: enter-hint-pulse 1.6s ease-in-out infinite;
}

.enter-hint.is-ready:hover {
  background: rgba(99, 91, 255, 0.18);
}

.enter-hint-icon {
  flex-shrink: 0;
}

.enter-hint-label {
  line-height: 1;
}

@keyframes enter-hint-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(99, 91, 255, 0.28);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(99, 91, 255, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .enter-hint.is-ready {
    animation: none;
  }
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
}

.pill.muted {
  color: var(--muted);
  font-weight: 500;
}

.pill.good {
  color: var(--good);
  background: var(--good-dim);
  border-color: rgba(10, 122, 82, 0.28);
}

.pill.bad {
  color: var(--bad);
  background: var(--bad-dim);
  border-color: rgba(223, 27, 65, 0.28);
}

.qwerty-pad {
  /* One shared column metric keeps rows staggered like morsle/Wordle. */
  --key-gap: 6px;
  --key-w: clamp(26px, calc((100% - 9 * var(--key-gap)) / 10), 44px);
  display: flex;
  flex-direction: column;
  gap: var(--key-gap);
}

.qwerty-row {
  display: flex;
  justify-content: center;
  gap: var(--key-gap);
}

/* Rows with fewer keys stay centered, self-indenting into the QWERTY stagger. */
.pad-key {
  flex: 0 0 auto;
  width: var(--key-w);
  min-width: 0;
  min-height: 48px;
  border-radius: 6px;
  background: var(--key-bg);
  border: none;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.05rem;
  text-transform: uppercase;
  padding: 0;
  color: var(--key-text);
  transition:
    background 0.1s ease,
    color 0.1s ease,
    transform 0.05s ease;
}

.pad-key:hover:not(:disabled) {
  background: var(--key-bg-active);
}

/* Pressed keys keep the Stripe purple accent. */
.pad-key:active:not(:disabled) {
  background: var(--accent-dim);
  color: var(--accent);
  transform: scale(0.95);
}

.pad-key:disabled {
  opacity: 0.45;
  cursor: default;
}

.action-row {
  margin-top: 2px;
}

.action-row .pad-key {
  width: auto;
  min-width: 56px;
  padding: 0 12px;
  font-size: 0.82rem;
  font-weight: 650;
  text-transform: none;
  color: var(--muted);
}

.pad-key.symbol {
  font-size: 0.95rem;
  font-weight: 650;
  text-transform: none;
}

.listen-stage {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.listen-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.listen-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.listen-char {
  min-width: 92px;
  padding: 10px 18px;
  border-radius: 16px;
  border: 1.5px solid var(--border);
  background: var(--bg-soft);
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  transition:
    background 0.14s ease,
    border-color 0.14s ease,
    color 0.14s ease;
}

.listen-char.is-empty {
  color: var(--muted);
  font-weight: 500;
}

.listen-char.is-live {
  background: var(--playing-dim);
  border-color: rgba(5, 112, 222, 0.34);
  color: var(--playing);
}

.listen-note {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--muted);
}

.listen-actions {
  display: flex;
  justify-content: center;
}

.pad-key.listen-key.is-sounding {
  background: var(--playing-dim);
  color: var(--playing);
}

@media (prefers-reduced-motion: reduce) {
  .listen-char {
    transition: none;
  }
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 37, 64, 0.35);
  backdrop-filter: blur(2px);
  z-index: 40;
}

.result-backdrop {
  z-index: 60;
}

.result-dialog {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--safe-top)) calc(20px + var(--safe-right))
    calc(20px + var(--safe-bottom)) calc(20px + var(--safe-left));
  pointer-events: none;
}

.result-dialog:not(.hidden) {
  pointer-events: auto;
}

.result-confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.result-card {
  position: relative;
  width: min(340px, 100%);
  max-height: min(90vh, 640px);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 28px 24px 22px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  text-align: center;
  animation: result-pop 0.35s ease-out;
}

.result-dialog.is-fail .result-card {
  border-color: rgba(223, 27, 65, 0.45);
  background: linear-gradient(180deg, #fff5f7 0%, var(--bg-elevated) 55%);
  box-shadow:
    0 15px 35px rgba(223, 27, 65, 0.12),
    0 5px 15px rgba(10, 37, 64, 0.05);
  animation: result-fail-shake 0.45s ease-out;
}

.result-dialog.is-success .result-card {
  border-color: rgba(10, 122, 82, 0.28);
}

.result-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 8px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--bg);
}

.result-dialog.is-success .result-icon {
  color: var(--good);
  background: var(--good-dim);
}

.result-dialog.is-fail .result-icon {
  color: var(--bad);
  background: var(--bad-dim);
}

.result-dialog.is-muted .result-icon {
  color: var(--muted);
  background: var(--bg-soft);
}

.result-kind {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.result-dialog.is-success .result-kind {
  color: var(--good);
}

.result-dialog.is-fail .result-kind {
  color: var(--bad);
}

@keyframes result-pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes result-fail-shake {
  0% {
    opacity: 0;
    transform: translateX(0) scale(0.96);
  }
  20% {
    opacity: 1;
    transform: translateX(-7px) scale(1);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(3px);
  }
  100% {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .result-card,
  .result-dialog.is-fail .result-card {
    animation: none;
  }
}

.result-stars {
  font-size: 1.85rem;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 8px;
  line-height: 1.2;
}

.result-dialog.is-muted .result-stars {
  color: var(--muted);
}

.result-dialog.is-fail .result-stars {
  color: var(--bad);
}

.result-title {
  margin: 0 0 10px;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.result-dialog.is-fail .result-title {
  color: var(--bad);
}

.result-accuracy {
  margin: -4px 0 10px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}

.result-dialog.is-fail .result-accuracy {
  color: var(--bad);
}

.result-answer {
  margin: 0 0 14px;
  padding: 12px 14px;
  max-height: min(32vh, 180px);
  overflow: auto;
  font-size: 1.05rem;
  font-weight: 650;
  line-height: 1.45;
  letter-spacing: 0.02em;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  -webkit-overflow-scrolling: touch;
}

/* Show answer step 1: answer only (settle stats come on Continue). */
.result-dialog.is-reveal-answer .result-stars,
.result-dialog.is-reveal-answer .result-watts,
.result-dialog.is-reveal-answer .result-balance,
.result-dialog.is-reveal-answer .result-meta,
.result-dialog.is-reveal-answer .result-accuracy {
  display: none;
}

.result-dialog.is-reveal-answer .result-title {
  margin-bottom: 12px;
}

.result-dialog.is-reveal-answer .result-answer {
  margin: 0 0 18px;
  max-height: min(48vh, 280px);
  font-size: 1.15rem;
  text-align: center;
}

.result-watts {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  color: var(--good);
}

.result-dialog.is-muted .result-watts {
  color: var(--muted);
  font-weight: 560;
}

.result-dialog.is-fail .result-watts {
  color: var(--bad);
}

.result-balance {
  margin: 6px 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 500;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 14px 0 18px;
  min-height: 1.4em;
}

.result-chaos {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.result-plays {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 520;
}

.result-continue {
  width: 100%;
}

.settings {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 100%);
  height: auto;
  max-height: 100%;
  max-height: 100dvh;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  z-index: 50;
  /* Full-bleed sheet: clear notch, home indicator, and landscape side insets. */
  padding: calc(16px + env(safe-area-inset-top, 0px))
    calc(16px + env(safe-area-inset-right, 0px))
    calc(20px + env(safe-area-inset-bottom, 0px))
    calc(16px + env(safe-area-inset-left, 0px));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: -12px 0 40px rgba(10, 37, 64, 0.12);
  box-sizing: border-box;
}

.session-sheet {
  position: fixed;
  left: 50%;
  top: 50%;
  bottom: auto;
  transform: translate(-50%, -50%);
  width: min(380px, calc(100vw - 40px - var(--safe-left) - var(--safe-right)));
  width: min(380px, calc(100dvw - 40px - var(--safe-left) - var(--safe-right)));
  max-height: min(78vh, 560px, calc(100dvh - 24px - var(--safe-top) - var(--safe-bottom)));
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  z-index: 50;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow);
  box-sizing: border-box;
}

#session-backdrop,
#store-backdrop,
#account-backdrop,
#stats-backdrop {
  z-index: 45;
}

.store-dialog,
.account-dialog,
.stats-dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, calc(100vw - 40px - var(--safe-left) - var(--safe-right)));
  width: min(420px, calc(100dvw - 40px - var(--safe-left) - var(--safe-right)));
  max-height: min(84vh, 640px, calc(100dvh - 24px - var(--safe-top) - var(--safe-bottom)));
  box-sizing: border-box;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  z-index: 50;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow);
}

.account-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.account-mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.account-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 650;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
}

.account-tab.is-active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.account-form .setting input[type="text"],
.account-form .setting input[type="password"] {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}

.account-form .setting small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.75rem;
}

.account-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bad-dim);
  border: 1px solid rgba(223, 27, 65, 0.28);
  color: var(--bad);
  font-size: 0.84rem;
  font-weight: 600;
}

.account-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.account-user-line,
.account-sync-line {
  margin: 0;
  font-size: 0.92rem;
}

.account-sync-line {
  color: var(--muted);
}

.account-sync-line #account-sync-status.is-pending {
  color: var(--accent-strong);
  font-weight: 650;
}

.account-sync-line #account-sync-status.is-offline {
  color: var(--bad);
  font-weight: 650;
}

.account-sync-line #account-sync-status.is-synced {
  color: var(--good);
  font-weight: 650;
}

.account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.account-actions .ghost-btn {
  flex: 1 1 auto;
  min-width: 0;
}

.stats-dialog:not(.hidden) {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.stats-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stats-section-title {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.stats-streak-card {
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.stats-streak-body {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.stats-streak-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.stats-streak-value {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  color: var(--accent);
  line-height: 1;
}

.stats-streak-unit {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.stats-streak-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-align: right;
}

.stats-streak-today.is-done {
  color: var(--good);
}

.stats-koch-meter {
  margin: 0;
}

.stats-rows {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stats-rows .stats-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  flex-wrap: nowrap;
}

.stats-rows .stats-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.stats-rows .stats-row dt {
  margin: 0;
  color: var(--muted);
  font-weight: 500;
}

.stats-rows .stats-row dd {
  margin: 0;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--text);
}

.store-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 0.82rem;
  font-weight: 600;
}

.store-balance {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

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

.store-bench {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.bench-slot {
  height: 42px;
  border-radius: 10px;
  border: 1.5px dashed var(--border-strong);
  background: var(--bg);
  display: grid;
  place-items: center;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--muted);
  opacity: 0.65;
}

.bench-slot.is-owned {
  border-style: solid;
  border-color: transparent;
  background: linear-gradient(160deg, #8b85ff, var(--accent));
  color: #ffffff;
  opacity: 1;
}

.store-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--good-dim);
  border: 1px solid rgba(10, 122, 82, 0.3);
  color: var(--good);
  font-size: 0.84rem;
  font-weight: 700;
}

.store-badge-mark {
  font-size: 1rem;
}

.store-bench.just-completed .bench-slot {
  animation: bench-pop 0.5s ease both;
}

.store-bench.just-completed .bench-slot:nth-child(2) { animation-delay: 0.05s; }
.store-bench.just-completed .bench-slot:nth-child(3) { animation-delay: 0.1s; }
.store-bench.just-completed .bench-slot:nth-child(4) { animation-delay: 0.15s; }
.store-bench.just-completed .bench-slot:nth-child(5) { animation-delay: 0.2s; }
.store-bench.just-completed .bench-slot:nth-child(6) { animation-delay: 0.25s; }

@keyframes bench-pop {
  0% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-6px) scale(1.06); }
  100% { transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .store-bench.just-completed .bench-slot {
    animation: none;
  }
}

.store-next {
  margin: 0 0 14px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.store-next.is-complete {
  color: var(--good);
}

.store-parts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.store-part {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--bg);
}

.store-part.is-owned {
  border-color: rgba(10, 122, 82, 0.3);
  background: var(--good-dim);
}

.store-part.is-next {
  border-color: rgba(99, 91, 255, 0.45);
  background: var(--accent-dim);
}

.store-part.is-locked {
  opacity: 0.6;
}

.store-part-main {
  flex: 1;
  min-width: 0;
}

.store-part-name {
  display: block;
  font-size: 0.9rem;
  font-weight: 650;
  color: var(--text);
}

.store-part-blurb {
  display: block;
  margin-top: 2px;
  font-size: 0.76rem;
  font-weight: 480;
  line-height: 1.35;
  color: var(--muted);
}

.store-part-action {
  flex-shrink: 0;
}

.store-part-owned,
.store-part-locked {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.store-part-owned {
  color: var(--good);
  background: rgba(10, 122, 82, 0.12);
}

.store-part-locked {
  color: var(--muted);
  background: var(--bg-soft);
  font-variant-numeric: tabular-nums;
}

.store-buy-btn {
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transition: background 0.15s ease;
}

.store-buy-btn:hover:not(:disabled) {
  background: var(--accent-strong);
}

.store-buy-btn:disabled {
  cursor: default;
  background: var(--bg-soft);
  color: var(--muted);
}

.store-foot {
  margin: 16px 0 0;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
}

.session-preview-note,
.settings-preview-note {
  margin: -8px 0 16px;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--muted);
}

.spend-toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 80;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  max-width: min(420px, calc(100vw - 28px - var(--safe-left) - var(--safe-right)));
  max-width: min(420px, calc(100dvw - 28px - var(--safe-left) - var(--safe-right)));
  box-sizing: border-box;
  padding: 12px 14px;
  border-radius: 14px;
  background: #0a2540;
  color: #ffffff;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  font-weight: 560;
}

.spend-toast-undo {
  font: inherit;
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.spend-toast-undo:hover {
  background: rgba(255, 255, 255, 0.24);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.settings-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
  font-weight: 560;
}

.setting em {
  font-style: normal;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.setting small {
  color: var(--muted);
  font-weight: 450;
  font-size: 0.8rem;
  line-height: 1.35;
}

.setting.checkbox {
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  font-weight: 500;
}

.setting input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.setting input[type="checkbox"] {
  margin-top: 3px;
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.settings-foot {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.settings-install-tip {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.4;
}

.settings-install-tip[hidden] {
  display: none;
}

.settings-foot a {
  color: var(--accent);
}

@media (min-width: 640px) {
  .qwerty-pad {
    --key-gap: 7px;
    --key-w: clamp(30px, calc((100% - 9 * var(--key-gap)) / 10), 50px);
  }

  .pad-key {
    min-height: 54px;
    font-size: 1.15rem;
  }

  .slot {
    width: 1.85rem;
    height: 2.6rem;
    min-height: 2.6rem;
    font-size: 1.12rem;
  }
}

@media (max-width: 420px) {
  .mode-picker {
    gap: 6px 10px;
  }

  .mode-select {
    height: 40px;
    font-size: 0.94rem;
  }

  .qwerty-pad {
    --key-gap: 4px;
  }

  .pad-key {
    min-height: 44px;
    font-size: 0.95rem;
  }

  .action-row .pad-key {
    min-width: 48px;
    padding: 0 10px;
    font-size: 0.76rem;
  }

  .listen-char {
    font-size: 2.2rem;
  }

  /* Keep Enter / Show answer on one phone-width row. */
  .stats-row {
    gap: 4px;
  }

  .stats-row .ghost-btn.compact,
  .stats-row .enter-hint {
    height: 30px;
    padding: 0 8px;
    font-size: 0.78rem;
    border-radius: 999px;
    box-shadow: none;
  }

  .stats-row .enter-hint {
    padding: 0 8px 0 7px;
    gap: 4px;
  }

  .stats-row .enter-hint-icon {
    width: 15px;
    height: 15px;
  }
}
