:root {
    --bg-main: radial-gradient(circle at 20% 20%, #0d1738 0%, #050912 40%, #010206 100%);
    --panel: rgba(13, 20, 40, 0.75);
    --panel-border: rgba(79, 208, 255, 0.2);
    --accent: #4fd0ff;
    --accent-hover: #7fe0ff;
    --text: #e0e6ff;
    --text-muted: #8a9bbd;
    --title: #ffd700;
    --input-bg: rgba(0, 0, 0, 0.4);
    --input-border: rgba(79, 208, 255, 0.3);
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    overflow: hidden;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-main);
    color: var(--text);
    color-scheme: dark;
}

.menu-toggle {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    background: rgba(13, 20, 40, 0.8);
    color: var(--accent);
    font-size: 1.2rem;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    z-index: 12;
    cursor: pointer;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    transition: background 0.2s ease, transform 0.2s ease;
}

.menu-toggle:hover {
    background: rgba(79, 208, 255, 0.12);
    transform: translateY(-1px);
}

#ui-container {
    position: absolute;
    top: 14px;
    left: 14px;
    background: var(--panel);
    padding: 14px;
    border-radius: 14px;
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    pointer-events: auto;
    z-index: 10;
    user-select: none;
    width: 240px;
    transition: opacity 0.3s ease;
}

.demo-mode #ui-container {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-110%);
}

.demo-mode .menu-toggle {
    display: flex;
    opacity: 0.9;
}

h1 {
    margin: 0 0 10px 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--title);
    letter-spacing: 0.05em;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
    text-align: center;
    text-transform: uppercase;
}

.control-group {
    margin-bottom: 12px;
}

label {
    display: block;
    font-size: 0.82rem;
    margin-bottom: 6px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Custom Inputs */
.control-input,
.control-select {
    width: 100%;
    padding: 8px 10px;
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.88rem;
    transition: all 0.2s ease;
    outline: none;
}

.control-input:focus,
.control-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(79, 208, 255, 0.1);
    background: rgba(0, 0, 0, 0.6);
}

.control-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M2.5 4.5L6 8L9.5 4.5' stroke='%234fd0ff' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* Slider Styling */
input[type=range] {
    width: 100%;
    height: 6px;
    background: var(--input-bg);
    border-radius: 3px;
    outline: none;
    appearance: none;
    margin: 10px 0;
}

input[type=range]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(79, 208, 255, 0.5);
    transition: transform 0.1s ease;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    background: var(--accent-hover);
}

/* Checkbox Grid */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.flex-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text);
    transition: color 0.2s;
}

.checkbox-label:hover {
    color: var(--accent);
}

input[type=checkbox] {
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}

input[type=checkbox]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

input[type=checkbox]:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 4px;
    height: 8px;
    border: solid #000;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

#speed-display {
    font-weight: 600;
    color: var(--accent);
    float: right;
}

.instruction {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--panel-border);
    line-height: 1.6;
}

.label {
    color: #ffffff;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    pointer-events: none;
    backdrop-filter: blur(4px);
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
    margin-top: 10px;
    transition: all 0.3s ease;
}

/* Time Controls */
.time-controls {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}

.control-btn {
    flex: 1;
    background: rgba(79, 208, 255, 0.15);
    border: 1px solid var(--panel-border);
    color: var(--accent);
    padding: 6px 0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn:hover {
    background: rgba(79, 208, 255, 0.3);
    box-shadow: 0 0 8px rgba(79, 208, 255, 0.2);
}

.control-btn.active {
    background: rgba(79, 208, 255, 0.35);
    color: #fff;
}

.timeline-readout {
    margin-top: 10px;
    background: rgba(0, 0, 0, 0.3);
    padding: 8px;
    border-radius: 6px;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.78rem;
    color: var(--accent);
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

#date-display {
    font-weight: bold;
    margin-bottom: 4px;
    color: #fff;
}

#elapsed-display {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.audio-player {
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.02);
    box-shadow: inset 0 0 0 1px rgba(79, 208, 255, 0.06);
}

.audio-top {
    display: block;
    margin-bottom: 4px;
}

