/* Visual layer: "temple dawn". Loaded after app.css, adds atmosphere on top of the existing tokens.
   Nothing here changes layout, data or behaviour: decoration sits in #backdrop (fixed, behind everything,
   aria-hidden), and the rest only refines surfaces, headings, states and motion.
   Motion gate: everything that moves is either driven by --dur-slow (zeroed for reduced motion) or sits inside
   @media (prefers-reduced-motion: no-preference) and :root:not([data-motion="off"]).
   The high-contrast theme drops all decoration and keeps opaque surfaces. */

:root {
  --dur-slow: 320ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --glow-a: rgba(245, 184, 102, 0.3);
  --glow-b: rgba(122, 30, 44, 0.07);
  --grain: rgba(122, 30, 44, 0.16);
  --wm-opacity: 0.08;
  --wm-a: var(--primary);
  --wm-b: var(--secondary);
  --glass: 0.86;
  --lift: 0 8px 22px rgba(94, 18, 32, 0.14);
}
:root[data-theme="light"] {
  --glow-a: rgba(245, 184, 102, 0.3);
  --glow-b: rgba(122, 30, 44, 0.07);
  --grain: rgba(122, 30, 44, 0.16);
  --wm-opacity: 0.08;
  --lift: 0 8px 22px rgba(94, 18, 32, 0.14);
}
:root[data-theme="dark"] {
  --glow-a: rgba(245, 184, 102, 0.09);
  --glow-b: rgba(240, 179, 185, 0.06);
  --grain: rgba(245, 184, 102, 0.16);
  --wm-opacity: 0.09;
  --lift: 0 8px 22px rgba(0, 0, 0, 0.45);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --glow-a: rgba(245, 184, 102, 0.09);
    --glow-b: rgba(240, 179, 185, 0.06);
    --grain: rgba(245, 184, 102, 0.16);
    --wm-opacity: 0.09;
    --lift: 0 8px 22px rgba(0, 0, 0, 0.45);
  }
}
:root[data-motion="off"] { --dur-slow: 0ms; }
@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="on"]) { --dur-slow: 0ms; }
}

/* ------------------------------------------------------------------ backdrop: glows, grain, watermarks */

