: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);
  --chaos-coral: #ef6849;
  --chaos-coral-strong: #d94a2f;
  --chaos-coral-dim: rgba(239, 104, 73, 0.12);
  --chaos-coral-ring: rgba(239, 104, 73, 0.28);
  --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;
  touch-action: manipulation;
  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 {
  position: relative;
  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: 2px;
  min-width: 0;
}

.brand-mark {
  display: block;
  /* Match station/watts badge height so the mark reads at chrome scale. */
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  /* Pull past residual transparent pad so text sits near the silhouette. */
  margin-right: -2px;
  /* Brand PNGs are composed with eyes on the vertical midline so
     align-items:center keeps them level with the wordmark. */
  object-fit: contain;
  object-position: center center;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 40px;
  /* 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-family: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  user-select: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

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

.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 {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--chaos-coral-ring);
  border-radius: 50%;
  background: var(--chaos-coral-dim);
  color: var(--chaos-coral-strong);
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.12s ease;
}

.seek-lock:disabled {
  cursor: default;
}

.seek-lock.is-broke {
  opacity: 0.45;
}

@media (hover: hover) and (pointer: fine) {
  .seek-lock:not(:disabled):hover {
    background: rgba(239, 104, 73, 0.2);
    border-color: rgba(239, 104, 73, 0.44);
    color: var(--chaos-coral-strong);
    box-shadow: 0 0 0 3px rgba(239, 104, 73, 0.14);
    transform: scale(1.06);
  }

  .seek-lock:not(:disabled):active {
    transform: scale(0.98);
    background: rgba(239, 104, 73, 0.28);
  }
}

.seek-lock:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

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

.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.is-set-menu-open {
  position: relative;
  z-index: 55;
}

.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.85rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.koch-meter-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

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

.koch-meter-title-row .koch-meter-count {
  font-size: 1rem;
}

.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-set-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.koch-set-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  text-align: center;
}

.koch-set-btn:focus {
  outline: none;
}

.koch-set-btn:focus-visible,
.koch-set-btn.is-open {
  border-color: rgba(99, 91, 255, 0.55);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.koch-set-label {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.08em;
}

.koch-set-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 55;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: min(42vh, 280px);
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.koch-set-menu.hidden {
  display: none;
}

.koch-set-backdrop {
  z-index: 50;
  background: transparent;
  backdrop-filter: none;
}

.koch-set-option {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-align: left;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
  cursor: pointer;
}

.koch-set-option:hover,
.koch-set-option:focus-visible {
  outline: none;
  background: var(--bg-soft);
}

.koch-set-option.is-selected,
.koch-set-option[aria-selected="true"] {
  background: var(--accent-dim);
  color: var(--accent);
}

.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;
}

/*
 * Practice-set picker v2 — horizontal chip strip (replaces the koch-nav
 * dropdown when the Learn polish flag is on). One chip per unlocked
 * character; tap to practice up through it. A trailing dashed chip previews
 * the next unlock.
 */
.koch-chip-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 2px 6px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.koch-chip-strip.hidden {
  display: none;
}

.koch-chip {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background 0.12s ease,
    border-color 0.12s ease,
    color 0.12s ease,
    transform 0.1s ease;
}

.koch-chip:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.koch-chip:active {
  transform: scale(0.94);
}

.koch-chip.is-reviewed {
  background: var(--bg-soft);
  color: var(--muted);
  border-color: var(--border);
}

.koch-chip.is-selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.koch-chip-locked {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 650;
  opacity: 0.6;
  cursor: pointer;
  touch-action: manipulation;
}

.koch-chip-locked:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.koch-chip-locked:active {
  transform: scale(0.94);
}

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

/* Tier 2 polish: quiet recent WPM/accuracy line under the alphabet meter. */
.koch-panel-stats {
  margin: -4px 0 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-align: right;
}

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

/* Tier 2 polish: one-time dismissible Learn hints, mirrors the QSO hint chip. */
.koch-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  padding: 7px 10px;
  border-radius: 10px;
  background: rgba(99, 91, 255, 0.1);
  color: var(--text);
  font-size: 0.72rem;
  line-height: 1.35;
}

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

.koch-hint-dismiss {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  margin: 0;
  padding: 4px 8px;
  border: none;
  border-radius: 999px;
  background: rgba(99, 91, 255, 0.18);
  color: var(--accent-strong);
  font: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

/* Tier 2 polish: brief celebratory pulse on the meter when a char unlocks. */
@keyframes koch-unlock-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(99, 91, 255, 0.45);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(99, 91, 255, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(99, 91, 255, 0);
  }
}

.koch-panel.is-unlock-pulse {
  animation: koch-unlock-pulse 0.9s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .koch-panel.is-unlock-pulse {
    animation: none;
  }
}

/*
 * Wrapper is layout-inert by default (same idiom as .qso-reply-dock) — no
 * effect on Word/Custom/desktop layouts. Only becomes a real container
 * inside the mobile Learn focus view (see .app.is-koch-focus below).
 */
.koch-practice-dock {
  display: contents;
}

.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;
  touch-action: manipulation;
}

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

.koch-flash-glyph {
  margin: 0;
  width: calc(100% - 18px);
  height: calc(100% - 18px);
  border-radius: 50%;
  border: none;
  background: var(--bg-soft);
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: clamp(3rem, 13vw, 5rem);
  font-weight: 700;
  line-height: 1;
  display: grid;
  place-items: center;
  pointer-events: none;
  user-select: none;
  transition:
    background 0.12s ease,
    color 0.12s ease;
}

.koch-flash-ring {
  position: relative;
  width: min(220px, 72vw);
  aspect-ratio: 1;
  margin: 0;
  display: grid;
  place-items: center;
  pointer-events: auto;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.koch-flash-ring-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.koch-flash-ring-track {
  fill: none;
  stroke: var(--bg-soft);
  stroke-width: 5;
}

.koch-flash-ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 5;
  stroke-linecap: round;
  opacity: 0.72;
  transition: stroke-dashoffset 0.16s ease, stroke 0.12s ease;
}

.koch-flash-ring.is-listening .koch-flash-ring-progress {
  stroke: var(--playing);
  opacity: 0.9;
}

.koch-flash-ring.is-correct .koch-flash-ring-progress {
  stroke: var(--good);
  opacity: 0.9;
}

.koch-flash-ring.is-wrong .koch-flash-ring-progress,
.koch-flash-ring.is-miss .koch-flash-ring-progress {
  stroke: var(--bad);
  opacity: 0.85;
}

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

.koch-flash-glyph.is-listening {
  background: var(--playing-dim);
  color: var(--playing);
}

.koch-flash-glyph.is-awaiting {
  color: var(--muted);
}

.koch-flash-glyph.is-correct {
  background: var(--good-dim);
  color: var(--good);
}

.koch-flash-glyph.is-wrong {
  background: var(--bad-dim);
  color: var(--bad);
}

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

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

/* Tier 1 polish: hint tone follows the same meaning as the flash-card color. */
.koch-flash-hint.is-good {
  color: var(--good);
}

.koch-flash-hint.is-warn {
  color: var(--bad);
}

.koch-flash-exit-hint {
  margin: -8px 0 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}

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

/*
 * Unlock row above the ring — what unlocks next at 90%.
 * Practiced set is shown in #koch-panel on the landing page.
 */
.koch-flash-intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: 0;
  max-width: min(280px, 78vw);
  text-align: center;
}

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

.koch-flash-intro-row {
  width: 100%;
  margin: 0;
  max-width: 100%;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.4;
  text-align: center;
}

