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

:root {
    --deep-navy: #1a1a2e;
    --warm-sand: #d4a574;
    --gold: #C9A45C;
    --gold-bright: #e8c56d;
    --parchment: #f4e4c1;
    --parchment-dark: #d9c9a3;
    --dark-bg: rgba(15, 12, 25, 0.85);
    --dark-bg-solid: #0f0c19;
}

html, body {
    overflow: hidden;
    width: 100%;
    height: 100%;
    background: #0a0816;
    font-family: 'Crimson Pro', serif;
    color: var(--parchment);
    -webkit-font-smoothing: antialiased;
    touch-action: none;
}

#scene-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

#scene-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* HEADER */
#header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    padding: 20px 28px 18px;
    background: linear-gradient(180deg, rgba(10, 8, 20, 0.92) 0%, rgba(10, 8, 20, 0.5) 60%, transparent 100%);
    pointer-events: none;
}

#header h1 {
    font-family: 'Cinzel', serif;
    font-weight: 900;
    font-size: 2.2rem;
    letter-spacing: 0.12em;
    color: var(--gold);
    text-shadow: 0 2px 20px rgba(201, 164, 92, 0.4), 0 0 60px rgba(201, 164, 92, 0.15);
    line-height: 1;
}

#header .subtitle {
    font-family: 'Crimson Pro', serif;
    font-weight: 300;
    font-style: italic;
    font-size: 1rem;
    color: var(--parchment-dark);
    letter-spacing: 0.08em;
    margin-top: 4px;
    opacity: 0.8;
}

/* CITY INFO PANEL */
#city-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 370px;
    height: 100%;
    z-index: 20;
    background: linear-gradient(135deg, rgba(30, 24, 16, 0.96) 0%, rgba(20, 16, 10, 0.98) 100%);
    backdrop-filter: blur(20px);
    border-left: 1px solid rgba(201, 164, 92, 0.2);
    transform: translateX(100%);
    transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
    overflow-y: auto;
    padding: 70px 26px 40px;
}

#city-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
    pointer-events: none;
}

#city-panel.visible {
    transform: translateX(0);
}

#city-panel.hidden {
    transform: translateX(100%);
}

.panel-drag-handle {
    display: none;
}

#panel-close {
    position: absolute;
    top: 18px;
    right: 18px;
    width: 40px;
    height: 40px;
    background: rgba(201, 164, 92, 0.1);
    border: 1px solid rgba(201, 164, 92, 0.3);
    color: var(--gold);
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    z-index: 2;
    -webkit-tap-highlight-color: transparent;
}

#panel-close:hover {
    background: rgba(201, 164, 92, 0.25);
    transform: rotate(90deg);
}

#panel-content {
    position: relative;
    z-index: 1;
}

#city-name {
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 1.7rem;
    color: var(--gold);
    margin-bottom: 4px;
    line-height: 1.2;
}

.city-country {
    font-size: 0.95rem;
    color: var(--warm-sand);
    opacity: 0.7;
    margin-bottom: 18px;
    font-style: italic;
}

.goods-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 22px;
}

.good-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    background: rgba(201, 164, 92, 0.1);
    border: 1px solid rgba(201, 164, 92, 0.2);
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--parchment-dark);
}

.city-desc {
    font-size: 1.05rem;
    line-height: 1.7;
    color: var(--parchment);
    opacity: 0.85;
}

/* LEGEND */
#legend-panel {
    position: fixed;
    bottom: 120px;
    left: 16px;
    z-index: 10;
    background: var(--dark-bg);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(201, 164, 92, 0.15);
    border-radius: 10px;
    overflow: hidden;
    min-width: 150px;
}

.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    cursor: pointer;
    font-family: 'Cinzel', serif;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    color: var(--gold);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#legend-arrow {
    transition: transform 0.3s;
    font-size: 0.8rem;
}

#legend-content {
    padding: 0 14px 10px;
    transition: all 0.3s;
}

#legend-content.collapsed {
    display: none;
}

.legend-item {
    font-size: 0.82rem;
    padding: 3px 0;
    color: var(--parchment-dark);
    opacity: 0.8;
}

.legend-icon {
    margin-right: 6px;
}

/* CONTROLS BAR */
#controls-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    background: linear-gradient(0deg, rgba(10, 8, 20, 0.95) 0%, rgba(10, 8, 20, 0.75) 70%, transparent 100%);
    padding: 20px 20px 16px;
}

