/* =============================================================================
   GazeJuke Skins — token overrides + decorative layers.
   Every skin keeps the eye-gaze invariants untouched: decorations only use
   box-shadow / outline / pseudo-elements (never change box size or position),
   never use :hover, and every animation is gated behind :root[data-motion="on"]
   (set by modules/theme.js from the Motion FX toggle AND prefers-reduced-motion).
   ============================================================================= */

@property --gj-angle {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

@layer theme {
  /* ---------------------------------------------------------------------------
     GRID RUNNER — Tron-style neon light-cycle grid
     --------------------------------------------------------------------------- */
  [data-theme="tron"] {
    --bg-canvas: #03060d;
    --bg-elevated: rgba(5, 17, 30, 0.9);
    --bg-surface-alt: #0a1f33;
    --text-primary: #e8fbff;
    --text-muted: #9fd9e6;
    --accent-sky: #00e5ff;
    --accent-green: #3dffb5;
    --accent-amber: #ffb000;
    --accent-red: #ff5a36;
    --border-subtle: rgba(0, 229, 255, 0.32);
    --surface-accent: rgba(0, 58, 78, 0.62);
    --surface-active: rgba(0, 78, 62, 0.62);
    --surface-success: rgba(0, 70, 54, 0.62);
    --surface-warning: rgba(72, 46, 0, 0.66);
    --surface-danger: rgba(84, 22, 8, 0.66);
    --surface-deep: rgba(0, 9, 18, 0.94);
    --monitor-bg: #000000;
    --font-display: "Bahnschrift", "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
    --tile-radius: 4px 16px 4px 16px;
    --tile-border-w: 2px;
    --glow-blur: 16px;
    --glow-mix: 42%;
    --label-transform: uppercase;
    --label-tracking: 0.06em;
    --icon-stroke: 1.7;
    --icon-duo: 0.18;
    --icon-glow: drop-shadow(0 0 6px currentColor);
    --backdrop: rgba(0, 6, 14, 0.84);
    --toast-bg: rgba(0, 38, 50, 0.96);
    --title-shadow: 0 0 14px rgba(0, 229, 255, 0.55);
    --viz-style: neon;
    --viz-color-a: #0061ff;
    --viz-color-b: #00e5ff;
    --viz-peak: #ffffff;
    --viz-opacity: 0.55;
  }

  /* ---------------------------------------------------------------------------
     CODE RAIN — Matrix digital rain (green phosphor + red/blue pill accents)
     --------------------------------------------------------------------------- */
  [data-theme="matrix"] {
    --bg-canvas: #000500;
    --bg-elevated: rgba(0, 14, 5, 0.9);
    --bg-surface-alt: rgba(0, 26, 9, 0.92);
    --text-primary: #d6ffe1;
    --text-muted: #86e0a0;
    --accent-sky: #00ff66;
    --accent-green: #c6ff4d;
    --accent-amber: #ffd23f;
    --accent-red: #ff3b5c;
    --border-subtle: rgba(0, 255, 102, 0.28);
    --surface-accent: rgba(0, 48, 18, 0.66);
    --surface-active: rgba(38, 66, 0, 0.66);
    --surface-success: rgba(38, 66, 0, 0.66);
    --surface-warning: rgba(60, 50, 0, 0.66);
    --surface-danger: rgba(72, 0, 16, 0.66);
    --surface-deep: rgba(0, 8, 2, 0.95);
    --monitor-bg: #000000;
    --font-sans: Consolas, "Cascadia Mono", "Lucida Console", monospace;
    --font-display: Consolas, "Cascadia Mono", "Lucida Console", monospace;
    --tile-radius: 3px;
    --tile-border-w: 2px;
    --glow-blur: 12px;
    --glow-mix: 32%;
    --label-transform: uppercase;
    --label-tracking: 0.02em;
    --icon-stroke: 1.8;
    --icon-glow: drop-shadow(0 0 5px currentColor);
    --backdrop: rgba(0, 4, 0, 0.86);
    --toast-bg: rgba(0, 30, 10, 0.96);
    --title-shadow: 0 0 10px rgba(0, 255, 102, 0.5);
    --viz-style: segments;
    --viz-color-a: #005c22;
    --viz-color-b: #00ff66;
    --viz-peak: #e8ffe8;
    --viz-opacity: 0.5;
    --fx-rain-fade: #000500;
    --fx-rain-head: #eaffea;
    --fx-rain-trail: #00c853;
    --fx-rain-opacity: 0.32;
  }

  /* ---------------------------------------------------------------------------
     INK STRIKE — graphic-novel panels, halftone, ink outlines, SFX bursts
     --------------------------------------------------------------------------- */
  [data-theme="comic"] {
    --ink: #0b0816;
    --bg-canvas: #1d1633;
    --bg-elevated: #2d2452;
    --bg-surface-alt: #3a2f66;
    --text-primary: #ffffff;
    --text-muted: #e4dcff;
    --accent-sky: #2fb8ff;
    --accent-green: #39e27a;
    --accent-amber: #ffb400;
    --accent-red: #ff4d6a;
    --border-subtle: var(--ink);
    --surface-accent: #1f4fc4;
    --surface-active: #12773c;
    --surface-success: #12773c;
    --surface-warning: #a34e00;
    --surface-danger: #c4162f;
    --surface-deep: #120d24;
    --monitor-bg: #000000;
    --font-display: Impact, Haettenschweiler, "Arial Black", "Segoe UI Black", sans-serif;
    --tile-radius: 12px 5px 14px 6px;
    --tile-border-w: 4px;
    --tile-shadow: 6px 6px 0 var(--ink);
    --label-transform: uppercase;
    --label-tracking: 0.04em;
    --icon-stroke: 2.2;
    --icon-duo: 0.3;
    --kicker-bg: #ffd400;
    --kicker-fg: #111111;
    --kicker-pad: 2px 8px;
    --kicker-radius: 2px;
    --backdrop: rgba(11, 8, 22, 0.84);
    --toast-bg: #c4162f;
    --title-shadow: 3px 3px 0 var(--ink);
    --viz-style: ink;
    --viz-color-a: #ff2e63;
    --viz-color-b: #ffd400;
    --viz-peak: #ffffff;
    --viz-ink: #0b0816;
    --viz-opacity: 0.5;
  }
}

@layer skins {
  /* ======================= GRID RUNNER decorations ======================== */
  :root[data-theme="tron"] .fx-layer::before {
    content: "";
    position: absolute;
    inset: auto -50% -12% -50%;
    block-size: 62%;
    background-image:
      linear-gradient(to top, rgba(0, 229, 255, 0.45) 1px, transparent 1px),
      linear-gradient(90deg, rgba(0, 229, 255, 0.45) 1px, transparent 1px);
    background-size: 80px 80px;
    transform: perspective(420px) rotateX(62deg);
    transform-origin: 50% 100%;
    mask-image: linear-gradient(to top, #000 25%, transparent 95%);
    opacity: 0.45;
  }

  :root[data-theme="tron"] .fx-layer::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
      radial-gradient(ellipse 70% 30% at 50% 62%, rgba(0, 229, 255, 0.16), transparent 70%),
      radial-gradient(ellipse 40% 25% at 85% 10%, rgba(255, 90, 54, 0.1), transparent 70%);
  }

  :root[data-theme="tron"][data-motion="on"] .fx-layer::before {
    animation: gjGridScroll 2.6s linear infinite;
  }

  /* HUD corner brackets inside every tile, coloured by the variant tint. */
  [data-theme="tron"] .gaze-btn,
  [data-theme="tron"] .gaze-key {
    background-image:
      linear-gradient(var(--tint, var(--accent-sky)), var(--tint, var(--accent-sky))),
      linear-gradient(var(--tint, var(--accent-sky)), var(--tint, var(--accent-sky))),
      linear-gradient(var(--tint, var(--accent-sky)), var(--tint, var(--accent-sky))),
      linear-gradient(var(--tint, var(--accent-sky)), var(--tint, var(--accent-sky)));
    background-repeat: no-repeat;
    background-size: 16px 2px, 2px 16px, 16px 2px, 2px 16px;
    background-position:
      6px 6px,
      6px 6px,
      calc(100% - 6px) calc(100% - 6px),
      calc(100% - 6px) calc(100% - 6px);
  }

  [data-theme="tron"] .tile-kicker {
    letter-spacing: 0.18em;
  }

  /* Light-cycle trail orbiting the active / now-playing tile. */
  [data-theme="tron"] .gaze-variant-active::before {
    content: "";
    position: absolute;
    inset: calc(var(--tile-border-w) * -1);
    border-radius: inherit;
    padding: 3px;
    background: conic-gradient(
      from var(--gj-angle),
      transparent 0 70%,
      var(--tint) 86%,
      #ffffff 91%,
      transparent 96%
    );
    mask:
      linear-gradient(#000 0 0) content-box,
      linear-gradient(#000 0 0);
    mask-composite: exclude;
    pointer-events: none;
  }

  :root[data-theme="tron"][data-motion="on"] .gaze-variant-active::before {
    animation: gjOrbit 3.2s linear infinite;
  }

  [data-theme="tron"] .player-panel {
    border-color: rgba(61, 255, 181, 0.52);
    box-shadow:
      0 0 22px rgba(61, 255, 181, 0.14),
      inset 0 0 32px rgba(61, 255, 181, 0.08);
  }

  [data-theme="tron"] .library-panel {
    border-color: rgba(0, 229, 255, 0.55);
    box-shadow:
      0 0 22px rgba(0, 229, 255, 0.16),
      inset 0 0 32px rgba(0, 229, 255, 0.08);
  }

  [data-theme="tron"] .status-banner,
  [data-theme="tron"] .status-telemetry-card {
    border-color: var(--accent-sky);
    box-shadow: 0 0 18px rgba(0, 229, 255, 0.25), inset 0 -2px 0 rgba(0, 229, 255, 0.6);
  }

  [data-theme="tron"] .yt-monitor-shell {
    border-color: var(--accent-sky);
    box-shadow: 0 0 18px rgba(0, 229, 255, 0.35);
  }

  /* ========================= CODE RAIN decorations ========================= */
  [data-theme="matrix"] .tile-kicker::before {
    content: "> ";
  }

  [data-theme="matrix"] .gaze-btn,
  [data-theme="matrix"] .gaze-key {
    background-image: repeating-linear-gradient(
      0deg,
      rgba(0, 255, 102, 0.05) 0 1px,
      transparent 1px 4px
    );
  }

  [data-theme="matrix"] .tile-label,
  [data-theme="matrix"] .gaze-key {
    text-shadow: 0 0 8px rgba(0, 255, 102, 0.45);
  }

  :root[data-theme="matrix"][data-motion="on"] .track-title::after {
    content: "_";
    color: var(--accent-sky);
    animation: gjBlink 1s steps(1) infinite;
  }

  [data-theme="matrix"] .player-panel,
  [data-theme="matrix"] .library-panel,
  [data-theme="matrix"] .status-banner,
  [data-theme="matrix"] .status-telemetry-card,
  [data-theme="matrix"] .yt-monitor-shell {
    border-color: var(--accent-sky);
    box-shadow: 0 0 14px rgba(0, 255, 102, 0.25);
  }

  /* ========================= INK STRIKE decorations ======================== */
  :root[data-theme="comic"] .fx-layer {
    background:
      radial-gradient(circle, rgba(255, 255, 255, 0.07) 1.6px, transparent 1.9px) 0 0 / 16px 16px,
      linear-gradient(135deg, #2a1b4f 0%, #1d1633 55%, #3b1640 100%);
  }

  [data-theme="comic"] .gaze-btn,
  [data-theme="comic"] .gaze-key {
    border: 4px solid var(--ink);
    box-shadow: 6px 6px 0 var(--ink);
  }

  [data-theme="comic"] .player-panel,
  [data-theme="comic"] .library-panel {
    border: 4px solid var(--ink);
    background-color: rgba(18, 13, 36, 0.72);
    box-shadow: 8px 8px 0 var(--ink);
  }

  [data-theme="comic"] .status-banner,
  [data-theme="comic"] .status-telemetry-card,
  [data-theme="comic"] .query-banner,
  [data-theme="comic"] .results-summary-box,
  [data-theme="comic"] .settings-info-strip,
  [data-theme="comic"] .yt-monitor-shell {
    border-width: 4px;
    border-color: var(--ink);
    box-shadow: 6px 6px 0 var(--ink);
  }

  /* Consistent high-contrast semantic icon colors across Ink Strike variants */
  [data-theme="comic"] .gaze-variant-default {
    --icon-tint: #ffd400;
  }

  [data-theme="comic"] .gaze-variant-accent,
  [data-theme="comic"] .gaze-variant-active,
  [data-theme="comic"] .gaze-variant-success,
  [data-theme="comic"] .gaze-variant-warning,
  [data-theme="comic"] .gaze-variant-danger {
    --icon-tint: #ffffff;
  }

  /* Impact lettering + caption-box kickers are taller: shrink genre badges to fit tiles. */
  [data-theme="comic"] .preset-grid .tile-icon {
    --icon-size: clamp(32px, 3.8vh, 48px);
  }

  [data-theme="comic"] .volume-meter {
    border: 3px solid var(--ink);
    border-radius: 8px;
  }

  [data-theme="comic"] .vol-seg[data-lit="true"] {
    border: 1px solid var(--ink);
  }

  [data-theme="comic"] .tile-kicker {
    border: 2px solid var(--ink);
    transform: skewX(-8deg);
    letter-spacing: 0.06em;
  }

  [data-theme="comic"] .tile-label,
  [data-theme="comic"] .pill-label,
  [data-theme="comic"] .gaze-key {
    text-shadow: 2px 2px 0 var(--ink);
  }

  /* Speed lines radiating behind the active / now-playing panel. */
  [data-theme="comic"] .gaze-variant-active {
    background-image: repeating-conic-gradient(
      from 0deg at 50% 50%,
      rgba(255, 255, 255, 0.11) 0deg 4deg,
      transparent 4deg 14deg
    );
  }

  [data-theme="comic"] .settings-dialog[open] {
    border: 4px solid var(--ink);
    box-shadow: 10px 10px 0 var(--ink);
  }

  /* Random onomatopoeia burst on every registered click (word set via data-sfx). */
  [data-theme="comic"] .gaze-click-pulse::after {
    content: attr(data-sfx);
    position: absolute;
    inset-block-start: 6px;
    inset-inline-end: 6px;
    z-index: 2;
    padding: 12px 16px;
    background: #ffd400;
    color: #c4162f;
    font-family: Impact, "Arial Black", sans-serif;
    font-size: 1.35rem;
    letter-spacing: 0.04em;
    clip-path: polygon(
      50% 0%, 61% 18%, 82% 8%, 78% 30%, 100% 34%, 84% 50%, 100% 66%, 78% 70%,
      82% 92%, 61% 82%, 50% 100%, 39% 82%, 18% 92%, 22% 70%, 0% 66%, 16% 50%,
      0% 34%, 22% 30%, 18% 8%, 39% 18%
    );
    transform: rotate(-10deg);
    pointer-events: none;
    animation: gjPop 320ms ease-out both;
  }

  [data-theme="comic"] .gaze-key.gaze-click-pulse::after {
    font-size: 0.8rem;
    padding: 8px 10px;
    inset-block-start: 2px;
    inset-inline-end: 2px;
  }

  /* ============================== Keyframes =============================== */
  @keyframes gjGridScroll {
    from { background-position: 0 0, 0 0; }
    to { background-position: 0 80px, 0 0; }
  }

  @keyframes gjOrbit {
    to { --gj-angle: 360deg; }
  }

  @keyframes gjBlink {
    50% { opacity: 0; }
  }

  @keyframes gjPop {
    0% { transform: rotate(-10deg) scale(0.4); opacity: 0; }
    40% { transform: rotate(-6deg) scale(1.1); opacity: 1; }
    100% { transform: rotate(-10deg) scale(1); opacity: 1; }
  }
}
