/* =============================================================================
   Base Styles — Shared across all pages
   ============================================================================= */

/* CSS Custom Properties (Design Tokens) */
:root,
[data-theme="dark"] {
  --bg: #090910;
  --bg-surface: #12121e;
  --bg-elevated: #191928;
  --bg-hover: #242436;
  --border: #282840;
  --border-active: #3e3e58;
  --text: #e4e4f0;
  --text-secondary: #b0b0c8;
  --text-muted: #8a8aa0;
  --accent: #5DAEFF;
  --accent-hover: #7EC0FF;
  --accent-subtle: rgba(93,174,255,0.10);
  --accent-glow: rgba(93,174,255,0.18);
  /* Text color for accent-tinted glass buttons — light blue reads well on
     the dark translucent surface used in dark mode. */
  --accent-btn-text: #7EC0FF;
  --success: #34d399;
  --success-text: #34d399;
  --success-subtle: rgba(52, 211, 153, 0.18);
  --error: #f87171;
  --warning: #fbbf24;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Transition durations — standardized across all overlays */
  --transition-fast: 0.15s;   /* Micro-interactions: button hovers, focus rings */
  --transition-normal: 0.2s;  /* Standard UI: dropdowns, small overlays */
  --transition-medium: 0.25s; /* Modal backdrops, toasts, medium overlays */
  --transition-slow: 0.3s;    /* Larger overlay fades, status bars */
  --transition-slower: 0.5s;  /* Idle UI hide/show — smooth, non-jarring fade */

  /* ===========================================================================
     Aero 2.0 — Design Language Tokens
     See Aero_2.0_Design_Philosophy_and_Principles.md and
     Aero_2.0_Media_Player_Design_Specification.md
     =========================================================================== */

  /* Wallpaper-derived ambient tint — updated at runtime by aero-tint.js from
     the current video frame. H/S/L channels only (no hsl() wrapper) so it
     composes inside hsla() elsewhere. Neutral blue default until then. */
  --wallpaper-tint: 210, 90%, 60%;
  --wallpaper-tint-dark: 220, 60%, 18%;
  --wallpaper-tint-light: 210, 38%, 90%;

  /* Always-on ambient "desktop" behind the page — a soft, blurless gradient
     in the same sky-blue family as --wallpaper-tint, so the glass surfaces
     visibly sample its color even before any item artwork loads. A real
     Jellyfin backdrop replaces it on .wallpaper-layer::before when set. */
  --wallpaper-default:
    radial-gradient(140% 100% at 50% -20%, rgba(93, 174, 255, 0.28) 0%, rgba(93, 174, 255, 0.08) 45%, transparent 72%),
    radial-gradient(90% 70% at 86% 112%, rgba(64, 160, 220, 0.18) 0%, transparent 65%),
    radial-gradient(80% 70% at 4% 100%, rgba(120, 140, 255, 0.14) 0%, transparent 65%),
    linear-gradient(180deg, #131831 0%, #0a0d1e 55%, #0a0c18 100%);

  /* Glass material (spec: opacity 75–90%, blur 20–40px, noise 2–3%). Alpha
     sits at the bottom of the spec range — high enough that the 28px blur
     reads as real glass while foreground text stays legible over the
     wallpaper scrim. */
  --glass-bg: hsla(var(--wallpaper-tint), 0.80);
  --glass-bg-strong: hsla(var(--wallpaper-tint), 0.88);
  --glass-blur: 28px;
  --glass-blur-sm: 20px;
  --glass-saturate: 1.35;
  --glass-noise-opacity: 0.025;
  --glass-border-highlight: rgba(255,255,255,0.28);
  --glass-border-highlight-soft: rgba(255,255,255,0.14);
  --glass-border-shadow: rgba(0,0,0,0.18);
  /* Soft luminous halo around glass edges (spec: "soft edge glow"). */
  --glass-edge-glow: rgba(140, 190, 255, 0.10);

  /* Same turbulence grain as --noise-svg with its opacity baked into the SVG
     rect, for surfaces that can't carry a ::before pseudo-element (e.g.
     <input>). Blend with the surface color via background-blend-mode. */
  --glass-noise-faint: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.045'/%3E%3C/svg%3E");

  /* Accent action-button material — soft-geometry gradient fill (spec:
     "Buttons feel like Aero, not Fluent"). A faint highlight at the top that
     fades down gives a gentle internal reflection instead of a flat pill. */
  --accent-btn-fill: linear-gradient(180deg, rgba(93,174,255,0.32) 0%, rgba(93,174,255,0.12) 100%);
  --accent-btn-fill-hover: linear-gradient(180deg, rgba(93,174,255,0.44) 0%, rgba(93,174,255,0.20) 100%);
  --accent-btn-border: rgba(93,174,255,0.55);
  --accent-btn-border-hover: rgba(93,174,255,0.85);

  /* Neutral glass-button sheen — white catch-light on the top edge fading
     into the plain glass base below. */
  --glass-btn-fill: linear-gradient(180deg, rgba(255,255,255,0.10) 0%, rgba(255,255,255,0) 55%);

  /* Scrim gradient behind all content. Theme-aware so light mode reads as a
     light surface (the old value was a dark gradient in both themes, which
     broke the light theme's text contrast). Kept lighter at the top so the
     ambient wallpaper's glow reads through; still dark enough at the bottom
     that overlaid text stays legible over any backdrop. */
  --scrim-1: hsla(var(--wallpaper-tint-dark), 0.42);
  --scrim-2: hsla(var(--wallpaper-tint-dark), 0.72);

  /* Bottom scrim behind overlaid card text (theme-aware: dark in dark mode,
     light in light mode so the theme's text color stays legible). Smooth
     fade from a solid base at the very bottom to transparent higher up. */
  --card-scrim: linear-gradient(to top, rgba(0,0,0,0.86) 0%, rgba(0,0,0,0.5) 45%, transparent 100%);

  /* Corner radii per spec */
  --radius-window: 24px;
  --radius-card: 18px;
  --radius-button: 14px;
  --radius-art: 16px;

  /* Accent per spec palette (kept alongside existing --accent so both
     systems blend cleanly during rollout) */
  --accent-aero: #5DAEFF;
  --accent-aero-hover: #7EC0FF;

  /* Shadows per spec */
  --shadow-window: 0 25px 60px rgba(0,0,0,0.22);
  --shadow-card: 0 12px 35px rgba(0,0,0,0.18);
  --shadow-button: 0 6px 18px rgba(0,0,0,0.15);

  /* Motion — glass "settling" easing + spec durations */
  --ease-glass: cubic-bezier(0.22, 1, 0.36, 1);
  --t-hover: 120ms;
  --t-click: 90ms;
  --t-panel: 180ms;
  --t-window: 250ms;
  --t-album: 300ms;
  /* Theme swap (background/foreground color cross-fade) — deliberately slow
     and calm per the Aero "calm motion" principle. */
  --t-theme: 360ms;

  /* Noise grain, generated once, reused by every glass surface */
  --noise-svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");

  /* Track color for range inputs (seek/volume) — needs a theme-aware value
     since a flat white track disappears in light mode. */
  --track-bg: rgba(255, 255, 255, 0.15);

  /* Skeleton loading shimmer */
  --skeleton-base: var(--bg-elevated);
  --skeleton-shine: var(--bg-hover);

  color-scheme: dark;
}

/* Respect reduced-transparency: fall back to solid surfaces, no blur/noise */
@media (prefers-reduced-transparency: reduce) {
  :root {
    --glass-bg: var(--bg-elevated);
    --glass-bg-strong: var(--bg-elevated);
    --glass-blur: 0px;
    --glass-blur-sm: 0px;
    --glass-noise-opacity: 0;
  }
}

/* =============================================================================
   Aero 2.0 — Light Theme

   Toggled via [data-theme="light"] on <html> (see js/aero-theme.js). Light
   glass needs a different alpha/blur balance than dark glass — spec's
   "opacity 75–90%" reads correctly against a dark backdrop but washes out
   against a bright one, so background alpha is raised and noise lowered.
   ============================================================================= */
[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-hover: #eef1f8;
  --border: #dde2ee;
  --border-active: #c3cadd;
  --text: #14141f;
  --text-secondary: #4a4a5c;
  --text-muted: #7a7a8c;

  --glass-bg: hsla(var(--wallpaper-tint), 0.75);
  --glass-bg-strong: hsla(var(--wallpaper-tint), 0.86);
  --accent-btn-text: #0b5cad;
  --success-text: #0f7a4f;
  --success-subtle: rgba(52, 211, 153, 0.22);
  --glass-border-highlight: rgba(255,255,255,0.6);
  --glass-border-highlight-soft: rgba(255,255,255,0.4);
  --glass-border-shadow: rgba(0,0,0,0.08);
  --glass-noise-opacity: 0.02;
  --glass-edge-glow: rgba(93, 174, 255, 0.08);

  /* Light-mode accent buttons — stronger alpha so the blue reads on a white
     glass base. */
  --accent-btn-fill: linear-gradient(180deg, rgba(93,174,255,0.38) 0%, rgba(93,174,255,0.16) 100%);
  --accent-btn-fill-hover: linear-gradient(180deg, rgba(93,174,255,0.52) 0%, rgba(93,174,255,0.26) 100%);
  --accent-btn-border: rgba(11, 92, 173, 0.45);
  --accent-btn-border-hover: rgba(11, 92, 173, 0.75);

  /* Light glass-button sheen — brighter catch-light than dark mode. */
  --glass-btn-fill: linear-gradient(180deg, rgba(255,255,255,0.55) 0%, rgba(255,255,255,0.15) 55%);

  --shadow-window: 0 20px 50px rgba(20,20,40,0.12);
  --shadow-card: 0 10px 28px rgba(20,20,40,0.09);
  --shadow-button: 0 4px 14px rgba(20,20,40,0.08);

  --track-bg: rgba(20, 20, 40, 0.12);
  --skeleton-base: #eef1f8;
  --skeleton-shine: #ffffff;

  /* Light scrim: a soft light gradient so the page reads as a light surface
     and dark theme text stays legible in light mode. */
  --scrim-1: hsla(var(--wallpaper-tint-light), 0.45);
  --scrim-2: hsla(var(--wallpaper-tint-light), 0.75);

  /* Light ambient desktop — pale sky-blue glows over a near-white base. */
  --wallpaper-default:
    radial-gradient(140% 110% at 50% -20%, rgba(93, 174, 255, 0.20) 0%, rgba(93, 174, 255, 0.06) 50%, transparent 75%),
    radial-gradient(90% 70% at 88% 112%, rgba(140, 180, 255, 0.22) 0%, transparent 65%),
    linear-gradient(180deg, #f1f5fd 0%, #e8eef9 100%);

  /* Light card scrim behind overlaid text. */
  --card-scrim: linear-gradient(to top, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0.68) 45%, transparent 100%);

  color-scheme: light;
}

/* Smooth theme swap — colors are custom properties so a plain transition on
   the properties that actually change is enough to make toggling feel like
   a deliberate lighting change rather than a flash. Skipped under
   reduced-motion below. */
body,
.glass, .glass-panel, .modal, .card, .toast, .party-card, .login-card,
.status-pill, .icon-btn, .ctrl-btn, .fullscreen-fab, header,
.search-dropdown, .matrix-command-box,
.breadcrumb-nav, .search-form input, .btn-folder {
  transition:
    background-color var(--t-theme) var(--ease-glass),
    border-color var(--t-theme) var(--ease-glass),
    color var(--t-theme) var(--ease-glass);
}

@media (prefers-reduced-motion: reduce) {
  body,
  .glass, .glass-panel, .modal, .card, .toast, .party-card, .login-card,
  .status-pill, .icon-btn, .ctrl-btn, .fullscreen-fab, header,
  .search-dropdown, .matrix-command-box,
  .breadcrumb-nav, .search-form input, .btn-folder {
    transition: none;
  }
}

/* =============================================================================
   Aero 2.0 — Wallpaper Layer (shared by index.html and viewer.html)

   Always-on ambient desktop behind the page. By default it's a soft gradient
   in the sky-blue family of --wallpaper-tint (--wallpaper-default), so the
   glass surfaces read as tinted by their environment from the first paint.
   When an item's Jellyfin backdrop is available (js/aero-wallpaper.js), the
   ::before pseudo-element cross-fades that backdrop on top and replaces it.
   Always paired with a scrim so text contrast never depends on how bright a
   given backdrop happens to be.

   Stacking order (all via positive z-index so body background never covers):
     1 = wallpaper-layer (dark fallback + default gradient + blurred backdrop)
     2 = wallpaper-scrim (theme gradient for text contrast)
     3 = page-content (all page elements)
   ============================================================================= */
.wallpaper-layer {
  position: fixed;
  inset: 0;
  z-index: 1;
  background-color: var(--bg);
  background-image: var(--wallpaper-default);
  pointer-events: none;
  transition: background-color var(--t-album) var(--ease-glass);
}

.wallpaper-layer::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: var(--wallpaper-backdrop, none);
  background-size: cover;
  background-position: center;
  filter: blur(60px) saturate(1.2);
  transform: scale(1.15);
  transition: opacity var(--t-album) var(--ease-glass);
  opacity: 0;
}

