/* ─── Mahler listening notes — page-specific styles ───
   Built on the site tokens in style.css and the shared chrome in
   assets/experiment.css (.btn, .seg).

   The page reads in a permanent light-on-dark mode: body.atmos-dark is always
   on (set in the markup) and the --m-* tokens below carry the dark palette.
   On top of that it carries an "atmosphere": as you scroll, a fixed background
   layer slowly cross-fades a per-work dark gradient (plus film grain) that
   reflects the character of the symphony in view (see ATMOS in mahler.js) —
   every work keeps its own colour, only the lightness stays pinned dark. The
   notation panels are a dark "slate" with light ink (abcjs draws in
   currentColor; the piano-roll palette lives in mahler.js) so the music keeps
   legible against the dark page. */

:root {
    /* Brightened for the dark page; --accent/-soft are also overridden per
       work by the atmosphere (see ATMOS in mahler.js). */
    --accent: hsl(210, 55%, 62%); --accent-soft: hsla(210, 55%, 62%, 0.18);
    --good: hsl(145, 52%, 58%); --good-soft: hsla(145, 52%, 50%, 0.18);
    --bad: hsl(8, 72%, 64%); --bad-soft: hsla(8, 72%, 55%, 0.18);

    /* Atmosphere-aware tokens (bare-fallback light defaults; the always-on
       body.atmos-dark below supplies the real dark palette). */
    --m-ink: var(--ink);
    --m-title: var(--title);
    --m-body: var(--body);
    --m-faint: var(--faint);
    --m-line: var(--line);
    --m-rule: var(--rule);
    --m-card: rgba(252, 252, 251, 0.86);
    --m-card-bd: var(--line);
    --m-paper: #FBFAF8;                 /* notation surface — light fallback (page is always dark, see body.atmos-dark) */
    --m-paper-ink: #1d2026;             /* notation ink (abcjs currentColor) for the light fallback */
    --m-bar: rgba(248, 248, 247, 0.86); /* sticky context bar */
    --m-panel: rgba(248, 248, 247, 0.96); /* fly-out drawer */
    --m-chip-bg: rgba(0, 0, 0, 0.04);
    --m-glow: rgba(31, 111, 158, 0.10);
}

/* Always on (see <body class="atmos-dark">): light text on the dark gradient,
   cards become dark glass. Every atmosphere in ATMOS is dark. */
body.atmos-dark {
    --m-ink: #f3efe8;
    --m-title: #f8f5ef;
    --m-body: rgba(238, 234, 226, 0.82);
    --m-faint: rgba(234, 230, 222, 0.5);
    --m-line: rgba(255, 255, 255, 0.14);
    --m-rule: rgba(255, 255, 255, 0.16);
    --m-card: rgba(18, 20, 22, 0.55);
    --m-card-bd: rgba(255, 255, 255, 0.12);
    --m-paper: #191c22;                 /* notation surface — dark slate */
    --m-paper-ink: #e9e4da;             /* notation ink — light, drawn by abcjs in currentColor */
    --m-bar: rgba(10, 12, 14, 0.62);
    --m-panel: rgba(13, 15, 17, 0.93);
    --m-chip-bg: rgba(255, 255, 255, 0.08);
    --m-glow: rgba(0, 0, 0, 0.5);
}

