/* === theme tokens === */
:root {
  --wood: #3a241a;
  --wood-light: #5a3a2a;
  --brass: #b08d57;
  --brass-bright: #e6c180;
  --brass-dim: #7a5a2c;
  --brass-dark: #3a2a15;
  --plate-bg: #2a1c0d;
  --plate-stroke: #7a5a2c;
  --label-text-idle: #c9a672;
  --label-text-on-path: #ffe7a5;
  --node-on-path: #ffd17a;
  --node-current: #fff1c2;
  --node-error: #c0432a;
  --node-committed: #ffe79a;
  --edge-idle: rgba(70, 50, 25, 0.85);
  --edge-on-path: #f0c87a;
  --paper-bg-top: #f6edd8;
  --paper-bg-bottom: #eadfc3;
  --paper-text: #3a2a15;

  --serif: 'Cormorant Garamond', Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Width every game-screen element caps at. Bumps up at tablet and
     desktop sizes so the tree, paper tape, etc. all grow together. */
  --content-max-width: 28rem;
}

@media (min-width: 720px) {
  :root { --content-max-width: 38rem; }
}

@media (min-width: 1024px) {
  :root { --content-max-width: 46rem; }
}

/* === base reset === */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body,
#app {
  margin: 0;
  padding: 0;
  height: 100vh;
  height: 100dvh;
}

body {
  background-color: var(--wood);
  color: var(--brass);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#app {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

button {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* === screen layout === */
.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* === home screen === */
#home-screen {
  position: relative;
  align-items: center;
  justify-content: center;
  gap: 2.5rem;
  padding: 0 1.5rem;
}

.settings-gear {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 0.75rem);
  right: calc(env(safe-area-inset-right) + 0.75rem);
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--brass);
  opacity: 0.7;
  border-radius: 50%;
  background: rgba(176, 141, 87, 0.08);
  border: 1px solid rgba(176, 141, 87, 0.25);
  transition: opacity 160ms, transform 220ms ease-out, border-color 160ms;
}

.settings-gear:hover,
.settings-gear:focus {
  opacity: 1;
  border-color: var(--brass);
  outline: none;
}

.settings-gear:active {
  transform: rotate(40deg);
}

.nameplate {
  background: linear-gradient(180deg, #c9a672 0%, var(--brass) 45%, #8a6c3d 100%);
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.35),
    inset 0 2px 4px rgba(255, 220, 170, 0.35),
    0 8px 24px rgba(0, 0, 0, 0.5);
  padding: 1.25rem 2.5rem;
  border-radius: 0.125rem;
  border: none;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 80ms ease-out, box-shadow 80ms ease-out;
}

.nameplate:active {
  transform: translateY(3px);
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.4),
    inset 0 1px 2px rgba(255, 220, 170, 0.25),
    0 3px 10px rgba(0, 0, 0, 0.45);
}

.nameplate:focus-visible {
  outline: 2px solid var(--brass-bright);
  outline-offset: 4px;
}

.nameplate-text {
  margin: 0;
  font-family: var(--serif);
  font-size: 3rem;
  font-weight: 600;
  letter-spacing: 0.25em;
  color: var(--brass-dark);
  text-shadow:
    0 1px 0 rgba(255, 230, 190, 0.35),
    0 -1px 0 rgba(0, 0, 0, 0.4);
}

.play-button {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.3em;
  color: #1a0e05;
  padding: 0.75rem 2rem;
  border-radius: 0.125rem;
  background: linear-gradient(180deg, #d4b47f 0%, var(--brass) 55%, #8a6c3d 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 230, 190, 0.5),
    inset 0 -2px 4px rgba(0, 0, 0, 0.35),
    0 4px 10px rgba(0, 0, 0, 0.45);
  transition: transform 80ms ease-out, box-shadow 80ms ease-out;
}

.play-button:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 230, 190, 0.3),
    inset 0 -1px 2px rgba(0, 0, 0, 0.45),
    0 2px 4px rgba(0, 0, 0, 0.4);
}

