:root {
  color-scheme: dark;
  --bg: #06060b;
  --ink: #ece9f2;
  --ink-soft: #a7a2b6;
  --ink-faint: #6f6a7e;
  --hair: rgba(255, 255, 255, 0.08);
  --accent: #7c30c0;
  --accent-rgb: 124, 48, 192;
  --display: "Fraunces", Georgia, serif;
  --body: "Inter", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { overflow-x: hidden; }
body {
  min-height: 100svh;
  background: radial-gradient(140% 100% at 50% 30%, rgba(124, 48, 192, 0.08) 0%, transparent 55%), var(--bg);
  color: var(--ink); font-family: var(--body); line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

/* ============ atmosphere ============ */
.wash { position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: 0; transition: opacity 2.4s ease; }
body.entered .wash { opacity: 1; }
.floats { position: fixed; inset: 0; pointer-events: none; z-index: 4; display: none; }
body.immerse .floats { display: block; }
.floats span { position: absolute; font-family: var(--display); font-style: italic; white-space: nowrap; opacity: 0; text-shadow: 0 0 22px rgba(var(--accent-rgb), 0.3); animation: float-drift var(--dur, 6s) ease-in-out forwards; }

/* ============ stage ============ */
.stage {
  position: relative; z-index: 1; min-height: 100svh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(18px, 3.2vh, 36px); padding: clamp(18px, 4vh, 44px) 20px clamp(70px, 9vh, 104px);
}
.eyebrow { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.32em; text-transform: uppercase; color: var(--ink-faint); text-align: center; }

/* ============ drift: ladder ============ */
.ladder-row { display: flex; align-items: center; justify-content: center; gap: clamp(28px, 6vw, 72px); width: 100%; max-width: 1080px; }
body.immerse .ladder-row { display: none; }

.ladder-col { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.rail-cap { font-family: var(--mono); font-size: 0.58rem; letter-spacing: 0.26em; text-transform: uppercase; color: var(--ink-faint); }

.ladder { --f: 0.5; position: relative; width: 132px; height: min(62vh, 540px); touch-action: none; outline: none; }
.ladder:focus-visible { outline: 1px solid rgba(var(--accent-rgb), 0.5); outline-offset: 14px; border-radius: 40px; }
.track { position: absolute; left: 50%; top: 0; transform: translateX(-50%); width: 46px; height: 100%; border-radius: 30px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.10), inset 0 0 36px rgba(0, 0, 0, 0.35), 0 18px 60px rgba(0, 0, 0, 0.4); cursor: grab; }
body.sliding .track { cursor: grabbing; }
.ticks { position: absolute; left: 50%; top: 0; height: 100%; transform: translateX(-50%); pointer-events: none; }
.tick { position: absolute; right: 42px; transform: translateY(50%); font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.06em; color: var(--ink-faint); white-space: nowrap; pointer-events: auto; cursor: pointer; padding: 2px 4px; transition: color 0.4s ease; }
.tick:hover { color: var(--ink); }
.rungs { position: absolute; left: 50%; top: 0; transform: translateX(-50%); width: 46px; height: 100%; display: flex; flex-direction: column-reverse; border-radius: 30px; overflow: hidden; pointer-events: none; }
.rung { flex: 1; width: 100%; background: transparent; }

.carriage { position: absolute; left: 50%; top: calc((1 - var(--f)) * 100%); transform: translate(-50%, -50%); pointer-events: none; }
.glow { position: absolute; left: 50%; top: 50%; width: 360px; height: 360px; transform: translate(-50%, -50%); border-radius: 50%; background: radial-gradient(circle, rgba(var(--accent-rgb), 0.5) 0%, rgba(var(--accent-rgb), 0.12) 42%, transparent 70%); filter: blur(26px); animation: glow-breathe 7.5s ease-in-out infinite; }
body.sliding .glow { animation-duration: 3s; }
.ripples { position: absolute; left: 50%; top: 50%; width: 132px; height: 132px; transform: translate(-50%, -50%); }
.ripples i { position: absolute; inset: 0; border-radius: 50%; border: 1.5px solid rgba(var(--accent-rgb), 0.55); box-shadow: 0 0 26px rgba(var(--accent-rgb), 0.22), inset 0 0 26px rgba(var(--accent-rgb), 0.14); opacity: 0; will-change: transform, opacity; animation: ripple 8s linear infinite; transition: border-color 1.4s ease; }
.ripples i:nth-child(2) { animation-delay: 2.6s; }
.ripples i:nth-child(3) { animation-delay: 5.2s; }
body:not(.entered) .ripples i { animation-play-state: paused; }
body.sliding .ripples i { animation-duration: 4.4s; border-color: rgba(var(--accent-rgb), 0.85); }
.handle { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; background: radial-gradient(circle at 50% 38%, rgba(255, 255, 255, 0.30), rgba(255, 255, 255, 0) 60%), rgba(12, 12, 20, 0.78); box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.55), 0 0 28px rgba(var(--accent-rgb), 0.7), 0 10px 30px rgba(0, 0, 0, 0.5); }
.handle-letter { font-family: var(--display); font-style: italic; font-size: 1.5rem; color: var(--ink); }
.handle-tag { position: absolute; left: calc(50% + 46px); top: 50%; transform: translateY(-50%); text-align: left; white-space: nowrap; }
.handle-tag strong { display: block; font-family: var(--display); font-size: 1.05rem; font-weight: 500; }
.handle-tag span { font-family: var(--mono); font-size: 0.56rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-faint); }