/* ─── Atmosphere background ─── */
html { background: #0a0b0e; }          /* dark base behind the fixed atmosphere */
body { background: transparent; color: var(--m-body); }
.atmos {
    position: fixed;
    inset: 0;
    z-index: -1;                       /* behind all page content */
    pointer-events: none;
    overflow: hidden;
}
.atmos-layer {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 1.2s ease;
    will-change: opacity;
}
.atmos-grain {
    position: absolute;
    inset: 0;
    opacity: 0;
    mix-blend-mode: overlay;
    transition: opacity 1.2s ease;
    background-repeat: repeat;
    background-size: 160px 160px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Slow, mood-following colour shifts for the chrome and cards. */
.ctxbar, .ctx-home, .ctx-work, .ctx-move,
.m-intro h1, .m-sub, .m-sub em, .m-note, .m-ctl-lab,
.m-section > h2, .m-work > h3, .m-work > h3::after,
.theme-name, .theme-blurb, .theme-meta, .theme-meta .mv,
.chip, .cite, .theme-view, .m-foot, .m-foot a {
    transition: background-color 0.9s ease, color 0.9s ease, border-color 0.9s ease;
}

/* ─── Slim sticky context bar ─── */
.ctxbar {
    position: sticky;
    top: 0;
    z-index: 70;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px max(14px, env(safe-area-inset-left)) 8px max(14px, env(safe-area-inset-left));
    min-height: 46px;
    background: var(--m-bar);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--m-rule);
}
.ctx-home {
    font-family: var(--mono);
    font-size: 17px;
    line-height: 1;
    color: var(--m-body);
    text-decoration: none;
    padding: 4px 6px;
    border-radius: 4px;
    flex: 0 0 auto;
}
.ctx-home:hover { color: var(--m-ink); }

/* Table-of-contents toggle (replaces the old work chips). */
.ctx-toc {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 11px;
}
.toc-ic {
    display: inline-block;
    width: 14px; height: 11px;
    position: relative;
    flex: 0 0 auto;
}
.toc-ic::before {
    content: "";
    position: absolute;
    left: 0; right: 0; top: 0;
    height: 1.6px;
    background: currentColor;
    box-shadow: 0 4.7px currentColor, 0 9.4px currentColor;
    border-radius: 1px;
}
.ctx-label {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}
.ctx-work {
    font-family: var(--serif);
    font-size: 16px;
    font-weight: 500;
    color: var(--m-ink);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ctx-move {
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--m-faint);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ctx-quiz { flex: 0 0 auto; }

/* The whole page reads light-on-dark, so the shared chrome (experiment.css
   .btn / .seg, tuned for light) needs lighter ink and an inverted active
   state. The notation "paper" and quiz card carry their own colours. */
body.atmos-dark .btn {
    color: var(--m-body);
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.22);
}
body.atmos-dark .btn:hover { color: var(--m-ink); border-color: rgba(255, 255, 255, 0.42); }
body.atmos-dark .btn.active,
body.atmos-dark .ctx-quiz.active { background: var(--m-ink); color: #16181d; border-color: var(--m-ink); }
body.atmos-dark .seg { border-color: var(--m-line); }
body.atmos-dark .seg button { color: var(--m-body); }
body.atmos-dark .seg button + button { border-left-color: var(--m-line); }
body.atmos-dark .seg button:hover { color: var(--m-ink); }
body.atmos-dark .seg button.active { background: var(--m-ink); color: #16181d; }

main.mahler {
    max-width: 840px;
    margin: 0 auto;
    padding: 22px 20px 16vh;
}

/* ─── Intro ─── */
.m-intro { margin-bottom: 26px; }
.m-intro h1 {
    font-family: var(--serif);
    font-weight: 500;
    font-size: clamp(28px, 5vw, 40px);
    line-height: 1.15;
    color: var(--m-ink);
    margin-bottom: 16px;
}
.m-sub { font-size: 18px; color: var(--m-body); max-width: 62ch; text-wrap: pretty; }
.m-sub em { font-style: italic; color: var(--m-title); }
.m-sub b, .m-note b { color: var(--m-title); font-weight: 600; }
.m-note {
    margin-top: 12px;
    font-size: 15px;
    color: var(--m-faint);
    max-width: 64ch;
    text-wrap: pretty;
}
.m-note code {
    font-family: var(--mono);
    font-size: 0.85em;
    background: var(--m-chip-bg);
    padding: 1px 4px;
    border-radius: 3px;
}
.m-opts {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 18px;
    flex-wrap: wrap;
}
.m-ctl-lab {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--m-faint);
}

/* ─── Section + work headings ─── */
.m-section > h2 {
    font-family: var(--serif);
    font-weight: 500;
    font-size: 16px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--m-faint);
    margin: 34px 0 4px;
}
.m-work { scroll-margin-top: 62px; margin-top: 26px; }
.m-work > h3 {
    font-family: var(--serif);
    font-weight: 500;
    font-size: 25px;
    color: var(--m-ink);
    margin-bottom: 2px;
}
.m-work > h3::after {
    content: "";
    display: block;
    width: 30px; height: 1px;
    background: var(--m-rule);
    margin: 12px 0 18px;
}

/* ─── Theme card ─── */
.theme {
    border: 1px solid var(--m-card-bd);
    border-radius: 10px;
    padding: 16px 18px 14px;
    margin-bottom: 16px;
    background: var(--m-card);
    scroll-margin-top: 60px;
    transition: background-color 0.9s ease, border-color 0.2s, box-shadow 0.2s;
}
/* the theme nearest the centre of the viewport (shown in the sticky bar) */
.theme.current {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent), 0 6px 24px var(--m-glow);
}
.theme-meta {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--m-faint);
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    margin-bottom: 5px;
}
.theme-meta .mv { color: var(--m-body); }
.theme-tag {
    color: var(--accent);
    border: 1px solid var(--accent-soft);
    background: var(--accent-soft);
    border-radius: 4px;
    padding: 0 6px;
}
.theme-name {
    font-family: var(--serif);
    font-weight: 500;
    font-size: 21px;
    line-height: 1.25;
    color: var(--m-title);
    margin-bottom: 6px;
}
.theme-blurb {
    font-size: 16px;
    line-height: 1.55;
    color: var(--m-body);
    margin-bottom: 10px;
    text-wrap: pretty;
}
/* character-adjective chips */
.theme-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 12px; }
.chip {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.02em;
    color: var(--m-body);
    background: var(--m-chip-bg);
    border: 1px solid var(--m-line);
    border-radius: 999px;
    padding: 2px 9px;
}
.work-emoji { font-style: normal; }

