:root {
  color-scheme: light;
  --paper: #f7f5f0;
  --paper-raised: #fdfcfa;
  --paper-recessed: #efece4;
  --paper-glass: rgba(253, 252, 250, 0.88);
  --ink: #171512;
  --ink-soft: #3c3833;
  --ink-mute: #6d675e;
  --ink-faint: #5e5851;
  --hairline: #d9d4ca;
  --hairline-strong: #171512;
  --veil: rgba(247, 245, 240, 0.82);
  --panel: rgba(253, 252, 250, 0.92);
  --shadow: rgba(23, 21, 18, 0.12);
  --shadow-lg: 0 24px 64px rgba(23, 21, 18, 0.18);
  --accent-gold: #b47818;
  --radius-panel: 6px;
  --radius-control: 4px;
  --radius-inset: 2px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Cormorant Garamond", "Iowan Old Style", Palatino, Georgia, serif;
  --font-mono: "Courier Prime", "Courier New", Courier, monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #121110;
  --paper-raised: #211f1c;
  --paper-recessed: #302d28;
  --paper-glass: rgba(33, 31, 28, 0.96);
  --ink: #f4f0e8;
  --ink-soft: #e0dacf;
  --ink-mute: #bdb5a8;
  --ink-faint: #ada597;
  --hairline: #605b52;
  --hairline-strong: #f4f0e8;
  --veil: rgba(18, 17, 16, 0.84);
  --panel: rgba(33, 31, 28, 0.97);
  --shadow: rgba(0, 0, 0, 0.46);
  --shadow-lg: 0 28px 72px rgba(0, 0, 0, 0.65);
  --accent-gold: #f3c14b;
  --control-edge: #867f73;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-serif);
  font-weight: 500;
}

button,
canvas {
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: var(--font-mono);
}

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

.shell {
  position: relative;
  width: 100vw;
  height: 100svh;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  background: var(--paper);
  transition: background 260ms ease;
}

/* Plain paper keeps the playing field and menus visually quiet. */
.paper-grain { display: none; }

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Top Action Controls (Theme & How to Play) */
.top-nav-actions {
  position: absolute;
  top: 24px;
  right: max(28px, calc(50vw - 520px));
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* In-Game Masthead Header */
.game-masthead {
  position: absolute;
  top: 28px;
  left: max(32px, calc(50vw - 520px));
  z-index: 7;
  width: 290px;
  transition: opacity 260ms ease;
}

.shell.is-awaiting-start .game-masthead {
  opacity: 0;
  pointer-events: none;
}

.masthead-rules {
  display: grid;
  gap: 4px;
}

.masthead-rules span {
  display: block;
  border-top: 1.5px solid var(--hairline-strong);
}

.masthead-rules-bottom {
  margin-top: 10px;
}

.masthead-row {
  min-height: 54px;
  display: flex;
  align-items: center;
  padding: 8px 0 0;
}

.game-title-lockup {
  text-align: left;
}

.game-title-lockup h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 44px;
  font-weight: 600;
  line-height: 0.92;
  letter-spacing: -0.015em;
}

.game-title-lockup p {
  margin: 6px 0 0;
  color: var(--ink-mute);
  font-size: 13px;
  font-style: italic;
  line-height: 1.2;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--hairline);
  border-radius: 50%;
  background: var(--paper-glass);
  color: var(--ink-mute);
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition:
    color 150ms ease,
    border-color 150ms ease,
    background 220ms ease,
    transform 150ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  color: var(--ink);
  border-color: var(--ink);
  transform: translateY(-1px);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

/* Action Banner (for clears and combos) */
.action-banner {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 8;
  pointer-events: none;
  text-align: center;
  opacity: 0;
}

.action-banner.is-active {
  animation: banner-pop 900ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.action-banner-text {
  display: inline-block;
  padding: 8px 24px;
  font-family: var(--font-serif);
  font-size: 38px;
  font-weight: 600;
  font-style: italic;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--panel);
  border-top: 2px solid var(--hairline-strong);
  border-bottom: 2px solid var(--hairline-strong);
  box-shadow: 0 12px 36px var(--shadow);
  backdrop-filter: blur(12px);
}

@keyframes banner-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -40%) scale(0.9);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.04);
  }
  35% {
    transform: translate(-50%, -50%) scale(1);
  }
  75% {
    opacity: 1;
    transform: translate(-50%, -52%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -64%) scale(0.98);
  }
}

