/* ==========================================================================
   Sonnensystem — Lernplattform (Spec v1.0)
   Dunkles Mission-Console-Theme (D-5): Monospace, Cyan-Akzente.
   Basis-Styles = Desktop; Mobil-Anpassungen als @media-Blöcke am Ende.
   ========================================================================== */

:root {
    --bg: #04060c;
    --panel-bg: rgba(8, 14, 24, 0.88);
    --panel-border: rgba(55, 200, 220, 0.28);
    --accent: #37c8dc;
    --accent-bright: #7fe3ff;
    --accent-dim: rgba(55, 200, 220, 0.35);
    --text: #cfe8ee;
    --text-dim: #6e8a94;
    --warn: #e8b45a;
    --error: #e86a5a;
    --font: 'Courier New', Courier, monospace;
    --radius: 6px;
    --panel-pad: 0.9rem;
    --hud-height: 46px;
    --touch: 44px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
}

button {
    font-family: var(--font);
    cursor: pointer;
}

.hidden { display: none !important; }

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

:focus-visible {
    outline: 2px solid var(--accent-bright);
    outline-offset: 1px;
}

/* --------------------------------------------------------------------------
   Ladebildschirm
   -------------------------------------------------------------------------- */

#loading-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 50% 35%, #0a1220 0%, var(--bg) 70%);
    z-index: 100;
}

#loading-inner { text-align: center; }

#loading-title {
    font-size: 1.6rem;
    letter-spacing: 0.5em;
    color: var(--accent);
    margin: 0 0 1.5rem;
    animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

#loading-progress-track {
    width: min(320px, 70vw);
    height: 3px;
    margin: 0 auto;
    background: rgba(55, 200, 220, 0.15);
    border-radius: 2px;
    overflow: hidden;
}

#loading-progress-fill {
    width: 0;
    height: 100%;
    background: var(--accent);
    transition: width 0.25s ease;
}

#loading-status {
    margin-top: 1rem;
    font-size: 0.8rem;
    color: var(--text-dim);
}

/* --------------------------------------------------------------------------
   App-Grundgerüst
   -------------------------------------------------------------------------- */

#app { position: fixed; inset: 0; }

#renderer-container {
    position: absolute;
    inset: 0;
}

#renderer-container canvas { display: block; }

/* Labels (HTML-Overlay) */
#label-layer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 3;
}

.body-label {
    position: absolute;
    left: 0; top: 0;
    transform: translate(-200px, -200px);
    background: none;
    border: none;
    padding: 1px 4px;
    color: var(--label-color, var(--accent-bright));
    font-family: var(--font);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.9);
    pointer-events: auto;
    white-space: nowrap;
}

.body-label.cat-moons { font-size: 10px; opacity: 0.85; }
.body-label:hover { text-decoration: underline; }

/* --------------------------------------------------------------------------
   HUD (oben)
   -------------------------------------------------------------------------- */

#hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: var(--hud-height);
    display: flex;
    align-items: center;
    gap: 1.2rem;
    padding: 0 0.9rem;
    background: linear-gradient(to bottom, rgba(4, 8, 14, 0.9), rgba(4, 8, 14, 0.0));
    z-index: 10;
    pointer-events: none;
}

#hud > * { pointer-events: auto; }

#hud-title {
    font-size: 0.95rem;
    letter-spacing: 0.4em;
    color: var(--accent);
}

#hud-date {
    font-size: 0.9rem;
    color: var(--text);
    background: rgba(8, 14, 24, 0.6);
    padding: 2px 8px;
    border: 1px solid var(--panel-border);
    border-radius: 3px;
}

#hud-validity {
    font-size: 0.75rem;
    color: var(--warn);
}

#hud-actions {
    margin-left: auto;
    display: flex;
    gap: 0.4rem;
}

#hud-actions button {
    min-width: 34px;
    height: 34px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    color: var(--accent);
    font-size: 0.9rem;
}