#backdrop {
  position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; user-select: none;
  background:
    radial-gradient(60% 42% at 92% 0%, var(--glow-a), transparent 72%),
    radial-gradient(52% 40% at 0% 100%, var(--glow-b), transparent 72%);
  /* Per-scene placement; see body[data-scene] below. */
  --a-x: 58%; --a-y: -14%; --a-s: clamp(240px, 56vmin, 600px); --a-r: 12deg;
  --b-x: -16%; --b-y: 58%; --b-s: clamp(200px, 44vmin, 480px); --b-r: -8deg;
}
#backdrop::before {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(circle at 1px 1px, var(--grain) 1px, transparent 1.4px);
  background-size: 24px 24px;
  opacity: 0.35;
  -webkit-mask-image: linear-gradient(160deg, #000 0%, transparent 38%, transparent 62%, #000 100%);
  mask-image: linear-gradient(160deg, #000 0%, transparent 38%, transparent 62%, #000 100%);
}
.wm-slot { position: absolute; aspect-ratio: 1; }
.wm-a { left: var(--a-x); top: var(--a-y); width: var(--a-s); height: var(--a-s); rotate: var(--a-r); color: var(--wm-a); opacity: var(--wm-opacity); }
.wm-b { left: var(--b-x); top: var(--b-y); width: var(--b-s); height: var(--b-s); rotate: var(--b-r); color: var(--wm-b); opacity: calc(var(--wm-opacity) * 0.85); }
.wm-slot .glyph { display: block; width: 100%; height: 100%; max-width: none; animation: wm-in calc(var(--dur-slow) * 2.5) var(--ease-out) backwards; }
@keyframes wm-in { from { opacity: 0; scale: 0.94; } to { opacity: 1; scale: 1; } }

body[data-scene="none"] #backdrop > * { display: none; }
body[data-scene="none"] #backdrop { background: none; }
body[data-scene="none"] #backdrop::before { display: none; }

body[data-scene="home"] #backdrop { --a-x: 56%; --a-y: -14%; --a-s: clamp(260px, 58vmin, 620px); --a-r: 12deg; --b-x: -18%; --b-y: 58%; --b-s: clamp(200px, 44vmin, 480px); --b-r: -8deg; }
body[data-scene="explore"] #backdrop,
body[data-scene="category"] #backdrop { --a-x: -20%; --a-y: 2%; --a-s: clamp(240px, 52vmin, 560px); --a-r: -10deg; --b-x: 62%; --b-y: 54%; --b-s: clamp(220px, 54vmin, 560px); --b-r: 14deg; }
body[data-scene="search"] #backdrop,
body[data-scene="searchResults"] #backdrop { --a-x: 66%; --a-y: 28%; --a-s: clamp(220px, 46vmin, 500px); --a-r: 6deg; --b-x: -12%; --b-y: 64%; --b-s: clamp(180px, 38vmin, 400px); --b-r: 0deg; }
body[data-scene="library"] #backdrop,
body[data-scene="playlist"] #backdrop { --a-x: -14%; --a-y: 48%; --a-s: clamp(240px, 52vmin, 560px); --a-r: 0deg; --b-x: 70%; --b-y: -8%; --b-s: clamp(180px, 40vmin, 420px); --b-r: 20deg; }
body[data-scene="profile"] #backdrop,
body[data-scene="account"] #backdrop { --a-x: 60%; --a-y: 50%; --a-s: clamp(260px, 56vmin, 600px); --a-r: -6deg; --b-x: -18%; --b-y: -8%; --b-s: clamp(190px, 40vmin, 420px); --b-r: 10deg; }
body[data-scene="content"] #backdrop { --a-x: 68%; --a-y: 6%; --a-s: clamp(190px, 40vmin, 420px); --a-r: 8deg; --b-x: -20%; --b-y: 60%; --b-s: clamp(240px, 48vmin, 520px); --b-r: -14deg; }
body[data-scene="collections"] #backdrop,
body[data-scene="collection"] #backdrop { --a-x: -16%; --a-y: -10%; --a-s: clamp(220px, 48vmin, 520px); --a-r: 0deg; --b-x: 62%; --b-y: 62%; --b-s: clamp(200px, 46vmin, 480px); --b-r: 8deg; }
body[data-scene="notifications"] #backdrop,
body[data-scene="assistant"] #backdrop { --a-x: 70%; --a-y: 56%; --a-s: clamp(200px, 44vmin, 480px); --a-r: 0deg; --b-x: -14%; --b-y: 8%; --b-s: clamp(180px, 38vmin, 400px); --b-r: -12deg; }
body[data-scene="about"] #backdrop,
body[data-scene="privacy"] #backdrop,
body[data-scene="terms"] #backdrop,
body[data-scene="support"] #backdrop { --a-x: 60%; --a-y: 4%; --a-s: clamp(220px, 50vmin, 540px); --a-r: 0deg; --b-x: -20%; --b-y: 60%; --b-s: clamp(200px, 44vmin, 480px); --b-r: 6deg; }
body[data-scene="onboarding"] #backdrop { --a-x: 30%; --a-y: -24%; --a-s: clamp(300px, 72vmin, 720px); --a-r: 0deg; --b-x: -22%; --b-y: 56%; --b-s: clamp(220px, 50vmin, 520px); --b-r: -10deg; }

/* High contrast: no decoration at all. */
:root[data-theme="contrast"] #backdrop { display: none; }

/* Slow parallax: the two watermarks drift in opposite directions as the page scrolls. */
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: scroll()) {
    :root:not([data-motion="off"]) .wm-a { animation: wm-drift-a linear both; animation-timeline: scroll(root); }
    :root:not([data-motion="off"]) .wm-b { animation: wm-drift-b linear both; animation-timeline: scroll(root); }
    @keyframes wm-drift-a { to { translate: 0 -9vmin; } }
    @keyframes wm-drift-b { to { translate: 0 7vmin; } }
  }
}