.koch-flash-intro-row-next {
  /* The label and badge are inline elements sized by different metrics (text
     baseline vs. a fixed-height pill), so relying on text-align + a manual
     vertical-align offset on the badge can't keep them on a shared visual
     center — it only fakes it for one font/zoom combination. Making the row
     itself a flex line guarantees both children are vertically centered on
     the same axis and the pair stays centered as a single horizontal unit. */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.koch-flash-intro-next-char {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.koch-flash-intro-next-char.hidden {
  display: none;
}

/* When there's no next character to unlock (full alphabet), the label
   itself becomes the "badge" so the row still reads as a deliberate state
   rather than leftover unlock copy. */
.koch-flash-intro-row-next--complete .koch-flash-intro-next-label {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

/* Tier 1 polish: Replay / Reset row under the hint line. */
.koch-flash-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: -4px;
}

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

.koch-flash-action {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  padding: 5px 12px;
  border: none;
  border-radius: 999px;
  background: rgba(10, 37, 64, 0.08);
  color: var(--text);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

.koch-flash-action:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.koch-flash-action:active {
  transform: scale(0.96);
}

.koch-flash-action:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

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

.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;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
}

.play-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px 0 11px;
  border-radius: 999px;
  background: linear-gradient(160deg, #8b85ff, var(--accent));
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(99, 91, 255, 0.28);
}

.play-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.play-btn-label {
  letter-spacing: -0.01em;
}

.play-btn:active {
  transform: scale(0.98);
  background: linear-gradient(160deg, #7a74e8, var(--accent-strong));
}

.play-btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

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

.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;
}

.feedback-control {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
}

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

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

.feedback-chip:active:not(:disabled) {
  background: #dce3eb;
}

.feedback-chip.is-on,
.feedback-chip[aria-pressed="true"] {
  color: #ffffff;
  background: linear-gradient(160deg, #8b85ff, var(--accent));
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(99, 91, 255, 0.28);
}

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

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

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

.feedback-chip--compact {
  flex-shrink: 0;
}

.qso-quick-setting-feedback {
  align-items: center;
}

@media (max-width: 640px), (pointer: coarse) {
  .stage-toolbar {
    flex-wrap: nowrap;
    gap: 5px;
  }

  .stage-toolbar > .play-btn,
  .stage-toolbar > .session-btn,
  .stage-toolbar > .chaos-control,
  .stage-toolbar > .feedback-control {
    flex: 1 1 0;
    min-width: 0;
  }

  .stage-toolbar > .chaos-control.hidden,
  .stage-toolbar > .feedback-control.hidden,
  .stage-toolbar > .chaos-control[hidden],
  .stage-toolbar > .feedback-control[hidden] {
    display: none;
    flex: 0 0 auto;
  }

  .stage-toolbar .chaos-control,
  .stage-toolbar .feedback-control {
    display: flex;
  }

  .stage-toolbar .play-btn,
  .stage-toolbar .session-btn,
  .stage-toolbar .chaos-chip,
  .stage-toolbar .feedback-chip {
    width: 100%;
    justify-content: center;
    padding-inline: 6px;
    font-size: 0.8rem;
  }

  .stage-toolbar .play-btn {
    padding-inline: 8px;
  }

  .stage-toolbar .chaos-chip-label,
  .stage-toolbar .feedback-chip-label,
  .stage-toolbar .play-btn-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.status-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
  text-align: left;
}

.round-stars {
  margin: 0;
  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 .seek-time {
  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;
}

.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 rgba(239, 104, 73, 0.18);
  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(--chaos-coral-ring);
  color: var(--text);
  background: rgba(239, 104, 73, 0.06);
}

.chaos-chip:active:not(:disabled) {
  background: rgba(239, 104, 73, 0.1);
  border-color: rgba(239, 104, 73, 0.34);
  color: var(--text);
}

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

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

.chaos-chip.is-on:active:not(:disabled),
.chaos-chip[aria-pressed="true"]:active:not(:disabled) {
  color: #ffffff;
  background: linear-gradient(160deg, #e05a3f, #c7432a);
  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(--chaos-coral-strong);
  background: var(--chaos-coral-dim);
  border: 1px solid rgba(239, 104, 73, 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: 260;
}

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

.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(239, 104, 73, 0.45);
  background: var(--chaos-coral-dim);
  color: var(--chaos-coral-strong);
}

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

.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(239, 104, 73, 0.45);
  background: var(--chaos-coral-dim);
  color: var(--chaos-coral-strong);
}

.chaos-pill[aria-pressed="true"] em {
  color: rgba(239, 104, 73, 0.75);
}

.chaos-pill:hover:not(:disabled) {
  border-color: rgba(239, 104, 73, 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: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .station-badge,
  .signal-badge {
    height: 34px;
    padding: 0 7px 0 6px;
    border-radius: 10px;
    font-size: 0.74rem;
    gap: 3px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    margin-right: -1px;
  }

  .brand h1 {
    /* LemurKey.app is wider than ditdit.app — scale down so the full wordmark
       fits beside badges + icon buttons at ~390px without ellipsis. */
    font-size: 0.94rem;
    line-height: 32px;
    letter-spacing: -0.035em;
    overflow: visible;
    text-overflow: unset;
  }

  .brand-tld {
    font-size: 0.92em;
  }

  .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 wrap + space between word groups */
  gap: 10px 8px;
  align-content: flex-start;
  -webkit-overflow-scrolling: touch;
}

/* QSO lives inside the shared practice stage (Play / Chaos / Session). */
.stage.is-qso .slots,
.stage.is-qso .slots-hint,
.stage.is-qso .almost-banner,
.stage.is-qso .stats-row,
.stage.is-qso #custom-empty,
.stage.is-qso #koch-flash {
  display: none !important;
}

/*
 * Scrubber only makes sense against the station's own transmission — hide it
 * outside stationTx/awaitCopy (idle, reply-keying, complete) and reuse the
 * exact same seek-block chrome Word/Callsign/Sentence use otherwise.
 */
.stage.is-qso .seek-block {
  display: none !important;
}
.stage.is-qso.is-qso-scrub .seek-block {
  display: flex !important;
}

.stage:not(.is-qso) .qso-stage {
  display: none !important;
}

.qso-stage {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
  position: relative;
  /* iMessage-inspired palette, scoped to the QSO chat thread only. */
  --imsg-gray: #e9e9eb;
  --imsg-gray-text: #0e0e10;
  /* Outgoing bubbles use solid brand purple (not iMessage blue). */
  --imsg-you: #635bff;
  --imsg-you-text: #ffffff;
}

.qso-stage:focus,
.qso-stage:focus-visible {
  outline: none;
}

.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: 1.1rem;
  min-width: 1.1rem;
  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.correct.locked {
  cursor: default;
}

.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-stage:focus,
.listen-stage:focus-visible {
  outline: none;
}

.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;
}

.send-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;
}

.send-stage:focus,
.send-stage:focus-visible {
  outline: none;
}

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

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

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

.send-paddle-modes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.send-paddle-mode {
  appearance: none;
  -webkit-appearance: none;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

.send-paddle-mode.is-active,
.send-paddle-mode[aria-pressed="true"] {
  background: var(--accent-dim);
  border-color: rgba(99, 91, 255, 0.45);
  color: var(--accent-strong);
}

.send-decoded {
  min-height: 3.2rem;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--bg-soft);
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  line-height: 1.35;
  text-align: center;
  word-break: break-word;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

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

.send-decoded-text {
  word-break: break-word;
}

/* Backspace has a physical-keyboard equivalent on desktop (see
   handleSendKeydown in app.js), so this tappable button is mobile-only —
   see the media query below for where it's actually shown. */
.send-decoded-backspace {
  display: none;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 32px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel, var(--bg));
  color: var(--muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.send-decoded-backspace svg {
  display: block;
}

.send-decoded-backspace:active:not(:disabled) {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-strong);
}

.send-decoded-backspace:disabled {
  opacity: 0.4;
  cursor: default;
}

@media (max-width: 640px), (pointer: coarse) {
  /* Match the QSO reply composer's white iMessage-style bubble — text +
     trailing backspace only (no mode toggle, send, or placeholder copy). */
  .send-decoded {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0;
    min-height: 36px;
    padding: 0;
    border: none;
    border-radius: 20px;
    background: #ffffff;
    box-shadow: 0 0 0 1px rgba(10, 37, 64, 0.06);
    overflow: hidden;
    text-align: left;
    font-size: inherit;
    font-weight: inherit;
    letter-spacing: normal;
    font-family: inherit;
  }

  .send-decoded.is-empty {
    color: inherit;
    font-weight: inherit;
  }

  .send-decoded-text {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 1.25em;
    padding: 8px 10px 8px 14px;
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.35;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--text);
    font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
    overflow-wrap: anywhere;
  }

  .send-decoded.is-empty .send-decoded-text,
  .send-decoded-text.is-placeholder {
    color: #8e8e93;
    font-family: inherit;
    font-weight: 400;
    letter-spacing: normal;
    text-transform: none;
  }

  .send-decoded.is-empty .send-decoded-backspace {
    display: none;
  }

  .send-decoded-backspace {
    display: inline-flex;
    align-self: center;
    width: 28px;
    height: 28px;
    margin: 0 8px 0 0;
    border: none;
    border-radius: 50%;
    background: rgba(10, 37, 64, 0.08);
    touch-action: manipulation;
  }

  .send-decoded-backspace:active:not(:disabled) {
    transform: scale(0.94);
    background: rgba(10, 37, 64, 0.08);
    border-color: transparent;
    color: var(--muted);
  }

  .send-decoded-backspace:disabled {
    opacity: 0.35;
  }

  .send-decoded-backspace:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-ring);
  }

  .send-decoded:not(.is-empty) .send-decoded-text {
    padding: 10px 10px 10px 14px;
  }
}

.send-deck {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.send-paddles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.send-deck[data-layout="straight"] .send-paddles {
  display: none;
}

.send-deck[data-layout="dual"] [data-send-lever="key"] {
  display: none;
}

.send-deck[data-layout="dual"] .send-paddles {
  display: grid;
}

.send-key {
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: min(32vh, 210px);
  margin: 0;
  padding: 18px 16px;
  border: 2px solid var(--border-strong);
  border-radius: 22px;
  background: linear-gradient(180deg, #ffffff 0%, var(--bg-soft) 100%);
  color: var(--text);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background 0.12s ease,
    border-color 0.12s ease,
    color 0.12s ease,
    transform 0.12s ease;
}

.send-paddle {
  min-height: min(24vh, 165px);
}

.send-key-label {
  font-size: 1.25rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.send-key-hint {
  font-size: 0.82rem;
  font-weight: 560;
  color: var(--muted);
}

.send-paddle .send-key-hint {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.15;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.send-kbd {
  display: none;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  padding: 0.12em 0.4em;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel, var(--bg));
  color: var(--muted);
  box-shadow: 0 1px 0 var(--border);
}

@media (hover: hover) and (pointer: fine) {
  .send-kbd {
    display: inline-block;
  }
}

.send-key:hover {
  border-color: var(--accent);
}

.send-key.is-down,
.send-key:active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-strong);
  transform: scale(0.985);
}

.send-key.is-down .send-key-hint,
.send-key:active .send-key-hint {
  color: var(--accent-strong);
}

.send-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.qso-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  text-align: left;
}

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

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

/*
 * No card-within-a-card: the transcript is plain white (matches the stage),
 * framed by two full-width rules (top = under the "Two-way QSO" heading,
 * bottom = above Replay/Skip/Reset) instead of a rounded bordered box.
 */
.qso-transcript {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(46vh, 26rem);
  overflow-y: auto;
  overflow-x: hidden;
  /*
   * Full-bleed to the stage's own border: cancel .stage's 16px padding with
   * matching negative margins + width so the top/bottom rules reach the card
   * edges, then restore the original 26px (16 stage + 10 transcript) inset
   * via padding so bubble content still sits where it did before.
   */
  margin-left: -16px;
  margin-right: -16px;
  width: calc(100% + 32px);
  padding: 14px 26px;
  border-radius: 0;
  border: none;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  scroll-behavior: smooth;
}

.qso-transcript.is-empty {
  min-height: 0;
  /* Center the placeholder block in the middle of the chat frame instead
   * of leaving it stuck against the top edge. */
  align-items: center;
  justify-content: center;
}

.qso-transcript-empty {
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  padding: 6px 6px 4px;
  width: 100%;
  max-width: 22rem;
}

.qso-transcript.is-empty .qso-transcript-empty {
  display: flex;
}

.qso-transcript-empty-ghosts {
  /*
   * Hidden: this mini chat-bubble mockup was pushing the title/hint text
   * off-center (it sat above the copy block inside the same centered
   * flex item), so the "CW chat" message no longer landed in the visual
   * middle of the transcript area. Dropping it lets the copy block alone
   * be centered both ways.
   */
  display: none;
}

.qso-ghost-bubble {
  max-width: 58%;
  height: 2.2rem;
  border-radius: 17px;
  border: none;
  opacity: 0.8;
}

.qso-ghost-bubble.is-station {
  align-self: flex-start;
  border-bottom-left-radius: 5px;
  background: var(--imsg-gray);
}

.qso-ghost-bubble.is-you {
  align-self: flex-end;
  max-width: 46%;
  border-bottom-right-radius: 5px;
  background: var(--imsg-you);
  opacity: 0.7;
}

.qso-transcript-empty-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
  padding: 0 6px;
}

.qso-transcript-empty-title {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.qso-transcript-empty-hint {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--muted);
  max-width: 28rem;
}

.qso-stage.is-tap-to-start .qso-transcript {
  cursor: pointer;
}

.qso-stage.is-tap-to-start .qso-transcript-empty {
  cursor: pointer;
}

.qso-stage.is-tap-to-start .qso-composer.is-inactive {
  cursor: pointer;
}

/* --- iMessage-style chat bubbles ------------------------------------- */

.qso-bubble {
  position: relative;
  max-width: 84%;
  padding: 8px 13px 9px;
  border-radius: 18px;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.4;
  word-break: break-word;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  box-shadow: 0 1px 0 rgba(10, 37, 64, 0.03);
  animation: qso-bubble-pop 0.18s ease-out;
  /* Let curly tails paint outside the rounded box. */
  overflow: visible;
}