#hud-actions button:hover { background: rgba(55, 200, 220, 0.18); }

/* --------------------------------------------------------------------------
   Navigations-/Ebenen-Panel (links)
   -------------------------------------------------------------------------- */

#nav-panel {
    position: absolute;
    top: calc(var(--hud-height) + 8px);
    left: 0;
    bottom: 110px;
    width: 275px;
    display: flex;
    z-index: 8;
    transition: transform 0.25s ease;
}

#nav-panel.collapsed { transform: translateX(-275px); }

#nav-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-left: none;
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: var(--panel-pad);
    overflow: hidden;
    backdrop-filter: blur(4px);
}

#nav-toggle {
    position: absolute;
    right: -30px;
    top: 8px;
    width: 30px;
    height: var(--touch);
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-left: none;
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--accent);
}

#nav-heading {
    margin: 0 0 0.6rem;
    font-size: 0.75rem;
    letter-spacing: 0.28em;
    color: var(--accent);
}

/* Suche */
#search-box { position: relative; }

#search-input {
    width: 100%;
    background: rgba(10, 20, 32, 0.9);
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
    padding: 0.5rem 0.6rem;
}

#search-results {
    position: absolute;
    top: 100%;
    left: 0; right: 0;
    margin: 2px 0 0;
    padding: 0;
    list-style: none;
    background: #0a1420;
    border: 1px solid var(--accent-dim);
    border-radius: 4px;
    max-height: 260px;
    overflow-y: auto;
    z-index: 20;
}

#search-results button {
    display: flex;
    justify-content: space-between;
    gap: 0.6rem;
    width: 100%;
    background: none;
    border: none;
    color: var(--text);
    font-size: 0.85rem;
    text-align: left;
    padding: 0.5rem 0.6rem;
    min-height: 36px;
}

#search-results button:hover,
#search-results button.active { background: rgba(55, 200, 220, 0.15); }

.search-cat {
    color: var(--text-dim);
    font-size: 0.7rem;
    align-self: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 45%;
}

#preset-select {
    margin-top: 0.5rem;
    width: 100%;
    background: rgba(10, 20, 32, 0.9);
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.8rem;
    padding: 0.45rem 0.4rem;
}

/* Ebenen-Baum */
#layer-list {
    margin: 0.6rem 0 0;
    padding: 0;
    list-style: none;
    overflow-y: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-dim) transparent;
}

.layer-section {
    margin-top: 0.7rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(55, 200, 220, 0.15);
    font-size: 0.7rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.layer-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-height: 30px;
}

.layer-expand {
    width: 22px;
    height: 22px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.7rem;
    padding: 0;
    flex: none;
}

.layer-expand.placeholder { visibility: hidden; }

.layer-row input[type="checkbox"],
.member-row input[type="checkbox"] {
    accent-color: var(--accent);
    width: 15px;
    height: 15px;
    flex: none;
}

.layer-name {
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}

.member-list {
    margin: 0;
    padding: 0 0 0.3rem 1.6rem;
    list-style: none;
}

.member-group {
    margin-top: 0.35rem;
    font-size: 0.68rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.member-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 26px;
}

.member-name {
    background: none;
    border: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.8rem;
    text-align: left;
    padding: 2px 0;
}

.member-name:hover { color: var(--accent-bright); text-decoration: underline; }
.member-name.static { cursor: default; color: var(--text-dim); }

/* --------------------------------------------------------------------------
   Info-Panel (rechts)
   -------------------------------------------------------------------------- */

#info-panel {
    position: absolute;
    top: calc(var(--hud-height) + 8px);
    right: 8px;
    width: 340px;
    /* endet oberhalb der Skalen-Toggles rechts unten */
    max-height: calc(100vh - var(--hud-height) - 235px);
    overflow-y: auto;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: var(--panel-pad);
    z-index: 9;
    backdrop-filter: blur(4px);
    scrollbar-width: thin;
    scrollbar-color: var(--accent-dim) transparent;
}

