:root {
    --v1-color: #00ffcc;
    --v2-color: #ff0055;
    --bg-color: #f4f3ef;
    --card-bg: #1a1a1a;
    --ink: #0a0a0a;
}

body {
    background: var(--bg-color);
    color: var(--ink);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: hidden;
}

#viz {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 20;
    pointer-events: none;
    background: transparent;
}

/* Coincidence FX layer — draws beam/ring/wash above the squares */
#vizFx {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 21;
    pointer-events: none;
    background: transparent;
}

/* Curved-glass overlay — suggests the page is sealed under a slightly
   domed glass surface. Three layered cues: a sharp inner-rim highlight
   + soft inner glow + gentle vignette (the "thickness" of the glass);
   diagonal corner light-catches (overhead light reflecting off the
   curve); and a thin backdrop-blur band masked to the outer ~20% of
   the viewport (the refraction at the rim where the glass curves
   away). Sits above everything with pointer-events: none so the UI
   underneath stays interactive. */
#glassEdge {
    position: fixed;
    inset: 0;
    z-index: 22;
    pointer-events: none;
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.35),
        inset 0 0 60px rgba(255, 255, 255, 0.40),
        inset 0 0 180px rgba(0, 0, 0, 0.18),
        inset 0 0 380px rgba(0, 0, 0, 0.10);
}
#glassEdge::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse 520px 400px at 0% 0%,
            rgba(255, 255, 255, 0.65), transparent 65%),
        radial-gradient(ellipse 480px 360px at 100% 100%,
            rgba(255, 255, 255, 0.55), transparent 65%),
        radial-gradient(ellipse 360px 300px at 100% 0%,
            rgba(255, 255, 255, 0.30), transparent 70%),
        radial-gradient(ellipse 360px 300px at 0% 100%,
            rgba(255, 255, 255, 0.30), transparent 70%);
}
#glassEdge::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    -webkit-mask-image: radial-gradient(
        ellipse 95% 95% at center,
        transparent 65%,
        black 100%
    );
    mask-image: radial-gradient(
        ellipse 95% 95% at center,
        transparent 65%,
        black 100%
    );
}

/* Score-card entry overlay — laid out as a printed program note
   rather than a landing page. .container fills the viewport so
   children can be placed asymmetrically; .dimmed (added on entry)
   fades the whole thing out and the canvas chrome takes over. */
.container {
    position: fixed;
    inset: 0;
    /* Sits above #viz/#vizFx so the homepage text + entry buttons
       stay readable while preview visuals draw on the canvas behind.
       Bottom chrome (color toggle, play button) and overlays (state
       indicator, buffering text) live at z≥25 and remain above this. */
    z-index: 23;
    pointer-events: none;
    color: var(--ink);
}
.container > * { pointer-events: auto; }
/* Page content constrained to letter-paper width (8.5"). The
   blocks anchor as absolute positions inside this column: voice
   mark vertically centered between top and program note (~22vh),
   program note centered at the page's vertical midpoint,
   entry block fixed near the bottom-right. */
.scoreCard {
    position: relative;
    width: 100%;
    max-width: 850px;
    height: 100%;
    margin: 0 auto;
}

/* Voices superposed — a single mark where "II" ghosts a few pixels
   to the left of "I". The leading 'I' of each is the alignment
   axis at rest; the small leftward offset on II reads as the
   piece's phase relationship (V2's accumulated lead) baked into
   the typography. Three vertical strokes appear: a faint ghost
   to the left (II's leading I), the solid I in the middle, and
   a faint ghost to the right (II's trailing I). */
.voiceMark {
    position: absolute;
    top: 22vh;
    transform: translateY(-50%);
    left: clamp(24px, 6vw, 88px);
    font-family: 'EB Garamond', Georgia, serif;
    font-style: italic;
    font-weight: 500;
    line-height: 0.9;
    color: var(--ink);
    user-select: none;
}
.voiceGlyph {
    font-size: clamp(7rem, 18vw, 14rem);
    font-style: italic;
    letter-spacing: -0.02em;
    display: block;
}
.voiceI {
    position: relative;
    opacity: 0.7;
}
.voiceII {
    position: absolute;
    top: 0;
    left: -0.05em;
    opacity: 0.3;
}