/* Smaller play-button used as the "CHOOSE A MODE" home-screen action. */
.play-button-secondary {
  font-size: 1.05rem;
  letter-spacing: 0.22em;
  padding: 0.6rem 1.5rem;
}

.modes-link {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  letter-spacing: 0.18em;
  color: var(--brass);
  opacity: 0.75;
  padding: 0.4rem 0.8rem;
  margin-top: -0.5rem;
  transition: opacity 120ms;
}

.modes-link:hover,
.modes-link:active {
  opacity: 1;
}

/* === game screen === */
#game-screen {
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem 0.5rem;
}

.game-header {
  width: 100%;
  max-width: var(--content-max-width);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.back-button {
  font-family: var(--serif);
  font-size: 0.85rem;
  letter-spacing: 0.25em;
  color: #f1e1c0;
  background: rgba(176, 141, 87, 0.12);
  border: 1px solid rgba(176, 141, 87, 0.4);
  padding: 0.25rem 0.75rem;
  border-radius: 0.125rem;
}

.mode-label {
  font-family: var(--serif);
  font-size: 0.85rem;
  letter-spacing: 0.35em;
  color: #c9a672;
}

.header-spacer {
  width: 68px;
}

/* === modes screen === */
#modes-screen {
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem 1rem;
}

.modes-grid {
  width: 100%;
  max-width: var(--content-max-width);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.5rem 0;
  overflow-y: auto;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  padding: 0.85rem 1rem;
  border-radius: 4px;
  text-align: left;
  background: linear-gradient(180deg, #6b4a22 0%, #4a2f15 100%);
  border: 1px solid rgba(176, 141, 87, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 170, 0.18),
    inset 0 -2px 4px rgba(0, 0, 0, 0.35),
    0 4px 10px rgba(0, 0, 0, 0.4);
  transition: transform 80ms ease-out, box-shadow 80ms ease-out, border-color 120ms;
}

.mode-card:not(.disabled):hover,
.mode-card:not(.disabled):focus {
  border-color: var(--brass);
  outline: none;
}

.mode-card:not(.disabled):active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 170, 0.12),
    inset 0 -1px 2px rgba(0, 0, 0, 0.4),
    0 2px 4px rgba(0, 0, 0, 0.35);
}

.mode-card.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.mode-card-name {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--brass-bright);
}

.mode-card-desc {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.92rem;
  color: rgba(201, 166, 114, 0.78);
}

.mode-card-score {
  margin-top: 0.25rem;
  font-family: var(--serif);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--brass-bright);
  text-shadow: 0 0 6px rgba(255, 209, 122, 0.35);
}

/* === settings screen === */
#settings-screen {
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem 1rem;
}

.settings-list {
  width: 100%;
  max-width: var(--content-max-width);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.5rem 0 1rem;
  overflow-y: auto;
}

.settings-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.75rem 0.9rem;
  border-radius: 4px;
  background: linear-gradient(180deg, #6b4a22 0%, #4a2f15 100%);
  border: 1px solid rgba(176, 141, 87, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 170, 0.14),
    inset 0 -2px 4px rgba(0, 0, 0, 0.3),
    0 3px 8px rgba(0, 0, 0, 0.35);
}

.settings-row.locked {
  opacity: 0.45;
}

.settings-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.settings-row-label {
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--brass-bright);
}

.settings-row-lock {
  font-size: 1rem;
}

.settings-row-help {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.85rem;
  color: rgba(201, 166, 114, 0.75);
}

.settings-row-control {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.2rem;
}

.settings-option {
  font-family: var(--serif);
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  color: var(--brass);
  padding: 0.3rem 0.7rem;
  background: rgba(255, 220, 170, 0.05);
  border: 1px solid rgba(176, 141, 87, 0.3);
  border-radius: 3px;
  transition: background 120ms, color 120ms, border-color 120ms;
}

.settings-option:hover {
  border-color: var(--brass);
}

