/* Moonbase — Retro-Futuro Lunar Biosphere Interface */

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

/* Retro-futuro lunar palette — cool dusk sky, warm regolith, glass domes */
:root {
    --sky-top: #23274d;
    --sky-mid: #5e5183;
    --sky-horizon: #9c6450;
    --regolith: #bd9a72;
    --regolith-dark: #7f6342;
    --frame-orange: #df6f3a;
    --frame-mustard: #d6a73c;
    --glass: #5fb8b0;
    --glass-light: #7fe0d2;
    --leaf: #3f8f49;
    --leaf-dark: #357a3d;
    --beacon: #ff5a47;
    --violet: #9d7bff;
    --cyan: #7bd0c8;
    --pink: #ff9ad2;
    --cream: #fff7e8;
    --spore: #ffe9b0;
    --bot: #e3b23c;
    --text-light: #fdf3e3;
    --text-dark: #241a3a;
    --panel-bg: rgba(28, 24, 54, 0.82);
    --panel-deep: #1b1730;
    --accent: #d6a73c;
    --accent-glow: rgba(214, 167, 60, 0.6);
    --danger: #e2603a;
    /* Picked up by the shared map overlay so the close button matches this site. */
    --map-accent: var(--accent);
    --map-accent-glow: var(--accent-glow);
}

body {
    font-family: 'Courier New', 'Monaco', 'Menlo', monospace;
    background: var(--sky-top);
    min-height: 100vh;
    overflow: hidden;
    position: relative;
    color: var(--text-light);
}

/* Scene Container — fallback fill behind the full-bleed backdrop SVG. */
.scene-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(to bottom, var(--sky-top) 0%, var(--sky-mid) 50%, var(--sky-horizon) 100%);
    overflow: hidden;
    cursor: default;
}

/* The hand-drawn colony scene — covers the whole viewport. */
.moon-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    z-index: 0;
    pointer-events: none;
}

/* ---- backdrop ambient animations ---- */
.m-twinkle { animation: mb-twinkle 3.4s ease-in-out infinite; }
@keyframes mb-twinkle { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

.m-aurora {
    transform-box: fill-box;
    transform-origin: center;
    animation: mb-aurora 17s ease-in-out infinite;
}
.m-aurora.alt { animation-duration: 23s; animation-delay: -6s; }
@keyframes mb-aurora {
    0%, 100% { opacity: 0.12; transform: translateY(0); }
    50%      { opacity: 0.22; transform: translateY(-10px); }
}

.m-spore {
    transform-box: fill-box;
    animation: mb-spore 13s linear infinite;
}
@keyframes mb-spore {
    0%   { transform: translate(0, 0);        opacity: 0; }
    15%  { opacity: 0.75; }
    100% { transform: translate(-26px, -64px); opacity: 0; }
}

/* Foliage sways gently; harder + faster while audio is playing. */
.moon-foliage,
.moon-vine {
    transform-box: fill-box;
    transform-origin: center bottom;
    animation: mb-sway 7s ease-in-out infinite;
}
.moon-vine { transform-origin: center top; animation-duration: 8.5s; }
@keyframes mb-sway {
    0%, 100% { transform: rotate(-1.3deg); }
    50%      { transform: rotate(1.3deg); }
}
body.playing .moon-foliage { animation-duration: 3.2s; }
body.playing .moon-vine    { animation-duration: 3.8s; }

/* Collector bot trundles + its inspection arm scans the ground. */
.moon-bot {
    transform-box: fill-box;
    transform-origin: center bottom;
    animation: mb-bot-roam 18s ease-in-out infinite;
}
@keyframes mb-bot-roam {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(46px); }
    55%      { transform: translateX(8px); }
    80%      { transform: translateX(-34px); }
}
.moon-bot-arm {
    transform-box: fill-box;
    transform-origin: left top;
    animation: mb-bot-scan 4.2s ease-in-out infinite;
}
@keyframes mb-bot-scan {
    0%, 100% { transform: rotate(0deg); }
    50%      { transform: rotate(9deg); }
}

/* ============ Drifting alien creatures (clickable, low-G) ============ */
.moon-critter {
    position: absolute;
    width: var(--size, 70px);
    height: var(--size, 70px);
    background-repeat: no-repeat;
    background-size: contain;
    background-position: center;
    cursor: pointer;
    transition: transform 0.3s ease, filter 0.3s ease;
    z-index: 10;
    filter: drop-shadow(0 0 6px rgba(157, 123, 255, 0.35));
}

.moon-critter:hover {
    transform: scale(1.12);
    filter: drop-shadow(0 0 12px rgba(157, 123, 255, 0.6));
}