.programBlock {
    position: absolute;
    left: clamp(24px, 6vw, 88px);
    top: 50%;
    transform: translateY(-50%);
    max-width: 38ch;
}
.programHead,
.performanceHead {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: 'Kumbh Sans', 'Segoe UI', sans-serif;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    opacity: 0.55;
    margin-bottom: 14px;
}
.programRule {
    display: inline-block;
    width: 36px;
    height: 1px;
    background: currentColor;
    opacity: 0.7;
}
.programBody {
    font-family: 'EB Garamond', Georgia, serif;
    font-size: clamp(1.05rem, 1.4vw, 1.3rem);
    line-height: 1.5;
    margin: 0 0 4px;
    color: var(--ink);
    text-wrap: pretty;
}
.programBody::first-letter {
    font-style: italic;
    font-size: 1.15em;
}
.programCoda {
    font-family: 'EB Garamond', Georgia, serif;
    font-size: clamp(1.05rem, 1.4vw, 1.3rem);
    line-height: 1.5;
    margin: 0 0 18px;
    color: var(--ink);
}

.programMeta {
    font-family: 'Kumbh Sans', 'Segoe UI', sans-serif;
    font-size: 0.65rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    opacity: 0.6;
    margin-bottom: 10px;
}
.programMeta .metaDot {
    margin: 0 0.7em;
    opacity: 0.45;
}
.programAttrib {
    font-family: 'EB Garamond', Georgia, serif;
    font-style: italic;
    font-size: 0.95rem;
    opacity: 0.7;
}

.performance {
    position: absolute;
    right: clamp(24px, 6vw, 88px);
    bottom: clamp(70px, 9vh, 120px);
    text-align: right;
}
.performance .performanceHead {
    justify-content: flex-end;
    margin-bottom: 18px;
}

.entryBtns {
    display: flex;
    gap: 22px;
    justify-content: flex-end;
    flex-wrap: wrap;
}
.entryBtn {
    background: transparent;
    color: var(--ink);
    border: none;
    border-bottom: 1px solid transparent;
    padding: 4px 0;
    font-family: 'EB Garamond', Georgia, serif;
    font-style: italic;
    font-size: clamp(1.1rem, 1.6vw, 1.45rem);
    cursor: pointer;
    border-radius: 0;
    text-transform: none;
    letter-spacing: 0;
    transition: border-color 0.3s ease, opacity 0.3s ease, color 0.3s ease;
    opacity: 0.82;
}
.entryBtn:hover {
    border-bottom-color: var(--ink);
    opacity: 1;
}
/* "Color" entry keeps a faint chromatic hint — the descender of its
   underline tints to the V2 magenta, and on hover the whole word
   shifts toward the V1 turquoise. Subtle enough to read as a
   typographic decision, not a candy button. */
#playColor {
    color: var(--ink);
}
#playColor:hover {
    color: hsl(165, 60%, 32%);
    border-bottom-color: hsl(165, 70%, 45%);
}
#playMono:hover {
    border-bottom-color: var(--ink);
}
.performance .homepageFresh {
    margin-top: 24px;
    text-align: right;
    opacity: 0.4;
}

/* Narrow viewports — small phones don't have enough vertical room
   to vertically-center both the voice mark and the program note
   without overlap, so fall back to flow layout with even spacing
   (voice top, program mid-band, entry bottom). */
@media (max-width: 720px) {
    .scoreCard {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding: clamp(96px, 22vw, 140px) clamp(20px, 6vw, 32px)
                 clamp(48px, 10vw, 80px);
        box-sizing: border-box;
    }
    .voiceGlyph {
        font-size: clamp(5.5rem, 28vw, 9rem);
    }
    .voiceMark,
    .programBlock,
    .performance {
        position: static;
        transform: none;
        top: auto; left: auto; right: auto; bottom: auto;
    }
    .programBlock {
        max-width: none;
    }
    .performance {
        align-self: flex-end;
    }
    .entryBtns {
        gap: 18px;
    }
}