@keyframes qso-bubble-pop {
  from {
    opacity: 0;
    transform: translateY(4px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.qso-bubble.is-station {
  align-self: flex-start;
  background: var(--imsg-gray);
  color: var(--imsg-gray-text);
  border-bottom-left-radius: 4px;
}

/*
 * Curly iMessage tails via SVG mask — concave inner edge, tip curling
 * down and outward (matches the classic Messages bubble geometry).
 */
.qso-bubble.is-station::after,
.qso-bubble.is-you::after {
  content: "";
  position: absolute;
  bottom: -1px;
  width: 14px;
  height: 17px;
  pointer-events: none;
  z-index: -1;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 17'%3E%3Cpath fill='%23000' d='M0 0v11.5C.4 14.8 3.2 17 7.5 17 2.8 15.6.2 10.2 0 0z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 17'%3E%3Cpath fill='%23000' d='M0 0v11.5C.4 14.8 3.2 17 7.5 17 2.8 15.6.2 10.2 0 0z'/%3E%3C/svg%3E");
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

.qso-bubble.is-station::after {
  left: -6px;
  background: var(--imsg-gray);
  transform: scaleX(-1);
  transform-origin: center;
}

.qso-bubble.is-you {
  align-self: flex-end;
  background: var(--imsg-you);
  color: var(--imsg-you-text);
  border-bottom-right-radius: 4px;
  max-width: 88%;
}

.qso-bubble.is-you::after {
  right: -6px;
  background: var(--imsg-you);
}

/*
 * Copy bubble (the operator's own free-type slots while/after copying the
 * station) reads as a pale light blue, not solid brand purple — keeps the
 * copy boxes legible and visually distinct from the outgoing reply bubble,
 * which stays brand purple. "is-copy" is a lasting marker kept after
 * grading.
 */
.qso-bubble.is-you.is-copy {
  background: #d4e8ff;
  color: var(--text);
}

.qso-bubble.is-you.is-copy::after {
  background: #d4e8ff;
}

/*
 * Classic iMessage typing indicator: fixed-size light-gray pill with three
 * bouncing dots. No size/progress animation — ellipses run for the whole TX.
 */
.qso-bubble.is-pending {
  font-weight: 500;
  font-family: inherit;
  align-self: flex-start;
  width: max-content;
  max-width: none;
  min-width: 0;
  padding: 9px 14px;
  border-radius: 18px;
  box-shadow: none;
  animation: qso-typing-appear 0.18s ease-out;
  /* Play/Pause toggle during station TX: quick expand/shrink of the pill
     itself, layered on top of the one-shot appear animation above. */
  transition: transform 0.18s ease-out, opacity 0.18s ease-out;
}

/* Thought-bubble tail (two trailing circles), not the curly SVG message tail. */
.qso-bubble.is-pending::after {
  content: "";
  bottom: -5px;
  left: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--imsg-gray);
  -webkit-mask-image: none;
  mask-image: none;
  transform: none;
}

.qso-bubble.is-pending::before {
  content: "";
  position: absolute;
  bottom: -11px;
  left: -2px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--imsg-gray);
  pointer-events: none;
  z-index: -1;
}

/*
 * Pause stops the station's audio, so the "..." pill (which implies a live
 * transmission) is hidden entirely until the same TX resumes. Never reveals
 * the CW text early — it just stops pretending the station is on the air.
 *
 * visibility:hidden (not display:none) so the pill keeps its box in the
 * transcript's flex flow — its height + the column `gap` stay reserved,
 * which keeps the copy bubble below it from jumping up while paused.
 *
 * The shrink-out (scale + fade) plays first; visibility only flips to
 * hidden once that's finished (delayed transition below), so the pill
 * visibly deflates instead of popping away. On resume the reverse — this
 * class is simply removed, so visibility snaps back to visible immediately
 * (not part of the base rule's transition list) while transform/opacity
 * animate back up to full size via the base `.is-pending` transition.
 */
.qso-bubble.is-pending.is-tx-paused {
  transform: scale(0.85);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    transform 0.16s ease-out,
    opacity 0.16s ease-out,
    visibility 0s linear 0.16s;
}

@keyframes qso-typing-appear {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.qso-bubble.is-skipped {
  opacity: 0.65;
}

.qso-bubble-meta {
  display: block;
  margin-bottom: 2px;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  /* Match Station / You labels — UI sans, not the bubble's mono body. */
  font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-style: normal;
}

/* Hide the meta label on the typing pill to match the compact reference look. */
.qso-bubble.is-pending .qso-bubble-meta {
  display: none;
}

.qso-bubble.is-station .qso-bubble-meta {
  color: var(--muted);
}

.qso-bubble.is-you .qso-bubble-meta {
  color: rgba(255, 255, 255, 0.85);
}

.qso-bubble.is-you.is-copy .qso-bubble-meta {
  color: rgba(10, 37, 64, 0.6);
}

/* Typing indicator — classic three-dot iMessage "..." bubble. */
.qso-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 2px 1px;
}

.qso-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: qso-typing-bounce 1.1s ease-in-out infinite;
}

.qso-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.qso-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes qso-typing-bounce {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 0.9;
    transform: translateY(-3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .qso-bubble {
    animation: none;
  }
  .qso-bubble.is-pending {
    animation: none;
    opacity: 1;
    transform: none;
    transition: none;
  }
  .qso-bubble.is-pending.is-tx-paused {
    transition: none;
    transform: none;
  }
  .qso-typing-dots span {
    animation: none;
    opacity: 0.6;
  }
}

.qso-bubble.is-copy.is-collapsing {
  overflow: hidden;
  pointer-events: none;
  transition:
    opacity 0.28s ease-out,
    max-height 0.32s ease-out,
    margin 0.32s ease-out,
    padding 0.32s ease-out,
    transform 0.28s ease-out;
  opacity: 0;
  max-height: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  transform: scale(0.96);
}

@media (prefers-reduced-motion: reduce) {
  .qso-bubble.is-copy.is-collapsing {
    transition: none;
  }
}

/* Live copy bubble — same soft drop shadow as other chat bubbles (no accent ring). */
.qso-bubble.is-live-copy {
  box-shadow: 0 1px 0 rgba(10, 37, 64, 0.03);
}

.qso-live-copy-body {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 8px;
  align-content: flex-start;
  margin-top: 6px;
}

.qso-live-copy-body .slot {
  cursor: pointer;
  pointer-events: auto;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.qso-bubble.is-you .qso-live-copy-body .slot {
  /* Solid white chips until graded — translucent fills would pick up purple. */
  background: #ffffff;
  border-color: rgba(10, 37, 64, 0.14);
  color: var(--text);
}

/* Word gaps are spacers only — never paint them as empty chips. */
.qso-bubble.is-you .qso-live-copy-body .slot.space {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: transparent;
  pointer-events: none;
}

.qso-bubble.is-you .qso-live-copy-body .slot.filled {
  background: #ffffff;
  border-color: #8792a2;
}

.qso-bubble.is-you .qso-live-copy-body .slot.punct {
  background: #ffffff;
  border-color: rgba(10, 37, 64, 0.14);
}

.qso-bubble.is-you .qso-live-copy-body .slot.correct {
  /* Same pale green chip as Copy modes, opaque so purple doesn't bleed through. */
  color: var(--good);
  background: color-mix(in srgb, var(--good) 12%, #ffffff);
  border-color: var(--good);
}

.qso-bubble.is-you .qso-live-copy-body .slot.wrong {
  color: var(--bad);
  background: color-mix(in srgb, var(--bad) 12%, #ffffff);
  border-color: var(--bad);
}

.qso-bubble.is-you .qso-live-copy-body .slot.cursor {
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.qso-bubble.is-you .qso-live-copy-body .slot.playing {
  /* Match Copy modes: ring highlight only, keep the chip white. */
  border-color: var(--playing);
  background: #ffffff;
  box-shadow: 0 0 0 3px var(--playing-dim);
}

/*
 * Always reachable even when the transcript grows tall enough to push the
 * page into scroll (e.g. reply keyer open + a long chat) — sticks to the
 * viewport bottom rather than scrolling away with the transcript above it.
 */
.qso-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  justify-content: flex-start;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: var(--bg-elevated);
  padding-top: 4px;
  padding-bottom: 2px;
}

/* Divider below reply pill, above Replay / Skip / Reset (default awaitReply). */
.qso-composer:not(.hidden) + .qso-actions {
  margin-left: -16px;
  margin-right: -16px;
  width: calc(100% + 32px);
  padding-left: 16px;
  padding-right: 16px;
  border-top: 1px solid rgba(10, 37, 64, 0.08);
  padding-top: 8px;
}

.qso-actions .play-btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.qso-watt-flash {
  position: absolute;
  inset: 2.5rem 0.5rem 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  overflow: visible;
}

.qso-watt-flash.is-on {
  opacity: 1;
}

.qso-watt-flash.is-spend .qso-watt-flash-layer {
  color: #c93400;
  text-shadow: 0 0 18px rgba(201, 52, 0, 0.35);
}

.qso-watt-flash-layer {
  position: absolute;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent-strong);
  text-shadow: 0 0 18px var(--accent-ring);
  opacity: 0;
  white-space: nowrap;
  line-height: 1;
}

.qso-watt-flash-layer.is-main {
  top: 18%;
  right: 8%;
  font-size: clamp(1.75rem, 5.5vw, 2.35rem);
}

.qso-watt-flash-layer.is-echo-1 {
  top: 38%;
  left: 10%;
  right: auto;
  font-size: clamp(1.15rem, 3.6vw, 1.55rem);
}

.qso-watt-flash-layer.is-echo-2 {
  top: 8%;
  left: 42%;
  right: auto;
  font-size: clamp(2.4rem, 8vw, 3.4rem);
}

.qso-watt-flash.is-on .qso-watt-flash-layer.is-main {
  animation: qso-watt-pop-main 1.85s ease-out forwards;
}

.qso-watt-flash.is-on .qso-watt-flash-layer.is-echo-1 {
  animation: qso-watt-pop-echo-1 1.85s ease-out forwards;
}

.qso-watt-flash.is-on .qso-watt-flash-layer.is-echo-2 {
  animation: qso-watt-pop-echo-2 1.85s ease-out forwards;
}

@keyframes qso-watt-pop-main {
  0% {
    opacity: 0;
    transform: translate(0, 18px) scale(0.88);
  }
  12% {
    opacity: 1;
    transform: translate(0, 0) scale(1.08);
  }
  55% {
    opacity: 1;
    transform: translate(4px, -16px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(6px, -40px) scale(0.96);
  }
}

@keyframes qso-watt-pop-echo-1 {
  0% {
    opacity: 0;
    transform: translate(0, 22px) scale(0.85);
  }
  16% {
    opacity: 0.5;
    transform: translate(0, 0) scale(1.1);
  }
  50% {
    opacity: 0.32;
    transform: translate(-10px, -22px) scale(1.02);
  }
  100% {
    opacity: 0;
    transform: translate(-14px, -48px) scale(0.94);
  }
}

@keyframes qso-watt-pop-echo-2 {
  0% {
    opacity: 0;
    transform: translate(0, 24px) scale(0.8);
  }
  20% {
    opacity: 0.2;
    transform: translate(0, 0) scale(1.06);
  }
  48% {
    opacity: 0.12;
    transform: translate(12px, -28px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(16px, -56px) scale(0.92);
  }
}

@media (prefers-reduced-motion: reduce) {
  .qso-watt-flash.is-on {
    opacity: 1;
  }

  .qso-watt-flash.is-on .qso-watt-flash-layer.is-main {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .qso-watt-flash.is-on .qso-watt-flash-layer.is-echo-1,
  .qso-watt-flash.is-on .qso-watt-flash-layer.is-echo-2 {
    animation: none;
    opacity: 0;
  }
}

.qso-stage .send-paddle-modes {
  justify-content: flex-start;
}

.qso-reply {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.qso-reply.is-type-locked {
  opacity: 0.45;
  pointer-events: none;
}

.qso-reply.is-type-locked .send-key,
.qso-reply.is-type-locked .send-paddle-mode {
  cursor: not-allowed;
}

.qso-live-reply-body {
  margin-top: 2px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  word-break: break-word;
}

/*
 * iMessage-style reply composer — gray input bar flush under the chat
 * transcript, above paddle mode buttons. Shown for the whole QSO turn
 * (station TX, copy, reply); dimmed/read-only until awaitReply.
 */
.qso-composer {
  flex-shrink: 0;
  margin-left: -16px;
  margin-right: -16px;
  width: calc(100% + 32px);
  padding: 8px 12px;
  background: #f2f2f7;
  border: none;
  transition: opacity 0.15s ease;
}

/* Classic desktop QSO — white pill only, no iMessage gray input bar. */
@media (min-width: 641px) {
  .qso-composer {
    background: transparent;
  }
}

.qso-composer.is-inactive {
  opacity: 0.88;
}

.qso-composer.is-inactive .qso-composer-field {
  cursor: default;
  opacity: 0.72;
}

.qso-composer.is-inactive .qso-composer-field:disabled {
  -webkit-user-select: none;
  user-select: none;
}

/* Cancel .qso-stage flex gap — composer flush under transcript. */
.qso-transcript + .qso-reply-dock .qso-composer {
  margin-top: -14px;
}

/* Wrapper is layout-inert on desktop/wide viewports. */
.qso-reply-dock {
  display: contents;
}

.qso-composer-shell {
  display: flex;
  align-items: center;
  gap: 6px;
}

.qso-composer.is-awaiting-reply.is-has-text .qso-composer-shell {
  align-items: flex-end;
}

.qso-composer.is-awaiting-reply .qso-composer-shell {
  align-items: center;
}

.qso-composer-mode-toggle {
  flex: 0 0 auto;
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.qso-composer-mode-toggle:hover {
  background: #e4eaf1;
}

.qso-composer-mode-toggle:active {
  transform: scale(0.94);
  background: #dce3eb;
}

.qso-composer-mode-toggle:focus {
  outline: none;
}

.qso-composer-mode-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.qso-composer-mode-icon {
  display: block;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
}

.qso-composer-mode-toggle.is-keyer-active .qso-composer-mode-icon--keyboard {
  display: block;
}

.qso-composer-mode-toggle.is-keyer-active .qso-composer-mode-icon--keyer {
  display: none;
}

.qso-composer-mode-toggle:not(.is-keyer-active) .qso-composer-mode-icon--keyboard {
  display: none;
}

.qso-composer-mode-toggle:not(.is-keyer-active) .qso-composer-mode-icon--keyer {
  display: block;
}

.qso-composer-field {
  flex: 1 1 auto;
  min-width: 0;
  display: block;
  margin: 0;
  padding: 10px 16px;
  border: none;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(10, 37, 64, 0.06);
  text-align: left;
  cursor: text;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.qso-composer-bubble {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0;
  min-height: 36px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(10, 37, 64, 0.06);
  overflow: hidden;
}

.qso-composer.is-has-text .qso-composer-bubble {
  align-items: center;
}

.qso-composer.is-has-text .qso-composer-bubble .qso-composer-field {
  align-items: flex-start;
  align-self: stretch;
}

.qso-composer.is-has-text .qso-composer-backspace {
  align-self: center;
  margin: 0 8px 0 0;
}

.qso-composer-bubble .qso-composer-field {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 36px;
  display: flex;
  align-items: center;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

/* Focus ring on the whole bubble — not the field alone — so a vertical seam
   does not appear beside the trailing backspace in keyer mode. */
.qso-composer-bubble .qso-composer-field:focus,
.qso-composer-bubble .qso-composer-field:focus:not(:focus-visible),
.qso-composer-bubble .qso-composer-field:focus-visible {
  outline: none;
  box-shadow: none;
}

.qso-composer-bubble:focus-within {
  box-shadow:
    0 0 0 1px rgba(10, 37, 64, 0.12),
    0 0 0 3px rgba(10, 37, 64, 0.1);
}

.qso-composer-bubble .qso-composer-display {
  flex: 1 1 auto;
  min-width: 0;
}

.qso-composer-backspace {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin: 0 6px 0 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(10, 37, 64, 0.08);
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
}

.qso-composer-backspace svg {
  display: block;
}

.qso-composer-backspace:not(:disabled):active {
  transform: scale(0.94);
}

.qso-composer-backspace:disabled {
  opacity: 0.35;
  cursor: default;
}

.qso-composer-backspace:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.qso-reply-dock.is-qso-keyer-input .qso-composer-backspace:not(.hidden):not([hidden]) {
  display: inline-flex;
}

.qso-composer-field:focus {
  outline: none;
}

.qso-composer-field:focus:not(:focus-visible) {
  box-shadow: 0 0 0 1px rgba(10, 37, 64, 0.06);
}

.qso-composer-field:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 1px rgba(10, 37, 64, 0.12),
    0 0 0 3px rgba(10, 37, 64, 0.1);
}

.qso-composer-display {
  display: block;
  min-height: 1.25em;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.35;
  color: var(--text);
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  word-break: break-word;
  white-space: pre-wrap;
}

.qso-composer-display.is-placeholder {
  color: #8e8e93;
  font-family: inherit;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
}

.qso-composer-display.is-pending {
  opacity: 0.72;
}

.qso-composer-send {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #007aff;
  color: #ffffff;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.15s ease, transform 0.12s ease;
}

.qso-composer-send:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
}

.qso-composer-send:not(:disabled):active {
  transform: scale(0.94);
}

.qso-composer-send:focus {
  outline: none;
}

.qso-composer-send:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.35);
}

/* No line above reply composer when the pill is shown (default + copy turns). */
.qso-stage:has(.qso-composer:not(.hidden)) .qso-transcript {
  border-bottom: none;
}

.qso-stage:not(:has(.qso-composer:not(.hidden))) .qso-transcript {
  border-bottom: none;
}

.qso-desktop-status {
  display: none;
}

.qso-actions-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}

/* Desktop classic QSO — tighter chrome, dropdown keyer, flex transcript. */
@media (min-width: 641px) {
  .stage.is-qso #status-line {
    display: none;
  }

  .stage.is-qso {
    min-height: min(72vh, 44rem);
  }

  .stage.is-qso .qso-stage {
    flex: 1 1 auto;
    min-height: 0;
  }

  .qso-stage .qso-head {
    display: none;
  }

  .qso-stage .qso-desktop-status {
    display: block;
    margin: -4px 0 -6px;
    font-size: 0.82rem;
    line-height: 1.35;
    color: var(--muted);
    min-height: 0;
  }

  .qso-stage .qso-desktop-status:empty {
    display: none;
    margin: 0;
  }

  .qso-stage .qso-desktop-status.is-warn {
    color: #c93400;
  }

  .qso-stage .qso-desktop-status.is-good {
    color: #0d7a45;
  }

  .qso-stage .qso-transcript {
    max-height: none;
    flex: 1 1 auto;
    min-height: 10rem;
  }

  .qso-stage .qso-actions {
    justify-content: flex-end;
    margin-left: -16px;
    margin-right: -16px;
    width: calc(100% + 32px);
    padding: 8px 16px;
    border-top: 1px solid rgba(10, 37, 64, 0.08);
  }

  .qso-stage
    .qso-actions:not(:has(.qso-actions-buttons > button:not(.hidden):not([hidden]))) {
    display: none;
  }

  .qso-stage .qso-composer:not(.hidden) + .qso-actions {
    margin-top: 0;
    padding-top: 8px;
  }

  .qso-stage .qso-reply .send-paddle-modes {
    display: none !important;
  }

  .qso-stage .qso-reply {
    gap: 8px;
  }

  .qso-stage .send-key {
    min-height: 128px;
    padding: 14px 16px;
  }

  .qso-stage .send-key-label {
    font-size: 1.05rem;
  }

  .qso-stage .send-paddle {
    min-height: 108px;
  }

  .qso-reply-dock.is-qso-keyboard-input .qso-reply {
    display: none !important;
  }

  .qso-composer-send {
    background: linear-gradient(160deg, #8b85ff, var(--accent));
    box-shadow: 0 2px 10px rgba(99, 91, 255, 0.28);
  }

  .qso-composer-send:focus-visible {
    box-shadow: 0 0 0 3px var(--accent-ring);
  }
}

.app.is-messages-copy .qso-desktop-status {
  display: none !important;
}

.primary-btn.compact {
  height: 36px;
  padding: 0 14px;
  font-size: 0.88rem;
}

@media (max-width: 420px) {
  .send-paddle-mode {
    flex: 1 1 calc(50% - 6px);
    min-width: 0;
  }
}

.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-dialog.is-streak .result-card {
  border-color: rgba(99, 91, 255, 0.4);
  background: linear-gradient(165deg, #f0eeff 0%, #fff8f0 48%, var(--bg-elevated) 100%);
  box-shadow:
    0 15px 35px rgba(99, 91, 255, 0.14),
    0 5px 15px rgba(10, 37, 64, 0.05);
}

.result-dialog.is-streak .result-icon,
.result-dialog.is-streak .result-stars,
.result-dialog.is-streak .result-watts,
.result-dialog.is-streak .result-balance,
.result-dialog.is-streak .result-meta,
.result-dialog.is-streak .result-accuracy,
.result-dialog.is-streak .result-answer {
  display: none;
}

.result-streak-value {
  margin: 4px 0 2px;
  font-size: clamp(3.4rem, 14vw, 4.5rem);
  font-weight: 750;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--accent);
}

.result-dialog.is-streak .result-kind {
  color: var(--accent-strong);
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.72rem;
}

.result-dialog.is-streak .result-title {
  margin-top: 6px;
  font-size: 1.35rem;
}

.result-streak-sub {
  margin: 8px 0 18px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.35;
}

.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(--chaos-coral-dim);
  color: var(--chaos-coral-strong);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.result-standard-gap {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(91, 107, 132, 0.12);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 620;
  letter-spacing: 0.01em;
}

.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;
}

#settings-backdrop.is-overlay-elevated {
  z-index: 250;
}

#settings.is-overlay-elevated {
  z-index: 251;
}

#session-backdrop.is-overlay-elevated {
  z-index: 250;
}

.session-sheet.is-overlay-elevated {
  z-index: 251;
}

.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,
#watts-backdrop {
  z-index: 45;
}

.store-dialog,
.account-dialog,
.stats-dialog,
.watts-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);
}