/* ------------------------------------------------------------------ glass surfaces */

@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  /* The bar is inset by the screen padding, so the glass lives on a pseudo-element that bleeds to both edges. */
  .screen .topbar { background: transparent; }
  .screen .topbar::before {
    content: ""; position: absolute; inset: 0 calc(-1 * var(--gutter)); z-index: -1; pointer-events: none;
    background: color-mix(in srgb, var(--background) calc(var(--glass) * 100%), transparent);
    -webkit-backdrop-filter: blur(14px) saturate(1.25); backdrop-filter: blur(14px) saturate(1.25);
  }
  .nav {
    background: color-mix(in srgb, var(--surface-container) 90%, transparent);
    -webkit-backdrop-filter: blur(16px) saturate(1.25); backdrop-filter: blur(16px) saturate(1.25);
  }
  .mini-player {
    background: color-mix(in srgb, var(--surface-highest) 92%, transparent);
    -webkit-backdrop-filter: blur(16px) saturate(1.25); backdrop-filter: blur(16px) saturate(1.25);
  }
  /* Other sticky bars (search header, assistant composer, onboarding actions) painted a solid box over the glow; same full-bleed treatment. */
  .screen.search .search-head,
  .screen.assistant-screen .assistant-composer,
  .screen.onb .onb-actions { background: transparent; isolation: isolate; }
  .screen.search .search-head::before,
  .screen.assistant-screen .assistant-composer::before,
  .screen.onb .onb-actions::before {
    content: ""; position: absolute; inset: 0 calc(-1 * var(--gutter)); z-index: -1; pointer-events: none;
    background: color-mix(in srgb, var(--background) calc(var(--glass) * 100%), transparent);
    -webkit-backdrop-filter: blur(14px) saturate(1.25); backdrop-filter: blur(14px) saturate(1.25);
  }
  /* Bottom bars fade in from the top so the glass does not slice the watermark with a hard edge. */
  .screen.assistant-screen .assistant-composer::before,
  .screen.onb .onb-actions::before {
    -webkit-mask-image: linear-gradient(to bottom, transparent, #000 28%);
    mask-image: linear-gradient(to bottom, transparent, #000 28%);
  }
  :root[data-theme="contrast"] .screen.assistant-screen .assistant-composer::before,
  :root[data-theme="contrast"] .screen.onb .onb-actions::before { -webkit-mask-image: none; mask-image: none; }
  :root[data-theme="contrast"] .screen .topbar::before,
  :root[data-theme="contrast"] .screen.search .search-head::before,
  :root[data-theme="contrast"] .screen.assistant-screen .assistant-composer::before,
  :root[data-theme="contrast"] .screen.onb .onb-actions::before { background: var(--background); -webkit-backdrop-filter: none; backdrop-filter: none; }
  :root[data-theme="contrast"] .nav { background: var(--surface-container); -webkit-backdrop-filter: none; backdrop-filter: none; }
  :root[data-theme="contrast"] .mini-player { background: var(--surface-highest); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
.nav a[aria-current="page"] .pill { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--secondary) 35%, transparent); }
.nav a .pill { transition: background var(--dur-short), transform var(--dur-medium) var(--ease-out); }
.nav a:active .pill { transform: scale(0.94); }
.mini-player { box-shadow: 0 -6px 18px rgba(42, 35, 32, 0.08); }

/* ------------------------------------------------------------------ headings */

.section-title h2 { display: flex; align-items: center; gap: 10px; }
.section-title h2::before {
  content: ""; flex: none; width: 10px; height: 16px; border-radius: 10px 0 10px 0;
  background: linear-gradient(135deg, var(--secondary), var(--primary));
}
.screen-title h1::after {
  content: ""; display: block; width: 56px; height: 3px; margin-top: 8px; border-radius: 2px;
  background: linear-gradient(90deg, var(--secondary), color-mix(in srgb, var(--primary) 0%, transparent));
}
.topbar h1 { letter-spacing: 0.005em; }
:root[data-theme="contrast"] .section-title h2::before { background: var(--primary); }
:root[data-theme="contrast"] .screen-title h1::after { background: var(--primary); }

.orn-divider { display: flex; align-items: center; gap: var(--sp-md); margin: var(--sp-lg) auto; max-width: 360px; color: var(--secondary); }
.orn-divider svg { flex: none; width: 20px; height: 20px; }
.orn-line { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, color-mix(in srgb, currentColor 55%, transparent)); }
.orn-line:last-child { background: linear-gradient(270deg, transparent, color-mix(in srgb, currentColor 55%, transparent)); }
:root[data-theme="contrast"] .orn-divider { display: none; }