#info-close {
    position: absolute;
    top: 6px; right: 6px;
    width: 30px; height: 30px;
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text-dim);
    font-size: 0.9rem;
}

#info-close:hover { color: var(--text); border-color: var(--panel-border); }

#info-headline { padding-right: 2rem; }

#info-name {
    margin: 0;
    font-size: 1.25rem;
    letter-spacing: 0.12em;
    color: var(--accent-bright);
}

#info-type {
    display: block;
    font-size: 0.75rem;
    color: var(--accent);
    margin-top: 2px;
}

#info-designation {
    display: block;
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-top: 1px;
}

#info-focus {
    margin-top: 0.6rem;
    background: rgba(55, 200, 220, 0.12);
    border: 1px solid var(--accent-dim);
    border-radius: 4px;
    color: var(--accent);
    font-size: 0.75rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    padding: 0.4rem 0.8rem;
}

#info-focus:hover { background: rgba(55, 200, 220, 0.25); }

#info-data {
    margin: 0.8rem 0 0;
    border-top: 1px solid rgba(55, 200, 220, 0.15);
}

.info-row {
    display: flex;
    justify-content: space-between;
    gap: 0.8rem;
    padding: 0.32rem 0;
    border-bottom: 1px solid rgba(55, 200, 220, 0.08);
    font-size: 0.8rem;
}

.info-row dt { color: var(--text-dim); }
.info-row dd { margin: 0; text-align: right; }

#info-desc {
    font-size: 0.82rem;
    line-height: 1.5;
    margin: 0.8rem 0 0;
}

#info-method {
    font-size: 0.72rem;
    line-height: 1.45;
    color: var(--warn);
    border-left: 2px solid var(--warn);
    padding-left: 0.6rem;
    margin: 0.8rem 0 0;
}

#info-sources-title {
    margin: 1rem 0 0.3rem;
    font-size: 0.75rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--accent);
}

#info-sources {
    margin: 0;
    padding: 0 0 0 1.1rem;
    font-size: 0.78rem;
}

#info-sources li { margin-bottom: 0.25rem; }
#info-sources a { color: var(--accent-bright); }
#info-sources span { color: var(--text-dim); font-size: 0.7rem; }

#info-scale-note {
    margin: 0.9rem 0 0;
    font-size: 0.68rem;
    color: var(--text-dim);
    font-style: italic;
}

/* --------------------------------------------------------------------------
   Skalenmodus + Badge (rechts unten)
   -------------------------------------------------------------------------- */

#scale-controls {
    position: absolute;
    right: 8px;
    bottom: 128px;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 0.55rem 0.7rem;
    z-index: 8;
}

#scale-controls label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.75rem;
    cursor: pointer;
    min-height: 24px;
}

#scale-controls input { accent-color: var(--accent); }

#scale-badge {
    position: absolute;
    right: 8px;
    bottom: 100px;
    font-size: 0.62rem;
    letter-spacing: 0.14em;
    color: var(--warn);
    border: 1px solid rgba(232, 180, 90, 0.5);
    border-radius: 3px;
    padding: 2px 7px;
    background: rgba(8, 14, 24, 0.85);
    z-index: 8;
}

#scale-badge.true-scale {
    color: #7de8a0;
    border-color: rgba(125, 232, 160, 0.5);
}

/* --------------------------------------------------------------------------
   Steuerungs-Hinweis + Zeitleiste (unten)
   -------------------------------------------------------------------------- */

#controls-hint {
    position: absolute;
    bottom: 76px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 1.4rem;
    margin: 0;
    font-size: 0.68rem;
    color: var(--text-dim);
    z-index: 5;
    pointer-events: none;
}

#timeline {
    position: absolute;
    bottom: 34px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.7rem;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 0.45rem 0.8rem;
    z-index: 9;
    backdrop-filter: blur(4px);
}

