:root {
  /* This is a dark-only design (see docs/DESIGN.md); without this the
     browser falls back to light UA chrome — a bright native scrollbar
     cutting through the dusk-to-night gradient on any page tall enough
     to scroll (e.g. the phone layout). */
  color-scheme: dark;

  --bg-top: #2d1b4e;
  --bg-bottom: #0a0518;
  --surface-1: #1c1030;
  --surface-2: #2a1a45;
  --text: #f5ecff;
  --text-muted: #a996c9;
  --accent: #ff3ea5;
  --accent-support: #38e8ff;
  --success: #4ade80;
  --danger: #ff5470;

  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-6: 48px;
  --space-8: 64px;

  --radius: 12px;
  --radius-pill: 999px;

  --font-display: 'Orbitron', system-ui, sans-serif;
  --font-ui: 'Inter', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  color: var(--text);
  font-family: var(--font-ui);
  display: flex;
  flex-direction: column;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.04em;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(255, 62, 165, 0.35);
}

#wordmark-glyph {
  width: 40px;
  height: 40px;
  margin-right: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.text-link {
  color: var(--accent-support);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 160ms ease-out;
}

.text-link:hover {
  border-bottom-color: var(--accent-support);
}

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

.stage {
  flex: 1;
  display: flex;
  gap: var(--space-3);
  padding: 0 var(--space-4) var(--space-4);
}

.canvas-panel {
  position: relative;
  flex: 1 1 65%;
  min-height: 60vh;
  border-radius: var(--radius);
  background: var(--surface-1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  touch-action: none;
}

#epicycle-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: var(--space-2) var(--space-3);
  color: var(--text-muted);
  font-size: 1.1rem;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}

.stroke-message {
  position: absolute;
  bottom: var(--space-3);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius);
  background: rgba(10, 5, 24, 0.85);
  color: var(--danger);
  font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.control-rail {
  flex: 0 0 30%;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  border-radius: var(--radius);
  background: var(--surface-1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  padding: var(--space-3);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.control-group--row {
  flex-direction: row;
  gap: var(--space-2);
}

.preset-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.preset-group .button {
  flex: 1 1 auto;
  min-width: 44px;
  padding-left: var(--space-2);
  padding-right: var(--space-2);
}

.control-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.control-label output {
  color: var(--accent-support);
  font-variant-numeric: tabular-nums;
}

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

/* Range sliders */
input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  outline: none;
  cursor: pointer;
  transition: box-shadow 160ms ease-out;
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  box-shadow: 0 0 12px rgba(255, 62, 165, 0.5);
  cursor: pointer;
  transition: transform 160ms ease-out, box-shadow 160ms ease-out;
}

input[type='range']::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--accent);
  box-shadow: 0 0 12px rgba(255, 62, 165, 0.5);
  cursor: pointer;
  transition: transform 160ms ease-out, box-shadow 160ms ease-out;
}

input[type='range']:hover::-webkit-slider-thumb,
input[type='range']:active::-webkit-slider-thumb {
  transform: scale(1.15);
}

input[type='range']:focus-visible {
  box-shadow: 0 0 0 3px rgba(56, 232, 255, 0.4);
}

input[type='range']:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

input[type='range']:disabled::-webkit-slider-thumb {
  box-shadow: none;
}

/* Toggle switch */
.switch {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  color: var(--text);
  font-size: 0.95rem;
}

.switch input[type='checkbox'] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.switch__track {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 22px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  transition: background 160ms ease-out;
}

.switch__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-pill);
  background: var(--text-muted);
  transition: transform 160ms ease-out, background 160ms ease-out;
}

.switch input:checked ~ .switch__track {
  background: rgba(255, 62, 165, 0.35);
}

.switch input:checked ~ .switch__track .switch__thumb {
  transform: translateX(18px);
  background: var(--accent);
  box-shadow: 0 0 10px rgba(255, 62, 165, 0.6);
}

.switch input:focus-visible ~ .switch__track {
  box-shadow: 0 0 0 3px rgba(56, 232, 255, 0.4);
}

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: 44px;
  padding: var(--space-1) var(--space-3);
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--surface-1);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 0 16px rgba(255, 62, 165, 0.35);
  transition: transform 160ms ease-out, box-shadow 160ms ease-out, background 160ms ease-out;
}

.button:hover:not(:disabled) {
  box-shadow: 0 0 24px rgba(255, 62, 165, 0.55);
}

.button:active:not(:disabled) {
  transform: scale(0.96);
}

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

.button:disabled {
  opacity: 0.6;
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
}

.button--ghost {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: none;
}

.button--ghost:hover:not(:disabled) {
  background: #35204f;
}

.button--recording {
  animation: recording-pulse 900ms ease-in-out infinite;
}

@keyframes recording-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(255, 84, 112, 0.5);
  }
  50% {
    box-shadow: 0 0 16px rgba(255, 84, 112, 0.7);
  }
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 160ms ease-out, background 160ms ease-out;
}

.icon-button:hover {
  background: #35204f;
  transform: scale(1.08);
}

.icon-button:active {
  transform: scale(0.94);
}

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

.icon-button[aria-pressed='true'] {
  color: var(--accent-support);
}

/* Below-the-fold about / FAQ */
.about {
  padding: var(--space-8) var(--space-4);
  border-top: 1px solid rgba(169, 150, 201, 0.15);
}

.about__inner {
  max-width: 68ch;
  margin: 0 auto;
}

.about h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.4rem;
  letter-spacing: 0.02em;
  color: var(--text);
  margin: var(--space-6) 0 var(--space-2);
}

.about h2:first-child {
  margin-top: 0;
}

.about p,
.about li,
.about dd {
  color: var(--text-muted);
  line-height: 1.65;
}

.about ol {
  padding-left: var(--space-3);
}

.about li {
  margin-bottom: var(--space-1);
}

.about code {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
  font-size: 0.9em;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--accent-support);
}

.faq dt {
  color: var(--text);
  font-weight: 600;
  margin-top: var(--space-3);
}

.faq dd {
  margin: var(--space-1) 0 0;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-4);
  border-top: 1px solid rgba(169, 150, 201, 0.15);
}

.site-footer a {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-decoration: none;
  transition: color 160ms ease-out;
}

.site-footer a:hover {
  color: var(--accent-support);
}

.site-footer a:focus-visible {
  outline: 2px solid var(--accent-support);
  outline-offset: 2px;
}

@media (max-width: 768px) {
  .stage {
    flex-direction: column;
  }

  .canvas-panel {
    flex: 0 0 60vh;
    min-height: 0;
  }

  .control-rail {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
