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

html,
body {
    width: 100%;
    height: 100%;
    background: #000;
    color: #f4ecd8;
    font-family: 'Cormorant Garamond', Georgia, serif;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.hidden {
    display: none !important;
}

.gate {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center, #06040e 0%, #000 70%);
    z-index: 100;
    opacity: 1;
    transition: opacity 1.6s ease;
}

.gate.fading {
    opacity: 0;
    pointer-events: none;
}

.gate-stars {
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(1px 1px at 20% 30%, rgba(255, 255, 255, 0.8), transparent),
        radial-gradient(1px 1px at 60% 70%, rgba(255, 255, 255, 0.6), transparent),
        radial-gradient(2px 2px at 80% 20%, rgba(255, 255, 255, 0.9), transparent),
        radial-gradient(1px 1px at 35% 85%, rgba(255, 255, 255, 0.7), transparent),
        radial-gradient(1px 1px at 90% 50%, rgba(255, 255, 255, 0.5), transparent),
        radial-gradient(1.5px 1.5px at 10% 60%, rgba(255, 255, 255, 0.8), transparent),
        radial-gradient(1px 1px at 50% 15%, rgba(255, 255, 255, 0.6), transparent),
        radial-gradient(1px 1px at 75% 90%, rgba(255, 255, 255, 0.7), transparent),
        radial-gradient(2px 2px at 25% 50%, rgba(255, 255, 255, 0.4), transparent),
        radial-gradient(1px 1px at 95% 75%, rgba(255, 255, 255, 0.8), transparent);
    background-size: 200% 200%;
    animation: twinkle 8s ease-in-out infinite alternate;
    opacity: 0.9;
}

@keyframes twinkle {
    0% {
        opacity: 0.6;
        transform: scale(1);
    }
    100% {
        opacity: 1;
        transform: scale(1.02);
    }
}

.gate-content {
    position: relative;
    text-align: center;
    padding: 2rem;
    max-width: 28rem;
    width: 100%;
    animation: gate-rise 1.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes gate-rise {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.gate-title {
    font-family: 'Italiana', serif;
    font-size: clamp(3rem, 8vw, 5.5rem);
    font-weight: 400;
    letter-spacing: 0.04em;
    color: #f4ecd8;
    text-shadow:
        0 0 20px rgba(244, 236, 216, 0.4),
        0 0 50px rgba(180, 200, 255, 0.2);
    margin-bottom: 0.5rem;
}

.gate-subtitle {
    font-size: clamp(0.95rem, 2.2vw, 1.2rem);
    font-style: italic;
    font-weight: 300;
    color: rgba(244, 236, 216, 0.65);
    letter-spacing: 0.1em;
    margin-bottom: 3rem;
}

.gate-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

.gate-input {
    width: 100%;
    max-width: 22rem;
    padding: 0.95rem 1.4rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(244, 236, 216, 0.25);
    border-radius: 999px;
    color: #f4ecd8;
    font-family: inherit;
    font-size: 1.05rem;
    letter-spacing: 0.05em;
    text-align: center;
    outline: none;
    transition: all 0.4s ease;
    backdrop-filter: blur(8px);
}

.gate-input::placeholder {
    color: rgba(244, 236, 216, 0.4);
    font-style: italic;
}

.gate-input:focus {
    border-color: rgba(244, 236, 216, 0.6);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 30px rgba(180, 200, 255, 0.15);
}

.gate-button {
    padding: 0.75rem 3rem;
    background: transparent;
    border: 1px solid rgba(244, 236, 216, 0.5);
    border-radius: 999px;
    color: #f4ecd8;
    font-family: 'Italiana', serif;
    font-size: 1rem;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.gate-button:hover {
    background: rgba(244, 236, 216, 0.1);
    border-color: rgba(244, 236, 216, 0.9);
    letter-spacing: 0.35em;
    box-shadow: 0 0 40px rgba(180, 200, 255, 0.2);
}

.gate-error {
    color: #ffb3a8;
    font-size: 0.9rem;
    font-style: italic;
    min-height: 1.2rem;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gate-error.visible {
    opacity: 1;
}

.gate-form.shake {
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

.loader {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 90;
    transition: opacity 1.4s ease;
}

.loader.fading {
    opacity: 0;
    pointer-events: none;
}

.loader-orb {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #f4ecd8, #8a8270 70%, #2a2722);
    box-shadow:
        0 0 40px rgba(244, 236, 216, 0.4),
        0 0 80px rgba(180, 200, 255, 0.2);
    animation: orb-pulse 2.4s ease-in-out infinite;
}

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

.loader-text {
    margin-top: 2rem;
    font-style: italic;
    color: rgba(244, 236, 216, 0.7);
    letter-spacing: 0.1em;
    font-size: 1rem;
}

.scene {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 2s ease;
}

.scene.visible {
    opacity: 1;
}

#moon-canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
}

#moon-canvas:active {
    cursor: grabbing;
}

.ui {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

.ui-top {
    position: absolute;
    top: 2rem;
    left: 0;
    right: 0;
    text-align: center;
    opacity: 0;
    animation: fade-down 2.4s ease 1.5s forwards;
}

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

.ui-greeting {
    font-family: 'Italiana', serif;
    font-size: clamp(1.1rem, 2.4vw, 1.5rem);
    letter-spacing: 0.3em;
    color: rgba(244, 236, 216, 0.85);
    text-shadow: 0 0 20px rgba(180, 200, 255, 0.3);
    text-transform: uppercase;
}

.ui-hint {
    position: absolute;
    bottom: 2.5rem;
    left: 0;
    right: 0;
    text-align: center;
    opacity: 0;
    animation: hint-pulse 3s ease 3s forwards;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

@keyframes hint-pulse {
    0% {
        opacity: 0;
    }
    40% {
        opacity: 0.65;
    }
    100% {
        opacity: 0.55;
    }
}

.hint-text {
    color: rgba(244, 236, 216, 0.55);
    font-size: 0.85rem;
    font-style: italic;
    letter-spacing: 0.12em;
}

.hint-text--click {
    color: rgba(244, 236, 216, 0.7);
    font-size: 0.95rem;
    animation: hint-click 2.6s ease-in-out infinite;
}

@keyframes hint-click {
    0%, 100% {
        opacity: 0.5;
    }
    50% {
        opacity: 1;
    }
}

.audio-control {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 0.8rem 0.4rem 0.4rem;
    border-radius: 999px;
    border: 1px solid rgba(244, 236, 216, 0.18);
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    pointer-events: auto;
    opacity: 0;
    animation: fade-in 1.6s ease 2.5s forwards;
    transition: border-color 0.4s ease, background 0.4s ease;
}

.audio-control:hover {
    border-color: rgba(244, 236, 216, 0.4);
}

.music-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #f4ecd8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
    flex-shrink: 0;
}

.music-toggle:hover {
    opacity: 0.7;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 90px;
    height: 3px;
    background: rgba(244, 236, 216, 0.2);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    transition: background 0.3s ease;
}

.volume-slider:hover {
    background: rgba(244, 236, 216, 0.35);
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #f4ecd8;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(244, 236, 216, 0.5);
    transition: transform 0.2s ease;
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border: none;
    border-radius: 50%;
    background: #f4ecd8;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(244, 236, 216, 0.5);
}

.audio-control.muted .volume-slider {
    opacity: 0.3;
    pointer-events: none;
}

@keyframes fade-in {
    to {
        opacity: 1;
    }
}

.music-toggle svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.music-toggle .icon-off {
    display: none;
}

.music-toggle.muted .icon-on {
    display: none;
}

.music-toggle.muted .icon-off {
    display: block;
}

.letter {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1.4s ease;
}

.letter.open {
    pointer-events: auto;
    opacity: 1;
}

.letter-backdrop {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, rgba(10, 15, 30, 0.7) 0%, rgba(0, 0, 0, 0.92) 80%);
    backdrop-filter: blur(6px);
}

.letter-card {
    position: relative;
    width: min(90vw, 38rem);
    max-height: 88vh;
    padding: clamp(2rem, 5vw, 4rem);
    background: linear-gradient(
        135deg,
        rgba(30, 25, 40, 0.65) 0%,
        rgba(15, 20, 35, 0.85) 100%
    );
    border: 1px solid rgba(244, 236, 216, 0.18);
    border-radius: 4px;
    box-shadow:
        0 30px 100px rgba(0, 0, 0, 0.6),
        0 0 80px rgba(180, 200, 255, 0.15),
        inset 0 1px 0 rgba(244, 236, 216, 0.08);
    color: #f4ecd8;
    overflow-y: auto;
    transform: translateY(20px) scale(0.97);
    transition: transform 1.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.letter.open .letter-card {
    transform: translateY(0) scale(1);
}

.letter-card::-webkit-scrollbar {
    width: 4px;
}

.letter-card::-webkit-scrollbar-thumb {
    background: rgba(244, 236, 216, 0.2);
    border-radius: 2px;
}

.letter-close {
    position: absolute;
    top: 0.75rem;
    right: 1rem;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: rgba(244, 236, 216, 0.5);
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    transition: color 0.3s ease;
}

.letter-close:hover {
    color: rgba(244, 236, 216, 1);
}

.letter-eyebrow {
    font-style: italic;
    font-size: 0.9rem;
    letter-spacing: 0.18em;
    color: rgba(244, 236, 216, 0.55);
    margin-bottom: 1.5rem;
    text-transform: lowercase;
}

.letter-title {
    font-family: 'Italiana', serif;
    font-size: clamp(2.2rem, 5vw, 3.2rem);
    font-weight: 400;
    letter-spacing: 0.02em;
    margin-bottom: 2rem;
    color: #f4ecd8;
    text-shadow: 0 0 30px rgba(180, 200, 255, 0.25);
}

.letter-body {
    font-size: clamp(1.05rem, 2.2vw, 1.2rem);
    line-height: 1.85;
    color: rgba(244, 236, 216, 0.92);
    margin-bottom: 2rem;
    white-space: pre-line;
}

.letter-body p {
    margin-bottom: 1.2rem;
}

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

.letter-signoff {
    font-style: italic;
    color: rgba(244, 236, 216, 0.75);
    margin-bottom: 0.4rem;
    font-size: 1.1rem;
}

.letter-name {
    font-family: 'Italiana', serif;
    font-size: 1.4rem;
    letter-spacing: 0.1em;
    color: #f4ecd8;
}

.hud {
    position: absolute;
    top: 2rem;
    left: 2rem;
    pointer-events: none;
    opacity: 0;
    animation: fade-in 1.6s ease 2.5s forwards;
    text-align: left;
}

.hud-label {
    font-family: 'Italiana', serif;
    font-size: 0.75rem;
    letter-spacing: 0.3em;
    color: rgba(244, 236, 216, 0.5);
    text-transform: uppercase;
    margin-bottom: 0.3rem;
}

.hud-value {
    font-family: 'Italiana', serif;
    font-size: 1.5rem;
    letter-spacing: 0.1em;
    color: rgba(244, 236, 216, 0.9);
    text-shadow: 0 0 20px rgba(180, 200, 255, 0.3);
    min-width: 6rem;
}

.compass {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 60px;
    height: 60px;
    margin-left: -30px;
    margin-top: -30px;
    color: rgba(255, 217, 236, 0.85);
    filter: drop-shadow(0 0 12px rgba(255, 180, 230, 0.6));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.6s ease;
    transform-origin: center;
}

.compass.visible {
    opacity: 0.85;
}

.compass svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
    animation: compass-pulse 2s ease-in-out infinite;
}

@keyframes compass-pulse {
    0%, 100% {
        opacity: 0.7;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.08);
    }
}

.planet-message {
    position: absolute;
    top: 38%;
    left: 50%;
    transform: translate(-50%, -50%) translateY(8px);
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1.4s ease, transform 1.4s cubic-bezier(0.16, 1, 0.3, 1);
    max-width: 32rem;
    padding: 0 1.5rem;
}

.planet-message.visible {
    opacity: 1;
    transform: translate(-50%, -50%) translateY(0);
}

.planet-message .planet-name {
    font-family: 'Italiana', serif;
    font-size: 0.85rem;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    color: rgba(244, 236, 216, 0.55);
    margin-bottom: 0.6rem;
}

.planet-message .planet-text {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: clamp(1.1rem, 2.4vw, 1.5rem);
    line-height: 1.5;
    color: rgba(244, 236, 216, 0.92);
    text-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
}

.surface-hint {
    position: absolute;
    bottom: 3rem;
    left: 0;
    right: 0;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1.6s ease;
}

.surface-hint.visible {
    opacity: 0.6;
}

body.on-surface .ui-top,
body.on-surface .ui-hint,
body.on-surface .hud,
body.on-surface .compass,
body.on-surface .planet-message,
body.on-surface .arrival-hint {
    display: none !important;
}

.sky-letter {
    position: absolute;
    top: 8%;
    left: 4%;
    width: min(48vw, 34rem);
    max-height: 75vh;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    text-align: left;
    overflow: hidden;
}

@media (max-width: 768px) {
    .sky-letter {
        top: 6%;
        left: 5%;
        width: 90vw;
    }
}

.sky-line {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: clamp(1.05rem, 2.2vw, 1.45rem);
    line-height: 1.55;
    color: rgba(255, 247, 224, 0.95);
    text-shadow:
        0 0 12px rgba(255, 230, 180, 0.55),
        0 0 30px rgba(0, 0, 0, 0.85),
        0 2px 14px rgba(0, 0, 0, 0.9);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 2.2s ease, transform 2.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.sky-line.visible {
    opacity: 1;
    transform: translateY(0);
}

.surface-signoff {
    position: absolute;
    bottom: 8.5rem;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Italiana', serif;
    font-size: 1.1rem;
    letter-spacing: 0.25em;
    color: rgba(255, 247, 224, 0.7);
    text-shadow: 0 0 14px rgba(0, 0, 0, 0.9);
    pointer-events: none;
    opacity: 0;
    transition: opacity 2s ease;
}

body.on-surface .surface-signoff {
    opacity: 0;
    animation: signoff-rise 3s ease 1s forwards;
    animation-play-state: paused;
}

body.on-surface.signoff-ready .surface-signoff {
    animation-play-state: running;
}

@keyframes signoff-rise {
    to { opacity: 0.85; }
}

.surface-close {
    position: absolute;
    bottom: 2.5rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.6rem 2.2rem;
    background: transparent;
    border: 1px solid rgba(244, 236, 216, 0.35);
    border-radius: 999px;
    color: #f4ecd8;
    font-family: 'Italiana', serif;
    font-size: 0.85rem;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    cursor: pointer;
    pointer-events: auto;
    opacity: 0;
    transition: opacity 1.4s ease, background 0.3s ease, border-color 0.3s ease;
    backdrop-filter: blur(6px);
}

.surface-close.visible {
    opacity: 0.7;
}

.surface-close:hover {
    background: rgba(244, 236, 216, 0.1);
    border-color: rgba(244, 236, 216, 0.8);
    opacity: 1;
}

.portal-veil {
    position: fixed;
    inset: 0;
    background: #000;
    opacity: 0;
    pointer-events: none;
    z-index: 200;
    transition: opacity 1.6s ease;
}

.portal-veil.fading-in {
    opacity: 1;
}

.portal-veil.fading-out {
    opacity: 0;
    transition: opacity 2.2s ease;
}

.arrival-hint {
    position: absolute;
    bottom: 6rem;
    left: 0;
    right: 0;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1.4s ease;
}

.arrival-hint.visible {
    opacity: 1;
}

.arrival-hint .hint-text--click {
    font-family: 'Italiana', serif;
    font-size: 1.2rem;
    color: rgba(255, 217, 236, 0.95);
    letter-spacing: 0.2em;
    text-shadow: 0 0 20px rgba(255, 180, 230, 0.5);
    animation: hint-click 2.6s ease-in-out infinite;
}

#journey-hint.faded {
    opacity: 0;
    transition: opacity 1.4s ease;
}

@media (max-width: 600px) {
    .ui-top {
        top: 1.2rem;
    }
    .ui-hint {
        bottom: 1.5rem;
    }
    .music-toggle {
        top: 1rem;
        right: 1rem;
        width: 40px;
        height: 40px;
    }
    .letter-card {
        max-height: 90vh;
    }
    .hud {
        top: 1rem;
        left: 1rem;
    }
    .hud-value {
        font-size: 1.2rem;
    }
    .arrival-hint {
        bottom: 4.5rem;
    }
}

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