#timeline-buttons { display: flex; gap: 0.25rem; }

#timeline button {
    min-width: 36px;
    height: 36px;
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--accent);
    font-size: 1rem;
}

#timeline button:hover { border-color: var(--panel-border); }
#timeline button.active {
    background: rgba(55, 200, 220, 0.2);
    border-color: var(--accent);
}

#speed-select {
    background: rgba(10, 20, 32, 0.9);
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.8rem;
    padding: 0.35rem 0.3rem;
    max-width: 130px;
}

#date-jump { display: flex; gap: 0.25rem; }

#date-input {
    background: rgba(10, 20, 32, 0.9);
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.8rem;
    padding: 0.3rem 0.4rem;
    color-scheme: dark;
}

/* --------------------------------------------------------------------------
   Genauigkeits-Dialog
   -------------------------------------------------------------------------- */

#accuracy-modal {
    background: none;
    border: none;
    padding: 0;
    max-width: none;
    max-height: none;
}

#accuracy-modal::backdrop { background: rgba(2, 4, 8, 0.75); }

#accuracy-inner {
    position: relative;
    width: min(640px, 92vw);
    max-height: 80vh;
    overflow-y: auto;
    background: #0a1420;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    color: var(--text);
    font-family: var(--font);
}

#accuracy-inner h2 {
    margin: 0 0 1rem;
    font-size: 1.05rem;
    letter-spacing: 0.18em;
    color: var(--accent);
}

#accuracy-body p {
    font-size: 0.82rem;
    line-height: 1.55;
    margin: 0 0 0.9rem;
}

#accuracy-close {
    position: absolute;
    top: 8px; right: 8px;
    width: 32px; height: 32px;
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text-dim);
}

#accuracy-close:hover { color: var(--text); border-color: var(--panel-border); }

/* --------------------------------------------------------------------------
   Tutorial
   -------------------------------------------------------------------------- */

#tutorial-prompt {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(420px, 90vw);
    background: #0a1420;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    z-index: 60;
}

#tutorial-prompt h2 {
    margin: 0 0 0.6rem;
    font-size: 1rem;
    letter-spacing: 0.15em;
    color: var(--accent);
}

#tutorial-prompt p { font-size: 0.85rem; margin: 0 0 1.1rem; }

#tutorial-prompt-actions { display: flex; gap: 0.7rem; justify-content: center; }

#tutorial-prompt button,
#tutorial-tooltip-nav button {
    background: rgba(55, 200, 220, 0.12);
    border: 1px solid var(--accent-dim);
    border-radius: 4px;
    color: var(--accent);
    font-size: 0.8rem;
    padding: 0.55rem 1rem;
    min-height: var(--touch);
}

#tutorial-prompt button:hover,
#tutorial-tooltip-nav button:hover { background: rgba(55, 200, 220, 0.25); }

#tutorial-overlay { position: fixed; inset: 0; z-index: 55; }

#tutorial-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 4, 8, 0.55);
}

#tutorial-spotlight {
    position: fixed;
    border: 2px solid var(--accent);
    border-radius: 8px;
    box-shadow: 0 0 0 4000px rgba(2, 4, 8, 0.55), 0 0 24px var(--accent-dim);
    transition: all 0.35s ease;
    pointer-events: none;
}

#tutorial-tooltip {
    position: fixed;
    width: min(340px, 88vw);
    background: #0a1420;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    z-index: 56;
    transition: left 0.3s ease, top 0.3s ease;
}

#tutorial-step-counter { font-size: 0.68rem; color: var(--text-dim); }
#tutorial-tooltip h3 { margin: 0.3rem 0 0.4rem; font-size: 0.92rem; color: var(--accent); }
#tutorial-tooltip p { margin: 0 0 0.9rem; font-size: 0.8rem; line-height: 1.5; }
#tutorial-tooltip-nav { display: flex; gap: 0.5rem; justify-content: space-between; }
#tutorial-tooltip-nav button { padding: 0.4rem 0.7rem; min-height: 36px; }
#tutorial-tooltip-nav button:disabled { opacity: 0.35; cursor: default; }

