/* ---------- tokens ---------- */
:root {
  --ink: #14110d;
  --ink-raised: #1d1812;
  --ink-raised-2: #251e15;
  --bone: #f3e9d8;
  --bone-dim: #b9ab93;
  --marigold: #e8a33d;
  --marigold-dim: #e8a33d33;
  --ember: #c1502e;

  --font-display: "Newsreader", serif;
  --font-body: "Manrope", sans-serif;
  --font-mono: "Space Mono", monospace;

  color-scheme: dark;
}

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;
  background: var(--ink);
  color: var(--bone);
  font-family: var(--font-body);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
  color: inherit;
}

svg {
  display: block;
}

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

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  background: var(--marigold);
  color: var(--ink);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-weight: 700;
  text-decoration: none;
  transition: top 0.2s ease;
  z-index: 200;
}

.skip-link:focus {
  top: 1rem;
}

:focus-visible {
  outline: 2px solid var(--marigold);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ---------- page shell ---------- */
.page {
  position: relative;
  min-height: 100dvh;
  overflow-x: hidden;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(circle at 18% 12%, rgba(232, 163, 61, 0.16), transparent 45%),
    radial-gradient(circle at 85% 78%, rgba(193, 80, 46, 0.14), transparent 50%);
  animation: atmosphere-drift 22s ease-in-out infinite alternate;
}

@keyframes atmosphere-drift {
  from {
    transform: translate3d(0, 0, 0) scale(1);
  }
  to {
    transform: translate3d(-2%, 2%, 0) scale(1.05);
  }
}

.page-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  transition: filter 0.3s ease;
}

.page-content.is-dimmed {
  filter: brightness(0.55);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: 1.25rem;
}

.brand-mark {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 600;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
  margin: 0;
}

.icon-btn {
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--ink-raised);
  border: 1px solid rgba(243, 233, 216, 0.08);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.icon-btn:hover {
  background: var(--ink-raised-2);
  transform: translateY(-1px);
}

.icon-btn svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: var(--bone);
}

/* ---------- stage ---------- */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  padding-block: 0.5rem 2rem;
}

.stage-body {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1.1rem;
}

/* ---------- mode switch ---------- */
.mode-switch {
  position: relative;
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--ink-raised);
  border: 1px solid rgba(243, 233, 216, 0.08);
  border-radius: 999px;
}

.mode-thumb {
  position: absolute;
  top: 0.25rem;
  bottom: 0.25rem;
  left: 0.25rem;
  border-radius: 999px;
  background: var(--marigold);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), width 0.25s ease;
  z-index: 0;
}

.mode-option {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: none;
  background: transparent;
  color: var(--bone-dim);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s ease;
}

.mode-option.is-active {
  color: var(--ink);
}

.mode-blurb {
  font-size: 0.8rem;
  color: var(--bone-dim);
  max-width: 34ch;
  min-height: 2.4em;
  margin: 0;
}

/* ---------- stage controls (niche + duration) ---------- */
.stage-controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.niche-select {
  position: relative;
  width: 100%;
}

.niche-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--ink-raised);
  border: 1px solid rgba(243, 233, 216, 0.1);
  border-radius: 999px;
  padding: 0.65rem 1.1rem;
  color: var(--bone);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.niche-emoji {
  font-size: 1.05rem;
}

.niche-label {
  flex: 1;
  text-align: left;
}

.niche-caret {
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--bone-dim);
  border-bottom: 2px solid var(--bone-dim);
  transform: rotate(45deg);
  margin-top: -4px;
  transition: transform 0.2s ease;
}

.niche-select.is-open .niche-caret {
  transform: rotate(-135deg);
  margin-top: 4px;
}

.niche-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  background: var(--ink-raised-2);
  border: 1px solid rgba(243, 233, 216, 0.12);
  border-radius: 14px;
  padding: 0.4rem;
  max-height: 280px;
  overflow-y: auto;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.niche-option {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: transparent;
  border: none;
  color: var(--bone);
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
}

.niche-option:hover,
.niche-option:focus-visible {
  background: rgba(243, 233, 216, 0.07);
}

.niche-option.is-active {
  background: var(--marigold-dim);
  color: var(--marigold);
}

/* ---------- duration slider ---------- */
.duration-field {
  width: 100%;
  text-align: left;
}

.duration-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}

.duration-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--bone-dim);
}

.duration-value {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--marigold);
}

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

.duration-ends {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--bone-dim);
  margin-top: 0.3rem;
}

.duration-hint {
  font-size: 0.72rem;
  color: var(--bone-dim);
  margin: 0.5rem 0 0;
}

/* ---------- reel ---------- */
.reel {
  width: 100%;
  min-height: 6em;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 1.1rem;
  border-radius: 20px;
  background: rgba(243, 233, 216, 0.03);
  border: 1px solid rgba(243, 233, 216, 0.06);
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

.reel.is-spinning {
  border-color: rgba(232, 163, 61, 0.35);
  box-shadow: 0 0 28px rgba(232, 163, 61, 0.15);
}

.reel.is-landed {
  animation: reel-flash 0.6s ease;
}

@keyframes reel-flash {
  0% {
    box-shadow: 0 0 0 rgba(232, 163, 61, 0);
  }
  35% {
    box-shadow: 0 0 36px rgba(232, 163, 61, 0.4);
  }
  100% {
    box-shadow: 0 0 0 rgba(232, 163, 61, 0);
  }
}

.reel-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--bone-dim);
  margin: 0;
}