.watts-dialog {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.watts-dialog.hidden {
  display: none;
}

.watts-balance {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.watts-balance-glyph {
  flex: 0 0 auto;
}

.watts-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.watts-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--text);
}

.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-tiers {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin: 0 0 14px;
}

.store-tier-tab {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  height: 34px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.store-tier-tab:hover:not(:disabled) {
  border-color: rgba(99, 91, 255, 0.4);
  color: var(--text);
}

.store-tier-tab.is-selected {
  border-color: rgba(99, 91, 255, 0.55);
  background: var(--accent-dim);
  color: var(--accent);
}

.store-tier-tab.is-active-build:not(.is-selected) {
  border-color: rgba(99, 91, 255, 0.3);
  color: var(--text);
}

.store-tier-tab.is-complete {
  border-color: rgba(10, 122, 82, 0.35);
  color: var(--good);
}

.store-tier-tab.is-complete.is-selected {
  background: var(--good-dim);
  border-color: rgba(10, 122, 82, 0.45);
}

.store-tier-tab.is-locked,
.store-tier-tab:disabled {
  opacity: 0.45;
  cursor: default;
}

.store-tier-heading {
  margin: 0 0 10px;
}

.store-tier-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.store-tier-blurb {
  margin: 3px 0 0;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--muted);
}

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

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