/* ─── Notation view (shared by cards and quiz) — dark "slate", light ink ─── */
.theme-view {
    position: relative;
    border: 1px solid var(--m-line);
    border-radius: 7px;
    background: var(--m-paper);
    color: var(--m-paper-ink);         /* abcjs draws staff + notes in currentColor */
    overflow: hidden;
    min-height: 96px;
}
.m-staff { overflow-x: auto; padding: 4px 6px; }
.m-staff svg { display: block; max-width: 100%; height: auto; }
.m-staff .m-active,
.m-staff .m-active path,
.m-staff .m-active ellipse {
    fill: var(--accent) !important;
    stroke: var(--accent) !important;
}
.m-roll { display: block; width: 100%; height: 132px; }

/* ─── Card controls ─── */
.theme-ctrls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    margin-top: 11px;
}
.play-btn {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 500;
    color: #ffffff;                 /* crisp white on a deeper blue for contrast */
    background: hsl(210, 66%, 42%);
    border: 1px solid hsl(210, 66%, 38%);
    border-radius: 5px;
    padding: 8px 15px 8px 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    transition: filter 0.15s, background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.play-btn:hover { filter: brightness(1.08); }
.play-btn .ic, .play-btn .lab { color: #ffffff; }
.play-btn.playing { background: #2b2f37; border-color: rgba(255, 255, 255, 0.22); }
.play-btn .ic { font-size: 11px; line-height: 1; }
.seg.seg--mini button { padding: 7px 11px; font-size: 12px; }
.cite {
    margin-left: auto;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--m-faint);
    text-decoration: none;
}
.cite:hover, .cite:focus-visible { color: var(--accent); text-decoration: underline; }

/* ─── Fly-out table of contents ─── */
.toc-backdrop {
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(10, 10, 12, 0.42);
    opacity: 0;
    transition: opacity 0.28s ease;
    -webkit-backdrop-filter: blur(1px);
    backdrop-filter: blur(1px);
}
.toc-backdrop.show { opacity: 1; }
.toc-panel {
    position: fixed;
    top: 0; left: 0;
    z-index: 95;
    height: 100%;
    width: min(340px, 86vw);
    display: flex;
    flex-direction: column;
    background: var(--m-panel);
    border-right: 1px solid var(--m-rule);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.18);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    transform: translateX(-102%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding-left: env(safe-area-inset-left);
}
.toc-panel.open { transform: translateX(0); }
.toc-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: max(12px, env(safe-area-inset-top)) 14px 10px 16px;
    border-bottom: 1px solid var(--m-rule);
}
.toc-title { font-family: var(--serif); font-size: 19px; font-weight: 500; color: var(--m-ink); }
.toc-close { line-height: 1; padding: 6px 9px; }
.toc-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 8px 10px calc(28px + env(safe-area-inset-bottom));
}
.toc-section { margin-bottom: 10px; }
.toc-section-h {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--m-faint);
    padding: 10px 10px 4px;
}
.toc-works { list-style: none; }
.toc-work-row { display: flex; align-items: stretch; gap: 2px; }
.toc-work-row--head { margin-top: 2px; }
.toc-work {
    flex: 1 1 auto;
    min-width: 0;
    display: block;
    font-family: var(--serif);
    font-size: 16.5px;
    line-height: 1.3;
    color: var(--m-body);
    text-decoration: none;
    padding: 9px 10px;
    border-radius: 7px;
}
.toc-work-row--head .toc-work { font-weight: 500; color: var(--m-ink); }
.toc-emoji { font-style: normal; margin-right: 2px; }
.toc-work:hover, .toc-work:focus-visible { background: var(--m-chip-bg); color: var(--m-ink); }
.toc-work-row.current .toc-work { color: var(--accent); }
.toc-exp {
    flex: 0 0 auto;
    width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--m-faint);
    cursor: pointer;
    border-radius: 7px;
    -webkit-tap-highlight-color: transparent;
}
.toc-exp:hover { color: var(--m-ink); background: var(--m-chip-bg); }
.toc-exp .caret {
    width: 0; height: 0;
    border-left: 5px solid currentColor;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform 0.2s ease;
}
.toc-exp[aria-expanded="true"] .caret { transform: rotate(90deg); }
.toc-moves { list-style: none; margin: 0 0 4px; padding-left: 16px; }
.toc-move {
    display: block;
    font-family: var(--sans);
    font-size: 13px;
    line-height: 1.35;
    color: var(--m-faint);
    text-decoration: none;
    padding: 7px 10px;
    border-left: 1px solid var(--m-line);
    border-radius: 0 6px 6px 0;
}
.toc-move:hover, .toc-move:focus-visible { color: var(--m-ink); background: var(--m-chip-bg); border-left-color: var(--accent); }
.toc-move.current { color: var(--accent); border-left-color: var(--accent); }