.settings-option.active {
  color: #1a0e05;
  background: linear-gradient(180deg, #d4b47f 0%, var(--brass) 100%);
  border-color: var(--brass-bright);
  box-shadow: inset 0 1px 0 rgba(255, 230, 190, 0.4);
}

.settings-about {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.85rem;
  color: rgba(201, 166, 114, 0.65);
  text-align: center;
  padding: 1rem 0.5rem 0;
  line-height: 1.5;
}

/* === listening status row === */
.listening-status {
  width: 100%;
  max-width: var(--content-max-width);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0.75rem;
  font-family: var(--serif);
  font-size: 1rem;
  letter-spacing: 0.12em;
  border: 1px solid rgba(176, 141, 87, 0.3);
  border-radius: 0.125rem;
  background: rgba(0, 0, 0, 0.18);
  font-style: italic;
  color: rgba(201, 166, 114, 0.78);
}

.listening-status strong {
  font-style: normal;
  font-weight: 600;
  color: var(--brass-bright);
  font-variant-numeric: tabular-nums;
  margin-left: 0.4em;
}

/* === replay button (listening mode) === */
.replay-button {
  font-family: var(--serif);
  font-size: 0.95rem;
  letter-spacing: 0.22em;
  color: var(--brass-bright);
  background: linear-gradient(180deg, rgba(176, 141, 87, 0.25) 0%, rgba(176, 141, 87, 0.1) 100%);
  border: 1px solid var(--brass);
  padding: 0.45rem 1.5rem;
  border-radius: 0.25rem;
  align-self: center;
  transition: transform 80ms ease-out, background 120ms;
}

.replay-button:hover,
.replay-button:focus {
  background: linear-gradient(180deg, rgba(176, 141, 87, 0.4) 0%, rgba(176, 141, 87, 0.18) 100%);
  outline: none;
}

.replay-button:active {
  transform: translateY(1px);
}

/* Word-display blanks for listening — show underscore as a slim mark */
.word-letter.hidden-letter {
  opacity: 0.55;
  letter-spacing: 0;
  color: var(--brass-dim);
}

/* === timed status row === */
.timed-status {
  width: 100%;
  max-width: var(--content-max-width);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0.75rem;
  font-family: var(--serif);
  font-size: 1.05rem;
  letter-spacing: 0.12em;
  border: 1px solid rgba(176, 141, 87, 0.3);
  border-radius: 0.125rem;
  background: rgba(0, 0, 0, 0.18);
}

.timed-clock {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--brass-bright);
}

.timed-progress {
  font-style: italic;
  font-size: 0.95rem;
  color: rgba(201, 166, 114, 0.82);
}

/* === results screen === */
#results-screen {
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
}

.results-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
  max-width: var(--content-max-width);
}

.results-headline {
  font-family: var(--serif);
  font-size: 4.5rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--brass-bright);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.results-new-high {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  letter-spacing: 0.3em;
  color: #fff1c2;
  text-shadow: 0 0 12px rgba(255, 209, 122, 0.7);
  animation: results-shimmer 2s ease-in-out infinite;
}

@keyframes results-shimmer {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}

.results-stats {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: center;
  font-family: var(--serif);
  font-size: 1.05rem;
  letter-spacing: 0.1em;
  color: var(--brass);
  margin-top: 0.5rem;
}

.results-stats strong {
  color: var(--brass-bright);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-left: 0.25rem;
}

.results-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

/* === practice mode === */
.practice-content {
  width: 100%;
  max-width: var(--content-max-width);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 1rem 0.25rem;
}

.practice-prompt {
  font-family: var(--serif);
  font-size: 5rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--brass-bright);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55);
  line-height: 1;
}

.practice-visualizer {
  position: relative;
  width: 100%;
  height: 3.25rem;
  border-radius: 0.25rem;
  overflow: hidden;
  background: linear-gradient(180deg, #1a1208 0%, #0e0904 100%);
  border: 1px solid var(--brass-dim);
  box-shadow:
    inset 0 1px 0 rgba(0, 0, 0, 0.5),
    inset 0 -1px 0 rgba(255, 220, 170, 0.08);
}

.visualizer-target-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(245, 176, 65, 0.22);
}