.wallpaper-layer.has-backdrop::before {
  opacity: 1;
}

.wallpaper-layer .swap-scrim {
  position: absolute;
  inset: 0;
  background: var(--bg);
  opacity: 0;
  transition: opacity var(--scrim-duration, 120ms) var(--ease-glass);
  pointer-events: none;
}

.wallpaper-layer .swap-scrim.flash {
  opacity: 0.85;
}

.wallpaper-scrim {
  position: fixed;
  inset: 0;
  z-index: 2;
  background: linear-gradient(180deg, var(--scrim-1), var(--scrim-2));
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .wallpaper-layer::before { transition: none; }
}

/* Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
}

/* Body */
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Page content wrapper — stacks above wallpaper layer & scrim */
.page-content {
  position: relative;
  z-index: 3;
  min-height: 100vh;
}

/* Skip Navigation Link */
.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  z-index: 300;
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: top var(--transition-normal) var(--ease-glass);
}
.skip-link:focus {
  top: 8px;
}

/* Universal Focus Styles */
*:focus-visible {
  outline: 2px solid var(--accent-hover);
  outline-offset: 2px;
}
*:focus:not(:focus-visible) {
  outline: none;
}

/* =============================================================================
   Aero 2.0 — Glass Primitive

   Reusable base for any floating surface (panels, modals, pills, buttons).
   Builds the spec's "1px inner highlight + 1px outer shadow" border from
   stacked box-shadow layers (a single CSS border can't do both at once),
   plus a subtle noise grain via ::before. Apply alongside a radius variant:
   .glass-window (24px) / .glass-card (18px, default) / .glass-button (14px).
   ============================================================================= */
.glass {
  position: relative;
  isolation: isolate;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  border-radius: var(--radius-card);
  box-shadow:
    inset 0 1px 0 var(--glass-border-highlight),
    inset 0 0 0 1px rgba(255,255,255,0.06),
    0 0 0 1px var(--glass-border-shadow),
    0 0 18px var(--glass-edge-glow),
    var(--shadow-card);
}

.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background-image: var(--noise-svg);
  opacity: var(--glass-noise-opacity);
  mix-blend-mode: overlay;
  pointer-events: none;
  z-index: -1;
}

.glass.glass-window { border-radius: var(--radius-window); box-shadow:
    inset 0 1px 0 var(--glass-border-highlight),
    inset 0 0 0 1px rgba(255,255,255,0.06),
    0 0 0 1px var(--glass-border-shadow),
    0 0 26px var(--glass-edge-glow),
    var(--shadow-window);
}
.glass.glass-button { border-radius: var(--radius-button); box-shadow:
    inset 0 1px 0 var(--glass-border-highlight),
    0 0 0 1px var(--glass-border-shadow),
    0 0 12px var(--glass-edge-glow),
    var(--shadow-button);
}