/* Very narrow phones — let the entry choices stack vertically so
   neither word truncates. */
@media (max-width: 380px) {
    .entryBtns {
        flex-direction: column;
        gap: 10px;
    }
}

h1 {
    position: fixed;
    bottom: 18px;
    left: 22px;
    margin: 0;
    z-index: 25;
    font-family: 'Kumbh Sans', 'Segoe UI', sans-serif;
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--ink);
    white-space: nowrap;
}

#topInfo {
    position: fixed;
    top: 18px;
    left: 22px;
    z-index: 25;
    font-family: 'Kumbh Sans', 'Segoe UI', sans-serif;
    color: var(--ink);
}
#topInfo .topFile {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 1px;
    line-height: 1.15;
}
/* LIVE badge — appears to the left of the song name when sc-tui
 * broadcasts /live 1 (body.live-mode toggled by player.js). Hidden
 * by default; .live-mode flips display + starts the pulses.
 *
 * The badge is a red pill with white "LIVE" text and a pulsing white
 * dot — the standard streaming-LIVE pattern (YouTube/Twitch/Insta).
 * Two animations layered:
 *   • liveBadgePulse — outer red ring expands and fades around the
 *     pill (~2s cycle, soft "broadcasting" radiation)
 *   • liveDotPulse   — inner white dot dims and shrinks (~1.4s cycle)
 * The mismatched cycles keep the indicator feeling organic, not
 * mechanical. */
#topInfo .topFile .liveBadge {
    display: none;
    align-items: center;
    gap: 0.32em;
    background: #ff1f30;
    color: #fff;
    padding: 0.18em 0.5em 0.18em 0.42em;
    border-radius: 0.22em;
    font-size: 0.58em;
    font-weight: 800;
    letter-spacing: 0.14em;
    line-height: 1;
    margin-right: 0.6em;
    vertical-align: 0.32em;
    text-transform: uppercase;
    user-select: none;
}
#topInfo .topFile .liveBadge .liveBadgeDot {
    display: inline-block;
    width: 0.65em;
    height: 0.65em;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0.3em rgba(255, 255, 255, 0.7);
}
body.live-mode #topInfo .topFile .liveBadge {
    display: inline-flex;
    animation: liveBadgePulse 2s ease-out infinite;
}
body.live-mode #topInfo .topFile .liveBadge .liveBadgeDot {
    animation: liveDotPulse 1.4s ease-in-out infinite;
}
@keyframes liveBadgePulse {
    0%   { box-shadow: 0 0 0 0   rgba(255, 31, 48, 0.55); }
    70%  { box-shadow: 0 0 0 8px rgba(255, 31, 48, 0); }
    100% { box-shadow: 0 0 0 0   rgba(255, 31, 48, 0); }
}
@keyframes liveDotPulse {
    0%, 100% { opacity: 1;   transform: scale(1); }
    50%      { opacity: 0.4; transform: scale(0.75); }
}
#topInfo .topAttrib {
    font-size: 0.78rem;
    font-weight: 400;
    letter-spacing: 1.8px;
    text-transform: uppercase;
    opacity: 0.55;
    line-height: 1.4;
    margin-top: 4px;
}
#runtime {
    font-family: 'Kumbh Sans', 'Segoe UI', sans-serif;
    font-weight: 400;
    font-size: 0.65rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--ink);
    opacity: 0.45;
    margin-top: 6px;
    white-space: nowrap;
}
.topViews {
    font-family: 'Kumbh Sans', 'Segoe UI', sans-serif;
    font-weight: 400;
    font-size: 0.62rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--ink);
    opacity: 0;
    margin-top: 4px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    transition: opacity 0.5s ease;
}
.topViews.visible { opacity: 0.4; }