.visualizer-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0%;
  background: linear-gradient(90deg, #b08d57 0%, var(--brass-bright) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 230, 190, 0.35);
}

.visualizer-fill.active {
  /* During press: width is set by rAF in practice.js, no CSS transition. */
}

.visualizer-fill.settled {
  transition: opacity 240ms ease-out;
}

.visualizer-threshold {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--brass-bright);
  box-shadow: 0 0 6px rgba(255, 209, 122, 0.7);
}

.practice-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  font-family: var(--serif);
  letter-spacing: 0.15em;
  color: var(--brass);
}

.practice-result {
  font-size: 2rem;
  line-height: 1;
  min-width: 1.5rem;
  text-align: left;
  color: rgba(0, 0, 0, 0);   /* default invisible */
  transition: color 120ms;
}

.practice-result.success {
  color: #6ee7b7;
  text-shadow: 0 0 10px rgba(110, 231, 183, 0.6);
}

.practice-result.fail {
  color: #ef4444;
  text-shadow: 0 0 10px rgba(239, 68, 68, 0.55);
}

.practice-streak {
  font-style: italic;
  font-size: 0.95rem;
  color: rgba(201, 166, 114, 0.78);
}

/* === speed mode === */
.speed-content {
  width: 100%;
  max-width: var(--content-max-width);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.5rem 0 0.25rem;
}

.speed-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  font-family: var(--serif);
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  color: var(--brass);
  border: 1px solid rgba(176, 141, 87, 0.3);
  border-radius: 0.125rem;
  background: rgba(0, 0, 0, 0.18);
  font-style: italic;
}

.speed-status .speed-stage {
  font-style: normal;
  font-weight: 600;
  color: var(--brass-bright);
  letter-spacing: 0.18em;
}

.speed-status strong {
  font-style: normal;
  font-weight: 600;
  color: var(--brass-bright);
  font-variant-numeric: tabular-nums;
  margin: 0 0.25em;
}

.speed-countdown {
  width: 100%;
  height: 0.5rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
  border: 1px solid rgba(176, 141, 87, 0.25);
}

.speed-countdown-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--brass) 0%, var(--brass-bright) 100%);
  transition: none;
}

.speed-countdown-fill.active {
  /* width is driven by rAF in speedGrid.js, no CSS transition */
}

.speed-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  flex: 1;
  align-content: start;
  padding: 0.25rem;
  transition: opacity 200ms;
}

.speed-grid.inactive {
  opacity: 0.5;
  pointer-events: none;
}

/* === speed track (tier × stage progress) === */
.speed-track {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  width: 100%;
  max-width: var(--content-max-width);
  padding: 0.5rem 0.4rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(176, 141, 87, 0.25);
  border-radius: 0.25rem;
}

.speed-track-row {
  display: grid;
  grid-template-columns: 5.25rem 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.15rem 0.25rem;
}

.speed-track-row.locked .speed-track-label {
  opacity: 0.35;
}

.speed-track-row.active {
  background: rgba(176, 141, 87, 0.08);
  border-radius: 3px;
}

.speed-track-row.active .speed-track-label {
  color: var(--brass-bright);
}

.speed-track-label {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--brass);
}

.speed-track-cells {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 0.2rem;
}