/* 360° Radar Mini-Map (Integrated into Left HUD Sidebar) */
.radar-panel {
  margin-top: 16px;
}

.radar-panel #radar {
  width: 100%;
  height: 62px;
  border: 1.5px solid var(--hairline-strong);
  border-radius: 4px;
  background: var(--paper-recessed);
  box-shadow: 0 4px 14px var(--shadow);
  display: block;
}

/* Dedicated Landing / Title Screen (Study Cover) */
.start-screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 80px 24px 48px;
  background: var(--veil);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  backdrop-filter: blur(8px);
  transition:
    opacity 320ms cubic-bezier(0.16, 1, 0.3, 1),
    visibility 320ms cubic-bezier(0.16, 1, 0.3, 1),
    background 260ms ease;
}

.start-screen.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.start-cover {
  position: relative;
  display: grid;
  justify-items: center;
  width: min(580px, calc(100vw - 48px));
  padding: 44px 48px 38px;
  border-top: 3px double var(--hairline-strong);
  border-bottom: 1.5px solid var(--hairline-strong);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  text-align: center;
  backdrop-filter: blur(16px);
  transition: background 260ms ease, transform 320ms cubic-bezier(0.16, 1, 0.3, 1);
  animation: cover-settle 600ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes cover-settle {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.cover-header {
  display: grid;
  justify-items: center;
  gap: 4px;
}

.cover-kicker,
.start-kicker,
.hud-heading,
.record-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.cover-rule {
  width: 64px;
  height: 1.5px;
  background: var(--hairline-strong);
  margin: 10px 0 12px;
}

.cover-header h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 78px;
  font-weight: 600;
  line-height: 0.92;
  letter-spacing: -0.015em;
}

.cover-subtitle {
  margin: 10px 0 0;
  color: var(--ink-mute);
  font-size: 18px;
  font-style: italic;
  line-height: 1.35;
  max-width: 480px;
}

/* High Score Card */
.cover-record {
  margin-top: 22px;
  padding: 10px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px dotted var(--hairline);
  background: var(--paper-recessed);
}

.record-label {
  font-size: 11px;
  letter-spacing: 0.16em;
}

.record-value {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* Controls Brief Grid */
.cover-controls-brief {
  margin-top: 24px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 22px;
  width: 100%;
  text-align: left;
  padding: 16px 20px;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  background: rgba(0, 0, 0, 0.015);
}

[data-theme="dark"] .cover-controls-brief {
  background: rgba(255, 255, 255, 0.015);
}

.control-key-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.keycap {
  display: inline-block;
  padding: 3px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--hairline);
  border-bottom: 2px solid var(--ink-mute);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.key-desc {
  color: var(--ink-mute);
  font-size: 13px;
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Cover Actions */
.cover-actions {
  margin-top: 26px;
  display: grid;
  justify-items: center;
  gap: 10px;
}

.start-button,
.state-actions button,
.guide-footer button {
  min-width: 200px;
  height: 52px;
  padding: 0 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1.5px solid var(--ink);
  border-radius: 0;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    color 150ms ease,
    background 150ms ease,
    transform 150ms ease,
    box-shadow 150ms ease;
}

.start-button:hover,
.start-button:focus-visible,
.state-actions .state-primary:hover,
.state-actions .state-primary:focus-visible,
.guide-footer button:hover,
.guide-footer button:focus-visible {
  background: transparent;
  color: var(--ink);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px var(--shadow);
}

.start-button:active,
.state-actions button:active,
.guide-footer button:active {
  transform: translateY(1px);
}

.start-button svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}



/* Audio Settings on Cover */
.start-audio-settings {
  margin-top: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 32px;
}

/* Cylinder Mode Selector */
.start-mode-setting {
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.mode-selector-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.mode-options {
  display: flex;
  border: 1px solid var(--hairline);
  background: var(--paper-recessed);
}

.mode-opt-btn {
  padding: 4px 12px;
  border: none;
  background: transparent;
  color: var(--ink-mute);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    background 140ms ease,
    color 140ms ease;
}

.mode-opt-btn:hover {
  color: var(--ink);
}

.mode-opt-btn.is-active {
  background: var(--ink);
  color: var(--paper);
}

/* SFX Segmented Pill Selector */
.sfx-selector {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sfx-selector-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.sfx-options {
  display: flex;
  border: 1px solid var(--hairline);
  background: var(--paper-recessed);
}

.sfx-opt-btn {
  padding: 3px 10px;
  border: none;
  background: transparent;
  color: var(--ink-mute);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    background 140ms ease,
    color 140ms ease;
}

.sfx-opt-btn:hover {
  color: var(--ink);
}

.sfx-opt-btn.is-active {
  background: var(--ink);
  color: var(--paper);
}

/* HUD Components */
.hud {
  position: absolute;
  top: 140px;
  z-index: 2;
  width: 200px;
  color: var(--ink);
  transition: opacity 220ms ease;
}

.hud-left {
  left: max(32px, calc(50vw - 520px));
}

.hud-right {
  right: max(32px, calc(50vw - 520px));
  display: grid;
  gap: 16px;
}

.brand {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 3px double var(--hairline-strong);
}

.audio-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.audio-toggle {
  width: 32px;
  height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--hairline);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink-mute);
  cursor: pointer;
  transition:
    background 150ms ease,
    border-color 150ms ease,
    color 150ms ease;
}

.audio-toggle:hover,
.audio-toggle:focus-visible,
.audio-toggle[aria-pressed="true"] {
  border-color: var(--ink);
  color: var(--ink);
}

.audio-toggle[aria-pressed="true"] {
  background: var(--paper-recessed);
}

.audio-toggle svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.speaker-wave,
.speaker-mute {
  fill: none;
}

.audio-toggle[aria-pressed="false"] .speaker-wave,
.audio-toggle[aria-pressed="true"] .speaker-mute {
  display: none;
}

/* In-HUD SFX 3-choice toggle badge */
.audio-toggle.sfx-toggle {
  width: auto;
  min-width: 58px;
  height: 28px;
  padding: 0 8px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.sfx-hud-label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink-mute);
  text-transform: uppercase;
}

.sfx-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: inherit;
  text-transform: uppercase;
}

