:root {
    /* === PALETTE: DARK LUXURY === */
    --color-bg-deep: #050505;       /* Almost black */
    --color-bg-start: #0f172a;      /* Deep Slate */
    --color-bg-end: #020617;        /* Darker Slate */

    --color-text-primary: #f8fafc;  /* White-ish */
    --color-text-secondary: #94a3b8;/* Muted Slate */
    --color-text-muted: #64748b;    /* Darker Muted */

    --color-accent: #c0a062;        /* Classic Gold */
    --color-accent-hover: #eecf85;  /* Lighter Gold */
    --color-accent-glow: rgba(192, 160, 98, 0.3);

    --color-glass: rgba(15, 23, 42, 0.6);
    --color-glass-border: rgba(255, 255, 255, 0.08);
    --color-surface: #1e293b;

    /* === TYPOGRAPHY === */
    --font-heading: 'Playfair Display', serif;
    --font-body: 'Poppins', sans-serif;

    --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
    --ease-elastic: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden; /* Main container manages overflow */
}

body {
    font-family: var(--font-body);
    background-color: var(--color-bg-deep);
    color: var(--color-text-primary);
    cursor: default;
}

/* === NOISE TEXTURE === */
.noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9998; /* Below loader, above content */
    opacity: 0.07;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

/* === CUSTOM CURSOR (Desktop Only) === */
@media (min-width: 901px) {
    body {
        cursor: none;
    }

    a, button, .site-node, .leaflet-interactive {
        cursor: none; /* Hide default cursor on interactive elements too */
    }

    #custom-cursor {
        position: fixed;
        top: 0;
        left: 0;
        width: 20px;
        height: 20px;
        border: 1px solid var(--color-accent);
        border-radius: 50%;
        pointer-events: none;
        z-index: 10000;
        transform: translate(-50%, -50%);
        transition: width 0.3s, height 0.3s, background-color 0.3s;
        mix-blend-mode: difference;
    }

    #custom-cursor.hovered {
        width: 50px;
        height: 50px;
        background-color: rgba(192, 160, 98, 0.2);
        border-color: transparent;
    }
}

/* === LOADER === */
#loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-bg-deep);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.8s ease;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 1s var(--ease-out-quart) infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

body.loaded #loader {
    opacity: 0;
    pointer-events: none;
}

/* === BACKGROUND === */
.background-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: radial-gradient(circle at center, var(--color-bg-start), var(--color-bg-deep));
}

.geometric-pattern {
    /* More subtle, abstract pattern */
    position: absolute;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        radial-gradient(rgba(255, 255, 255, 0.02) 2px, transparent 2px);
    background-size: 40px 40px, 100px 100px;
    background-position: 0 0, 20px 20px;
    opacity: 0.5;
}

/* === APP STRUCTURE === */
#app-container {
    width: 100%;
    height: 100%;
    position: relative;
    /* overflow: hidden; Removed to allow better mobile handling */
}

/* Sections */
#orrery-view, #detail-view {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    transition: all 0.8s var(--ease-out-quart);
}

/* === ORRERY (DESKTOP) === */
/* Hide mobile view on desktop */
#mobile-cards-view {
    display: none;
}

#orrery-view {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.main-header {
    text-align: center;
    position: absolute;
    top: 10%;
    width: 100%;
    z-index: 20;
    pointer-events: none;
}

.main-header h1 {
    font-family: var(--font-heading);
    font-size: clamp(3rem, 5vw, 6rem);
    font-weight: 400;
    letter-spacing: -0.02em;
    background: linear-gradient(to bottom, #fff 20%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.2em;
    text-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.main-header p {
    font-size: 0.85rem;
    letter-spacing: 0.5em;
    text-transform: uppercase;
    color: var(--color-accent);
    opacity: 0.8;
}

#heritage-orrery {
    position: relative;
    width: 60vh;
    height: 60vh;
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1000px; /* Slight 3D feel */
}

/* The Sun/Core */
.orrery-core {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #000;
    border: 1px solid var(--color-accent);
    box-shadow: 0 0 30px var(--color-accent-glow);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
}

.orrery-core::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200%;
    height: 200%;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, var(--color-accent-glow) 0%, transparent 70%);
    opacity: 0.5;
}

/* Rings */
.orbit-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 1px solid rgba(255, 255, 255, 0.03);
    border-radius: 50%;
    pointer-events: none;
}

/* Nodes */
.site-node {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 12px;
    margin: -6px;
    background: #fff;
    border-radius: 50%;
    border: none;
    z-index: 30;
    transition: transform 0.4s var(--ease-elastic);
    box-shadow: 0 0 10px rgba(255,255,255,0.5);
}