.speed-track-cell {
  width: 100%;
  aspect-ratio: 1;
  position: relative;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(176, 141, 87, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  line-height: 1;
  color: rgba(176, 141, 87, 0.4);
  transition: background 160ms, border-color 160ms, color 160ms, transform 160ms;
}

.speed-track-cell.completed {
  background: linear-gradient(180deg, var(--brass-bright) 0%, var(--brass) 100%);
  border-color: var(--brass-bright);
  color: var(--brass-dark);
  box-shadow: 0 0 4px rgba(255, 209, 122, 0.45);
}
.speed-track-cell.completed::before {
  content: '★';
  font-size: 0.7rem;
}

.speed-track-cell.current {
  background: rgba(255, 220, 170, 0.18);
  border-color: var(--brass-bright);
  color: var(--brass-bright);
  transform: scale(1.15);
  box-shadow: 0 0 8px rgba(255, 209, 122, 0.55);
  animation: speed-track-current-pulse 1.4s ease-in-out infinite;
}
.speed-track-cell.current::before {
  content: '◆';
  font-size: 0.65rem;
}

@keyframes speed-track-current-pulse {
  0%, 100% { box-shadow: 0 0 8px rgba(255, 209, 122, 0.55); }
  50%      { box-shadow: 0 0 14px rgba(255, 209, 122, 0.85); }
}

/* === dim letters that aren't part of the active tier === */
.speed-letter.off-tier {
  opacity: 0.35;
}
.speed-letter.off-tier .speed-letter-char,
.speed-letter.off-tier .speed-letter-code {
  color: var(--brass-dim);
}

#speed-start-button {
  align-self: center;
  margin: 0.25rem 0;
}

.speed-letter {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.45rem 0.75rem;
  background: linear-gradient(180deg, #6b4a22 0%, #4a2f15 100%);
  border: 1px solid rgba(176, 141, 87, 0.45);
  border-radius: 0.25rem;
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 170, 0.18),
    0 2px 6px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 80ms, background 120ms, border-color 120ms, color 120ms;
}

.speed-letter-char {
  font-family: var(--serif);
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--brass-bright);
  flex-shrink: 0;
}

.speed-letter-code {
  font-family: var(--mono);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  color: var(--brass-bright);
  font-variant-numeric: tabular-nums;
}

.speed-letter:hover,
.speed-letter:focus {
  border-color: var(--brass);
  outline: none;
}

.speed-letter:active {
  transform: translateY(2px);
}