/* ─── Quiz ─── (dark, like the rest of the page; notation is the same dark slate) */
.quiz { max-width: 640px; margin: 8px auto 0; }
.quiz-head {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.quiz-head h2 {
    font-family: var(--serif); font-weight: 500; font-size: 24px; color: var(--m-title);
}
.quiz-score { font-family: var(--mono); font-size: 13px; color: var(--m-body); }
.quiz-score b { color: var(--m-ink); }
.quiz-card {
    border: 1px solid var(--m-card-bd);
    border-radius: 12px;
    padding: 16px 18px 18px;
    background: var(--m-card);
}
.quiz-prompt {
    font-family: var(--mono); font-size: 12px; letter-spacing: 0.03em;
    text-transform: uppercase; color: var(--m-faint); margin-bottom: 10px;
}
.quiz-play { margin: 12px 0 4px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.quiz-q { margin-top: 18px; }
.quiz-q > .ql {
    font-family: var(--sans); font-size: 14px; color: var(--m-body);
    margin-bottom: 7px; display: block;
}
.quiz-q > .ql b { color: var(--m-ink); font-weight: 600; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.opt {
    font-family: var(--sans);
    font-size: 14px;
    text-align: left;
    color: var(--m-title);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--m-line);
    border-radius: 7px;
    padding: 9px 11px;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
    -webkit-tap-highlight-color: transparent;
    line-height: 1.3;
}
.opt:hover { border-color: var(--m-faint); }
.opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.opts.locked .opt { cursor: default; }
.opt.correct { border-color: var(--good); background: var(--good-soft); color: var(--good); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
.quiz-actions { display: flex; gap: 10px; align-items: center; margin-top: 20px; flex-wrap: wrap; }
.quiz-actions .grow { margin-left: auto; }
.btn-primary {
    font-family: var(--mono); font-size: 14px;
    color: #16181d; background: #e9e5dc; border: 1px solid #e9e5dc;
    border-radius: 6px; padding: 9px 18px; cursor: pointer;
}
.btn-primary[disabled] { opacity: 0.4; cursor: default; }
.quiz-reveal {
    margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--m-line);
    font-size: 15px; color: var(--m-body); line-height: 1.5;
}
.quiz-reveal .rname { font-family: var(--serif); font-size: 18px; color: var(--m-title); }
.quiz-reveal .pts { font-family: var(--mono); color: var(--accent); }
.quiz-reveal a { color: var(--accent); font-family: var(--mono); font-size: 13px; }

.m-foot {
    margin-top: 48px;
    padding-top: 18px;
    border-top: 1px solid var(--m-rule);
    font-family: var(--mono);
    font-size: 13px;
    color: var(--m-faint);
    line-height: 1.6;
}
.m-foot a { color: var(--m-body); }
.m-loading { color: var(--m-faint); font-family: var(--mono); }
[hidden] { display: none !important; }

/* ─── Mobile ─── */
@media (max-width: 560px) {
    main.mahler { padding-left: 14px; padding-right: 14px; }
    .theme { padding: 14px 13px 12px; }
    .theme-name { font-size: 19px; }
    .ctx-work { font-size: 15px; }
    .opts { grid-template-columns: 1fr; }
    .quiz-card { padding: 14px 13px 16px; }
    .m-sub { font-size: 17px; }
}
@media (max-width: 480px) {
    .ctx-toc-lab { display: none; }       /* icon-only toggle on narrow screens */
    .ctx-toc { padding: 7px 9px; }
}
@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto; }
    .atmos-layer, .atmos-grain { transition-duration: 0.2s; }
    .toc-panel { transition-duration: 0.001s; }
    .ctxbar, .ctx-home, .ctx-work, .ctx-move,
    .m-intro h1, .m-sub, .m-sub em, .m-note, .m-ctl-lab,
    .m-section > h2, .m-work > h3, .m-work > h3::after,
    .theme, .theme-name, .theme-blurb, .theme-meta, .theme-meta .mv,
    .chip, .cite, .theme-view, .m-foot, .m-foot a {
        transition-duration: 0.2s;
    }
}
