:root {
  --ink: #ece6ff;
  --muted: rgba(236, 230, 255, 0.62);
  --gold: #ffc660;
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --sans: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #02010a;
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

body.idle { cursor: none; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* Intro */
#intro {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  background: radial-gradient(ellipse at center, rgba(2, 1, 10, 0.1) 0%, rgba(2, 1, 10, 0.72) 75%);
  transition: opacity 1.8s ease, visibility 1.8s;
}
body.started #intro { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-inner { max-width: 720px; animation: rise 2.4s cubic-bezier(0.2, 0.7, 0.1, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); filter: blur(6px); } }

.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--muted);
}
h1 {
  margin: 0.08em 0 0.1em;
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(64px, 12vw, 164px);
  line-height: 1;
  white-space: nowrap;
  letter-spacing: 0.02em;
  background: linear-gradient(180deg, #fff 10%, #ffe2b0 55%, #d0924e 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 32px rgba(255, 190, 110, 0.28));
}
h1 em { font-style: italic; font-size: 0.62em; }
.lede {
  margin: 0 0 30px;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(18px, 2.2vw, 24px);
  color: rgba(236, 230, 255, 0.82);
}

.tempo {
  display: inline-flex;
  gap: 6px;
  margin: 0 0 16px;
  padding: 5px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(12, 10, 30, 0.45);
  backdrop-filter: blur(8px);
}
.tempo label { position: relative; cursor: pointer; }
.tempo input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.tempo span {
  display: block;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--muted);
  transition: background 0.3s, color 0.3s;
}
.tempo small { display: block; font-size: 10px; opacity: 0.7; margin-top: 2px; }
.tempo input:checked + span { background: rgba(255, 198, 96, 0.16); color: #fff; box-shadow: inset 0 0 0 1px rgba(255, 198, 96, 0.4); }
.tempo input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }

.toggle {
  display: block;
  margin: 0 0 30px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.toggle input { accent-color: var(--gold); vertical-align: -2px; margin-right: 6px; }

#begin, #again {
  padding: 16px 54px;
  border: 1px solid rgba(255, 214, 150, 0.55);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 200, 120, 0.22), rgba(255, 170, 90, 0.06));
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  text-transform: uppercase;
  box-shadow: 0 0 40px rgba(255, 180, 90, 0.18), inset 0 0 20px rgba(255, 200, 140, 0.08);
  transition: box-shadow 0.4s, transform 0.4s, background 0.4s;
}
#begin:hover, #again:hover, #begin:focus-visible, #again:focus-visible {
  box-shadow: 0 0 70px rgba(255, 180, 90, 0.4), inset 0 0 24px rgba(255, 200, 140, 0.16);
  transform: translateY(-1px);
  outline: none;
}
#begin[disabled] { opacity: 0.6; cursor: progress; }
.hint { margin-top: 26px; font-size: 12px; color: rgba(236, 230, 255, 0.45); letter-spacing: 0.04em; }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 5px;
  margin: 0 1px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 4px;
  font: 11px var(--sans);
}

/* Chapter cards */
#chapter {
  position: fixed;
  left: 0;
  right: 0;
  top: 9vh;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px);
  filter: blur(4px);
  transition: opacity 1.6s ease, transform 2.4s cubic-bezier(0.2, 0.7, 0.1, 1), filter 1.6s ease;
  text-shadow: 0 0 24px rgba(0, 0, 0, 0.8);
}
#chapter.show { opacity: 1; transform: none; filter: none; }
#chapter .num { font-size: 11px; font-weight: 600; letter-spacing: 0.6em; text-indent: 0.6em; text-transform: uppercase; color: rgba(255, 220, 170, 0.8); }
#chapter .title { margin: 6px 0 4px; font-family: var(--serif); font-weight: 300; font-style: italic; font-size: clamp(38px, 5.4vw, 72px); line-height: 1.05; }
#chapter .sub { font-size: 13px; letter-spacing: 0.14em; color: var(--muted); }

/* Legend */
#legend {
  position: fixed;
  top: 22px;
  left: 24px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 1.2s;
}
body.started #legend { opacity: 1; }
body.started.idle #legend { opacity: 0.35; }
#legend li { display: flex; align-items: center; gap: 10px; margin: 0 0 9px; color: rgba(236, 230, 255, 0.28); transition: color 1s; }
#legend li::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
  opacity: 0.25;
  transition: opacity 1s, box-shadow 1s;
}
#legend li.on { color: rgba(236, 230, 255, 0.85); }
#legend li.on::before { opacity: 1; box-shadow: 0 0 12px 2px var(--c); }

/* HUD */
#hud {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  width: min(900px, calc(100% - 32px));
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(10, 8, 24, 0.45);
  backdrop-filter: blur(12px);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.7s;
}
body.started #hud { opacity: 1; pointer-events: auto; }
body.started.idle #hud, body.ended #hud { opacity: 0; pointer-events: none; }
#hud button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
}
#hud button:hover, #hud button:focus-visible { background: rgba(255, 255, 255, 0.16); outline: none; }
#hud svg { width: 16px; height: 16px; fill: currentColor; }
#play .i-play { display: none; }
body.paused #play .i-play { display: block; }
body.paused #play .i-pause { display: none; }
#time { min-width: 76px; }
#where { min-width: 132px; text-align: right; }
#track { position: relative; flex: 1; height: 26px; cursor: pointer; }
#segments { position: absolute; inset: 11px 0; display: flex; gap: 2px; }
#segments div { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.12); position: relative; }
#segments div:hover::after {
  content: attr(data-title);
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(10, 8, 24, 0.85);
  color: var(--ink);
  font-size: 11px;
}
#fill {
  position: absolute;
  left: 0;
  top: 11px;
  height: 4px;
  width: 0;
  border-radius: 2px;
  background: linear-gradient(90deg, #ffc660, #ff60a0, #62d2ff);
  box-shadow: 0 0 12px rgba(255, 190, 120, 0.6);
  pointer-events: none;
}

/* Credits */
#credits {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: radial-gradient(ellipse 60% 55% at center, rgba(2, 1, 10, 0.72), rgba(2, 1, 10, 0.5) 60%, rgba(2, 1, 10, 0.85));
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.9);
  opacity: 0;
  visibility: hidden;
  transition: opacity 3s ease, visibility 3s;
}
body.ended #credits { opacity: 1; visibility: visible; }
#credits h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 300;
  font-style: italic;
  font-size: clamp(64px, 10vw, 130px);
  color: #fff3dc;
  filter: drop-shadow(0 0 30px rgba(255, 200, 130, 0.4));
}
#credits .work { font-family: var(--serif); font-size: 24px; margin: 8px 0 22px; }
#credits .work span { font-size: 15px; letter-spacing: 0.3em; text-transform: uppercase; color: var(--muted); font-family: var(--sans); }
#credits .small { max-width: 620px; font-size: 12px; line-height: 1.7; color: rgba(236, 230, 255, 0.55); margin: 0 0 28px; }
#credits a { color: rgba(255, 214, 160, 0.85); }

@media (max-width: 640px) {
  #where { display: none; }
  #legend { top: 14px; left: 14px; font-size: 9px; }
  #chapter { top: 12vh; }
}

@media (prefers-reduced-motion: reduce) {
  .intro-inner { animation: none; }
}