.site-node:hover {
    transform: scale(2);
    background: var(--color-accent);
    box-shadow: 0 0 20px var(--color-accent);
}

.node-label {
    position: absolute;
    left: 50%;
    top: -40px;
    transform: translateX(-50%) translateY(10px);
    background: rgba(0,0,0,0.8);
    color: var(--color-accent);
    border: 1px solid var(--color-glass-border);
    padding: 8px 16px;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    white-space: nowrap;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    backdrop-filter: blur(4px);
}

.site-node:hover .node-label {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* === MAP INTEGRATION === */
#map-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40vh; /* Taller map */
    z-index: 5;
    mask-image: linear-gradient(to bottom, transparent 0%, black 40%);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 40%);
    opacity: 0.6;
    transition: opacity 0.5s ease;
}

#map-container:hover {
    opacity: 1;
}

#map {
    width: 100%;
    height: 100%;
    background: transparent;
}

/* Map Tooltip Polish */
.custom-map-tooltip {
    background: var(--color-bg-deep);
    border: 1px solid var(--color-accent);
    color: var(--color-text-primary);
    font-family: var(--font-heading);
    padding: 5px 10px;
}
.leaflet-tooltip-top:before { border-top-color: var(--color-accent); }

/* === DETAIL VIEW (DESKTOP) === */
#detail-view {
    z-index: 50;
    background: var(--color-bg-deep);
    opacity: 0;
    visibility: hidden;
    transform: scale(1.05);
}

body.detail-active #detail-view {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

.back-button {
    position: fixed;
    top: 30px;
    right: 30px; /* Moved to right for editorial feel */
    width: 60px;
    height: 60px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    background: rgba(0,0,0,0.2);
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.back-button:hover {
    border-color: var(--color-accent);
    transform: rotate(90deg);
}

.detail-content {
    display: grid;
    grid-template-columns: 45% 55%;
    height: 100vh;
}

.detail-image-container {
    height: 100%;
    position: relative;
    overflow: hidden;
}

.detail-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: brightness(0.8);
}

.detail-text {
    padding: 80px 100px;
    overflow-y: auto;
    /* Hide scrollbar but allow scroll */
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.detail-text::-webkit-scrollbar { display: none; }

#detail-title {
    font-family: var(--font-heading);
    font-size: 5rem;
    line-height: 1;
    margin-bottom: 2rem;
    color: var(--color-accent);
    opacity: 0; /* Animated in JS */
    transform: translateY(20px);
    transition: all 0.8s 0.2s var(--ease-out-quart);
}

.detail-meta {
    display: flex;
    gap: 30px;
    margin-bottom: 4rem;
    font-size: 0.8rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 20px;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.8s 0.3s var(--ease-out-quart);
}

#detail-description, #detail-significance, .user-contributions {
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.8s 0.4s var(--ease-out-quart);
}

body.detail-active #detail-title,
body.detail-active .detail-meta,
body.detail-active #detail-description,
body.detail-active #detail-significance,
body.detail-active .user-contributions {
    opacity: 1;
    transform: translateY(0);
}

#detail-description {
    font-size: 1.2rem;
    line-height: 1.8;
    color: var(--color-text-secondary);
    margin-bottom: 3rem;
    max-width: 800px;
}

#detail-significance {
    font-family: var(--font-heading);
    font-style: italic;
    font-size: 1.8rem;
    color: var(--color-text-primary);
    margin-bottom: 4rem;
    padding-left: 2rem;
    border-left: 2px solid var(--color-accent);
}

#detail-link {
    display: inline-block;
    margin-bottom: 5rem;
    color: var(--color-accent);
    text-decoration: none;
    border-bottom: 1px solid var(--color-accent);
    padding-bottom: 5px;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    transition: color 0.3s;
}

#detail-link:hover {
    color: #fff;
    border-color: #fff;
}

/* === USER CONTRIBUTIONS & FORM (POLISHED) === */
.user-contributions h3 {
    font-family: var(--font-heading);
    font-size: 2rem;
    margin-bottom: 2rem;
    color: var(--color-text-primary);
}

#contributions-container .story {
    background: rgba(255, 255, 255, 0.02);
    padding: 20px;
    margin-bottom: 20px;
    border-left: 2px solid rgba(255, 255, 255, 0.1);
}

#contributions-container .story h4 {
    color: var(--color-accent);
    margin-bottom: 5px;
    font-family: var(--font-heading);
}

#contributions-container .story p {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--color-text-secondary);
}

#contribution-form {
    margin-top: 3rem;
    padding: 2.5rem;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.01) 0%, rgba(255, 255, 255, 0.03) 100%);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    backdrop-filter: blur(5px);
}