.store-bench {
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.station-scene {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 17 / 10;
}

.station-scene-frame,
.station-scene-part {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.station-scene-frame {
  stroke: var(--border-strong);
  stroke-width: 1.2;
}

.station-scene-part {
  transform-box: fill-box;
  transform-origin: center;
  transition: stroke 0.2s ease, opacity 0.2s ease;
}

.station-scene-part.is-owned {
  stroke: var(--accent);
  stroke-width: 2;
  opacity: 1;
}

.station-scene-part.is-ghost {
  stroke: var(--muted);
  stroke-width: 1.2;
  stroke-dasharray: 3 3;
  opacity: 0.28;
}

.store-bench.is-complete .station-scene-part.is-owned {
  stroke: var(--good);
}

.store-event {
  margin: 0 0 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1.5px solid rgba(196, 120, 12, 0.4);
  background: rgba(196, 120, 12, 0.1);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.store-event.hidden {
  display: none;
}

.store-event-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

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

.store-event-btn {
  align-self: flex-start;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: none;
  background: #c4780c;
  color: #ffffff;
  cursor: pointer;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.store-event-btn:hover:not(:disabled) {
  background: #a86408;
}

.store-event-btn:disabled {
  cursor: default;
  opacity: 0.55;
}

.store-start-next {
  width: 100%;
  margin-top: 12px;
}

.store-start-next.hidden {
  display: none;
}

.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 .station-scene-part.is-owned {
  animation: bench-pop 0.5s ease both;
}

.store-bench.just-completed .station-scene-part:nth-of-type(2) { animation-delay: 0.05s; }
.store-bench.just-completed .station-scene-part:nth-of-type(3) { animation-delay: 0.1s; }
.store-bench.just-completed .station-scene-part:nth-of-type(4) { animation-delay: 0.15s; }
.store-bench.just-completed .station-scene-part:nth-of-type(5) { animation-delay: 0.2s; }
.store-bench.just-completed .station-scene-part:nth-of-type(6) { animation-delay: 0.25s; }
.store-bench.just-completed .station-scene-part:nth-of-type(7) { animation-delay: 0.3s; }
.store-bench.just-completed .station-scene-part:nth-of-type(8) { animation-delay: 0.35s; }
.store-bench.just-completed .station-scene-part:nth-of-type(9) { animation-delay: 0.4s; }

@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) {
  .station-scene-part,
  .store-bench.just-completed .station-scene-part.is-owned {
    transition: none;
    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);
}

.session-gap-standard-row {
  margin-top: -6px;
  margin-bottom: 14px;
}

.session-gap-standard-row .ghost-btn.compact {
  flex-shrink: 0;
  min-width: 72px;
}

.session-gap-locked-note {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--muted);
  font-weight: 450;
  white-space: nowrap;
  flex: 0 0 auto;
}

.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-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.setting-label-row > span:first-child {
  flex: 0 1 auto;
  min-width: 0;
}

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

.setting.setting-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.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;
}

.setting-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
}

.setting-select:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.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;
  }

  .slot.space {
    width: 1.25rem;
    min-width: 1.25rem;
  }
}

@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;
  }
}

/* —— App footer —— */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  padding: 4px 4px 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.footer-link {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 650;
  padding: 4px 2px;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
}

.footer-link:hover,
.footer-link:focus-visible {
  color: var(--accent);
  text-decoration-color: currentColor;
}

.footer-sep {
  opacity: 0.55;
}

.footer-note {
  font-weight: 500;
}

/* —— About dialog —— */
.about-dialog {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}

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

.about-card {
  width: min(440px, 100%);
  max-height: min(82vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 0;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.about-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.about-body {
  padding: 14px 18px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.about-body p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--text);
}

.about-body h3 {
  margin: 6px 0 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.about-body a {
  color: var(--accent);
}

.about-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}

#about-backdrop {
  z-index: 55;
}

/* —— First-visit / replay tour (swipe-card v2) —— */
.tour-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(48px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}

.tour-root:not(.hidden) {
  pointer-events: auto;
}

.tour-scrim {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--text) 48%, transparent);
  pointer-events: auto;
}

.tour-skip {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  z-index: 102;
  margin: 0;
  padding: 6px 12px;
  border: 1px solid color-mix(in srgb, #8b85ff 28%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-elevated) 14%, transparent);
  color: var(--bg-elevated);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  cursor: pointer;
  pointer-events: auto;
}

.tour-skip:hover {
  background: color-mix(in srgb, var(--bg-elevated) 22%, transparent);
}

.tour-card {
  position: relative;
  z-index: 101;
  width: min(296px, calc(100vw - 32px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  max-height: calc(100vh - 80px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  padding: 16px 16px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  touch-action: manipulation;
  pointer-events: auto;
  cursor: pointer;
}

@media (min-width: 768px) {
  .tour-card {
    width: min(460px, calc(100vw - 48px));
  }
}

.tour-visual {
  flex: 0 0 auto;
}

.tour-title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tour-body {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--text);
}

.tour-footnote {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 650;
  color: var(--muted);
}

.tour-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 2px;
}

.tour-progress {
  font-size: 0.6875rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.tour-dots {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tour-dot {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 22%, var(--border));
  transition: width 0.15s ease, background 0.15s ease;
}

.tour-dot.is-active {
  width: 18px;
  background: var(--accent);
}

.tour-hint {
  margin: 0;
  margin-top: 2px;
  font-size: 0.6875rem;
  text-align: center;
  color: var(--muted);
}

body.is-touring {
  overflow: hidden;
}

/* Tour card visuals */
.tour-visual-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tour-visual-stack--start {
  align-items: center;
}

.tour-visual-mascot {
  display: block;
  width: auto;
  height: 72px;
  max-width: 100%;
  margin: 0 auto;
  object-fit: contain;
  object-position: center bottom;
}

.tour-visual-mascot--welcome {
  position: relative;
  z-index: 1;
  height: 72px;
  margin-bottom: -4px;
  filter: drop-shadow(0 6px 14px color-mix(in srgb, var(--accent-strong) 35%, transparent));
}

.tour-visual-mascot--learn {
  height: 64px;
  flex-shrink: 0;
  margin-left: auto;
}

.tour-visual-mascot--qso {
  height: 58px;
}

.tour-visual-welcome {
  height: 168px;
  border-radius: 14px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--accent-ring);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 12px;
  gap: 2px;
}

.tour-visual-welcome__gradient {
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, #8b85ff 0%, var(--accent) 52%, var(--accent-strong) 100%);
}

.tour-visual-welcome__shine {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 90% 65% at 50% 8%, color-mix(in srgb, white 22%, transparent), transparent 62%);
}

.tour-visual-welcome__depth {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--accent-strong) 16%, transparent);
}

.tour-visual-welcome__tagline {
  position: relative;
  z-index: 1;
  font-size: 0.8125rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.05em;
  text-align: center;
  text-shadow: 0 1px 10px color-mix(in srgb, var(--accent-strong) 50%, transparent);
}

.tour-visual-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.tour-visual-modes__cell {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 8px 10px;
}

.tour-visual-modes__label {
  display: block;
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--accent);
}

.tour-visual-modes__items {
  display: block;
  margin-top: 2px;
  font-size: 0.625rem;
  line-height: 1.35;
  color: var(--muted);
}

.tour-visual-economy {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.tour-visual-economy__badge {
  flex: 1;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 1px 2px rgba(10, 37, 64, 0.06);
  font-size: 1.125rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text);
}

.tour-visual-economy__badge--watts {
  border-color: var(--accent-ring);
  background: var(--accent-dim);
  color: var(--accent);
}

.tour-visual-economy__icon {
  flex-shrink: 0;
  color: var(--accent);
}

.tour-visual-drill__controls {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.tour-visual-drill__play {
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
}

.tour-visual-drill__chip {
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 0.75rem;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
}

.tour-visual-drill__slots {
  display: flex;
  gap: 6px;
}

.tour-visual-drill__slot {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--key-bg);
  color: var(--text);
  display: grid;
  place-items: center;
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-size: 0.875rem;
}

.tour-visual-drill__slot--enter {
  border: none;
  background: var(--accent);
  color: #fff;
}

.tour-visual-learn {
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 12px 14px;
}

.tour-visual-learn__chars {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.tour-visual-learn__char {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--muted);
  display: grid;
  place-items: center;
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-size: 0.75rem;
}

.tour-visual-learn__char.is-current {
  border-color: var(--accent-ring);
  background: var(--accent-dim);
  color: var(--accent);
}

.tour-visual-learn__char.is-next {
  border-style: dashed;
  background: var(--bg-elevated);
}

.tour-visual-learn__progress {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tour-visual-learn__meta {
  flex: 1;
  min-width: 0;
}

.tour-visual-learn__ring {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid var(--accent-dim);
  display: grid;
  place-items: center;
  position: relative;
  flex-shrink: 0;
  font-size: 1.0625rem;
  font-weight: 650;
  color: var(--accent);
}

.tour-visual-learn__ring::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  clip-path: polygon(50% 0%, 100% 0%, 100% 50%, 50% 50%);
}

.tour-visual-learn__meta-title {
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--text);
}

.tour-visual-learn__meta-sub {
  font-size: 0.6875rem;
  color: var(--muted);
}

.tour-visual-qso {
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 10px 12px;
}

.tour-visual-qso__header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.tour-visual-qso__header-hint {
  font-size: 0.625rem;
  font-weight: 650;
  color: var(--muted);
}