.moon-critter.active {
    animation: mb-critter-wobble 1.5s infinite ease-in-out !important;
    filter: drop-shadow(0 0 14px rgba(127, 224, 210, 0.7)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

@keyframes mb-critter-wobble {
    0%, 100% { transform: rotate(-7deg) translateY(0); }
    50%      { transform: rotate(7deg) translateY(-6px); }
}

.moon-critter.nebula-jelly {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 92'><ellipse cx='40' cy='34' rx='30' ry='15' fill='%239d7bff' opacity='0.25'/><path d='M12 36 Q40 6 68 36 Q68 48 58 50 L22 50 Q12 48 12 36 Z' fill='%239d7bff'/><path d='M18 34 Q40 14 62 34' stroke='%23d8c8ff' stroke-width='2' fill='none' opacity='0.6'/><g stroke='%239d7bff' stroke-width='3' fill='none' stroke-linecap='round' opacity='0.9'><path d='M24 50 Q20 70 26 88'/><path d='M34 50 Q36 72 30 90'/><path d='M46 50 Q44 72 50 90'/><path d='M56 50 Q60 70 54 88'/></g><circle cx='34' cy='34' r='2.4' fill='%23241a3a'/><circle cx='46' cy='34' r='2.4' fill='%23241a3a'/></svg>");
    animation: mb-drift-a 9s infinite ease-in-out;
}
.moon-critter.glow-mote {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 70'><circle cx='30' cy='40' r='20' fill='%237bd0c8' opacity='0.25'/><circle cx='30' cy='40' r='15' fill='%237bd0c8'/><line x1='24' y1='26' x2='20' y2='12' stroke='%237bd0c8' stroke-width='2.4'/><circle cx='20' cy='10' r='3' fill='%23ffd24a'/><line x1='36' y1='26' x2='40' y2='12' stroke='%237bd0c8' stroke-width='2.4'/><circle cx='40' cy='10' r='3' fill='%23ffd24a'/><circle cx='24' cy='38' r='2.2' fill='%23163a40'/><circle cx='36' cy='38' r='2.2' fill='%23163a40'/><path d='M23 48 Q30 54 37 48' stroke='%23163a40' stroke-width='2' fill='none'/></svg>");
    animation: mb-drift-b 7.5s infinite ease-in-out;
}
.moon-critter.puff-drifter {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 72 70'><ellipse cx='36' cy='34' rx='27' ry='23' fill='%23ff9ad2' opacity='0.22'/><path d='M12 36 Q12 14 36 14 Q60 14 60 36 Q60 52 36 54 Q12 52 12 36 Z' fill='%23ff9ad2'/><circle cx='22' cy='38' r='3' fill='%23ff6f9c' opacity='0.5'/><circle cx='50' cy='38' r='3' fill='%23ff6f9c' opacity='0.5'/><circle cx='29' cy='32' r='2.6' fill='%23fff'/><circle cx='43' cy='32' r='2.6' fill='%23fff'/><circle cx='29' cy='32' r='1.2' fill='%23241a3a'/><circle cx='43' cy='32' r='1.2' fill='%23241a3a'/><g stroke='%23ff9ad2' stroke-width='3' stroke-linecap='round' fill='none'><path d='M24 54 Q22 64 26 68'/><path d='M36 55 V68'/><path d='M48 54 Q50 64 46 68'/></g></svg>");
    animation: mb-drift-c 8.5s infinite ease-in-out;
}

@keyframes mb-drift-a { 0%, 100% { transform: translate(0, 0)    rotate(-4deg); } 50% { transform: translate(8px, -16px)  rotate(4deg); } }
@keyframes mb-drift-b { 0%, 100% { transform: translate(0, 0)    rotate(3deg); }  50% { transform: translate(-10px, -12px) rotate(-3deg); } }
@keyframes mb-drift-c { 0%, 100% { transform: translate(0, 0)    rotate(-2deg); } 50% { transform: translate(6px, -20px)  rotate(3deg); } }

body.playing .moon-critter.nebula-jelly { animation-duration: 5s; }
body.playing .moon-critter.glow-mote    { animation-duration: 4.2s; }
body.playing .moon-critter.puff-drifter { animation-duration: 4.6s; }

/* ============ Play-state signal — small wifi waves toward Earth ============ */
.moon-signal {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120px;
    height: 120px;
    transform: translate(-30%, -150%);
    z-index: 19;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}
body.playing .moon-signal { opacity: 1; }

.moon-wave { opacity: 0; }
body.playing .moon-wave   { animation: mb-wave 1.9s ease-out infinite; }
body.playing .moon-wave.b { animation-delay: 0.63s; }
body.playing .moon-wave.c { animation-delay: 1.26s; }
@keyframes mb-wave {
    0%   { opacity: 0; }
    22%  { opacity: 0.9; }
    60%  { opacity: 0.45; }
    100% { opacity: 0; }
}

/* ============ Radio Element — retro transmitter console ============ */
.radio-element {
    position: absolute;
    width: 116px;
    height: 92px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, transparent 22%),
        var(--panel-deep);
    border: 3px solid var(--frame-mustard);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 20;
    box-shadow:
        0 5px 0 rgba(0, 0, 0, 0.35),
        inset 0 2px 0 rgba(255, 255, 255, 0.08);
    animation: mb-radio-idle 6s infinite ease-in-out;
}

/* Play / pause glyph */
.radio-element::before {
    content: '';
    position: absolute;
    top: 50%;
    left: calc(50% + 3px);
    transform: translate(-50%, -50%);
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 13px 0 13px 22px;
    border-color: transparent transparent transparent var(--glass-light);
    filter: drop-shadow(0 0 8px rgba(127, 224, 210, 0.6));
    transition: all 0.3s ease;
}
.radio-element.playing::before {
    left: 50%;
    width: 6px;
    height: 24px;
    border-style: solid;
    border-width: 0 6px 0 6px;
    border-color: transparent var(--glass-light) transparent var(--glass-light);
}

/* Antenna beacon sitting on top of the console */
.radio-element::after {
    content: '';
    position: absolute;
    top: -19px;
    left: 50%;
    width: 9px;
    height: 9px;
    margin-left: -4.5px;
    border-radius: 50%;
    background: var(--beacon);
    box-shadow: 0 0 9px var(--beacon), 0 11px 0 -3px var(--frame-mustard);
    animation: mb-beacon-idle 2.6s infinite ease-in-out;
}
.radio-element.playing::after {
    animation: mb-beacon-live 1.3s infinite ease-in-out;
}
@keyframes mb-beacon-idle { 0%, 100% { opacity: 0.9; } 50% { opacity: 0.4; } }
@keyframes mb-beacon-live {
    0%, 100% { opacity: 1;   transform: scale(1); }
    50%      { opacity: 0.6; transform: scale(1.35); }
}

.radio-element.playing {
    animation: mb-radio-playing 2s infinite ease-in-out;
    border-color: var(--frame-orange);
}

@keyframes mb-radio-idle {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50%      { transform: translate(-50%, -50%) scale(1.02); }
}
@keyframes mb-radio-playing {
    0%, 100% { box-shadow: 0 5px 0 rgba(0,0,0,0.35), inset 0 2px 0 rgba(255,255,255,0.08), 0 0 22px var(--accent-glow); }
    50%      { box-shadow: 0 5px 0 rgba(0,0,0,0.35), inset 0 2px 0 rgba(255,255,255,0.08), 0 0 34px var(--accent); }
}

.radio-element:hover {
    transform: translate(-50%, -50%) scale(1.05);
    border-color: var(--frame-orange);
    box-shadow: 0 5px 0 rgba(0,0,0,0.35), inset 0 2px 0 rgba(255,255,255,0.08), 0 0 20px var(--accent-glow);
}
.radio-element:active {
    transform: translate(-50%, -50%) scale(0.95);
    box-shadow: 0 2px 0 rgba(0,0,0,0.35), inset 0 2px 0 rgba(255,255,255,0.08);
}

/* ============ Pixel Text ============ */
.pixel-text {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-light);
    text-shadow: 2px 2px 0 var(--panel-deep), 0 0 10px rgba(253, 243, 227, 0.3);
}