#contribution-form h4 {
    font-family: var(--font-heading);
    color: var(--color-accent);
    margin-bottom: 1.5rem;
    font-size: 1.4rem;
    letter-spacing: 0.02em;
}

/* Form Elements - World Class Polish */
input[type="text"],
input[type="url"],
textarea {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--color-glass-border);
    padding: 16px 20px;
    margin-bottom: 20px;
    color: var(--color-text-primary);
    font-family: var(--font-body);
    font-size: 0.95rem;
    transition: all 0.3s ease;
    border-radius: 2px;
}

input[type="text"]::placeholder,
input[type="url"]::placeholder,
textarea::placeholder {
    color: var(--color-text-muted);
    opacity: 0.7;
}

input[type="text"]:focus,
input[type="url"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    background: rgba(0, 0, 0, 0.5);
    box-shadow: 0 0 20px rgba(192, 160, 98, 0.1);
}

textarea {
    min-height: 120px;
    resize: vertical;
}

button[type="submit"] {
    background: transparent;
    border: 1px solid var(--color-accent);
    color: var(--color-accent);
    padding: 14px 40px;
    font-family: var(--font-heading);
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    cursor: pointer;
    transition: all 0.4s var(--ease-out-quart);
    margin-top: 10px;
    position: relative;
    overflow: hidden;
}

button[type="submit"]:hover {
    background: var(--color-accent);
    color: #000;
    box-shadow: 0 0 30px var(--color-accent-glow);
    transform: translateY(-2px);
}

/* === MOBILE HYPER-OPTIMIZATION === */
@media (max-width: 900px) {
    /* Hide desktop cursor elements */
    #custom-cursor { display: none; }
    body { cursor: auto; }

    /* Hide Orrery, Show Mobile Cards */
    #heritage-orrery {
        display: none;
    }

    /* Mobile Header */
    .main-header {
        position: relative;
        top: 0;
        margin-top: 15vh;
        margin-bottom: 5vh;
        text-align: left;
        padding: 0 30px;
    }

    .main-header h1 {
        font-size: 3rem;
    }

    .main-header p {
        letter-spacing: 0.2em;
    }

    /* Mobile Cards Container */
    #mobile-cards-view {
        display: flex; /* We'll create this element in JS */
        flex-direction: column; /* Vertical stack is often cleaner than horizontal on mobile if content is heavy, but prompt says "Card Stack" */
        gap: 20px;
        padding: 0 20px 100px 20px;
        overflow-y: auto;
        height: 60vh; /* Remaining height */
    }

    /* We will use a Horizontal Snap Scroll for "World Class" feel */
    #mobile-cards-view {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        height: 55vh;
        padding: 0 30px;
        gap: 20px;
        align-items: center;
        /* Hide scrollbar */
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
    #mobile-cards-view::-webkit-scrollbar { display: none; }

    .mobile-card {
        flex: 0 0 85%; /* Shows a bit of next card */
        height: 100%;
        scroll-snap-align: center;
        border-radius: 20px;
        overflow: hidden;
        position: relative;
        background-size: cover;
        background-position: center;
        box-shadow: 0 10px 30px rgba(0,0,0,0.5);
        border: 1px solid rgba(255,255,255,0.1);
        transition: transform 0.3s;
    }

    /* Interaction Hint */
    .mobile-card:active {
        transform: scale(0.98);
    }

    .mobile-card-content {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        padding: 30px;
        background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
    }

    .mobile-card h3 {
        font-family: var(--font-heading);
        font-size: 2rem;
        color: #fff;
        margin-bottom: 5px;
    }

    .mobile-card span {
        color: var(--color-accent);
        text-transform: uppercase;
        font-size: 0.8rem;
        letter-spacing: 0.1em;
    }

    /* Mobile Map */
    #map-container {
        display: none; /* Map is too heavy for this specific "Card" view, or strictly desktop */
    }

    /* Mobile Detail View (Bottom Sheet style) */
    .detail-content {
        display: block;
        padding: 0;
        height: auto;
        min-height: 100vh;
    }

    .detail-image-container {
        height: 40vh;
        position: relative;
    }

    .detail-text {
        padding: 40px 25px 100px 25px;
        background: var(--color-bg-deep);
        border-radius: 30px 30px 0 0;
        position: relative;
        top: -30px; /* Overlap */
        box-shadow: 0 -10px 30px rgba(0,0,0,0.5);
    }

    #detail-title {
        font-size: 2.5rem;
    }

    .back-button {
        top: 20px;
        left: 20px;
        right: auto;
        background: rgba(0,0,0,0.5);
    }

    /* Form Adjustment for Mobile */
    #contribution-form {
        padding: 1.5rem;
    }

    button[type="submit"] {
        width: 100%;
    }
}