.homepageFresh {
    margin-top: 28px;
    font-family: 'Kumbh Sans', 'Segoe UI', sans-serif;
    font-weight: 400;
    font-size: 0.7rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--ink);
    opacity: 0.45;
    font-variant-numeric: tabular-nums;
}

#listenerCount {
    position: fixed;
    top: 18px;
    right: 22px;
    z-index: 25;
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'Kumbh Sans', 'Segoe UI', sans-serif;
    font-weight: 400;
    font-size: 0.78rem;
    letter-spacing: 1.5px;
    color: var(--ink);
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
    font-variant-numeric: tabular-nums;
}
#listenerCount.ready { opacity: 0.55; }
#listenerCount svg {
    width: 14px;
    height: 14px;
    display: block;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 18px 44px;
    justify-content: center;
    max-width: 480px;
    margin: 0 auto 32px;
    font-size: 0.78rem;
    opacity: 0.72;
    text-align: left;
}
.legendSection h3 {
    margin: 0 0 6px;
    font-family: 'Kumbh Sans', 'Segoe UI', sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.8px;
    opacity: 0.85;
}
.legendRow {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 3px 0;
    line-height: 1.35;
    white-space: nowrap;
}
.legendIcon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    font-size: 0.9rem;
    line-height: 1;
    flex-shrink: 0;
}
.legendSwatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}

.container {
    transition: opacity 0.8s ease;
}
.container.dimmed {
    opacity: 0;
    pointer-events: none;
}

#bufferingStatus {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 25;
    font-family: 'Kumbh Sans', 'Segoe UI', sans-serif;
    font-size: 0.85rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--ink);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    white-space: nowrap;
}

/* State + pool indicator — center bottom, vertically aligned with the
   row of player buttons on both sides (which sit at bottom: 18px,
   height 28px). line-height: 28px matches the button height so the
   text baseline lands exactly on the button center axis. */
#stateIndicator {
    position: fixed;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    height: 28px;
    line-height: 28px;
    z-index: 25;
    font-family: 'Kumbh Sans', 'Segoe UI', sans-serif;
    font-size: 0.7rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--ink);
    opacity: 0;
    pointer-events: none;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    transition: opacity 0.4s ease;
}
body.streaming #stateIndicator { opacity: 0.55; }
#stateIndicator .sep {
    margin: 0 14px;
    opacity: 0.4;
}
/* Chord block keeps its source case — case is the only thing
   distinguishing major (I, IV, …) from minor (i, iv, …) in roman-
   numeral notation, so the indicator's blanket uppercase would
   collapse i7 → I7 and iv6 → IV6 without this. Same applies to
   .planLine (the planner blueprint readout) and the .key span
   (key/tonality label — "Am" needs to stay "Am" not "AM" so
   minor modes are visually distinct from majors). */
#stateIndicator .chord,
#stateIndicator .key,
#totalViews .key,
.planLine {
    text-transform: none;
}
#bufferingStatus.active {
    opacity: 0.55;
    animation: bufferingPulse 1.6s ease-in-out infinite;
}
@keyframes bufferingPulse {
    0%, 100% { opacity: 0.35; }
    50%      { opacity: 0.7; }
}
/* One-shot "SYNCED!" flash on first real /note. Holds visible
   briefly then fades out and stays hidden. */
#bufferingStatus.success {
    animation: syncedFlash 2s ease forwards;
}
@keyframes syncedFlash {
    0%  { opacity: 0; }
    18% { opacity: 0.85; }
    55% { opacity: 0.85; }
    100% { opacity: 0; }
}
/* Terminal failure state — replaces the pulsing buffering text
   when warmup never completes. Multi-line, static (no pulse). */
#bufferingStatus.failed {
    opacity: 0.75;
    animation: none;
    white-space: normal;
    text-align: center;
    line-height: 1.7;
}