.tour-visual-qso__bubbles {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.tour-visual-qso__bubble {
  max-width: 72%;
  padding: 7px 12px;
  border-radius: 17px;
  font-size: 0.6875rem;
  line-height: 1.35;
}

.tour-visual-qso__bubble--them {
  align-self: flex-start;
  border-bottom-left-radius: 5px;
  background: var(--imsg-gray, #e9e9eb);
  color: var(--text);
}

.tour-visual-qso__bubble--you {
  align-self: flex-end;
  max-width: 58%;
  border-bottom-right-radius: 5px;
  background: var(--accent);
  color: #fff;
}

.tour-visual-qso__composer {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tour-visual-qso__composer-hint {
  font-size: 0.6875rem;
  color: var(--muted);
}

.tour-visual-qso__send {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.tour-visual-start {
  height: 72px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.9375rem;
}

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

/*
 * QSO conversation shell — mobile full-screen iMessage layout (CSS swap, no portaling).
 * Kill switch: localStorage.setItem("ditdit-messages-copy", "false") and reload.
 * Layout: ditdit-qso-layout = conversation | classic (also in ditdit.settings.v1).
 */
.qso-messages-copy-bar,
.qso-messages-copy-backdrop {
  display: none;
}

.qso-messages-copy-bar {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: calc(max(8px, env(safe-area-inset-top)) + 44px);
  padding: max(8px, env(safe-area-inset-top)) 12px 6px;
  background: #f2f2f7;
  border-bottom: 1px solid rgba(10, 37, 64, 0.08);
  position: relative;
  z-index: 5;
}

.qso-messages-copy-row {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 44px;
  width: 100%;
}

.qso-messages-copy-leading {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  padding-right: 118px;
}

.qso-messages-copy-trailing {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  z-index: 4;
  padding-left: 10px;
  background: #f2f2f7;
  box-shadow: -10px 0 14px -6px #f2f2f7;
}

.qso-messages-copy-status {
  margin: 0;
  padding: 0 2px 2px;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--muted);
  min-height: 0;
}

.qso-messages-copy-status:empty {
  display: none;
}

.qso-messages-copy-status.is-warn {
  color: #c93400;
}

.qso-messages-copy-status.is-good {
  color: #0d7a45;
}

.qso-messages-copy-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  padding: 7px 10px;
  border-radius: 10px;
  background: rgba(99, 91, 255, 0.1);
  color: var(--text);
  font-size: 0.72rem;
  line-height: 1.35;
}

.qso-messages-copy-hint-dismiss {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  margin: 0;
  padding: 4px 8px;
  border: none;
  border-radius: 999px;
  background: rgba(99, 91, 255, 0.18);
  color: var(--accent-strong);
  font: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

.qso-messages-copy-icon-btn {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(10, 37, 64, 0.08);
  color: var(--muted);
  font: inherit;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.qso-messages-copy-icon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.qso-messages-copy-icon-btn:active {
  transform: scale(0.94);
}

.qso-messages-copy-reply-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.qso-messages-copy-action {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  padding: 5px 9px;
  border: none;
  border-radius: 999px;
  background: rgba(10, 37, 64, 0.08);
  color: var(--text);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

.qso-messages-copy-action:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.qso-messages-copy-action:active {
  transform: scale(0.96);
}

.qso-messages-copy-transport {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 0;
  min-width: 0;
  min-height: 32px;
  overflow: hidden;
}

.qso-messages-copy-play {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(99, 91, 255, 0.14);
  color: var(--accent);
  cursor: pointer;
  touch-action: manipulation;
}

.qso-messages-copy-play:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.qso-messages-copy-play:active {
  transform: scale(0.94);
}

.qso-messages-copy-watts {
  flex-direction: row;
  gap: 3px;
  width: auto;
  min-width: 32px;
  height: 32px;
  padding: 0 8px 0 7px;
  border-radius: 999px;
  color: var(--text);
  font-size: 0.62rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

.qso-messages-copy-watts-glyph {
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  color: var(--accent);
}

.qso-messages-copy-watts-glyph.is-empty {
  opacity: 0.45;
}

.qso-messages-copy-seek {
  flex: 0 0 clamp(88px, 26vw, 124px);
  width: clamp(88px, 26vw, 124px);
  max-width: clamp(88px, 26vw, 124px);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.qso-messages-copy-seek-lock {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--chaos-coral-ring);
  border-radius: 50%;
  background: var(--chaos-coral-dim);
  color: var(--chaos-coral-strong);
  cursor: pointer;
  touch-action: manipulation;
}

.qso-messages-copy-seek-lock:disabled {
  cursor: default;
  opacity: 0.45;
}

.qso-messages-copy-seek-lock:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.qso-messages-copy-seek:not(.locked) .qso-messages-copy-seek-lock {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: var(--accent-ring);
  cursor: default;
  pointer-events: none;
}

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

.qso-messages-copy-seek:not(.locked) .qso-messages-copy-slider {
  height: 1.2rem;
  cursor: pointer;
  pointer-events: auto;
}

.qso-messages-copy-slider {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
}

.qso-messages-copy-backdrop {
  display: none !important;
}

.qso-paddle-mode-picker {
  position: relative;
  display: none;
  flex: 0 0 auto;
}

.qso-composer-shell .qso-paddle-mode-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 10px;
  font-size: 0.75rem;
  white-space: nowrap;
  box-sizing: border-box;
}

.qso-composer.is-awaiting-reply .qso-paddle-mode-picker {
  display: block;
}

.qso-composer.is-awaiting-reply .qso-composer-mode-toggle {
  display: flex;
}

.qso-paddle-mode-trigger {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}

.qso-paddle-mode-menu {
  display: none !important;
}

.qso-keyer-dialog {
  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)));
  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);
  z-index: 260;
}

#qso-keyer-backdrop {
  z-index: 259;
}

.qso-keyer-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.qso-keyer-option {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.qso-keyer-option.is-active,
.qso-keyer-option[aria-pressed="true"] {
  border-color: var(--accent-ring);
  background: var(--accent-dim);
  color: var(--accent-strong);
}

.qso-keyer-option:not(:disabled):active {
  transform: scale(0.99);
}

.qso-paddle-mode-option {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.qso-paddle-mode-option.is-active,
.qso-paddle-mode-option[aria-pressed="true"] {
  background: var(--accent-dim);
  color: var(--accent-strong);
}

.qso-quick-settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 240;
  background: rgba(0, 0, 0, 0.32);
}

.qso-quick-settings {
  position: fixed;
  left: 50%;
  top: 50%;
  bottom: auto;
  z-index: 241;
  transform: translate(-50%, -50%);
  width: min(100%, 26rem);
  max-height: min(78vh, 28rem, calc(100dvh - 48px - var(--safe-top) - var(--safe-bottom)));
  overflow: auto;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow);
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 640px) and (pointer: coarse) {
  .qso-quick-settings {
    top: auto;
    bottom: 0;
    transform: translateX(-50%);
    max-height: min(70vh, 28rem);
    padding: 14px 16px max(16px, env(safe-area-inset-bottom));
    border: none;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 32px rgba(10, 37, 64, 0.16);
  }
}

.qso-quick-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.qso-quick-settings-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.qso-quick-setting {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 12px;
  font-size: 0.84rem;
}

.qso-quick-setting-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.qso-quick-setting-chaos {
  margin-bottom: 12px;
}

.qso-quick-setting-title {
  font-weight: 600;
  line-height: 1.25;
}

.app-toggle {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  width: 44px;
  height: 26px;
}

.app-toggle input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.app-toggle input:disabled {
  cursor: default;
}

.app-toggle-track {
  position: relative;
  display: block;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: rgba(10, 37, 64, 0.12);
  transition: background 0.18s ease;
  pointer-events: none;
}

.app-toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(10, 37, 64, 0.18);
  transition: transform 0.18s ease;
}

.app-toggle input:checked + .app-toggle-track {
  background: linear-gradient(160deg, var(--accent), var(--accent-strong));
}

.app-toggle input:checked + .app-toggle-track::after {
  transform: translateX(18px);
}

.app-toggle input:disabled + .app-toggle-track {
  opacity: 0.55;
}