.reel-phrase {
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(1.4rem, 5.5vw, 2.1rem);
  line-height: 1.2;
  margin: 0;
  color: var(--bone);
}

/* ---------- actions ---------- */
.actions {
  width: 100%;
}

.actions-main {
  display: flex;
  gap: 0.6rem;
}

.actions-main .btn {
  flex: 1;
}

/* ---------- buttons ---------- */
.btn {
  border: none;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.85rem 1.5rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--marigold);
  color: var(--ink);
}

.btn.primary:hover {
  background: #f0ae4c;
}

.btn.secondary {
  background: var(--ink-raised);
  color: var(--bone);
  border: 1px solid rgba(243, 233, 216, 0.12);
}

.btn.secondary:hover {
  background: var(--ink-raised-2);
}

.btn.ghost {
  background: transparent;
  color: var(--bone-dim);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn.ghost:hover {
  color: var(--bone);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- footer ---------- */
.site-footer {
  text-align: center;
  padding-block: 1rem 1.5rem;
  color: var(--bone-dim);
  font-size: 0.75rem;
}

.site-footer p {
  margin: 0;
}

/* ---------- overlays (timer + settings) ---------- */
.timer-overlay,
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(10, 8, 5, 0.72);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.timer-overlay.is-open,
.settings-overlay.is-open {
  opacity: 1;
}

.timer-overlay-inner,
.settings-panel {
  transform: translateY(12px) scale(0.98);
  transition: transform 0.25s ease;
}

.timer-overlay.is-open .timer-overlay-inner,
.settings-overlay.is-open .settings-panel {
  transform: translateY(0) scale(1);
}

.timer-overlay-inner {
  width: min(420px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--ink-raised);
  border: 1px solid rgba(243, 233, 216, 0.08);
  border-radius: 24px;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.85rem;
}

.timer-topic {
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(1.1rem, 4vw, 1.4rem);
  margin: 0;
  color: var(--bone);
}

.timer-phase {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 0;
  color: var(--marigold);
}

.timer-overlay-inner[data-phase="research"] .timer-phase {
  color: var(--ember);
}

.speech-stages {
  list-style: none;
  display: flex;
  gap: 0.5rem;
  padding: 0;
  margin: 0.25rem 0;
}

.speech-stage {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(243, 233, 216, 0.12);
  color: var(--bone-dim);
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.speech-stage.is-hit {
  border-color: rgba(232, 163, 61, 0.5);
  color: var(--marigold);
  background: var(--marigold-dim);
}

.timer-ring-wrap {
  position: relative;
  width: clamp(170px, 46vw, 210px);
  aspect-ratio: 1;
}

.timer-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: rgba(243, 233, 216, 0.09);
  stroke-width: 8;
}

.ring-progress {
  fill: none;
  stroke: var(--marigold);
  stroke-width: 8;
  stroke-linecap: round;
}

.timer-overlay-inner[data-phase="research"] .ring-progress {
  stroke: var(--ember);
}

.timer-digits {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: clamp(1.4rem, 6vw, 1.9rem);
  font-variant-numeric: tabular-nums;
}

.timer-status {
  font-size: 0.85rem;
  color: var(--bone);
  margin: 0;
}

.timer-next {
  font-size: 0.78rem;
  color: var(--bone-dim);
  margin: 0;
}

.timer-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.timer-actions .btn {
  width: 100%;
}

/* ---------- settings panel ---------- */
.settings-panel {
  width: min(360px, 90vw);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--ink-raised);
  border: 1px solid rgba(243, 233, 216, 0.08);
  border-radius: 24px;
  padding: 1.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  text-align: left;
}

.settings-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-panel-title {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.3rem;
  margin: 0;
}

.settings-panel-blurb {
  font-size: 0.78rem;
  color: var(--bone-dim);
  margin: -0.5rem 0 0;
}

.settings-mute {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.88rem;
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--marigold);
  width: 1.05rem;
  height: 1.05rem;
}

.settings-note {
  font-size: 0.72rem;
  color: var(--bone-dim);
  margin: 0;
}

.settings-done {
  width: 100%;
}

/* ---------- error fallback ---------- */
.error-fallback {
  position: fixed;
  inset: 0;
  background: var(--ink);
  color: var(--bone);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  text-align: center;
  padding: 2rem;
  z-index: 100;
}

.error-fallback h1 {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.6rem;
  margin: 0;
}

.error-fallback p {
  color: var(--bone-dim);
  margin: 0 0 0.5rem;
  max-width: 32ch;
}

/* ---------- utility state ---------- */
[hidden] {
  display: none !important;
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- small screens ---------- */
@media (max-width: 360px) {
  .page-content {
    padding-inline: 1rem;
  }

  .btn {
    padding: 0.75rem 1.2rem;
  }
}

/* ---------- roomier viewports ---------- */
@media (min-width: 640px) {
  .stage-body {
    gap: 1.4rem;
  }
}
