/* Dark theme — the hand-written look. Loaded after every other sheet, only for users who picked a dark
   theme on the profile page. App.razor sets on <html>:
     data-theme="dark"          the dark design is on
     data-motion="on" | "off"   animated or still backgrounds (dt-theme.js may switch "on" to "off")
   dt-theme.js adds:
     data-scene="…"             which background suits the page (from <ThemeScene>)
     data-glass="solid"         no backdrop blur: old browsers and very weak devices
   Colours of individual components come from theme-dark-colors.css; this file sets the tokens, the glass,
   the background scenes and the pieces that need more than a colour swap. */

/* ---- Tokens ---- */
html[data-theme="dark"] {
    color-scheme: dark;
    --dash-bg: #05070A;
    --page-wash: none;
    --dash-card: rgba(10, 13, 18, 0.6);
    --dash-border: rgba(255, 255, 255, 0.14);
    --dash-line: rgba(255, 255, 255, 0.09);
    --dash-text: #F2F4F7;
    --dash-muted: #A9B2BF;
    --dash-faint: #7D8796;
    --dash-indigo: #2FA8E0;
    --dash-hot: #FF7A72;
    --dash-cold: #9AA6B8;
    --dash-amber: #F5A94A;
    --dash-never: rgba(255, 255, 255, 0.14);
    --dash-guess: #5BD08F;
    --dash-ink: #F2F4F7;

    --an-accent: #2FA8E0;
    --an-surface: rgba(255, 255, 255, 0.04);
    --an-line: rgba(255, 255, 255, 0.1);

    /* the glass recipe ("defined edges"): darker where the text sits (left), lighter in the middle, a
       little darker right — with a crisp light border, a thin dark outline and a firm shadow, so each
       card reads as its own tile against the background */
    --glass-tint: linear-gradient(90deg, rgba(6, 8, 12, 0.66) 0%, rgba(6, 8, 12, 0.34) 55%, rgba(6, 8, 12, 0.5) 100%);
    --glass-sheen: radial-gradient(120% 70% at 50% -20%, rgba(255, 255, 255, 0.09), transparent 60%),
                   linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0) 45%);
    --glass-blur: blur(6px) saturate(140%) brightness(0.85);
    --glass-bg: rgba(6, 8, 12, 0.45);
    --glass-edge: rgba(255, 255, 255, 0.22);
    --float-1: inset 0 1px 0 rgba(255, 255, 255, 0.24), inset 0 -1px 0 rgba(0, 0, 0, 0.4),
               0 0 0 1px rgba(0, 0, 0, 0.35), 0 24px 50px -18px rgba(0, 0, 0, 0.85);
    --float-2: inset 0 1px 0 rgba(255, 255, 255, 0.28), inset 0 -1px 0 rgba(0, 0, 0, 0.4),
               0 0 0 1px rgba(0, 0, 0, 0.35), 0 32px 60px -20px rgba(0, 0, 0, 0.9);

    --gloss-ball: radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.45) 0%, rgba(255, 255, 255, 0) 46%),
                  radial-gradient(circle at 50% 115%, rgba(0, 0, 0, 0.35) 0%, rgba(0, 0, 0, 0) 60%);
    --raise-ball: inset 0 -2px 0 rgba(0, 0, 0, 0.3), 0 3px 8px -2px rgba(0, 0, 0, 0.6);
    --raise-chip: inset 0 -1px 0 rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.45);

    /* number tones: deep teal (low numbers) → bright cyan (high), replacing lavender → indigo */
    --tone-lo: #1B5578;
    --tone-hi: #8FDCFF;
}

html[data-theme="dark"] body {
    background: #05070A;
    color: var(--dash-text);
    --bs-body-bg: #05070A;
    --bs-body-color: #F2F4F7;
    --bs-border-color: rgba(255, 255, 255, 0.14);
    --bs-secondary-color: #A9B2BF;
}