.speed-letter.correct {
  background: linear-gradient(180deg, #6ee7b7 0%, #4ca97a 100%);
  border-color: var(--node-committed);
  animation: speed-flash-pulse 320ms ease-out;
}
.speed-letter.correct .speed-letter-char,
.speed-letter.correct .speed-letter-code {
  color: #1a2c20;
}

.speed-letter.wrong {
  background: linear-gradient(180deg, #ef4444 0%, #a02828 100%);
  border-color: var(--node-error);
  animation: speed-flash-pulse 320ms ease-out;
}
.speed-letter.wrong .speed-letter-char,
.speed-letter.wrong .speed-letter-code {
  color: #fff;
}

@keyframes speed-flash-pulse {
  0%   { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* === debug panel === */
.debug-panel {
  width: 100%;
  max-width: var(--content-max-width);
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(176, 141, 87, 0.3);
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--brass);
}

.debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
  letter-spacing: 0.15em;
  color: rgba(201, 166, 114, 0.65);
  font-size: 0.7rem;
  text-transform: uppercase;
}

.debug-list {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.debug-item {
  display: grid;
  grid-template-columns: 3rem 4rem auto;
  gap: 0.5rem;
  font-variant-numeric: tabular-nums;
}

.debug-item .debug-symbol {
  letter-spacing: 0.1em;
}

.debug-item.debug-clear {
  color: #6ee7b7;
}

.debug-item.debug-mild {
  color: #f5b041;
}

.debug-item.debug-borderline {
  color: #ef4444;
}

.debug-item .debug-margin {
  color: rgba(201, 166, 114, 0.6);
}

/* === word display === */
.word-display {
  width: 100%;
  max-width: var(--content-max-width);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.5rem;
  padding: 0.4rem 0.5rem;
}

.word-letter {
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--brass);
  opacity: 0.32;
  transition: opacity 220ms ease-out, color 220ms ease-out, text-shadow 220ms;
}

.word-letter.completed {
  opacity: 1;
  color: var(--brass-bright);
  text-shadow: 0 0 6px rgba(255, 209, 122, 0.45);
}

/* === paper tape === */
.paper-tape {
  width: 100%;
  max-width: var(--content-max-width);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  border: 1px solid rgba(176, 141, 87, 0.45);
  border-radius: 0.125rem;
  background: linear-gradient(180deg, var(--paper-bg-top) 0%, var(--paper-bg-bottom) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    inset 0 -2px 4px rgba(0, 0, 0, 0.15),
    0 6px 14px rgba(0, 0, 0, 0.45);
}

.tape-letters {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-align: right;
  font-family: var(--mono);
  font-size: 1.125rem;
  letter-spacing: 0.35em;
  color: var(--paper-text);
}

.tape-letters.empty {
  color: rgba(58, 42, 21, 0.4);
  letter-spacing: 0.15em;
}

.tape-current {
  margin-left: 1rem;
  min-width: 3rem;
  text-align: left;
  font-family: var(--mono);
  font-size: 1rem;
  letter-spacing: 0.1em;
  color: rgba(58, 42, 21, 0.25);
  transition: color 120ms;
}

.tape-current.active {
  color: #6b3f1c;
}

/* === tree container === */
.tree-container {
  position: relative;
  width: 100%;
  max-width: var(--content-max-width);
  /* Match the SVG viewBox aspect (160:110) so the brass border doesn't
     stretch past the actual tree art. With margin-top:auto removed from
     the key area, leftover space goes naturally below the key. */
  aspect-ratio: 16 / 11;
  border-radius: 6px;
  background: radial-gradient(ellipse at center, var(--brass-dark) 0%, #2a1d0d 60%, #1a1208 100%);
  box-shadow:
    inset 0 0 0 2px #1a1208,
    inset 0 0 0 4px var(--brass-dim),
    inset 0 0 22px rgba(0, 0, 0, 0.55),
    0 8px 22px rgba(0, 0, 0, 0.6);
  padding: 6px;
}

.tree-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.corner-bracket {
  position: absolute;
  width: 14px;
  height: 14px;
  border-color: #c9a672;
  border-style: solid;
  pointer-events: none;
  box-shadow: 0 0 4px rgba(201, 166, 114, 0.5);
}

.corner-bracket.tl { top: 4px; left: 4px; border-width: 2px 0 0 2px; border-radius: 4px 0 0 0; }
.corner-bracket.tr { top: 4px; right: 4px; border-width: 2px 2px 0 0; border-radius: 0 4px 0 0; }
.corner-bracket.bl { bottom: 4px; left: 4px; border-width: 0 0 2px 2px; border-radius: 0 0 0 4px; }
.corner-bracket.br { bottom: 4px; right: 4px; border-width: 0 2px 2px 0; border-radius: 0 0 4px 0; }

/* === SVG tree styles === */
.tree-edge {
  stroke: var(--edge-idle);
  stroke-width: 0.4;
  stroke-linecap: round;
  transition: stroke 120ms, stroke-width 120ms;
}

.tree-edge.on-path {
  stroke: var(--edge-on-path);
  stroke-width: 0.9;
}

.tree-edge.hint {
  stroke: #f5b041;
  stroke-width: 0.7;
  animation: hint-fade 240ms ease-out;
}

@keyframes hint-fade {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.tree-node {
  fill: url(#brass-fill);
  stroke: var(--brass-dark);
  stroke-width: 0.4;
  /* SVG transforms default origin to (0,0). fill-box anchors transforms
     to the element's own bbox so scale animations don't fly across. */
  transform-box: fill-box;
  transform-origin: center;
  transition: fill 120ms, stroke-width 120ms, opacity 220ms;
}

.tree-node.on-path {
  fill: var(--node-on-path);
  stroke-width: 0.55;
}

.tree-node.current {
  fill: var(--node-current);
  stroke-width: 0.9;
}

.tree-node.error {
  fill: var(--node-error);
  stroke-width: 0.7;
  animation: node-error-flash 320ms ease-out;
}

/* Pressed too fast: pressed dot when dash was expected. Same red as a
   generic mistake — distinguishable by context. */
.tree-node.error.too-fast {
  fill: var(--node-error);
}

/* Pressed too slow: held a dash when a dot was expected. Blue. */
.tree-node.error.too-slow {
  fill: #4a90e2;
}

.tree-node.committed {
  fill: var(--node-committed);
  stroke-width: 0.7;
  animation: node-commit-flash 320ms ease-out;
}

.tree-node.hint {
  fill: #f5b041;
  stroke-width: 0.6;
  animation: hint-fade 240ms ease-out;
}

@keyframes node-error-flash {
  0%   { transform: scale(1.5); }
  100% { transform: scale(1); }
}

@keyframes node-commit-flash {
  0%   { transform: scale(1.4); }
  100% { transform: scale(1); }
}

.tree-label-plate {
  fill: var(--plate-bg);
  stroke: var(--plate-stroke);
  stroke-width: 0.25;
  transition: opacity 220ms;
}

.tree-label-text {
  font-family: var(--serif);
  font-weight: 700;
  fill: var(--label-text-idle);
  text-anchor: middle;
  transition: fill 120ms, opacity 220ms;
}

.tree-label-text.on-path,
.tree-label-text.target {
  fill: var(--label-text-on-path);
}

/* Focus mode: dim everything not on the path to a letter in the current word. */
.tree-edge.dimmed,
.tree-node.dimmed,
.tree-label-plate.dimmed,
.tree-label-text.dimmed {
  opacity: 0.08;
}

/* Tappable mode (Listen · Letters / Listen · Words): each node group
   becomes a clickable surface. Hover/active states give an affordance. */
#tree-container.tappable .tree-svg {
  touch-action: manipulation;
}

#tree-container.tappable .tree-node-group {
  cursor: pointer;
}

@media (hover: hover) {
  #tree-container.tappable .tree-node-group:hover .tree-node {
    fill: var(--node-on-path);
    stroke-width: 0.6;
  }
  #tree-container.tappable .tree-node-group:hover .tree-label-text {
    fill: var(--label-text-on-path);
  }
}

#tree-container.tappable .tree-node-group:active .tree-node {
  fill: var(--node-current);
}


.tree-antenna-rect {
  fill: url(#brass-fill);
  stroke: var(--brass-dark);
  stroke-width: 0.5;
}

.tree-antenna-line {
  stroke: #c9a672;
  stroke-width: 0.6;
}

.tree-antenna-bulb {
  fill: url(#brass-fill-bright);
  stroke: var(--brass-dark);
  stroke-width: 0.3;
}

/* === telegraph key === */
.key-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0 0.5rem;
}

.telegraph-key {
  position: relative;
  width: 11rem;
  height: 11rem;
  border-radius: 50%;
  outline: none;
  background:
    radial-gradient(circle at 35% 30%, #a86c33 0%, #7a4920 50%, #4a2a12 100%);
  box-shadow:
    inset 0 3px 8px rgba(255, 210, 160, 0.45),
    inset 0 -8px 18px rgba(0, 0, 0, 0.55),
    inset 0 0 0 2px rgba(0, 0, 0, 0.35),
    0 12px 24px rgba(0, 0, 0, 0.6);
  transform: translateY(0);
  transition: transform 60ms ease-out, box-shadow 60ms ease-out;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.telegraph-key.pressing {
  transform: translateY(4px);
  box-shadow:
    inset 0 8px 18px rgba(0, 0, 0, 0.6),
    inset 0 -2px 6px rgba(255, 210, 160, 0.3),
    inset 0 0 0 2px rgba(0, 0, 0, 0.4),
    0 4px 10px rgba(0, 0, 0, 0.5);
}

.key-label {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--serif);
  font-size: 0.85rem;
  letter-spacing: 0.22em;
  white-space: nowrap;
  color: var(--brass-bright);
  opacity: 0.85;
  text-shadow:
    0 1px 0 rgba(0, 0, 0, 0.55),
    0 0 6px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.key-base {
  width: 13rem;
  height: 0.4rem;
  border-radius: 9999px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0) 70%);
  box-shadow: none;
}