.mode-toggle { display: inline-flex; gap: 2px; margin-top: 6px; border: 1px solid var(--hair); border-radius: 999px; padding: 3px; background: rgba(8, 8, 14, 0.5); }
.mode-opt { font-family: var(--mono); font-size: 0.6rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-faint); padding: 6px 16px; border-radius: 999px; transition: color 0.4s ease, background 0.4s ease; }
.mode-opt.on { color: var(--ink); background: rgba(var(--accent-rgb), 0.22); }

/* ============ drift: reveal ============ */
.reveal { width: min(420px, 90vw); display: grid; gap: 10px; justify-items: start; text-align: left; }
.reveal.swap { animation: drift-in 1.1s ease; }
.r-rule { width: 76px; height: 1px; background: linear-gradient(90deg, rgba(var(--accent-rgb), 0.9), transparent); transition: background 1.2s ease; }
#r-color { font-family: var(--display); font-style: italic; font-weight: 500; font-size: clamp(1.6rem, 3.4vw, 2.1rem); line-height: 1.1; transition: color 1.2s ease; }
#r-quality { font-size: 0.94rem; color: var(--ink-soft); }
#r-chakra { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-soft); margin-top: 4px; }
#r-mantra { font-family: var(--display); font-style: italic; font-size: 1.04rem; color: var(--ink); opacity: 0.94; }
.r-meanings { display: grid; gap: 6px; margin-top: 8px; }
.r-meanings p { font-size: 0.9rem; color: var(--ink-soft); }
.r-meanings b { font-family: var(--mono); font-weight: 500; font-size: 0.6rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-faint); margin-right: 10px; }
#r-freq { font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.06em; color: var(--ink-faint); margin-top: 6px; }

/* ============ immerse: chord studio ============ */
.studio { display: none; width: 100%; max-width: 760px; flex-direction: column; align-items: center; gap: clamp(14px, 2.4vh, 22px); }
body.immerse .studio { display: flex; }

.chord-readout { text-align: center; min-height: 76px; }
#chord-name { font-family: var(--display); font-style: italic; font-weight: 500; font-size: clamp(1.8rem, 5vw, 2.6rem); line-height: 1.05; transition: color 1s ease; }
#chord-color { font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-soft); margin-top: 6px; }
#chord-notes { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em; color: var(--ink-faint); margin-top: 6px; }