/* The scene layer replaces the page wash; text keeps a faint shadow so it reads over busy pictures. */
html[data-theme="dark"] main,
html[data-theme="dark"] .auth-page { background: transparent; }
html[data-theme="dark"] .dash-page,
html[data-theme="dark"] .app-header { text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
html[data-theme="dark"] .dash-page canvas,
html[data-theme="dark"] .dash-page input,
html[data-theme="dark"] .dash-page select,
html[data-theme="dark"] .dash-page textarea { text-shadow: none; }

/* ---- Background scenes ----
   Dark (still): one calm picture — the aurora — behind every page, so the app looks the same throughout.
   Dark, animated: a moving scene that suits each page (data-scene), with a slight parallax.
   An animated user on a slow device falls back to the still aurora (dt-theme.js sets data-motion="off"). */
html[data-theme="dark"] .dt-scene {
    position: fixed;
    inset: -3%;
    z-index: -1;
    pointer-events: none;
    background: #05070A center / cover no-repeat;
    background-image: url("../img/scenes/profile-still.svg");
    transition: background-image 0.6s ease;
    --b1: #0E5A6E; --b2: #4A2A8E; --b3: #1E5B45;
}

/* soft coloured glows (screen-blended, no blur filter: cheap) + a gentle top-to-bottom shade */
html[data-theme="dark"] .dt-scene::before,
html[data-theme="dark"] .dt-scene::after {
    content: "";
    position: absolute;
    inset: 0;
}

html[data-theme="dark"] .dt-scene::before {
    mix-blend-mode: screen;
    opacity: 0.32;
    background:
        radial-gradient(40% 45% at 8% 6%, var(--b1), transparent 70%),
        radial-gradient(35% 40% at 96% 30%, var(--b2), transparent 70%),
        radial-gradient(40% 35% at 50% 104%, var(--b3), transparent 70%);
}

html[data-theme="dark"] .dt-scene::after {
    background:
        repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.03) 0 2px, transparent 2px 90px),
        linear-gradient(180deg, rgba(3, 5, 8, 0.12), rgba(3, 5, 8, 0.34));
}