/* ------------------------------------------------------------------ cards and buttons */

.art-box::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 88% 0%, rgba(255, 255, 255, 0.2), transparent 58%);
}
.content-card, .content-row-card { box-shadow: 0 0 0 1px color-mix(in srgb, var(--outline-variant) 70%, transparent); }
.content-card { transition: transform var(--dur-short), translate var(--dur-medium) var(--ease-out), box-shadow var(--dur-medium); }
.content-row-card { transition: translate var(--dur-medium) var(--ease-out), box-shadow var(--dur-medium); }
@media (hover: hover) {
  .content-card:hover, .content-row-card:hover { translate: 0 -2px; box-shadow: var(--lift), 0 0 0 1px color-mix(in srgb, var(--outline-variant) 70%, transparent); }
}
.cat-card { transition: transform var(--dur-short), box-shadow var(--dur-medium); }
.cat-card:active { transform: scale(var(--press-scale)); }
@media (hover: hover) { .cat-card:hover { box-shadow: var(--lift); } }

.btn:not(.tonal):not(.outlined):not(.text):not(.danger) {
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0) 60%);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 26%, transparent);
}
:root[data-theme="contrast"] .btn:not(.tonal):not(.outlined):not(.text):not(.danger) { background-image: none; box-shadow: none; }
.chip { transition: background var(--dur-short), color var(--dur-short), transform var(--dur-short); }
.chip:active { transform: scale(var(--press-scale)); }

/* ------------------------------------------------------------------ states: empty, error, loading */

.state-art { position: relative; display: grid; place-items: center; width: 112px; height: 112px; margin-bottom: var(--sp-xs); color: var(--primary); }
.state-art.tone-gold { color: var(--secondary); }
.state-art.tone-quiet { color: var(--on-surface-variant); }
.state-art.tone-error { color: var(--error); }
.state-art::before {
  content: ""; position: absolute; inset: -22%; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, currentColor 16%, transparent), transparent 66%);
}
.state-art::after {
  content: ""; position: absolute; inset: 27%; border-radius: 50%;
  background: color-mix(in srgb, currentColor 11%, var(--surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 28%, transparent);
}
.state .state-art .halo { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.6; z-index: 0; }
.state .state-art .icon { position: relative; z-index: 1; width: 32px; height: 32px; opacity: 1; }
.state-art.tone-error::after { background: color-mix(in srgb, var(--error) 12%, var(--surface)); }
@media (prefers-reduced-motion: no-preference) {
  :root:not([data-motion="off"]) .state-art .halo { animation: halo-turn 90s linear infinite; }
  :root:not([data-motion="off"]) .state-art { animation: art-in calc(var(--dur-slow) * 1.5) var(--ease-out) backwards; }
}
@keyframes halo-turn { to { transform: rotate(360deg); } }
@keyframes art-in { from { opacity: 0; scale: 0.9; } to { opacity: 1; scale: 1; } }
.state { max-width: 440px; margin-inline: auto; }

/* Banners: icons passed without a size attribute had no width rule and stretched to fill the row. */
.banner { border-radius: var(--r-md); box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 12%, transparent); }
.banner > svg { width: 22px; height: 22px; flex: none; margin-top: 2px; }
.banner > span, .banner > p { min-width: 0; }
.state p { max-width: 36ch; }