/* ============ Song Display ============ */
.song-display {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    background: var(--panel-bg);
    border: 2px solid var(--accent);
    border-radius: 6px;
    z-index: 30;
    min-width: 200px;
    max-width: 80%;
    text-align: center;
    box-shadow: 0 0 0 1px var(--panel-deep), 0 4px 0 rgba(0,0,0,0.3), 0 0 15px var(--accent-glow);
    transition: all 0.3s ease;
    user-select: none;
}
.song-display:hover {
    transform: translateX(-50%) translateY(-5px);
    box-shadow: 0 0 0 1px var(--panel-deep), 0 6px 0 rgba(0,0,0,0.3), 0 0 25px var(--accent-glow);
}
.song-display:active { transform: translateX(-50%) translateY(-3px); }
.song-display.generating { animation: mb-generating 2s infinite; }
@keyframes mb-generating {
    0%, 100% { box-shadow: 0 0 0 1px var(--panel-deep), 0 4px 0 rgba(0,0,0,0.3), 0 0 15px var(--accent-glow); }
    50%      { box-shadow: 0 0 0 1px var(--panel-deep), 0 4px 0 rgba(0,0,0,0.3), 0 0 25px var(--accent); }
}
.song-display .pixel-text {
    font-size: 12px;
    line-height: 1.4;
    word-wrap: break-word;
    display: block;
}