/* --------------------------------------------------------------------------
   Toasts + Footer
   -------------------------------------------------------------------------- */

#toast-container {
    position: fixed;
    bottom: 96px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    z-index: 70;
    pointer-events: none;
}

.toast {
    background: #0a1420;
    border: 1px solid var(--accent);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.8rem;
    padding: 0.5rem 0.9rem;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.visible { opacity: 1; transform: translateY(0); }

#site-footer {
    position: absolute;
    bottom: 0;
    left: 0; right: 0;
    display: flex;
    justify-content: center;
    gap: 1.4rem;
    padding: 6px 0;
    font-size: 0.68rem;
    color: var(--text-dim);
    background: linear-gradient(to top, rgba(4, 8, 14, 0.85), rgba(4, 8, 14, 0));
    z-index: 6;
}

#site-footer a { color: var(--text-dim); }
#site-footer a:hover { color: var(--text); }

/* --------------------------------------------------------------------------
   Reduzierte Bewegung (NFR-3)
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    #loading-title { animation: none; }
    #tutorial-spotlight,
    #tutorial-tooltip,
    #nav-panel,
    .toast { transition: none; }
}

/* ==========================================================================
   Responsive Anpassungen (NFR-2, mobile Pflicht) — additiv am Ende
   ========================================================================== */

@media (max-width: 900px) {
    #nav-panel { width: 250px; }
    #nav-panel.collapsed { transform: translateX(-250px); }
    #info-panel { width: 300px; }
    #controls-hint { display: none; }
}

@media (max-width: 640px) {
    :root { --hud-height: 42px; }

    #hud { gap: 0.5rem; padding: 0 0.5rem; }
    #hud-title { display: none; }
    #hud-date { font-size: 0.75rem; }
    #hud-validity {
        position: absolute;
        top: calc(var(--hud-height) + 2px);
        left: 50%;
        transform: translateX(-50%);
        white-space: nowrap;
        font-size: 0.65rem;
    }

    /* Panels: Nav als Overlay, Info als Bottom-Sheet */
    #nav-panel {
        width: min(78vw, 300px);
        bottom: 170px;
    }
    #nav-panel.collapsed { transform: translateX(calc(-1 * min(78vw, 300px))); }

    #info-panel {
        top: auto;
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        max-height: 46vh;
        border-radius: var(--radius) var(--radius) 0 0;
        border-left: none;
        border-right: none;
        z-index: 12;
    }

    #timeline {
        bottom: 26px;
        left: 8px;
        right: 8px;
        transform: none;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.4rem;
        padding: 0.4rem 0.5rem;
    }

    #timeline button { min-width: var(--touch); height: var(--touch); }
    #speed-select { max-width: 110px; min-height: 38px; }
    #date-input { min-height: 38px; }

    #scale-controls {
        bottom: auto;
        top: calc(var(--hud-height) + 8px);
        right: 8px;
        padding: 0.4rem 0.5rem;
    }
    #scale-controls label { font-size: 0.68rem; }

    #scale-badge {
        top: calc(var(--hud-height) + 76px);
        bottom: auto;
        font-size: 0.55rem;
    }

    /* Impressum/Datenschutz muessen auch mobil erreichbar bleiben */
    #site-footer {
        gap: 0.9rem;
        padding: 3px 0;
        font-size: 0.6rem;
        background: rgba(4, 8, 14, 0.85);
    }
    #toast-container { bottom: auto; top: calc(var(--hud-height) + 110px); }

    .layer-row { min-height: var(--touch); }
    .member-row { min-height: 38px; }
    .layer-expand { width: 30px; height: 30px; font-size: 0.85rem; }
    .layer-row input[type="checkbox"],
    .member-row input[type="checkbox"] { width: 18px; height: 18px; }
}
