/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #080e09;
    --surface: rgba(255,255,255,0.04);
    --surface2: rgba(255,255,255,0.07);
    --surface3: rgba(255,255,255,0.10);
    --border: rgba(255,255,255,0.08);
    --text: #eaf2e8;
    --text-dim: rgba(255,255,255,0.45);
    --text-mid: rgba(255,255,255,0.65);
    --accent: #4ade80;
    --accent-dim: rgba(74, 222, 128, 0.15);
    --accent-glow: rgba(74, 222, 128, 0.12);
    --ring: 565.48;
}

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Screens ── */
.screen {
    position: fixed;
    inset: 0;
    display: none;
    flex-direction: column;
}
.screen.active { display: flex; }

/* ── SCREEN 1: Picker ── */
.pick-header {
    text-align: center;
    padding: 20px 16px 14px;
    background: linear-gradient(to bottom, rgba(8,14,9,0.95), rgba(8,14,9,0.8));
    backdrop-filter: blur(12px);
    z-index: 1000;
    border-bottom: 1px solid var(--border);
}
.logo {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent), #a7f3d0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.subtitle {
    color: var(--text-dim);
    margin-top: 4px;
    font-size: 14px;
    font-weight: 400;
}

#map { flex: 1; z-index: 1; }

.pick-footer {
    background: linear-gradient(to top, rgba(8,14,9,0.95), rgba(8,14,9,0.8));
    backdrop-filter: blur(12px);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    z-index: 1000;
    border-top: 1px solid var(--border);
}
.selected-location {
    flex: 1;
    font-size: 14px;
    color: var(--text-dim);
}
.selected-location.has-location {
    color: var(--text);
    font-weight: 500;
}

.btn-primary {
    background: var(--accent);
    color: #0a1a0e;
    border: none;
    border-radius: 10px;
    padding: 11px 22px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn-primary:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-primary:not(:disabled):hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:not(:disabled):active { transform: scale(0.97); }

/* ── SCREEN 2: Loading ── */
#screen-loading {
    align-items: center;
    justify-content: center;
    background: var(--bg);
}
.loading-content {
    text-align: center;
    padding: 24px;
    max-width: 500px;
}
.loading-content h2 {
    font-size: 18px;
    font-weight: 500;
    margin: 20px 0 6px;
}
.loading-content p {
    color: var(--text-dim);
    font-size: 13px;
}
.spinner {
    width: 40px;
    height: 40px;
    border: 2px solid var(--surface2);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.bird-list {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
}
.bird-tag {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 12px;
    color: var(--text-mid);
    animation: fadeIn 0.3s ease-out;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── SCREEN 3: Player ── */
#screen-player {
    align-items: center;
    background: var(--bg);
    overflow-y: auto;
}
.player-bg {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 50% 0%, rgba(74,222,128,0.06), transparent 60%),
        radial-gradient(ellipse at 80% 100%, rgba(74,222,128,0.03), transparent 50%);
    pointer-events: none;
}
.player-content {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    padding: 20px 20px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.player-header {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}
.btn-back {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-mid);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}
.btn-back:hover { background: var(--surface3); color: var(--text); }

.player-title h2 { font-size: 16px; font-weight: 600; }
.player-title p { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* Scene Visualization */
.scene-container {
    position: relative;
    width: 100%;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border);
    aspect-ratio: 16 / 10;
}
#scene-canvas {
    width: 100%;
    height: 100%;
    display: block;
}
.scene-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    pointer-events: none;
}
.scene-overlay .btn-play { pointer-events: auto; }
.timer-text {
    font-size: 28px;
    font-weight: 300;
    font-variant-numeric: tabular-nums;
    color: rgba(255,255,255,0.85);
    letter-spacing: 1px;
    text-shadow: 0 1px 8px rgba(0,0,0,0.5);
}
.scene-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: var(--accent);
    transition: width 1s linear;
    width: 0%;
    box-shadow: 0 0 8px var(--accent-dim);
}