.audio-label {
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.audio-buttons {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    width: 100%;
}

.audio-volume {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.volume-icon {
    font-size: 0.9rem;
    opacity: 0.8;
}

.audio-volume input[type=range] {
    margin: 0;
    flex: 1;
}

.volume-value {
    width: 44px;
    text-align: right;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.now-playing {
    position: fixed;
    right: 14px;
    bottom: 12px;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    font-size: 0.82rem;
    color: var(--text);
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
    z-index: 20;
}

.now-playing.visible {
    opacity: 0.75;
}

.motd-bar {
    position: fixed;
    left: 14px;
    right: 14px;
    top: 12px;
    display: none;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: transparent;
    border: none;
    border-radius: 12px;
    box-shadow: none;
    z-index: 14;
    overflow: hidden;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.motd-bar.show {
    display: flex;
}

.motd-marquee {
    flex: 1;
    overflow: hidden;
}

.motd-text {
    display: inline-block;
    white-space: nowrap;
    min-width: 100%;
    color: var(--text);
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.35);
    will-change: transform;
    font-family: 'Trebuchet MS', 'Segoe UI', 'Montserrat', sans-serif;
    letter-spacing: 0.04em;
    font-weight: 700;
    opacity: 0.65;
}

.motd-text.animating {
    animation-name: motd-scroll;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
    animation-fill-mode: forwards;
}

.motd-text.paused {
    animation-play-state: paused;
}

@keyframes motd-scroll {
    0% {
        transform: translate3d(100%, 0, 0);
    }
    100% {
        transform: translate3d(-100%, 0, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .motd-text.animating {
        animation: none;
        transform: translate3d(0, 0, 0);
    }
}

.motd-dismiss {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.2s, color 0.2s;
}

.motd-dismiss:hover {
    opacity: 1;
    color: var(--accent);
}

/* Focus Row */
.focus-row {
    display: flex;
    gap: 8px;
}

.small-btn {
    flex: 0 0 32px;
    padding: 0;
    font-size: 1.1rem;
}

/* Legend */
.legend-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--panel-border);
    margin-top: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.dot.planet {
    background: #4fd0ff;
    box-shadow: 0 0 4px #4fd0ff;
}

.dot.dwarf {
    background: #ff99cc;
    box-shadow: 0 0 4px #ff99cc;
}

.dot.comet {
    background: #aaddff;
    box-shadow: 0 0 4px #aaddff;
}

.dot.belt {
    background: #888;
}

@media (max-width: 768px) {
    #ui-container {
        width: calc(100% - 32px);
        max-width: 340px;
        max-height: calc(100vh - 80px);
        overflow-y: auto;
        transform: translateX(-110%);
        opacity: 0;
        pointer-events: none;
        transition: transform 0.3s ease, opacity 0.3s ease;
    }

    body.panel-open #ui-container {
        transform: translateX(0);
        opacity: 1;
        pointer-events: auto;
    }

    .menu-toggle {
        display: flex;
    }

    body.panel-open .menu-toggle {
        background: rgba(79, 208, 255, 0.15);
    }
}

/* Spaceship HUD */
.hud-panel {
    position: absolute;
    bottom: 30px;
    right: 30px;
    /* Move to right to avoid left panel */
    left: auto;
    transform: none;
    background: rgba(10, 15, 30, 0.6);
    border: 1px solid rgba(79, 208, 255, 0.3);
    border-radius: 16px;
    padding: 24px;
    color: var(--accent);
    font-family: 'Segoe UI', 'Roboto', sans-serif;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(79, 208, 255, 0.05);
    z-index: 1000;
    /* Ensure on top */
    text-align: center;
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    min-width: 280px;
}

.hud-panel.hidden {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    display: none !important;
}

.hud-panel h3 {
    margin: 0 0 20px 0;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 3px;
    font-size: 14px;
    font-weight: 600;
    text-shadow: 0 0 10px rgba(79, 208, 255, 0.5);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 10px;
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    justify-items: center;
}

.key-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.key {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    font-weight: 700;
    font-size: 14px;
    color: #fff;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
}

.hud-panel .label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    text-shadow: none;
    pointer-events: none;
}

.hint {
    margin-top: 20px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 12px;
}

.hint strong {
    color: var(--accent);
}

/* Info Chart Overlay */
.info-chart {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 320px;
    background: rgba(13, 20, 40, 0.9);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 100;
    color: var(--text);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.info-chart.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -45%);
}

.demo-mode .info-chart {
    top: 16px;
    right: 16px;
    left: auto;
    transform: none;
    max-width: min(360px, 40vw);
}

.demo-mode .info-chart.hidden {
    transform: translateY(-6px);
}

.close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--accent);
}

#chart-title {
    margin: 0 0 20px 0;
    font-size: 1.5rem;
    color: var(--title);
    text-align: center;
    text-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
}

.chart-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chart-row {
    display: flex;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.chart-row:last-child {
    border-bottom: none;
    flex-direction: column;
    gap: 4px;
}

.chart-label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.chart-value {
    color: var(--accent);
    font-weight: 500;
    text-align: right;
}

.trivia-row .chart-value {
    text-align: left;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #e0e6ff;
    font-style: italic;
}

.label {
    cursor: pointer;
}

.label:hover {
    background: rgba(79, 208, 255, 0.2);
    border-color: var(--accent);
    transform: scale(1.1);
}

.demo-mode .label {
    display: none !important;
}

.demo-mode .menu-toggle {
    display: none !important;
}

.demo-watermark {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: min(12vw, 120px);
    letter-spacing: 0.2em;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.04);
    text-transform: uppercase;
    pointer-events: none;
    user-select: none;
    z-index: 1;
    mix-blend-mode: screen;
    text-shadow: 0 0 60px rgba(79, 208, 255, 0.2);
    opacity: 0.7;
    backdrop-filter: blur(1px);
}

.pip-view {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 240px;
    height: 160px;
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    background: rgba(5, 8, 16, 0.5);
    pointer-events: none;
    z-index: 6;
}

.gravity-widget {
    position: fixed;
    left: 16px;
    bottom: 16px;
    width: 140px;
    height: 140px;
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    background: rgba(5, 8, 16, 0.5);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    pointer-events: none;
    z-index: 20;
    opacity: 1;
    transition: opacity 0.6s ease;
}

.demo-trivia {
    position: fixed;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 18px;
    background: linear-gradient(120deg, rgba(79, 208, 255, 0.18), rgba(255, 255, 255, 0.05), rgba(255, 88, 180, 0.18));
    border: 1px solid rgba(79, 208, 255, 0.55);
    border-radius: 14px;
    color: #e9f6ff;
    font-family: "Space Grotesk", "Audiowide", "Rajdhani", "Inter", sans-serif;
    font-size: 1rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    text-align: center;
    max-width: 70vw;
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.7), 0 0 24px rgba(79, 208, 255, 0.2);
    backdrop-filter: blur(14px);
    pointer-events: none;
    z-index: 18;
    opacity: 0;
    transition: opacity 0.6s ease;
    background-clip: padding-box;
    text-shadow: 0 0 12px rgba(79, 208, 255, 0.6), 0 0 30px rgba(255, 88, 180, 0.35);
}