/* Animated: a scene per page, each with its own tint for the soft glows */
html[data-motion="on"] .dt-scene                        { background-image: url("../img/scenes/dash.svg");      --b1: #1B4F78; --b2: #6A3A1C; --b3: #1E5B45; }
html[data-motion="on"][data-scene="draws"] .dt-scene     { background-image: url("../img/scenes/draws.svg");     --b1: #1D3F8A; --b2: #2FA8E0; --b3: #4A2A8E; }
html[data-motion="on"][data-scene="analytics"] .dt-scene { background-image: url("../img/scenes/analytics.svg"); --b1: #0E5A6E; --b2: #1E5B45; --b3: #2FA8E0; }
html[data-motion="on"][data-scene="patterns"] .dt-scene  { background-image: url("../img/scenes/patterns.svg");  --b1: #4A2A8E; --b2: #9B6CFF; --b3: #1D6F7E; }
html[data-motion="on"][data-scene="draw"] .dt-scene      { background-image: url("../img/scenes/draw.svg");      --b1: #7A4A1C; --b2: #8A3A2A; --b3: #5A4A1C; }
html[data-motion="on"][data-scene="profile"] .dt-scene   { background-image: url("../img/scenes/profile.svg");   --b1: #0E5A6E; --b2: #4A2A8E; --b3: #1E5B45; }

/* the ticket desk has bright paper in it: shade it a little more so the number picker stays readable */
html[data-motion="on"][data-scene="draw"] .dt-scene::after {
    background:
        repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.03) 0 2px, transparent 2px 90px),
        linear-gradient(180deg, rgba(3, 5, 8, 0.38), rgba(3, 5, 8, 0.55));
}

html[data-motion="on"] .dt-scene {
    transform: translate3d(var(--dt-px, 0px), var(--dt-py, 0px), 0);
    transition: background-image 0.6s ease, transform 0.25s ease-out;
    will-change: transform;
}

/* ---- Glass surfaces ---- */
html[data-theme="dark"] .dash-card:not(.dash-dashed),
html[data-theme="dark"] .dash-kpi,
html[data-theme="dark"] .ma-card,
html[data-theme="dark"] .m3-hero,
html[data-theme="dark"] .auth-card {
    background: var(--glass-sheen), var(--glass-tint);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-edge);
    box-shadow: var(--float-1);
}

html[data-theme="dark"] .ma-card:hover { box-shadow: var(--float-2); border-color: rgba(47, 168, 224, 0.45); }

/* bands inside a card: just a breath lighter, so the scene still shows through */
html[data-theme="dark"] .ma-card-head { background: rgba(255, 255, 255, 0.03); }
html[data-theme="dark"] .dash-card-head { background: rgba(255, 255, 255, 0.04); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08); }
html[data-theme="dark"] .dash-card.dash-dashed,
html[data-theme="dark"] .ma-create {
    background: rgba(255, 255, 255, 0.03);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    border-color: rgba(255, 255, 255, 0.25);
}

html[data-theme="dark"] .an-section {
    background: rgba(6, 8, 12, 0.18);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* Things that float over content stay nearly opaque so they read over anything */
html[data-theme="dark"] .m3-menu,
html[data-theme="dark"] .m3-dialog,
html[data-theme="dark"] .confirm-dialog,
html[data-theme="dark"] dialog {
    background: rgba(12, 16, 22, 0.94);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    backdrop-filter: blur(18px) saturate(140%);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: var(--dash-text);
    box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

html[data-theme="dark"] dialog::backdrop,
html[data-theme="dark"] .confirm-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

/* ---- Header ---- */
html[data-theme="dark"] .app-header {
    background: linear-gradient(90deg, rgba(6, 8, 12, 0.55), rgba(6, 8, 12, 0.3) 55%, rgba(6, 8, 12, 0.5)),
                linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0) 60%);
    -webkit-backdrop-filter: blur(12px) saturate(140%) brightness(0.85);
    backdrop-filter: blur(12px) saturate(140%) brightness(0.85);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.8);
}

html[data-theme="dark"] .app-nav a.active {
    color: #FFFFFF;
    background: rgba(47, 168, 224, 0.18);
    box-shadow: inset 0 -2px 0 #2FA8E0;
}

html[data-theme="dark"] .app-lang { background: rgba(0, 0, 0, 0.35); border-color: rgba(255, 255, 255, 0.18); color: #F2F4F7; }
html[data-theme="dark"] .app-lang option { background: #10141A; color: #F2F4F7; }

/* ---- Buttons: glossy cyan with dark text (white on cyan is too faint) ---- */
html[data-theme="dark"] .m3-btn,
html[data-theme="dark"] .m3-btn:disabled,
html[data-theme="dark"] .m3-btn:disabled:hover,
html[data-theme="dark"] .dash-btn-primary {
    background: linear-gradient(180deg, #5CC4F2 0%, #2FA8E0 50%, #1F8CC2 100%);
    border-color: transparent;
    color: #04121A;
    text-shadow: none;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 6px 18px -6px rgba(47, 168, 224, 0.7);
}

html[data-theme="dark"] .m3-btn:hover,
html[data-theme="dark"] .dash-btn-primary:hover {
    background: linear-gradient(180deg, #7DD2F7 0%, #3DB3E8 50%, #2496CC 100%);
    color: #04121A;
}

html[data-theme="dark"] .dash-btn-success { color: #FFFFFF; }

/* ---- Number tones (balls, chips, picker, grid columns) ---- */
html[data-theme="dark"] .ball,
html[data-theme="dark"] .picker-btn.on,
html[data-theme="dark"] .hg-chip {
    background-color: color-mix(in srgb, var(--tone-hi) calc(var(--t, 0) * 100%), var(--tone-lo));
    color: #F2F4F7;
    text-shadow: none;
}

/* the light theme marks high numbers "dark" for white text; here high numbers are the bright ones */
html[data-theme="dark"] .ball.dark,
html[data-theme="dark"] .picker-btn.on.dark,
html[data-theme="dark"] .hg-chip.hg-chip-dark { color: #06121C; }

html[data-theme="dark"] .ball.sub { background-color: #F5A94A; color: #2A1604; }
html[data-theme="dark"] .ball.match { background-color: #1F9D5B; color: #FFFFFF; }
html[data-theme="dark"] .ball.sub.match { background-color: #22C3DD; color: #04161A; }
html[data-theme="dark"] .picker-btn.on.drawn { background: #1F9D5B; color: #FFFFFF; }
html[data-theme="dark"] .picker-btn:not(.on) { background: rgba(8, 11, 16, 0.55); color: #DDE3EA; }
html[data-theme="dark"] .picker-btn:not(.on):hover { background: rgba(47, 168, 224, 0.18); }
html[data-theme="dark"] .hg-chip.hg-chip-sub { background-color: #F5A94A; color: #2A1604; }
html[data-theme="dark"] .hg-chip.hg-chip-guessed { background-color: #1F9D5B; color: #FFFFFF; }
html[data-theme="dark"] .hg-chip.hg-chip-sub-guessed { background-color: #22C3DD; color: #04161A; }

html[data-theme="dark"] .draw-ball {
    color: #06121C;
    text-shadow: none;
    background: radial-gradient(circle at 32% 28%,
        color-mix(in srgb, var(--tone-hi) calc(55% + var(--t) * 45%), #FFFFFF) 0%,
        color-mix(in srgb, var(--tone-hi) calc(var(--t) * 100%), var(--tone-lo)) 60%,
        #0B2A3D 100%);
    box-shadow: 0 0 18px rgba(47, 168, 224, 0.35), inset 0 -4px 0 rgba(0, 0, 0, 0.25), inset 0 3px 0 rgba(255, 255, 255, 0.3);
}

html[data-theme="dark"] .draw-ball-sub { color: #2A1604; text-shadow: none; box-shadow: 0 0 18px rgba(245, 169, 74, 0.4), inset 0 -4px 0 rgba(0, 0, 0, 0.2); }

html[data-theme="dark"] .hg tbody .hg-main { background: color-mix(in srgb, rgba(47, 168, 224, 0.16) calc(var(--t, 0) * 100%), rgba(255, 255, 255, 0.03)); }
html[data-theme="dark"] .hg thead .hg-main { background: color-mix(in srgb, rgba(47, 168, 224, 0.28) calc(var(--t, 0) * 100%), rgba(255, 255, 255, 0.05)); }
html[data-theme="dark"] .hg tbody .hg-sub { background: rgba(245, 169, 74, 0.08); }
html[data-theme="dark"] .hg thead .hg-sub { background: rgba(245, 169, 74, 0.18); color: #FFC985; }

/* ---- Disclaimer: the same attention pulse, as a glow that keeps the light text readable ---- */
html[data-theme="dark"] .dash-alert-core { color: #FFC985; animation-name: dash-attention-dark; }

@keyframes dash-attention-dark {
    0%, 100% { background-color: rgba(245, 169, 74, 0); box-shadow: none; }
    50%      { background-color: rgba(245, 169, 74, 0.26); box-shadow: 0 0 14px rgba(245, 169, 74, 0.35); }
}

@media (prefers-reduced-motion: reduce) {
    html[data-theme="dark"] .dash-alert-core { background-color: rgba(245, 169, 74, 0.18); }
}

/* ---- Appearance picker on the profile page ---- */
html[data-theme="dark"] .theme-option:has(input:checked) { border-color: #2FA8E0; box-shadow: 0 0 0 3px rgba(47, 168, 224, 0.25), 0 0 18px -4px rgba(47, 168, 224, 0.6); }

/* ---- Fallbacks ---- */
/* No backdrop blur (old browser, or a very weak device): more solid panels keep text readable. */
html[data-theme="dark"][data-glass="solid"] {
    --glass-tint: linear-gradient(90deg, rgba(10, 13, 18, 0.9) 0%, rgba(10, 13, 18, 0.78) 55%, rgba(10, 13, 18, 0.86) 100%);
    --glass-blur: none;
}

html[data-theme="dark"][data-glass="solid"] .app-header,
html[data-theme="dark"][data-glass="solid"] .dash-card.dash-dashed,
html[data-theme="dark"][data-glass="solid"] .ma-create {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

html[data-theme="dark"][data-glass="solid"] .app-header { background: rgba(8, 10, 14, 0.94); }

/* Reduced motion from the OS always wins, whatever the profile says. */
@media (prefers-reduced-motion: reduce) {
    html[data-theme="dark"] .dt-scene { transform: none !important; transition: none; }
}