/* Play Button — inside ring */
.btn-play {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    box-shadow: 0 0 20px var(--accent-dim);
}
.btn-play:hover { transform: scale(1.08); box-shadow: 0 0 28px var(--accent-dim); }
.btn-play:active { transform: scale(0.94); }
.btn-play svg { width: 22px; height: 22px; fill: #0a1a0e; }
.hidden { display: none; }

/* Controls Section */
.controls-section {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
}
.control-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.control-row input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 3px;
    background: var(--surface3);
    border-radius: 2px;
    outline: none;
}
.control-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 8px var(--accent-dim);
}

/* ── Narration Card ── */
.narration-card {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    transition: border-color 0.3s;
}
.narration-card.active {
    border-color: rgba(74, 222, 128, 0.25);
}
.narration-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
}
.narration-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.narration-icon {
    width: 18px;
    height: 18px;
    fill: var(--text-dim);
    flex-shrink: 0;
    transition: fill 0.3s;
}
.narration-card.active .narration-icon { fill: var(--accent); }
.narration-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-mid);
    transition: color 0.3s;
}
.narration-card.active .narration-title { color: var(--text); }

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 22px;
    flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--surface3);
    border-radius: 11px;
    cursor: pointer;
    transition: all 0.25s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    background: var(--text-dim);
    border-radius: 50%;
    transition: all 0.25s;
}
.toggle input:checked + .toggle-slider {
    background: var(--accent-dim);
}
.toggle input:checked + .toggle-slider::before {
    transform: translateX(16px);
    background: var(--accent);
}

/* Narration Body — visible when active */
.narration-body {
    display: none;
    padding: 0 16px 14px;
    flex-direction: column;
    gap: 10px;
}
.narration-card.active .narration-body { display: flex; }

.narration-now-reading {
    font-size: 13px;
    color: var(--accent);
    font-weight: 500;
    min-height: 18px;
}
.narration-now-reading:empty { display: none; }

.narration-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}
.btn-skip {
    display: flex;
    align-items: center;
    gap: 5px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    color: var(--text-mid);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn-skip:hover { background: var(--surface3); color: var(--text); }

.narration-vol {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}
.narration-vol-label {
    font-size: 11px;
    color: var(--text-dim);
    white-space: nowrap;
}
.narration-vol input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 3px;
    background: var(--surface3);
    border-radius: 2px;
    outline: none;
}
.narration-vol input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

/* ── Now Playing ── */
.now-playing {
    width: 100%;
}
.now-playing h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-dim);
    margin-bottom: 10px;
    font-weight: 500;
}
.bird-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 36px;
}
.bird-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 7px 14px 7px 10px;
    animation: pillIn 0.5s ease-out;
    transition: opacity 0.4s, transform 0.4s;
}
@keyframes pillIn {
    from { opacity: 0; transform: scale(0.85); }
    to { opacity: 1; transform: scale(1); }
}
.bird-pill-out {
    opacity: 0;
    transform: scale(0.8);
    width: 0;
    padding: 0;
    gap: 0;
    border-width: 0;
    margin: 0;
    overflow: hidden;
    transition: all 0.4s ease-in;
}
.bird-pill-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}
.bird-pill-icon svg {
    width: 18px;
    height: 18px;
}
.bird-pill-dot {
    position: relative;
    width: 8px;
    height: 8px;
    flex-shrink: 0;
    margin: 0 5px;
}
.bird-pill-dot::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--accent);
}
.bird-pill-dot-ring {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 1.5px solid var(--accent);
    animation: dotRingPulse 2s ease-out infinite;
}
@keyframes dotRingPulse {
    0% { transform: scale(0.6); opacity: 0.6; }
    100% { transform: scale(1.6); opacity: 0; }
}
.bird-pill-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-mid);
    white-space: nowrap;
}

/* Leaflet overrides */
.leaflet-container { background: #070e12; }
.leaflet-control-attribution { font-size: 10px !important; background: rgba(0,0,0,0.6) !important; color: #666 !important; }
.leaflet-control-attribution a { color: #888 !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 2px; }