/* keyboard */
.keyboard-wrap { width: 100%; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.keyboard { position: relative; height: clamp(120px, 22vh, 190px); min-width: 520px; display: flex; touch-action: pan-x; border-radius: 12px; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.4); }
.key { position: relative; border: 0; padding: 0; cursor: pointer; transition: filter 0.18s ease, box-shadow 0.3s ease, transform 0.12s ease; }
.key.white {
  height: 100%; border-radius: 0 0 7px 7px;
  background: linear-gradient(to bottom, #f3f0f6 0%, color-mix(in srgb, var(--kc) 16%, #e7e2ec) 100%);
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.18), inset 0 -3px 6px rgba(0, 0, 0, 0.08);
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 9px;
}
.key.white span { font-family: var(--mono); font-size: 0.6rem; color: #4a4754; pointer-events: none; }
.key.black {
  position: absolute; top: 0; height: 62%; transform: translateX(-50%); z-index: 2; border-radius: 0 0 5px 5px;
  background: linear-gradient(to bottom, #15131c 0%, color-mix(in srgb, var(--kc) 50%, #181620) 100%);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5), inset 0 -2px 3px rgba(0, 0, 0, 0.6);
}
.key.white.lit { background: linear-gradient(to bottom, color-mix(in srgb, var(--kc) 55%, #fff) 0%, var(--kc) 100%); box-shadow: 0 0 22px -2px var(--kc), inset 0 0 0 1px rgba(255, 255, 255, 0.4); }
.key.white.lit span { color: rgba(255, 255, 255, 0.95); }
.key.black.lit { background: linear-gradient(to bottom, color-mix(in srgb, var(--kc) 70%, #fff) 0%, var(--kc) 100%); box-shadow: 0 0 22px 0 var(--kc), inset 0 0 0 1px rgba(255, 255, 255, 0.5); }

/* panels of controls */
.panels { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.panel { display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: flex-start; justify-content: center; padding: 12px 14px; border: 1px solid var(--hair); border-radius: 16px; background: rgba(12, 12, 20, 0.5); }
.ctl { display: flex; flex-direction: column; gap: 7px; align-items: flex-start; }
.ctl-label { font-family: var(--mono); font-size: 0.56rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-faint); }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.04em; color: var(--ink-soft);
  border: 1px solid var(--hair); border-radius: 8px; padding: 7px 10px; min-width: 34px; min-height: 32px;
  transition: color 0.25s ease, background 0.25s ease, border-color 0.25s ease;
}
.chip[data-pc] { border-bottom: 2px solid var(--cc); }
.chip:hover { color: var(--ink); border-color: rgba(255, 255, 255, 0.22); }
.chip.on { color: #fff; background: rgba(var(--accent-rgb), 0.30); border-color: rgba(var(--accent-rgb), 0.7); }

.prog-key { font-style: normal; color: var(--ink-soft); text-transform: none; letter-spacing: 0.04em; margin-left: 6px; }

.tempo-row { display: flex; align-items: center; gap: 10px; }
.tempo-end { font-family: var(--mono); font-size: 0.54rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-faint); }
#tempo { -webkit-appearance: none; appearance: none; width: 150px; height: 4px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); cursor: pointer; outline: none; }
#tempo::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border-radius: 50%; background: rgb(var(--accent-rgb)); box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.6); cursor: pointer; transition: background 0.4s ease; }
#tempo::-moz-range-thumb { width: 18px; height: 18px; border: 0; border-radius: 50%; background: rgb(var(--accent-rgb)); box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.6); cursor: pointer; }

.mini { font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); border: 1px solid var(--hair); border-radius: 8px; padding: 8px 14px; min-height: 34px; transition: all 0.25s ease; }
.mini:hover { color: var(--ink); border-color: rgba(255, 255, 255, 0.25); }
.panel-foot { align-items: center; justify-content: space-between; }

.drone-ctl { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; align-self: center; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: rgb(var(--accent-rgb)); }
.dropdown { font-family: var(--mono); font-size: 0.62rem; color: var(--ink-soft); background: rgba(8, 8, 14, 0.6); border: 1px solid var(--hair); border-radius: 8px; padding: 7px 10px; min-height: 34px; cursor: pointer; }
.dropdown:hover { color: var(--ink); border-color: rgba(255, 255, 255, 0.25); }

/* ============ hint + pills ============ */
.hint { font-family: var(--mono); font-size: 0.6rem; letter-spacing: 0.13em; color: var(--ink-faint); text-align: center; line-height: 2; max-width: 64ch; }
.hint-imm { display: none; }
body.immerse .hint-drift { display: none; }
body.immerse .hint-imm { display: inline; }

.modes { position: fixed; right: 16px; bottom: 14px; z-index: 10; display: flex; gap: 10px; }
.pill { font-family: var(--mono); font-size: 0.6rem; letter-spacing: 0.26em; text-transform: uppercase; color: var(--ink-faint); border: 1px solid var(--hair); border-radius: 999px; padding: 9px 16px; background: rgba(8, 8, 14, 0.62); backdrop-filter: blur(6px); transition: color 0.5s ease, border-color 0.5s ease, box-shadow 0.8s ease; }
.pill:hover { color: var(--ink); border-color: rgba(255, 255, 255, 0.25); }
.pill[aria-pressed="true"] { color: var(--ink); border-color: rgba(var(--accent-rgb), 0.6); box-shadow: 0 0 16px rgba(var(--accent-rgb), 0.25); }
body:not(.entered) .modes { visibility: hidden; }

/* ============ veil ============ */
.veil { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: radial-gradient(circle at 50% 42%, #11101c 0%, #07070d 55%, #050509 100%); transition: opacity 1.6s ease, visibility 1.6s ease; }
.veil.lift { opacity: 0; visibility: hidden; }
.veil-inner { text-align: center; display: grid; justify-items: center; gap: 24px; padding: 24px; max-width: 540px; }
.veil h1 { font-family: var(--display); font-weight: 500; font-size: clamp(2.2rem, 6vw, 3.6rem); line-height: 1.04; }
.veil h1 em { font-style: italic; color: var(--ink-soft); font-weight: 400; }
.veil .veil-sub { color: var(--ink-soft); font-size: 0.98rem; max-width: 46ch; }
.enter { position: relative; width: 148px; height: 148px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.22); font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.34em; text-transform: uppercase; color: var(--ink); background: radial-gradient(circle, rgba(var(--accent-rgb), 0.20) 0%, rgba(var(--accent-rgb), 0) 70%); animation: breathe 4.6s ease-in-out infinite; }
.enter::after { content: ""; position: absolute; inset: -14px; border-radius: 50%; border: 1px solid rgba(var(--accent-rgb), 0.35); animation: enter-pulse 4.6s ease-out infinite; }
.enter:hover { border-color: rgba(255, 255, 255, 0.5); }
.veil-note { font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.18em; color: var(--ink-faint); text-transform: uppercase; }

/* ============ motion ============ */
@keyframes ripple { 0% { transform: scale(0.5); opacity: 0; } 12% { opacity: 0.5; } 100% { transform: scale(2.4); opacity: 0; } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes glow-breathe { 0%, 100% { transform: translate(-50%, -50%) scale(1); } 50% { transform: translate(-50%, -50%) scale(1.08); } }
@keyframes enter-pulse { 0% { transform: scale(0.92); opacity: 0; } 30% { opacity: 0.8; } 100% { transform: scale(1.45); opacity: 0; } }
@keyframes drift-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes float-drift { 0% { opacity: 0; transform: translate(0, 10px); } 22% { opacity: 0.95; } 68% { opacity: 0.5; } 100% { opacity: 0; transform: translate(var(--dx, 0), var(--dy, -28px)); } }
@keyframes float-fade { 0% { opacity: 0; } 25% { opacity: 0.9; } 100% { opacity: 0; } }

/* ============ responsive ============ */
@media (max-width: 760px) {
  .ladder-row { flex-direction: column; gap: 24px; }
  .ladder { height: min(46vh, 360px); }
  .reveal { width: min(440px, 92vw); justify-items: center; text-align: center; }
  .r-rule { margin: 0 auto; }
  .panel { gap: 12px 16px; }
  .ctl { align-items: center; width: 100%; }
  .btn-row { justify-content: center; }
}
@media (max-width: 420px) {
  .stage { padding-bottom: 92px; }
  .chip { font-size: 0.62rem; padding: 6px 8px; }
  .keyboard { min-width: 460px; }
}

@media (prefers-reduced-motion: reduce) {
  .ripples i, .glow, .enter, .enter::after { animation: none; }
  .ripples i { opacity: 0.22; transform: scale(1.4); }
  .reveal.swap { animation: none; }
  .floats span { animation: float-fade 4.5s ease forwards; }
}