#colorToggle,
#playPauseBtn,
#infoBtn,
#playerPrev,
#playerNext {
    position: fixed;
    bottom: 18px;
    z-index: 30;
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--ink);
    border-radius: 50%;
    cursor: pointer;
    color: var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}
body.streaming #colorToggle,
body.streaming #playPauseBtn,
body.streaming #infoBtn,
body.streaming #playerPrev,
body.streaming #playerNext {
    opacity: 0.35;
    pointer-events: auto;
}
#colorToggle  { right: 18px; }
#playPauseBtn { right: 56px; }
#infoBtn      { right: 94px; }
#playerPrev   { left: 18px; }
#playerNext   { left: 56px; }
#colorToggle:hover,
#playPauseBtn:hover,
#infoBtn:hover,
#playerPrev:hover,
#playerNext:hover { opacity: 1; }
#colorToggle svg,
#playPauseBtn svg,
#infoBtn svg,
#playerPrev svg,
#playerNext svg { width: 14px; height: 14px; display: block; }

#infoPopover {
    position: fixed;
    bottom: 60px;
    right: 18px;
    z-index: 35;
    min-width: 280px;
    max-width: 360px;
    padding: 18px 22px 16px;
    background: rgba(244, 243, 239, 0.96);
    border: 1px solid rgba(10, 10, 10, 0.22);
    border-radius: 4px;
    backdrop-filter: blur(8px);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.12);
    color: var(--ink);
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 0.22s ease, transform 0.22s ease;
}
#infoPopover.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}
#infoPopover .infoHead {
    font-family: 'Kumbh Sans', 'Segoe UI', sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    opacity: 0.55;
    margin-bottom: 12px;
}
#infoPopover .legend {
    margin: 0;
    opacity: 1;
    max-width: none;
    gap: 14px 36px;
    font-size: 0.78rem;
}
#infoPopover .infoClose {
    position: absolute;
    top: 4px;
    right: 6px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    color: var(--ink);
    font-size: 1.15rem;
    line-height: 1;
    opacity: 0.45;
    transition: opacity 0.15s ease;
}
#infoPopover .infoClose:hover { opacity: 1; }

/* Coincidence-detection tweak panel — top-left, hidden by default;
   Shift+C toggles. */
#fxPanel {
    position: fixed;
    top: 10px; left: 10px;
    z-index: 30;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(10, 10, 10, 0.2);
    font: 11px/1.3 ui-monospace, monospace;
    color: var(--ink);
    padding: 6px 8px;
    border-radius: 3px;
    backdrop-filter: blur(6px);
    user-select: none;
    min-width: 160px;
    display: none;
}
#fxPanel.visible { display: block; }
#fxPanel .fxHead {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; margin-bottom: 6px; opacity: 0.75;
}
#fxPanel.collapsed .fxHead { margin-bottom: 0; }
#fxPanel.collapsed .fxBody { display: none; }
#fxPanel .fxToggle {
    background: none; border: none; padding: 0 4px;
    cursor: pointer; font: inherit; color: inherit;
}
#fxPanel label {
    display: flex; justify-content: space-between; align-items: center;
    gap: 8px; margin: 2px 0;
}
#fxPanel input, #fxPanel select {
    font: inherit; padding: 1px 4px; width: 80px;
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(10, 10, 10, 0.2);
    color: inherit;
}
#fxPanel input[type="color"] {
    padding: 0; width: 32px; height: 18px; cursor: pointer;
}
#fxPanel .fxStatus {
    margin-top: 6px; padding-top: 6px;
    border-top: 1px dashed rgba(10, 10, 10, 0.15);
    opacity: 0.7; font-size: 10px; line-height: 1.4;
}
#fxPanel .fxLog {
    margin-top: 4px;
    opacity: 0.85; font-size: 10px; line-height: 1.5;
    white-space: pre;
    max-height: 96px;
    overflow: hidden;
}
#fxPanel .fxLog .fxLogDot {
    display: inline-block; width: 7px; height: 7px;
    border-radius: 50%; margin-right: 4px;
    vertical-align: middle;
}