.stat-grid {
  display: grid;
}

.stat {
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px 8px;
  border-bottom: 1px dotted var(--hairline);
}

.stat-best {
  border-bottom: 1px solid var(--hairline);
  background: rgba(0, 0, 0, 0.015);
}

[data-theme="dark"] .stat-best {
  background: rgba(255, 255, 255, 0.015);
}

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

.stat-combo strong {
  color: var(--accent-gold) !important;
}

.stat span,
.preview-header > span {
  color: var(--ink-mute);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.stat strong {
  min-width: 0;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* Previews (Hold & Next) */
.preview {
  padding: 10px 2px 0;
  border-top: 3px double var(--hairline-strong);
  transition: opacity 180ms ease;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.preview-tag {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

.preview.is-held-locked {
  opacity: 0.52;
}

.preview.is-held-locked .preview-tag::after {
  content: "HELD";
  padding: 1px 5px;
  border: 1px solid var(--hairline);
  background: var(--paper-recessed);
}

.preview canvas {
  width: 148px;
  height: auto;
  margin-top: 8px;
  display: block;
  border-bottom: 1px solid var(--hairline);
}

/* Hide in-game elements during title screen */
.shell.is-awaiting-start .hud,
.shell.is-awaiting-start .touch-controls,
.shell.is-awaiting-start .game-colophon {
  opacity: 0;
  pointer-events: none;
}

/* Guide Modal & State Panel */
.guide-modal,
.state-panel {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 80px 24px 64px;
  background: var(--veil);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  backdrop-filter: blur(8px);
  transition:
    opacity 240ms ease,
    visibility 240ms ease,
    background 240ms ease;
}

.state-panel {
  z-index: 30;
}

.guide-modal {
  z-index: 100;
}

.guide-modal.is-visible,
.state-panel.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.guide-modal-content,
.state-panel-content {
  position: relative;
  display: grid;
  justify-items: center;
  width: min(520px, calc(100vw - 48px));
  padding: 36px 42px 34px;
  border-top: 3px double var(--hairline-strong);
  border-bottom: 1.5px solid var(--hairline-strong);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  text-align: center;
  backdrop-filter: blur(16px);
  transition: background 260ms ease;
}

.guide-header h2,
.state-panel h2 {
  margin: 6px 0 0;
  font-family: var(--font-serif);
  font-size: 48px;
  font-weight: 600;
  line-height: 0.98;
  letter-spacing: -0.015em;
}

.guide-body {
  width: 100%;
  margin: 20px 0 24px;
  display: grid;
  gap: 20px;
  text-align: left;
}

.guide-section h3 {
  margin: 0 0 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.guide-table {
  display: grid;
  gap: 8px;
  font-size: 13px;
}

.guide-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 6px;
  border-bottom: 1px dotted var(--hairline);
}

.guide-row span:last-child {
  color: var(--ink-soft);
  font-size: 13px;
}

.guide-section p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-soft);
}

/* State Panel (Paused / Game Over) */
.state-panel p {
  min-height: 20px;
  margin: 10px 0 22px;
  color: var(--ink-mute);
  font-size: 18px;
  font-style: italic;
  line-height: 1.35;
}

.over-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 16px;
  width: 100%;
  margin-bottom: 24px;
  padding: 16px 18px;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  background: var(--paper-recessed);
  text-align: left;
}

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

.over-stat span {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.over-stat strong {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.state-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

.state-actions button {
  min-width: 130px;
}

.state-actions button:not(.state-primary) {
  background: transparent;
  color: var(--ink);
}

.state-actions button:not(.state-primary):hover,
.state-actions button:not(.state-primary):focus-visible {
  background: var(--ink);
  color: var(--paper);
}

.state-panel[data-mode="paused"] #tryAgainButton,
.state-panel[data-mode="paused"] #overStatsGrid,
.state-panel[data-mode="over"] #resumeButton,
.state-panel[data-mode="over"] #pauseRestartButton,
.state-panel[data-mode="error"] .state-actions {
  display: none;
}

/* Colophon Footer */
.game-colophon {
  position: absolute;
  left: max(32px, calc(50vw - 520px));
  bottom: 22px;
  z-index: 2;
  width: 200px;
  text-align: left;
  transition: opacity 220ms ease;
}

.game-colophon > span {
  display: block;
  border-top: 3px double var(--hairline-strong);
}

.game-colophon p {
  margin: 8px 0 0;
  color: var(--ink-mute);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* Touch Controls: Dual-Cluster Layout */
.touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 20;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 max(12px, env(safe-area-inset-left)) 0 max(12px, env(safe-area-inset-right));
  pointer-events: none;
  touch-action: none;
}

.touch-cluster {
  display: grid;
  gap: 6px;
  padding: 6px;
  border-top: 3px double var(--hairline-strong);
  border-bottom: 1.5px solid var(--hairline-strong);
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: 0 8px 24px var(--shadow);
  pointer-events: auto;
  touch-action: none;
}

.touch-cluster-left {
  grid-template-columns: repeat(2, 48px);
  grid-template-rows: repeat(2, 44px);
}

.touch-cluster-right {
  grid-template-columns: repeat(2, 48px);
  grid-template-rows: repeat(2, 44px);
}

.touch-btn {
  width: 100%;
  height: 100%;
  border: 1px solid var(--hairline);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.touch-btn span {
  display: block;
  font-family: var(--font-serif);
  font-size: 24px;
  line-height: 1;
}

.touch-btn-hold {
  grid-column: span 2;
}

.touch-btn-hold span {
  font-family: var(--font-mono) !important;
  font-size: 11px !important;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.touch-btn:active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
  transform: translateY(1px);
}

/* Quiet menus: one primary action, with secondary settings tucked away. */
.start-screen, .guide-modal, .state-panel {
  padding: 68px 20px 28px;
  overflow-y: auto;
  overscroll-behavior: contain;
  align-items: safe center;
}
.start-cover, .guide-modal-content, .state-panel-content {
  width: min(420px, calc(100vw - 40px));
  padding: 30px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-panel);
  box-shadow: 0 8px 24px var(--shadow);
}
.start-cover { grid-template-columns: minmax(0, 1fr); }
.start-cover > * { min-width: 0; max-width: 100%; }
.cover-kicker, .start-kicker { font-family: var(--font-ui); font-size: 11px; letter-spacing: 0.1em; }
.cover-rule, .guide-header .masthead-rules { display: none; }
.cover-header h2 { margin-top: 6px; font-size: 64px; }
.cover-subtitle { margin-top: 8px; font-family: var(--font-ui); font-size: 16px; font-style: normal; line-height: 1.5; }
.cover-record {
  margin-top: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  gap: 12px;
}
.record-label { font-family: var(--font-ui); font-size: 11px; letter-spacing: 0.08em; }
.record-value { font-size: 16px; }
.cover-actions { width: 100%; margin-top: 22px; gap: 12px; }
.start-button { width: 100%; min-width: 0; }
.start-button, .state-actions button, .guide-footer button {
  font-family: var(--font-ui); font-size: 15px; font-weight: 600;
  text-transform: none; letter-spacing: 0; border-radius: var(--radius-control); height: 48px;
}
.start-mode-setting { margin-top: 20px; gap: 8px; flex-direction: column; width: 100%; }
.mode-selector-label { display: none; }
.mode-options { width: 100%; padding: 3px; border-radius: var(--radius-control); }
.mode-opt-btn { flex: 1; min-height: 42px; border-radius: var(--radius-inset); font-family: var(--font-ui); font-size: 13px; font-weight: 500; text-transform: none; padding: 6px; letter-spacing: 0; }
.text-button, .menu-settings summary, .keyboard-guide summary {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 400;
  color: var(--ink-soft);
  cursor: pointer;
}
.text-button { padding: 10px 12px; min-height: 40px; border: 0; background: transparent; border-radius: var(--radius-control); }
.text-button:hover { background: var(--paper-recessed); }
#startGuideButton { margin-top: 16px; width: 100%; }
.menu-settings { width: 100%; margin-top: 12px; }
.menu-settings summary { padding: 10px; color: var(--ink-mute); }
.start-audio-settings { margin-top: 12px; flex-wrap: wrap; gap: 14px; padding: 10px 0; }
.start-audio-setting, .sfx-selector-label { font-family: var(--font-ui); font-size: 13px; text-transform: none; letter-spacing: 0; }
.sfx-opt-btn { min-height: 38px; font-family: var(--font-ui); font-size: 13px; font-weight: 500; text-transform: none; letter-spacing: 0; padding: 6px 10px; }
.sfx-options { border-radius: var(--radius-control); overflow: hidden; }
.guide-modal-content { text-align: left; justify-items: stretch; width: min(440px, calc(100vw - 40px)); }
.guide-header h2, .state-panel h2 { font-size: 38px; }
.guide-body { gap: 18px; margin: 24px 0; }
.guide-section h3 { font-family: var(--font-ui); font-size: 15px; font-weight: 600; text-transform: none; letter-spacing: 0; margin-bottom: 8px; }
.guide-section p { font-family: var(--font-ui); font-size: 15px; line-height: 1.6; }
.guide-section p + p { margin-top: 8px; }
.keyboard-guide { border-top: 1px solid var(--hairline); padding-top: 12px; }
.keyboard-guide summary { padding: 8px 0; }
.guide-table { margin-top: 14px; }
.guide-row { flex-wrap: wrap; gap: 6px 10px; }
.guide-row span:last-child { flex: 1 1 160px; font-family: var(--font-ui); font-size: 14px; }
.guide-footer button { width: 100%; min-width: 0; }
.touch-guide-note { display: none; }
.state-panel-content { --pause-button-gap: 12px; width: min(400px, calc(100vw - 40px)); padding: 32px; }
.state-panel .start-kicker { display: none; }
.state-panel p { margin: 12px 0 24px; font-family: var(--font-ui); font-size: 16px; font-style: normal; line-height: 1.5; }
.state-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--pause-button-gap) 8px; }
.state-actions button { min-width: 0; padding: 0 12px; }
.state-actions .state-primary { grid-column: 1 / -1; }
.state-panel[data-mode="over"] #returnTitleButton { grid-column: 1 / -1; }
.pause-settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: 100%; margin: 24px 0 var(--pause-button-gap); }
.pause-settings .text-button { background: var(--paper-recessed); padding: 10px 6px; min-height: 48px; }
.state-panel:not([data-mode="paused"]) .pause-settings { display: none; }
.over-stats-grid { padding: 14px 0; border: 0; background: transparent; }
.over-stat span { font-family: var(--font-ui); font-size: 12px; letter-spacing: 0; text-transform: none; }
.over-stat strong { font-size: 20px; }
.icon-button:disabled { opacity: 0.3; cursor: default; }
.shell.is-awaiting-start .hud,
.shell.is-awaiting-start .touch-controls,
.shell.is-awaiting-start .game-masthead { visibility: hidden; }