.app-toggle input:focus-visible + .app-toggle-track {
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.qso-quick-setting-chaos .app-toggle input:checked + .app-toggle-track {
  background: linear-gradient(160deg, #f8846a, var(--chaos-coral-strong));
}

.qso-quick-setting-chaos .app-toggle input:focus-visible + .app-toggle-track {
  box-shadow: 0 0 0 3px var(--chaos-coral-ring);
}

.qso-quick-settings-link {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  margin: 4px 0 0;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: rgba(10, 37, 64, 0.06);
  color: var(--accent-strong);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}

.qso-bubble.is-live-copy.is-copy-passed {
  animation: qso-copy-pass-pulse 0.55s ease-out;
}

.qso-bubble.is-live-copy.is-copy-failed {
  animation: qso-copy-fail-shake 0.45s ease-out;
}

@keyframes qso-copy-pass-pulse {
  0% { transform: scale(1); box-shadow: none; }
  35% { transform: scale(1.01); box-shadow: 0 0 0 3px rgba(13, 122, 69, 0.35); }
  100% { transform: scale(1); box-shadow: none; }
}

@keyframes qso-copy-fail-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

/* Mobile QSO landing card — shown before entering conversation shell */
.qso-start-card {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 20rem;
  margin: 0 auto;
  padding: 22px 20px 18px;
  border: none;
  border-radius: 20px;
  background: #fff;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.06),
    0 8px 24px rgba(0, 0, 0, 0.08);
  text-align: center;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.qso-start-card-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
  text-align: center;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease;
}

.qso-start-card-main:active {
  transform: scale(0.98);
}

.qso-start-card-main:focus-visible {
  outline: none;
  border-radius: 14px;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.qso-start-card-visual {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  padding: 4px 8px 6px;
}

.qso-start-card-bubble {
  height: 2rem;
  border-radius: 17px;
  opacity: 0.85;
}

.qso-start-card-bubble.is-station {
  align-self: flex-start;
  width: 58%;
  border-bottom-left-radius: 5px;
  background: var(--imsg-gray, #e5e5ea);
}

.qso-start-card-bubble.is-you {
  align-self: flex-end;
  width: 44%;
  border-bottom-right-radius: 5px;
  background: var(--imsg-you, #007aff);
  opacity: 0.75;
}

.qso-start-card-title {
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.qso-start-card-subtitle {
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--muted);
  max-width: 16rem;
}

/* Learn mobile landing card — same shell as QSO, ring glyph matches focus view */
.koch-start-card-visual {
  align-items: center;
  padding: 8px 8px 4px;
}

.koch-start-card-ring {
  width: min(148px, 68%);
  pointer-events: none;
}

.koch-start-card-ring .koch-flash-glyph {
  font-size: clamp(2rem, 10vw, 2.8rem);
  font-weight: 500;
}

@media (max-width: 640px), (pointer: coarse) {
  .app.is-qso-mobile-landing .stage .play-row,
  .app.is-qso-mobile-landing .stage .seek-block,
  .app.is-qso-mobile-landing .stage .stats-row,
  .app.is-qso-mobile-landing .stage .slots,
  .app.is-qso-mobile-landing .stage .slots-hint,
  .app.is-qso-mobile-landing .stage .custom-empty,
  .app.is-qso-mobile-landing .stage #koch-flash,
  .app.is-qso-mobile-landing .stage .almost-banner,
  .app.is-qso-mobile-landing .qso-stage {
    display: none !important;
  }

  .app.is-qso-mobile-landing .stage {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
    justify-content: center;
    padding: 20px 18px;
    background: #f2f2f7;
    border: none;
    box-shadow: none;
  }

  .app.is-qso-mobile-landing #qso-start-card {
    display: flex !important;
  }

  .app.is-qso-mobile-landing .koch-start-card {
    display: none !important;
  }

  .app.is-koch-mobile-landing .stage #koch-practice-dock,
  .app.is-koch-mobile-landing .stage .seek-block,
  .app.is-koch-mobile-landing .stage .stats-row,
  .app.is-koch-mobile-landing .stage .slots,
  .app.is-koch-mobile-landing .stage .slots-hint,
  .app.is-koch-mobile-landing .stage .custom-empty,
  .app.is-koch-mobile-landing .stage .almost-banner,
  .app.is-koch-mobile-landing .stage .status-line {
    display: none !important;
  }

  .app.is-koch-mobile-landing .stage {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
    justify-content: center;
    padding: 20px 18px;
    background: #f2f2f7;
    border: none;
    box-shadow: none;
  }

  .app.is-koch-mobile-landing .koch-start-card {
    display: flex !important;
  }

  /*
   * Static page layout — every practice mode shares this on mobile: the
   * practice card stretches down to meet the footer (so About / Created
   * by is always visible without scrolling) and the page itself cannot
   * scroll at all. Toggled via .is-static-stage on <html> and .app (see
   * syncStaticStageUi in app.js). QSO only gets this while the "Tap to
   * start QSO" landing card is showing — once the conversation starts,
   * QSO's own messages-copy mobile shell (.is-qso-mobile-landing /
   * .is-messages-copy) takes over layout duties instead.
   *
   * Whatever content genuinely varies in height (Word/Callsign/Sentence's
   * .slots character-box grid, Learn's #koch-flash, Listen's #listen-pad,
   * Send's #send-deck) is the one element per mode allowed to scroll
   * internally if it doesn't fit — everything around it (toolbar, seek
   * bar, Play/Session, head text) stays fully visible and pinned in
   * place, never pushed off-screen.
   */
  html.is-static-stage,
  html.is-static-stage body,
  html:has(.app.is-static-stage),
  body:has(.app.is-static-stage) {
    overflow: hidden;
    height: 100%;
    overscroll-behavior: none;
  }

  html.is-static-stage body,
  body:has(.app.is-static-stage) {
    position: fixed;
    inset: 0;
    width: 100%;
    touch-action: none;
  }

  .app.is-static-stage {
    height: 100%;
    max-height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .app.is-static-stage .topbar,
  .app.is-static-stage .mode-picker,
  .app.is-static-stage .koch-panel,
  .app.is-static-stage .custom-panel {
    flex: 0 0 auto;
  }

  /* Only one of these three sections is ever visible at a time (the
     others are .hidden/[hidden]), so it's safe to give all three the
     same "stretch to the footer" treatment unconditionally. */
  .app.is-static-stage .stage,
  .app.is-static-stage #listen-stage,
  .app.is-static-stage #send-stage {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    touch-action: none;
  }

  .app.is-static-stage .app-footer {
    flex: 0 0 auto;
  }

  .app.is-static-stage .stage:not(.is-koch) .slots {
    flex: 1 1 auto;
    min-height: 0;
    /* Override the default min(38vh, 280px) cap — here .slots is meant to
       grow and fill the card down to Check/Show answer, not stay pinned to
       a fraction of the viewport (which left a dead gap of bare card
       background between the buttons and the card's own bottom edge). */
    max-height: none;
    align-content: flex-start;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  .app.is-static-stage .stage.is-koch #koch-practice-dock {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    gap: 14px;
  }

  .app.is-static-stage .stage.is-koch #koch-practice-dock .play-row {
    flex: 0 0 auto;
  }

  .app.is-static-stage .stage.is-koch #koch-practice-dock #koch-flash {
    flex: 1 1 auto;
    min-height: 0;
    justify-content: flex-start;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  /* Learn's practice-card content needs a bit more headroom than the
     dedicated focus view gets, since the alphabet-progress meter/chip
     strip above it (hidden in focus view) is still on-screen here. */
  .app.is-static-stage .stage.is-koch .koch-flash-ring {
    width: min(180px, 58vw);
  }

  .app.is-static-stage .stage.is-koch .koch-flash-glyph {
    font-size: clamp(2rem, 8dvh, 4.2rem);
  }

  /* Listen (Keys): head text and the Session button stay pinned; the
     QWERTY reference pad — the one part whose footprint can get tight on
     short screens — is free to shrink and scroll internally. */
  .app.is-static-stage #listen-stage {
    display: flex;
    flex-direction: column;
  }

  .app.is-static-stage #listen-stage .listen-head,
  .app.is-static-stage #listen-stage .listen-actions {
    flex: 0 0 auto;
  }

  .app.is-static-stage #listen-stage #listen-pad {
    flex: 1 1 auto;
    min-height: 0;
    /* flex-start, not center: if this overflows and needs to scroll, a
       centered flex container can't be scrolled up far enough to reach
       the part of its content that overflowed above the fold — the
       browser clamps scrollTop at 0, so that portion is stuck clipped
       and unreachable. Starting from the top keeps all of it scrollable. */
    justify-content: flex-start;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  /* Send: head text, paddle-mode picker, decoded readout, and Clear/
     Session stay pinned; the key/paddle deck — the biggest, most
     touch-critical part — gets the remaining space and can scroll rather
     than get squeezed below a usable size. */
  .app.is-static-stage #send-stage {
    display: flex;
    flex-direction: column;
  }

  .app.is-static-stage #send-stage .send-head,
  .app.is-static-stage #send-stage #send-paddle-modes,
  .app.is-static-stage #send-stage #send-decoded,
  .app.is-static-stage #send-stage .send-actions {
    flex: 0 0 auto;
  }

  .app.is-static-stage #send-stage #send-deck {
    flex: 1 1 auto;
    min-height: 0;
    /* flex-start, not center — see #listen-pad above for why: a centered
       flex container can strand overflow above scrollTop 0, where it's
       clipped and permanently unreachable no matter how far you scroll. */
    justify-content: flex-start;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  /* The straight-key / paddle buttons' base min-height (min(32vh, 210px) /
     min(24vh, 165px)) is tall enough that on a short static-stage screen
     it can force #send-deck to overflow before the browser lets it shrink
     — so the button's own border and corners get clipped instead of
     cleanly scrolling into view. Give them a smaller, dvh-based floor
     here so they shrink to actually fit the space left over once the
     head/paddle-picker/decoded/actions rows above and below take theirs. */
  .app.is-static-stage #send-stage .send-key {
    min-height: clamp(64px, 20dvh, 210px);
  }

  .app.is-static-stage #send-stage .send-paddle {
    min-height: clamp(56px, 16dvh, 165px);
  }

  /*
   * Messages copy fills the viewport — lock page scroll so rubber-banding
   * does not reveal empty space below the iMessage-style overlay.
   */
  html.is-messages-copy,
  html.is-messages-copy body,
  html:has(.app.is-messages-copy),
  body:has(.app.is-messages-copy) {
    overflow: hidden;
    height: 100%;
    overscroll-behavior: none;
  }

  html.is-messages-copy body,
  body:has(.app.is-messages-copy) {
    padding: 0;
  }

  .app.is-messages-copy .topbar,
  .app.is-messages-copy .mode-picker,
  .app.is-messages-copy .koch-panel,
  .app.is-messages-copy .custom-panel,
  .app.is-messages-copy .app-footer {
    display: none !important;
  }

  .app.is-messages-copy .stage.is-messages-copy {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: none;
    margin: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    gap: 0;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    background: transparent;
    overflow: hidden;
    pointer-events: auto;
  }

  .app.is-messages-copy .stage.is-messages-copy .play-row,
  .app.is-messages-copy .stage.is-messages-copy .seek-block,
  .app.is-messages-copy .stage.is-messages-copy .stats-row,
  .app.is-messages-copy .stage.is-messages-copy .custom-empty,
  .app.is-messages-copy .stage.is-messages-copy #koch-flash,
  .app.is-messages-copy .stage.is-messages-copy .slots,
  .app.is-messages-copy .stage.is-messages-copy .slots-hint,
  .app.is-messages-copy .stage.is-messages-copy .almost-banner {
    display: none !important;
  }

  .app.is-messages-copy .qso-stage.is-messages-copy {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    display: flex !important;
    flex-direction: column;
    gap: 0;
    background: #f2f2f7;
    pointer-events: auto;
  }

  .app.is-messages-copy .qso-messages-copy-bar {
    display: flex !important;
    pointer-events: auto;
  }

  .app.is-messages-copy .qso-watt-flash {
    inset: 18% 12px 28%;
    z-index: 210;
  }

  .app.is-messages-copy .qso-messages-copy-backdrop {
    display: none !important;
  }

  .app.is-messages-copy .qso-reply .send-paddle-modes {
    display: none !important;
  }

  .app.is-messages-copy .qso-stage:not(.is-replying) .qso-reply-dock .qso-composer {
    display: none !important;
  }

  .app.is-messages-copy .qso-head,
  .app.is-messages-copy .qso-actions {
    display: none !important;
  }

  .app.is-messages-copy .qso-transcript {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    margin: 0;
    width: 100%;
    padding: 12px 16px 8px;
    border: none;
    background: #f2f2f7;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-padding-bottom: 8px;
    pointer-events: auto;
  }

  /*
   * Pin composer at the bottom of the copy overlay — override display:contents
   * so the dock is a flex sibling of the transcript. Same column through TX,
   * copy, and reply; keyboard offset lifts the whole dock without fixed layout.
   */
  .app.is-messages-copy .qso-reply-dock {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    width: 100%;
    margin-bottom: var(--qso-keyboard-offset, 0px);
    transition: margin-bottom 0.08s ease-out;
  }

  .app.is-messages-copy .qso-transcript + .qso-reply-dock .qso-composer {
    margin-top: 0;
  }

  .app.is-messages-copy .qso-reply-dock .qso-composer {
    order: 1;
    flex-shrink: 0;
    margin: 0;
    width: 100%;
    background: #f2f2f7;
    border: none;
    padding: 10px 12px max(10px, env(safe-area-inset-bottom, 0px));
    pointer-events: auto;
  }

  .app.is-messages-copy .qso-composer.is-awaiting-reply .qso-composer-shell {
    align-items: center;
    gap: 6px;
  }

  .app.is-messages-copy .qso-composer.is-awaiting-reply.is-has-text .qso-composer-shell {
    align-items: flex-end;
  }

  .app.is-messages-copy .qso-composer.is-awaiting-reply .qso-composer-bubble {
    border-radius: 20px;
    align-items: center;
    max-height: min(36vh, 11rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .app.is-messages-copy .qso-composer.is-awaiting-reply .qso-composer-field {
    padding: 8px 10px 8px 14px;
  }

  .app.is-messages-copy .qso-composer.is-awaiting-reply .qso-composer-display {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .app.is-messages-copy .qso-composer.is-awaiting-reply .qso-composer-backspace {
    margin: 0 8px 0 0;
    align-self: center;
  }

  .app.is-messages-copy .qso-composer.is-awaiting-reply.is-has-text .qso-composer-bubble {
    align-items: center;
    border-radius: 20px;
  }

  .app.is-messages-copy .qso-composer.is-awaiting-reply.is-has-text .qso-composer-field {
    align-items: flex-start;
    padding: 10px 10px 10px 14px;
  }

  .app.is-messages-copy .qso-composer.is-awaiting-reply.is-has-text .qso-composer-backspace {
    align-self: center;
    margin: 0 8px 0 0;
  }

  .app.is-messages-copy .qso-reply-dock .qso-actions {
    order: 0;
  }

  .app.is-messages-copy .qso-reply-dock .qso-reply {
    order: 2;
  }

  .app.is-messages-copy .qso-reply-dock.is-keyboard-docked {
    position: static;
    transform: none;
    left: auto;
    bottom: auto;
    z-index: auto;
    width: 100%;
    max-width: none;
    padding-left: 0;
    padding-right: 0;
    box-shadow: none;
    background: transparent;
  }

  .app.is-messages-copy .qso-reply-dock.is-keyboard-docked .qso-composer {
    border: none;
  }

  /* Hide paddles during copy; show during awaitReply keyer mode in the mobile shell. */
  .app.is-messages-copy .qso-reply {
    display: none !important;
  }

  .app.is-messages-copy .qso-stage.is-replying .qso-reply:not(.hidden) {
    display: flex !important;
  }

  .app.is-messages-copy .qso-stage.is-replying .qso-reply-dock.is-qso-keyboard-input .qso-reply {
    display: none !important;
  }

  /*
   * Reply keyer — composer stays at the copy-mode anchor (flush under the
   * transcript); paddles scroll in a band below without lifting the pill.
   */
  .app.is-messages-copy .qso-stage.is-replying .qso-reply-dock {
    min-height: 0;
  }

  .app.is-messages-copy .qso-stage.is-replying .qso-reply-dock .qso-composer {
    padding-bottom: 8px;
  }

  .app.is-messages-copy .qso-stage.is-replying .qso-reply-dock .qso-reply:not(.hidden) {
    flex: 0 1 auto;
    min-height: 0;
    max-height: min(40vh, 260px);
    margin: 0;
    padding: 0 12px max(8px, env(safe-area-inset-bottom));
    background: #f2f2f7;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .app.is-messages-copy .qso-stage.is-replying .qso-reply-dock .qso-reply:not(.hidden) .send-key {
    min-height: min(18vh, 120px);
  }

  .app.is-messages-copy .qso-stage.is-replying .qso-reply-dock .qso-reply:not(.hidden) .send-paddle {
    min-height: min(14vh, 100px);
  }

  /* TX + copy: safe-area inset on the inactive composer pill only. */
  .app.is-messages-copy .qso-stage:not(.is-replying) .qso-reply-dock .qso-composer {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .qso-stage.is-messages-copy-minimized .qso-bubble.is-copy-reenter {
    cursor: pointer;
  }

  .qso-stage.is-messages-copy-minimized .qso-composer.is-inactive {
    cursor: pointer;
  }

  /*
   * QSO reply dock — iMessage-style composer pinned above the iOS keyboard.
   * Transcript scrolls independently; composer + keyer stay in the visible
   * viewport as the keyboard opens and closes (visualViewport offset in JS).
   */
  .stage.is-qso.is-qso-keyboard-dock {
    min-height: 0;
  }

  .qso-stage.is-keyboard-docked {
    flex: 1 1 auto;
    min-height: 0;
  }

  .qso-stage.is-keyboard-docked .qso-transcript {
    flex: 1 1 auto;
    min-height: 0;
    max-height: var(--qso-transcript-max-height, none);
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
    scroll-padding-bottom: 8px;
  }

  /* Same bounded transcript scroll when awaitReply keyboard dock is active in copy mode. */
  .app.is-messages-copy .qso-stage.is-keyboard-docked .qso-transcript {
    flex: 1 1 auto;
    min-height: 0;
    max-height: var(--qso-transcript-max-height, none);
  }

  .qso-reply-dock.is-keyboard-docked {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(var(--qso-keyboard-offset, 0px) + env(safe-area-inset-bottom, 0px));
    z-index: 6;
    width: min(720px, 100%);
    max-width: 100%;
    padding-left: calc(14px + env(safe-area-inset-left, 0px));
    padding-right: calc(14px + env(safe-area-inset-right, 0px));
    box-sizing: border-box;
    background: var(--bg-elevated);
    box-shadow: 0 -1px 0 var(--border);
    transition: bottom 0.08s ease-out;
  }

  .qso-reply-dock.is-keyboard-docked .qso-composer {
    order: 1;
    flex-shrink: 0;
    margin: 0;
    width: 100%;
    margin-top: 0;
    border-top: 1px solid rgba(10, 37, 64, 0.08);
    border-bottom: none;
  }

  .qso-reply-dock.is-keyboard-docked .qso-reply {
    order: 2;
    flex-shrink: 0;
    gap: 8px;
  }

  .qso-reply-dock.is-keyboard-docked .qso-actions {
    order: 0;
    position: static;
    flex-shrink: 0;
    padding: 6px 0 2px;
    background: transparent;
    box-shadow: none;
    border-top: none;
  }

  .qso-reply-dock.is-keyboard-docked .send-key {
    min-height: min(22vh, 140px);
    padding: 14px 12px;
  }

  .qso-reply-dock.is-keyboard-docked .send-paddle {
    min-height: min(18vh, 120px);
    padding: 12px;
  }

  /* awaitReply mobile — keyboard vs keyer input toggle on composer bar. */
  .qso-reply-dock.is-qso-keyboard-input.is-keyboard-docked .qso-reply {
    display: none !important;
  }

  .qso-reply-dock.is-qso-keyer-input.is-keyboard-docked .qso-composer-field {
    cursor: default;
  }

  /*
   * Learn (Koch) mobile focus view — tap #koch-flash-glyph to bring the
   * play-session card (#koch-practice-dock, wrapping .play-row + #koch-flash)
   * into a dedicated full-screen view docked to the on-screen keyboard.
   * Deliberately does not touch #koch-panel (the alphabet-progress
   * meter/chip strip) at all — it stays on the normal page. Same idiom as
   * QSO's is-messages-copy shell above, but its own independent class so
   * the two full-screen shells never interfere with each other.
   */
  html.is-koch-focus,
  html.is-koch-focus body,
  html:has(.app.is-koch-focus),
  body:has(.app.is-koch-focus) {
    overflow: hidden;
    height: 100%;
    overscroll-behavior: none;
  }

  /*
   * Belt-and-suspenders scroll lock: overflow: hidden alone is not always
   * enough on iOS Safari once the soft keyboard is involved — a focused
   * input can still pan the whole page out from under fixed-position
   * content. Pinning the body itself in place is the standard, more
   * forceful iOS scroll-lock idiom.
   */
  html.is-koch-focus body,
  body:has(.app.is-koch-focus) {
    position: fixed;
    inset: 0;
    width: 100%;
    padding: 0;
    touch-action: none;
  }

  .app.is-koch-focus .topbar,
  .app.is-koch-focus .mode-picker,
  .app.is-koch-focus #koch-panel,
  .app.is-koch-focus .custom-panel,
  .app.is-koch-focus .app-footer {
    display: none !important;
  }

  .app.is-koch-focus .stage.is-koch-focus {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: none;
    margin: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    gap: 0;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    background: var(--bg-elevated);
    overflow: hidden;
    touch-action: none;
    /* Counter iOS visualViewport pan while the soft keyboard is open. */
    transform: translateY(calc(-1 * var(--koch-focus-vv-top, 0px)));
  }

  .app.is-koch-focus .stage.is-koch-focus .seek-block,
  .app.is-koch-focus .stage.is-koch-focus .custom-empty,
  .app.is-koch-focus .stage.is-koch-focus .slots,
  .app.is-koch-focus .stage.is-koch-focus .slots-hint,
  .app.is-koch-focus .stage.is-koch-focus .almost-banner,
  .app.is-koch-focus .stage.is-koch-focus .status-line {
    display: none !important;
  }

  /*
   * Pinned to the TOP of the screen, deliberately not tracking the
   * keyboard at all. The soft keyboard only ever covers the bottom portion
   * of the screen, so as long as this card stays compact enough to live
   * in roughly the top half of a typical phone, it's guaranteed to stay
   * clear of the keyboard on its own — no measurement, no dvh-shrink
   * assumptions. (Real-device testing showed 100dvh does not reliably
   * shrink when the keyboard opens here, so the previous bottom-anchored
   * layout ended up hidden underneath the keyboard instead of docked
   * above it — top-pinning sidesteps that failure mode entirely.)
   *
   * No scrolling, ever: overflow is hidden (not auto), touch-action: none
   * blocks touch-drag scrolling outright, and every element in the column
   * below is allowed to shrink (min-height: 0 down the whole chain,
   * dvh-relative clamps instead of fixed floors) so the card always fits
   * comfortably instead of requiring — or even allowing — a scroll.
   */
  .app.is-koch-focus .stage.is-koch-focus #koch-practice-dock {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    gap: clamp(8px, 3dvh, 20px);
    padding: max(16px, env(safe-area-inset-top, 0px))
      calc(18px + env(safe-area-inset-right, 0px))
      calc(12px + env(safe-area-inset-bottom, 0px))
      calc(18px + env(safe-area-inset-left, 0px));
    overflow: hidden;
    touch-action: none;
  }

  .app.is-koch-focus .stage.is-koch-focus #koch-practice-dock .play-row {
    width: 100%;
    max-width: 420px;
    flex: 0 0 auto;
  }

  .app.is-koch-focus .stage.is-koch-focus #koch-practice-dock #koch-flash {
    width: 100%;
    flex: 0 1 auto;
    min-height: 0;
    gap: clamp(6px, 1.6dvh, 14px);
  }

  /* Only the square gets bigger in focus mode — Play/Session buttons and
     the rest of the card keep their normal size. Deliberately capped
     lower than the old bottom-anchored version: since the whole card now
     has to live statically in roughly the top half of the screen (see
     above), it needs real margin to spare even on a small phone with the
     keyboard's predictive-text bar included — sized to fit comfortably
     rather than maximized. */
  .app.is-koch-focus .stage.is-koch-focus .koch-flash-ring {
    width: min(200px, 64vw);
  }

  .app.is-koch-focus .stage.is-koch-focus .koch-flash-glyph {
    font-size: clamp(2.2rem, 9dvh, 4.8rem);
  }
}