/* ============ Startup Overlay ============ */
.startup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(20, 16, 40, 0.94);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.5s ease-out;
}
.startup-message {
    text-align: center;
    padding: 30px 40px;
    background: rgba(20, 16, 40, 0.9);
    border: 3px solid var(--accent);
    border-radius: 8px;
    box-shadow: 0 0 0 2px var(--panel-deep), 0 8px 0 rgba(0,0,0,0.4), 0 0 30px var(--accent-glow);
}
.startup-message .pixel-text {
    font-size: 18px;
    margin-bottom: 15px;
    color: var(--accent);
    text-shadow: 2px 2px 0 var(--panel-deep), 0 0 15px var(--accent-glow);
}
.startup-dots { display: flex; justify-content: center; gap: 8px; font-size: 24px; color: var(--accent); }
.startup-dots span { animation: mb-dot 1.4s infinite; animation-delay: calc(var(--dot-index, 0) * 0.2s); }
.startup-dots span:nth-child(1) { --dot-index: 0; }
.startup-dots span:nth-child(2) { --dot-index: 1; }
.startup-dots span:nth-child(3) { --dot-index: 2; }
@keyframes mb-dot { 0%, 100% { opacity: 0.3; transform: scale(1); } 50% { opacity: 1; transform: scale(1.2); } }

/* ============ Status Indicator ============ */
.status-indicator {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 6px 12px;
    background: var(--panel-bg);
    border: 2px solid var(--accent);
    border-radius: 4px;
    z-index: 30;
    box-shadow: 0 0 0 1px var(--panel-deep), 0 2px 0 rgba(0,0,0,0.3);
}
.status-indicator.online { border-color: var(--accent); animation: mb-status 2s infinite; }
.status-indicator.offline { border-color: var(--danger); }
@keyframes mb-status {
    0%, 100% { box-shadow: 0 0 0 1px var(--panel-deep), 0 2px 0 rgba(0,0,0,0.3), 0 0 10px var(--accent-glow); }
    50%      { box-shadow: 0 0 0 1px var(--panel-deep), 0 2px 0 rgba(0,0,0,0.3), 0 0 20px var(--accent); }
}

/* ============ Ripple ============ */
.ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(127, 224, 210, 0.5);
    transform: scale(0);
    animation: mb-ripple 0.6s ease-out;
    pointer-events: none;
    z-index: 100;
}
@keyframes mb-ripple { to { transform: scale(4); opacity: 0; } }

/* ============ Map button ============ */
.map-button {
    position: absolute;
    top: max(20px, env(safe-area-inset-top) + 12px);
    left: 20px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px 10px 12px;
    background: var(--panel-deep);
    color: var(--accent);
    border: 3px solid var(--frame-mustard);
    border-radius: 8px;
    box-shadow: 0 4px 0 rgba(0,0,0,0.35), inset 0 2px 0 rgba(255,255,255,0.08);
    font-family: 'Courier New', 'Monaco', 'Menlo', monospace;
    font-size: 12px;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    text-decoration: none;
    z-index: 30;
    cursor: pointer;
    user-select: none;
    transition: all 0.3s ease;
}
.map-button:hover {
    transform: translateY(-3px);
    border-color: var(--frame-orange);
    box-shadow: 0 7px 0 rgba(0,0,0,0.35), inset 0 2px 0 rgba(255,255,255,0.08), 0 0 20px var(--accent-glow);
}
.map-button:active {
    transform: translateY(-1px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.35), inset 0 2px 0 rgba(255,255,255,0.08);
}
.map-button:focus-visible { outline: 2px solid var(--cream); outline-offset: 3px; }
.map-button-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    filter: drop-shadow(0 0 4px var(--accent-glow));
    animation: mb-needle 4s ease-in-out infinite;
    transform-origin: center;
}
@keyframes mb-needle { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
.map-button-label { line-height: 1; }

@media (max-width: 600px) {
    .map-button { padding: 6px 10px 6px 8px; font-size: 10px; letter-spacing: 0.16em; }
    .map-button-icon { width: 18px; height: 18px; }
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
    .moon-critter { --size: 54px; }
    .moon-critter.glow-mote { --size: 44px; }
    .radio-element { width: 104px; height: 84px; }
    .song-display {
        bottom: max(100px, env(safe-area-inset-bottom) + 85px);
        padding: 10px 16px;
        min-width: 150px;
        max-width: 90%;
    }
    .pixel-text { font-size: 12px; }
    .status-indicator { top: max(15px, env(safe-area-inset-top) + 10px); right: 15px; }
    .moon-signal { transform: translate(-26%, -150%) scale(0.85); }
}

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