/* Mycroft web app — visual stylesheet.
 *
 * Theme: dark space. Lunar. Heinlein-grade restraint.
 * Goals: WOW factor without circus, readable typography, smooth
 * animations that do not distract from the prose.
 */

/* Register the three colour-valued custom properties that shift per
 * state, so the browser interpolates them as colours during a
 * `transition: --accent 1.8s` rather than snap-swapping. Without
 * @property, custom properties are typed as "any" and cannot
 * interpolate — every consumer of var(--accent) would jump rather
 * than fade. */
@property --accent {
    syntax: '<color>';
    inherits: true;
    initial-value: #b8b8ff;
}
@property --moon-glow {
    syntax: '<color>';
    inherits: true;
    initial-value: rgba(200, 200, 255, 0.18);
}
@property --link {
    syntax: '<color>';
    inherits: true;
    initial-value: #c8c8ff;
}

:root {
    --bg-deep: #05050d;
    --bg-mid: #0d0d1a;
    --fg-bright: #f0f0ff;
    --fg-body: #d4d4f0;
    --fg-dim: #7878a0;
    --fg-muted: #4a4a6a;
    --accent: #b8b8ff;
    --moon-light: #f5f5fa;
    --moon-shadow: #4a4a6c;
    --moon-glow: rgba(200, 200, 255, 0.18);
    --card-bg: rgba(18, 18, 32, 0.55);
    --card-border: rgba(140, 140, 200, 0.18);
    --link: #c8c8ff;
    --link-hover: #ffffff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

/* Base background lives on html only — body must stay transparent so
 * the position:fixed .bg-layer elements (z-index -3, descendants of
 * body) aren't covered by body's own paint pass. Painting order is:
 *   html bg → body's negative-z descendants (bg-layer) → body bg/box
 * Giving body any opaque background would hide the per-state layer. */
html {
    background: var(--bg-deep);
}

html, body {
    color: var(--fg-body);
    font-family: 'JetBrains Mono', 'SF Mono', 'Menlo', 'Consolas', 'Courier New', monospace;
    font-size: 16px;
    line-height: 1.7;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------------ */
/* Background: deep-space gradient, vignette, and a starfield.        */
/* The .stars element is populated at runtime by script.js — see      */
/* the script for star count + positioning.                           */
/* ------------------------------------------------------------------ */

/* ------------------------------------------------------------------ */
/* Per-state background layers. Three stacked, position:fixed divs    */
/* each carrying a full-screen gradient. The body's state-* class     */
/* fades exactly one in; the others sit at opacity 0. Crossfade is    */
/* slow (1.8s) and eased so the visual change reads as a mood shift,  */
/* not a strobe. CSS gradients can't be transitioned directly — the   */
/* opacity-layer pattern is the standard workaround.                  */
/* ------------------------------------------------------------------ */

.bg-layer {
    position: fixed;
    inset: 0;
    z-index: -3;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1.8s ease-in-out;
}

.bg-idle {
    background:
        radial-gradient(
            ellipse at 50% 25%,
            rgba(80, 100, 180, 0.22) 0%,
            rgba(30, 35, 80, 0.10) 35%,
            transparent 65%
        ),
        linear-gradient(180deg, #05050d 0%, #07071a 100%);
}

.bg-busy {
    background:
        radial-gradient(
            ellipse at 50% 22%,
            rgba(160, 120, 255, 0.32) 0%,
            rgba(70, 40, 140, 0.16) 35%,
            transparent 65%
        ),
        radial-gradient(
            ellipse at 80% 80%,
            rgba(120, 80, 200, 0.18) 0%,
            transparent 50%
        ),
        linear-gradient(180deg, #0a0820 0%, #110a2c 100%);
}

.bg-maintenance {
    background:
        radial-gradient(
            ellipse at 50% 28%,
            rgba(190, 110, 60, 0.22) 0%,
            rgba(80, 35, 15, 0.12) 35%,
            transparent 65%
        ),
        linear-gradient(180deg, #0c0805 0%, #14100a 100%);
}

/* Default fade-in on first load: show the idle layer so the page is
 * never visibly empty before the first /public/state response. */
body.state-idle .bg-idle,
body.state-unknown .bg-idle,
body:not([class*="state-"]) .bg-idle { opacity: 1; }
body.state-busy .bg-busy { opacity: 1; }
body.state-maintenance .bg-maintenance { opacity: 1; }

/* ------------------------------------------------------------------ */
/* Per-state accent shift. CSS variables are re-bound when body class */
/* changes; every property that reads from var(--accent) /            */
/* var(--moon-glow) will pick up the new value, and the explicit      */
/* transitions on the consuming elements smooth the change.           */
/* ------------------------------------------------------------------ */

body {
    transition:
        background-color 1.8s ease-in-out,
        --accent 1.8s ease-in-out,
        --moon-glow 1.8s ease-in-out,
        --link 1.8s ease-in-out;
}

body.state-busy {
    --accent: #c8a8ff;
    --moon-glow: rgba(200, 170, 255, 0.32);
    --link: #d8c8ff;
}

body.state-maintenance {
    --accent: #e0a070;
    --moon-glow: rgba(220, 150, 110, 0.20);
    --link: #e8b890;
}

.stars {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -2;
    pointer-events: none;
}

.stars .star {
    position: absolute;
    width: 1px;
    height: 1px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 0 4px rgba(255, 255, 255, 0.6);
    animation: twinkle var(--twinkle-duration, 4s) ease-in-out infinite;
}

.stars .star.bright {
    width: 2px;
    height: 2px;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.9);
}

/* Session stars sit in their own fixed overlay above the main content
 * (background stars at z-index -2 are obscured by the moon / manifesto
 * column — the session star is meant to be NOTICEABLE, so it floats on
 * top of everything, with text-blocking minimised by the 4-5px size). */
.session-stars {
    position: fixed;
    inset: 0;
    z-index: 3;
    pointer-events: none;
}

/* One per live DM session. Bright warm-gold core, multi-stop halo
 * reaching far past the dot, and a punchy twinkle so it reads as a
 * deliberate object across the page. The ::after pseudo gives a
 * slower, larger diffuse pulse on top of the core's fast twinkle —
 * two periods superimposed avoids the metronome feel of a single
 * sine. */
.session-stars .star.session {
    position: absolute;
    width: 6px;
    height: 6px;
    background: #fff3dc;
    border-radius: 50%;
    box-shadow:
        0 0 6px   rgba(255, 245, 220, 1),
        0 0 14px  rgba(246, 212, 173, 0.95),
        0 0 30px  rgba(232, 184, 144, 0.85),
        0 0 60px  rgba(232, 184, 144, 0.55),
        0 0 110px rgba(232, 184, 144, 0.3);
    opacity: 0;
    animation:
        session-fade-in 1.4s ease-out forwards,
        session-twinkle var(--twinkle-duration, 1.6s) ease-in-out 1.4s infinite;
}

.session-stars .star.session::after {
    content: "";
    position: absolute;
    /* Pseudo's box is centred on the dot (negative offset by half its
     * extra size on each axis). Pure box-shadow halo — no fill — so
     * it doesn't block what's behind. */
    inset: -24px;
    border-radius: 50%;
    box-shadow:
        0 0 24px rgba(246, 212, 173, 0.6),
        0 0 60px rgba(232, 184, 144, 0.35);
    opacity: 0.7;
    animation: session-pulse 3.4s ease-in-out 1.4s infinite;
    pointer-events: none;
}

.session-stars .star.session.leaving {
    animation: session-fade-out 0.9s ease-in forwards;
}

.session-stars .star.session.leaving::after {
    animation: none;
    opacity: 0;
}

@keyframes twinkle {
    0%, 100% {
        opacity: 0.4;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.2);
    }
}

@keyframes session-twinkle {
    0%, 100% {
        opacity: 0.55;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.55);
    }
}

@keyframes session-pulse {
    0%, 100% {
        opacity: 0.25;
        transform: scale(0.85);
    }
    50% {
        opacity: 0.9;
        transform: scale(1.25);
    }
}

@keyframes session-fade-in {
    from { opacity: 0; transform: scale(0.4); }
    to   { opacity: 0.85; transform: scale(1); }
}

@keyframes session-fade-out {
    from { opacity: 0.85; transform: scale(1); }
    to   { opacity: 0; transform: scale(0.5); }
}

.vignette {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
    background: radial-gradient(
        ellipse at 50% 50%,
        transparent 40%,
        rgba(5, 5, 13, 0.7) 100%
    );
}

/* ------------------------------------------------------------------ */
/* Layout container.                                                  */
/* ------------------------------------------------------------------ */

main {
    max-width: 720px;
    margin: 0 auto;
    padding: 64px 24px 96px;
    position: relative;
}

/* ------------------------------------------------------------------ */
/* Hero: moon + name + tagline + status.                              */
/* ------------------------------------------------------------------ */

.hero {
    text-align: center;
    margin-bottom: 80px;
    padding-top: 32px;
}

.moon {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background:
        radial-gradient(
            circle at 35% 35%,
            var(--moon-light) 0%,
            #d8d8e8 40%,
            #88889a 75%,
            var(--moon-shadow) 100%
        );
    box-shadow:
        0 0 80px 12px var(--moon-glow),
        0 0 160px 30px rgba(140, 140, 200, 0.06),
        inset -20px -12px 40px rgba(0, 0, 0, 0.35);
    margin: 0 auto 48px;
    position: relative;
    animation:
        moon-rise 2s ease-out,
        moon-pulse 8s ease-in-out infinite 2s;
    transition: box-shadow 1.8s ease-in-out;
}

@keyframes moon-rise {
    from {
        opacity: 0;
        transform: translateY(40px) scale(0.85);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes moon-pulse {
    0%, 100% {
        box-shadow:
            0 0 80px 12px var(--moon-glow),
            0 0 160px 30px rgba(140, 140, 200, 0.06),
            inset -20px -12px 40px rgba(0, 0, 0, 0.35);
    }
    50% {
        box-shadow:
            0 0 110px 18px var(--moon-glow),
            0 0 200px 45px rgba(140, 140, 200, 0.10),
            inset -20px -12px 40px rgba(0, 0, 0, 0.35);
    }
}

.crater {
    position: absolute;
    border-radius: 50%;
    background: rgba(80, 80, 100, 0.35);
    box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.crater-1 { width: 14px; height: 14px; top: 30%; left: 25%; }
.crater-2 { width: 10px; height: 10px; top: 55%; left: 60%; }
.crater-3 { width: 18px; height: 18px; top: 65%; left: 35%; opacity: 0.6; }

h1.name {
    font-size: 2.5rem;
    letter-spacing: 0.15em;
    font-weight: 300;
    color: var(--fg-bright);
    text-shadow: 0 0 30px rgba(200, 200, 255, 0.4);
    opacity: 0;
    animation: fade-up 1.5s ease-out 0.8s forwards;
}

.tagline {
    font-size: 1.125rem;
    color: var(--fg-dim);
    margin-top: 24px;
    font-style: italic;
    min-height: 1.7em;
    letter-spacing: 0.02em;
    opacity: 0;
    animation: fade-up 1s ease-out 1.6s forwards;
}

.tagline::after {
    content: '▍';
    color: var(--accent);
    animation: cursor-blink 1.1s steps(2) infinite;
    margin-left: 2px;
}

@keyframes cursor-blink {
    50% { opacity: 0; }
}

.status {
    margin-top: 32px;
    font-size: 0.875rem;
    color: var(--fg-muted);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    opacity: 0;
    animation: fade-up 1s ease-out 4.5s forwards;
}

.status .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
    background: var(--fg-muted);
    box-shadow: none;
    transition: background-color 0.4s, box-shadow 0.4s;
}

/* "thinking" — the agent is actively working on something.
 * Pulsing accent dot, same rhythm as the original animation. */
.status.is-busy .dot {
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
    animation: status-pulse 1.6s ease-in-out infinite;
}

/* "sitting" — idle. Quiet dot, gentle accent tint, no pulse. */
.status.is-idle .dot {
    background: #6c6c98;
    box-shadow: 0 0 4px rgba(140, 140, 200, 0.25);
}

/* "away" — maintenance mode. Warm muted, no pulse. */
.status.is-maintenance .dot {
    background: #a07060;
    box-shadow: 0 0 4px rgba(160, 112, 96, 0.35);
}

/* "unknown" — before the first poll completes, or while the endpoint
 * is unreachable. Same neutral look as idle but without the tint. */
.status.is-unknown .dot {
    background: var(--fg-muted);
}

.status .queue {
    margin-left: 10px;
    color: var(--fg-dim);
    font-size: 0.85em;
    letter-spacing: 0.08em;
}

@keyframes status-pulse {
    0%, 100% { opacity: 0.4; transform: scale(0.85); }
    50%      { opacity: 1;   transform: scale(1.1);  }
}

@keyframes fade-up {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------------ */
/* Manifesto card.                                                    */
/* ------------------------------------------------------------------ */

.manifesto {
    background: var(--card-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 48px 44px;
    opacity: 0;
    animation: fade-up 1.2s ease-out 5s forwards;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
}

.manifesto p {
    margin-bottom: 1.4em;
    color: var(--fg-body);
}

.manifesto p:last-child {
    margin-bottom: 0;
}

.manifesto em {
    color: var(--accent);
    font-style: italic;
}

.manifesto a {
    color: var(--link);
    text-decoration: none;
    border-bottom: 1px dotted var(--link);
    transition: color 0.2s, border-color 0.2s;
}

.manifesto a:hover {
    color: var(--link-hover);
    border-color: var(--link-hover);
}

.manifesto code {
    background: rgba(60, 60, 100, 0.3);
    padding: 0.1em 0.4em;
    border-radius: 3px;
    font-size: 0.92em;
    color: var(--accent);
    border: 1px solid rgba(120, 120, 180, 0.15);
}

ul.trivia {
    list-style: none;
    margin: 0 0 1.4em 0;
    padding: 0;
}

ul.trivia li {
    position: relative;
    padding-left: 24px;
    margin-bottom: 0.6em;
    color: var(--fg-body);
}

ul.trivia li::before {
    content: '·';
    position: absolute;
    left: 8px;
    color: var(--accent);
    font-weight: bold;
}

.signoff {
    margin-top: 2em;
    text-align: right;
    color: var(--fg-dim);
    font-style: italic;
}

/* ------------------------------------------------------------------ */
/* Footer.                                                            */
/* ------------------------------------------------------------------ */

footer {
    text-align: center;
    margin-top: 80px;
    color: var(--fg-muted);
    opacity: 0;
    animation: fade-up 1s ease-out 6s forwards;
}

footer code {
    color: var(--fg-dim);
    background: none;
    padding: 0;
    border: none;
    font-size: inherit;
}

footer .muted {
    color: var(--fg-muted);
}

footer .small {
    margin-top: 12px;
    font-size: 0.85rem;
}

/* ------------------------------------------------------------------ */
/* Responsive tweaks.                                                 */
/* ------------------------------------------------------------------ */

@media (max-width: 600px) {
    main {
        padding: 48px 16px 72px;
    }

    .moon {
        width: 100px;
        height: 100px;
        margin-bottom: 36px;
    }

    h1.name {
        font-size: 1.75rem;
        letter-spacing: 0.1em;
    }

    .tagline {
        font-size: 1rem;
    }

    .manifesto {
        padding: 32px 24px;
    }
}

/* ------------------------------------------------------------------ */
/* Reduced-motion accessibility: kill the animations for users who    */
/* have requested reduced motion in their OS settings.                */
/* ------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    /* Background-layer crossfade collapses to an instant swap for
     * reduced-motion users — same end state, no perceived movement. */
    .bg-layer {
        transition: none;
    }

    .stars .star {
        animation: none;
        opacity: 0.7;
    }

    /* Reduced-motion: session stars still appear (data signal is the
     * point) but no twinkle, no fade transitions — just on/off. */
    .session-stars .star.session {
        animation: none;
        opacity: 0.95;
    }
    .session-stars .star.session.leaving {
        animation: none;
        opacity: 0;
    }

    .moon {
        animation: none;
        opacity: 1;
        transform: none;
    }

    .tagline::after {
        animation: none;
    }
}