.controls-inner {
    max-width: 700px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.controls-row-top {
    display: flex;
    align-items: center;
    gap: 14px;
}

.controls-row-bottom {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.timeline-section {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.era-label {
    font-family: 'Cinzel', serif;
    font-size: 0.6rem;
    letter-spacing: 0.05em;
    color: var(--warm-sand);
    opacity: 0.6;
    white-space: nowrap;
    flex-shrink: 0;
}

.era-display {
    font-family: 'Cinzel', serif;
    font-size: 0.8rem;
    color: var(--gold);
    white-space: nowrap;
    min-width: 75px;
    text-align: center;
    flex-shrink: 0;
}

input[type="range"] {
    flex: 1;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: rgba(201, 164, 92, 0.2);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--gold);
    box-shadow: 0 0 10px rgba(201, 164, 92, 0.5);
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--gold);
    box-shadow: 0 0 10px rgba(201, 164, 92, 0.5);
    cursor: pointer;
    border: none;
}

.ctrl-btn {
    padding: 8px 18px;
    background: rgba(201, 164, 92, 0.1);
    border: 1px solid rgba(201, 164, 92, 0.25);
    color: var(--gold);
    font-family: 'Cinzel', serif;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    min-height: 38px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ctrl-btn:hover {
    background: rgba(201, 164, 92, 0.2);
    border-color: rgba(201, 164, 92, 0.45);
}

.ctrl-btn.active {
    background: rgba(201, 164, 92, 0.25);
    border-color: var(--gold);
}

/* TOOLTIP */
#tooltip {
    position: fixed;
    z-index: 30;
    padding: 6px 14px;
    background: var(--dark-bg);
    border: 1px solid rgba(201, 164, 92, 0.3);
    border-radius: 6px;
    font-family: 'Cinzel', serif;
    font-size: 0.8rem;
    color: var(--gold);
    pointer-events: none;
    white-space: nowrap;
    transition: opacity 0.2s;
}

#tooltip.hidden {
    opacity: 0;
}

/* FOOTER */
#footer {
    position: fixed;
    bottom: 100px;
    right: 16px;
    z-index: 10;
    font-size: 0.7rem;
    display: flex;
    gap: 14px;
    align-items: center;
    color: var(--warm-sand);
    opacity: 0.45;
}

#footer a {
    color: var(--gold);
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.3s;
}

#footer a:hover {
    opacity: 1;
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
    #header h1 {
        font-size: 1.4rem;
        letter-spacing: 0.08em;
    }

    #header .subtitle {
        font-size: 0.78rem;
    }

    #header {
        padding: 14px 16px 12px;
    }

    /* City panel becomes bottom sheet */
    #city-panel {
        width: 100%;
        height: auto;
        max-height: 55vh;
        top: auto;
        bottom: 0;
        border-left: none;
        border-top: 1px solid rgba(201, 164, 92, 0.25);
        border-radius: 16px 16px 0 0;
        padding: 12px 18px 30px;
        transform: translateY(100%);
    }

    #city-panel.visible {
        transform: translateY(0);
    }

    #city-panel.hidden {
        transform: translateY(100%);
    }

    .panel-drag-handle {
        display: block;
        width: 36px;
        height: 4px;
        background: rgba(201, 164, 92, 0.3);
        border-radius: 2px;
        margin: 0 auto 12px;
    }

    #panel-close {
        top: 10px;
        right: 14px;
        width: 36px;
        height: 36px;
    }

    #city-name {
        font-size: 1.3rem;
    }

    .city-desc {
        font-size: 0.95rem;
        line-height: 1.6;
    }

    .good-tag {
        padding: 5px 10px;
        font-size: 0.8rem;
    }

    /* Legend panel */
    #legend-panel {
        bottom: auto;
        top: 72px;
        left: 10px;
        min-width: 130px;
    }

    .legend-header {
        padding: 8px 12px;
        font-size: 0.68rem;
    }

    #legend-content {
        padding: 0 12px 8px;
    }

    .legend-item {
        font-size: 0.76rem;
    }

    /* Controls bar */
    #controls-bar {
        padding: 14px 12px 12px;
    }

    .controls-row-top {
        gap: 8px;
    }

    .era-label {
        font-size: 0.55rem;
    }

    .era-display {
        font-size: 0.68rem;
        min-width: 60px;
    }

    .ctrl-btn {
        padding: 7px 14px;
        font-size: 0.65rem;
        min-height: 36px;
    }

    /* Footer */
    #footer {
        display: none;
    }

    /* Tooltip - hide on mobile (use panel instead) */
    #tooltip {
        display: none;
    }
}

@media (max-width: 380px) {
    #header h1 {
        font-size: 1.2rem;
    }

    .era-label {
        display: none;
    }

    .timeline-section {
        gap: 4px;
    }
}