/* Loading: a turning lotus ring and a few skeleton lines that hint at content. */
.state.loading { gap: var(--sp-md); }
.loader { position: relative; width: 56px; height: 56px; color: var(--primary); }
.loader::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 0deg, currentColor, color-mix(in srgb, currentColor 0%, transparent) 70%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  animation: spin 1.1s linear infinite;
}
.loader svg { position: absolute; inset: 14px; width: 28px; height: 28px; color: var(--secondary); }
.skel-lines { display: flex; flex-direction: column; gap: var(--sp-sm); width: 100%; max-width: 280px; }
.skel-lines .skeleton { height: 12px; border-radius: 6px; }
.skel-lines .skeleton:nth-child(1) { width: 100%; }
.skel-lines .skeleton:nth-child(2) { width: 84%; }
.skel-lines .skeleton:nth-child(3) { width: 62%; }
.skel-card { display: flex; gap: var(--sp-md); padding: var(--sp-md); border-radius: var(--r-md); background: var(--surface-container); }
.skel-card .skeleton:first-child { flex: none; width: 72px; height: 72px; border-radius: var(--r-sm); }
.skel-card .skel-lines { max-width: none; justify-content: center; }

/* ------------------------------------------------------------------ dialogs and sheets */

dialog.modal, dialog.sheet { box-shadow: 0 24px 64px rgba(20, 12, 8, 0.32); }
dialog[open]::backdrop { animation: fade-in var(--dur-medium) both; -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
dialog.modal[open] { animation: dlg-in var(--dur-slow) var(--ease-out) backwards; }
dialog.sheet[open] { animation: sheet-in var(--dur-slow) var(--ease-out) backwards; }
@keyframes dlg-in { from { opacity: 0; translate: 0 12px; scale: 0.97; } to { opacity: 1; translate: 0 0; scale: 1; } }
@keyframes sheet-in { from { opacity: 0.4; translate: 0 36px; } to { opacity: 1; translate: 0 0; } }
.dialog-inner .grabber { width: 40px; background: var(--outline); opacity: 0.55; }
.toast { animation: toast-in var(--dur-slow) var(--ease-out) backwards; }
@keyframes toast-in { from { opacity: 0; translate: 0 10px; } to { opacity: 1; translate: 0 0; } }

/* ------------------------------------------------------------------ screen entrance and reveals */

.screen { animation: screen-in var(--dur-slow) var(--ease-out) backwards; }
@keyframes screen-in { from { opacity: 0; translate: 0 10px; } to { opacity: 1; translate: 0 0; } }

@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    :root:not([data-motion="off"]) .screen :is(.section-title, .content-card, .content-row-card, .cat-card):not(.hscroll > *) {
      animation: reveal-up linear backwards;
      animation-timeline: view();
      animation-range: entry 0% entry 30%;
    }
    @keyframes reveal-up { from { opacity: 0; translate: 0 14px; } to { opacity: 1; translate: 0 0; } }
    /* A hairline appears under the sticky top bar once the page has scrolled. */
    :root:not([data-motion="off"]) .screen .topbar::before { animation: bar-line linear both; animation-timeline: scroll(root); animation-range: 0 48px; }
    @keyframes bar-line { from { box-shadow: 0 1px 0 transparent; } to { box-shadow: 0 1px 0 var(--outline-variant); } }
  }
}

/* The reader and the player keep their own calm, opaque surfaces. */
.reader-screen .state-art { color: var(--r-accent); }
.reader-screen .state-art::after { background: color-mix(in srgb, currentColor 11%, var(--r-bg)); }