/* A single bottom dock; visual labels are small, tap targets stay comfortable. */
.touch-controls {
  left: 50%; right: auto; bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(460px, calc(100% - 24px));
  padding: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-panel);
  background: var(--paper-glass);
  backdrop-filter: blur(16px);
  box-shadow: 0 4px 12px var(--shadow);
  pointer-events: auto;
}
.touch-btn { height: 44px; border: 0; border-radius: var(--radius-control); background: var(--paper-recessed); }
.touch-btn span { font-family: system-ui, sans-serif; font-size: 22px; }
.touch-btn-word span { font-family: var(--font-mono); font-size: 10px; }
.touch-btn-drop { grid-column: span 2; background: var(--ink); color: var(--paper); }

.fatal-error {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: safe center; overflow: auto;
  padding: 24px; background: var(--paper);
}
.fatal-error[hidden] { display: none; }
.fatal-error p { font-size: 18px; line-height: 1.5; }
@media (pointer: coarse) {
  .touch-controls { display: grid; }
  .touch-guide-note { display: block; }
}
@media (max-width: 840px) and (min-width: 641px) {
  .game-masthead { top: 20px; left: 20px; width: 240px; }
  .game-title-lockup h1 { font-size: 32px; }
  .hud { top: 126px; width: 150px; }
  .hud-left { left: 20px; }
  .hud-right { right: 20px; }
  .stat strong { font-size: 22px; }
  .preview canvas { width: 112px; }
}
@media (max-width: 640px) {
  .shell { min-height: 0; }
  .paper-grain { opacity: 0.18; }
  .game-masthead { top: 16px; left: 20px; right: 130px; width: auto; }
  .masthead-rules, .game-title-lockup p { display: none; }
  .masthead-row { display: block; min-height: 0; padding: 0; }
  .game-title-lockup h1 { font-size: 26px; line-height: 32px; }
  .top-nav-actions { top: 12px; right: 14px; gap: 3px; }
  .icon-button { width: 36px; height: 36px; border: 0; background: transparent; }
  .icon-button svg { width: 16px; height: 16px; }
  .hud-left { top: 64px; left: 20px; right: 20px; width: auto; }
  .hud-left .brand, .stat-best, .radar-panel, .game-colophon { display: none; }
  .stat-grid { display: flex; width: 100%; gap: 28px; }
  .stat { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 0; border: 0; background: transparent; }
  .stat span { font-size: 8px; letter-spacing: 0.09em; }
  .stat strong { font-size: 16px; line-height: 1; }
  .hud-right { top: 114px; left: 20px; right: 20px; bottom: auto; width: auto; display: flex; justify-content: space-between; gap: 12px; pointer-events: none; }
  .hud-right .preview { display: flex; align-items: center; gap: 6px; }
  .preview-header { border: 0; padding: 0; }
  .preview-header > span { font-size: 8px; letter-spacing: 0.06em; }
  .preview-tag { display: none; }
  .hud-right .preview canvas { width: 44px; height: 32px; border: 0; margin: 0; }
  .hud-right #next { width: 132px; }
  .shell:not(.is-awaiting-start) #scene { top: 142px; bottom: 140px; height: calc(100% - 282px); }
  .touch-controls { display: grid; }
  .touch-guide-note { display: block; }
  .start-screen, .guide-modal, .state-panel { padding: 60px 16px 20px; }
  .start-cover, .guide-modal-content, .state-panel-content { width: min(380px, calc(100vw - 32px)); padding: 24px; border-radius: var(--radius-panel); }
  .cover-header h2 { font-size: 50px; }
  .cover-kicker { font-size: 11px; }
  .cover-subtitle { font-size: 15px; }
  .cover-record { margin-top: 18px; }
  .cover-actions { margin-top: 18px; }
    .start-mode-setting { margin-top: 16px; }
  .mode-opt-btn { min-height: 42px; font-size: 13px; }
  .guide-header h2, .state-panel h2 { font-size: 32px; }
  .action-banner { top: 160px; font-size: 14px; max-width: calc(100% - 40px); }
}
@media (max-height: 550px) and (min-width: 641px) {
  .game-masthead { top: 12px; }
  .hud { top: 100px; }
  .stat { padding: 5px 0; }
  .stat strong { font-size: 20px; }
  .hud-right { gap: 4px; width: 90px; }
  .hud-right .preview canvas { width: 64px; }
  .radar-panel, .game-colophon { display: none; }
  .touch-controls { width: min(600px, calc(100% - 32px)); grid-template-columns: repeat(7, minmax(0,1fr)); padding: 8px; }
  .touch-btn-drop { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.touch-btn:disabled { opacity: 0.4; cursor: default; }
@media (max-width: 640px) {
  .hud-left .stat-best { display: none; }
  .hud-right .preview { border: 0; padding: 0; }
  .action-banner-text { font-size: 20px; padding: 6px 14px; border: 0; border-radius: var(--radius-control); }
}
/* Keep modal changes crisp; overlapping fades obscure both sets of controls. */
.start-screen, .guide-modal, .state-panel,
.shell, .start-cover, .guide-modal-content, .state-panel-content { transition: none; }
.start-cover { animation: none; }
.shell.is-guide-open .state-panel { opacity: 0; visibility: hidden; }
@media (max-height: 550px) and (min-width: 641px) and (max-width: 1000px) {
  .game-masthead { left: 20px; top: 16px; width: 180px; }
  .game-title-lockup h1 { font-size: 26px; }
  .game-title-lockup p, .game-masthead .masthead-rules { display: none; }
  .masthead-row { min-height: 0; padding: 0; }
  .hud-left { top: 72px; left: 20px; width: 150px; }
  .hud-left .brand, .hud-left .stat-best { display: none; }
  .hud-right { top: 72px; right: 20px; width: 76px; }
  .hud-right .preview { border: 0; padding: 0; }
  .hud-right .preview canvas { width: 58px; margin-top: 0; border: 0; }
  .preview-header > span, .stat span { font-size: 9px; }
  .stat strong { font-size: 16px; }
  .touch-controls { display: grid; }
  .touch-guide-note { display: block; }
  .shell:not(.is-awaiting-start) #scene { top: 12px; bottom: 90px; height: calc(100% - 102px); }
}

/* Shared menu interactions: solid primary, soft secondary, one accessible focus ring. */
.start-button:is(:hover, :focus-visible),
.state-actions .state-primary:is(:hover, :focus-visible),
.guide-footer button:is(:hover, :focus-visible) {
  background: var(--ink-soft); color: var(--paper); transform: none; box-shadow: none;
}
.state-actions button:not(.state-primary) {
  border: 1px solid var(--hairline); background: var(--paper-recessed); color: var(--ink);
}
.state-actions button:not(.state-primary):is(:hover, :focus-visible) {
  background: var(--hairline); color: var(--ink); transform: none; box-shadow: none;
}
:is(.start-screen, .state-panel, .guide-modal) :focus-visible {
  outline: 1px solid var(--ink-mute); outline-offset: 3px;
}

/* Matching secondary menu controls and a restrained audio glyph family. */
#startGuideButton, .menu-settings summary {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 44px; padding: 10px 12px;
  border: 0; border-radius: var(--radius-control);
  background: var(--paper-recessed); color: var(--ink-soft);
  font-family: var(--font-ui); font-size: 14px; font-weight: 400;
}
#startGuideButton:hover, .menu-settings summary:hover { background: var(--hairline); }
.menu-settings summary { list-style: none; }
.menu-settings summary::-webkit-details-marker { display: none; }
.menu-settings summary::after {
  content: ""; width: 6px; height: 6px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}
.menu-settings[open] summary::after { transform: translateY(2px) rotate(225deg); }
.audio-glyph {
  display: block; flex: 0 0 auto; width: 18px; height: 18px;
  fill: none !important; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}
.pause-settings .text-button { display: flex; align-items: center; justify-content: center; gap: 10px; }
.start-audio-settings { margin-top: 16px; row-gap: 16px; }

/* Website navigation stays separate from the game's Main Menu action. */
.website-home-icon { text-decoration: none; }
.website-home-icon svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.website-home-link {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 44px; margin-top: 12px; padding: 8px;
  font: 13px var(--font-ui); color: var(--ink-mute);
  text-decoration: underline; text-decoration-color: var(--hairline);
  text-underline-offset: 3px; border-radius: var(--radius-control);
}
.website-home-link:hover { color: var(--ink); text-decoration-color: currentColor; }
.guide-footer { text-align: center; }
@media (max-width: 640px) {
  .game-masthead { right: 158px; }
}

/* The note is crossed out until its existing music control is enabled. */
#musicToggle[aria-pressed="true"] .music-off-mark,
#pauseMusicButton[aria-pressed="true"] .music-off-mark { display: none; }

/* All speaker glyphs follow the shared sound-effects toggle state. */
.sfx-off-mark { display: none; }
.shell:has(#sfxToggle[aria-pressed="false"]) .sfx-off-mark { display: inline; }
.shell:has(#sfxToggle[aria-pressed="false"]) .sfx-waves { display: none; }

/* Compact shared scores; the list stays collapsed until requested. */
.leaderboard table { width: 100%; margin-top: 14px; border-collapse: collapse; font: 13px var(--font-mono); text-align: left; }
.leaderboard th { color: var(--ink-mute); font: 11px var(--font-ui); padding: 5px 4px; }
.leaderboard td { padding: 5px 4px; }
.leaderboard td:first-child { color: var(--ink-mute); width: 48px; }
.leaderboard th:last-child, .leaderboard td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.leaderboard-status, .state-panel .leaderboard-status { min-height: 0; margin: 12px 0; font: 13px/1.45 var(--font-ui); color: var(--ink-mute); }
.leaderboard-status:empty { display: none; }
.score-entry { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin: 12px 0 20px; font: 13px var(--font-ui); }
.score-entry[hidden], .state-panel:not([data-mode="over"]) .score-entry-area { display: none; }
.score-entry input { width: 66px; min-height: 44px; padding: 8px; border: 1px solid var(--hairline); border-radius: var(--radius-control); background: var(--paper-raised); color: var(--ink); font: 16px var(--font-mono); text-align: center; }
.score-entry button { min-height: 44px; padding: 8px 12px; border: 1px solid var(--hairline); border-radius: var(--radius-control); background: var(--paper-recessed); color: var(--ink); font: 13px var(--font-ui); cursor: pointer; }
.score-entry button:disabled { opacity: .6; cursor: default; }

/* A quiet home link beneath the playing-field title. */
.masthead-home-link { justify-content: flex-start; min-height: 32px; margin: 2px 0 0; padding: 4px 0; font-size: 12px; }
@media (max-width: 640px) {
  .hud-left { top: 90px; }
  .hud-right { top: 140px; }
  .shell:not(.is-awaiting-start) #scene { top: 168px; height: calc(100% - 308px); }
}
@media (max-height: 550px) and (min-width: 641px) and (max-width: 1000px) {
  .hud-left { top: 90px; }
}

/* Dark surfaces retain their hierarchy without losing labels or control edges. */
:root[data-theme="dark"] :is(#startGuideButton, .menu-settings summary, .pause-settings .text-button, .mode-options, .sfx-options, .touch-btn:not(.touch-btn-drop), .score-entry input, .score-entry button, .state-actions button:not(.state-primary)) {
  border: 1px solid var(--control-edge); box-shadow: none;
}
:root[data-theme="dark"] .icon-button { color: var(--ink-soft); }
:root[data-theme="dark"] .website-home-link { text-decoration-color: var(--ink-faint); }
:root[data-theme="dark"] :is(.start-screen, .state-panel, .guide-modal) :focus-visible {
  outline: 2px solid var(--ink); outline-offset: 3px;
}
@media (max-width: 640px) {
  :root[data-theme="dark"] :is(.stat span, .preview-header > span) { font-size: 10px; letter-spacing: 0.04em; }
  :root[data-theme="dark"] .touch-btn-word span { font-size: 12px; }
}

/* Matching two- and three-position audio controls. */
.start-audio-settings { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; width: 100%; }
.audio-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px; width: 100%; padding: 3px; background: var(--paper-recessed); border: 1px solid var(--hairline); border-radius: var(--radius-control); overflow: visible; }
.music-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.audio-options .audio-choice { display: flex; align-items: center; justify-content: center; gap: 7px; min-width: 0; min-height: 44px; padding: 6px; border: 0; border-radius: var(--radius-inset); background: transparent; color: var(--ink-mute); font: 14px var(--font-ui); text-transform: none; letter-spacing: 0; cursor: pointer; }
.audio-options .audio-choice:hover { color: var(--ink); }
.audio-options .audio-choice[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.audio-options .audio-choice:focus-visible { outline-offset: -3px; outline-color: currentColor; }
:root[data-theme="dark"] .audio-options { border-color: var(--control-edge); }
