/* ===== BASE RESET & VARIABLES ===== */
:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2a2a2a;
    --bg-tertiary: #333333;
    --border: #444444;
    --text-primary: #e8e8e8;
    --text-secondary: #999999;
    --primary: #4CAF50;
    --accent: #4CAF50;
    --accent-dark: #388E3C;
    --theme: #1a472a;
    --surface: #1e1e1e;
    --surface-hover: #2a2a2a;
    --danger: #ef5350;
    --warning: #FFA726;
    --confidence-high: #4CAF50;
    --confidence-medium: #FFA726;
    --confidence-low: #ef5350;
    --st-common: #27ae60;
    --st-uncommon: #f1c40f;
    --st-rare: #e67e22;
    --st-absent: #e74c3c;
    --chip-region: #2980b9;
    --chip-family: #8e44ad;
    --chip-nearme: #27ae60;
    --chip-sensitive: #c0392b;
    --nav-height: 52px;
    --header-height: 56px;
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
    --safe-left: env(safe-area-inset-left);
    --safe-right: env(safe-area-inset-right);
}

[data-theme="light"] {
    --bg-primary: #f0eeea;
    --bg-secondary: #e7e5e0;
    --bg-tertiary: #dbd9d3;
    --border: #c5c3bd;
    --text-primary: #1a1a1a;
    --text-secondary: #555555;
    --primary: #2e7d32;
    --accent: #2e7d32;
    --accent-dark: #1b5e20;
    --theme: #e8f5e9;
    --surface: #e2e0db;
    --surface-hover: #d8d6d0;
    --danger: #d32f2f;
    --warning: #f57c00;
    --confidence-high: #2e7d32;
    --confidence-medium: #e65100;
    --confidence-low: #c62828;
    --st-common: #1b7a3d;
    --st-uncommon: #c8a600;
    --st-rare: #bf5600;
    --st-absent: #c62828;
    --chip-region: #1565c0;
    --chip-family: #6a1b9a;
    --chip-nearme: #1b7a3d;
    --chip-sensitive: #b23028;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-primary);
}

/* ===== APP SHELL ===== */
#app {
    height: 100vh; /* fallback */
    height: 100svh;
    padding-top: var(--safe-top);
    padding-bottom: calc(var(--nav-height) + 10px);
    position: relative;
    overflow: hidden;
}

/* ===== SCREENS ===== */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding-top: var(--safe-top);
    padding-bottom: calc(var(--nav-height) + 10px);
    display: none;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
}

.screen.active {
    display: flex;
    transform: translateX(0);
    opacity: 1;
}

.screen.slide-out-left {
    transform: translateX(-30%);
    opacity: 0;
}

.screen-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--bg-tertiary);
    flex-shrink: 0;
}

.screen-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
}

.screen-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

/* ===== Shared Layout Classes ===== */

/* Content layout: single centered column for non-ID pages */
.content-layout {
    padding: 16px;
}

@media (min-width: 900px) {
    .content-layout {
        padding: 24px 20%;
    }
}

/* ID layout: two-box responsive container for Photo & Sound screens */
.id-layout {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.id-input-panel {
    min-width: 0;
}

.id-context-panel {
    min-width: 0;
}

@media (min-width: 900px) {
    .id-layout {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr;
        grid-template-areas: "input context";
        gap: 16px;
        height: 100%;
    }

    .id-input-panel {
        grid-area: input;
    }

    .id-context-panel {
        grid-area: context;
        display: flex;
        flex-direction: column;
    }

    .id-context-panel .location-section {
        margin-top: 0;
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
    }

    .id-context-panel .map-container {
        flex: 1;
        min-height: 0;
    }

    .id-context-panel .map-container #map {
        height: 100%;
    }
}

/* Header page name */
.header-page {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 1rem;
}

/* ===== BOTTOM NAV ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-height) + 10px);
    padding-bottom: 10px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 1000;
}

.nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 100%;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 0.7rem;
    cursor: pointer;
    transition: color 0.2s ease;
    min-height: 48px;
}

.nav-tab.active {
    color: var(--accent);
}

.nav-tab svg {
    width: 24px;
    height: 24px;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
    touch-action: manipulation;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-dark);
}

.btn-primary:disabled {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-large {
    width: 100%;
    margin-top: 16px;
}

.btn-send {
    min-height: 48px;
    min-width: 48px;
    padding: 12px;
    border-radius: 50%;
}

/* ===== CAPTURE AREA ===== */
.capture-area {
    position: relative;
    overflow: hidden;
    border-radius: 16px;
    display: none;
}

.capture-area.showing {
    display: flex;
    min-height: 200px;
    align-items: center;
    justify-content: center;
}

.capture-placeholder {
    text-align: center;
    color: var(--text-secondary);
    padding: 32px;
}

.capture-placeholder svg {
    margin-bottom: 12px;
    opacity: 0.6;
}

.capture-placeholder p {
    font-size: 0.9rem;
}

.preview-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    max-height: 300px;
}

/* ===== CROP AREA ===== */
.crop-area {
    margin-top: 16px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-secondary);
}

.crop-image {
    width: 100%;
    max-height: 60vh;
    display: block;
}

/* Cropper.js: enlarge all corner handles (touch-friendly) */
.cropper-point.point-nw,
.cropper-point.point-ne,
.cropper-point.point-sw,
.cropper-point.point-se {
    height: 20px;
    width: 20px;
    opacity: 1;
}
.cropper-point.point-nw:before,
.cropper-point.point-ne:before,
.cropper-point.point-sw:before,
.cropper-point.point-se:before {
    background-color: #39f;
    bottom: -50%;
    content: " ";
    display: block;
    height: 200%;
    opacity: 0;
    position: absolute;
    left: -50%;
    width: 200%;
}
@media (min-width: 768px) {
    .cropper-point.point-nw,
    .cropper-point.point-ne,
    .cropper-point.point-sw,
    .cropper-point.point-se {
        height: 15px;
        width: 15px;
    }
}
@media (min-width: 992px) {
    .cropper-point.point-nw,
    .cropper-point.point-ne,
    .cropper-point.point-sw,
    .cropper-point.point-se {
        height: 10px;
        width: 10px;
    }
}
@media (min-width: 1200px) {
    .cropper-point.point-nw,
    .cropper-point.point-ne,
    .cropper-point.point-sw,
    .cropper-point.point-se {
        height: 5px;
        width: 5px;
        opacity: .75;
    }
}

.crop-actions {
    display: flex;
    gap: 12px;
    padding: 12px;
}

.crop-actions .btn {
    flex: 1;
}

/* ===== MAP ===== */
.map-container {
    margin-top: 12px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-secondary);
    position: relative;
}

.map-expand-btn {
    position: absolute;
    bottom: 8px;
    left: 8px;
    z-index: 1000;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: none;
    background: rgba(255,255,255,0.9);
    color: #333;
    font-size: 18px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

@media (max-width: 768px) {
    .map-expand-btn { display: flex; }
}

.map-container.map-fullscreen #map {
    height: 70vh;
}

.map-container.map-fullscreen .map-expand-btn {
    font-size: 16px;
}

#map {
    height: 206px;
    width: 100%;
}

.map-container.map-expanded #map {
    height: 206px;
}

.map-container.map-expanded.map-fullscreen #map {
    height: 70vh;
}

.location-text {
    padding: 4px 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* ===== MODEL TOGGLES ===== */
.model-toggles {
    margin-top: 16px;
}

.model-toggles h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.toggle-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.toggle-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-switch {
    position: relative;
    width: 40px;
    height: 22px;
    background: var(--bg-tertiary);
    border-radius: 11px;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.toggle-label input:checked + .toggle-switch {
    background: var(--accent);
}

.toggle-label input:checked + .toggle-switch::after {
    transform: translateX(18px);
}

.toggle-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 6px;
}

/* Settings page model toggles */
.model-toggles-settings {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.model-toggles-settings .setting-toggle {
    flex-direction: row;
    align-items: center;
    padding: 12px;
}

.model-toggles-settings .toggle-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.model-toggles-settings .toggle-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.model-toggles-settings .toggle-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Stepper (− value +) — scroll-proof replacement for a slider on touch pages.
   Tap-only, so a vertical swipe can never change the value. Both themes via vars. */
.stepper {
    display: flex;
    align-items: stretch;
    width: fit-content;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.stepper-btn {
    border: none;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1.4rem;
    line-height: 1;
    font-weight: 600;
    width: 48px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;   /* no double-tap-zoom delay; tap only */
}
.stepper-btn:hover:not(:disabled) {
    background: var(--bg-tertiary);
}
.stepper-btn:active:not(:disabled) {
    background: var(--primary);
    color: #fff;
}
.stepper-btn:disabled {
    opacity: 0.4;
    cursor: default;
}
.stepper-value {
    min-width: 56px;
    padding: 10px 0;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    align-self: center;
    line-height: 1.4;
}

/* ===== RESULTS CARDS ===== */
.results-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    gap: 12px;
}

.result-card-thumb {
    width: 64px;
    height: 64px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.result-card-info {
    flex: 1;
    min-width: 0;
}

.result-card-species {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 4px;
}

.result-card-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* ===== CONFIDENCE BARS ===== */
.confidence-bar {
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    overflow: hidden;
    margin-top: 4px;
}

.confidence-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease;
}

.confidence-bar-fill.high {
    background: var(--confidence-high);
}

.confidence-bar-fill.medium {
    background: var(--confidence-medium);
}

.confidence-bar-fill.low {
    background: var(--confidence-low);
}

/* ===== LOADING SPINNER ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(26, 26, 26, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    gap: 16px;
}

.loading-overlay[hidden] {
    display: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--bg-tertiary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ===== CHAT / BIRD AI ===== */
.conversation {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.4;
}

.chat-bubble.user {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-bubble.ai {
    align-self: flex-start;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.chat-input-area {
    display: flex;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--bg-tertiary);
}

.chat-input {
    flex: 1;
    min-height: 48px;
    padding: 12px 16px;
    border: 1px solid var(--bg-tertiary);
    border-radius: 24px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.chat-input:focus {
    border-color: var(--accent);
}

/* ===== SETTINGS ===== */
.settings-group {
    margin-bottom: 24px;
}

.settings-group h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.setting-item {
    margin-bottom: 12px;
}

.setting-item label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.setting-input {
    width: 100%;
    min-height: 48px;
    padding: 12px 16px;
    border: 1px solid var(--bg-tertiary);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.setting-input:focus {
    border-color: var(--accent);
}

.setting-masked {
    -webkit-text-security: disc;
    text-security: disc;
}

.server-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.server-status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
}

.server-status.connected::before {
    background: var(--accent);
}

.server-status.disconnected::before {
    background: var(--danger);
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-state p {
    margin-bottom: 4px;
}

/* ===== RESULTS SCREEN ===== */
#screen-results .screen-content > * {
    width: 100%;
}

.results-crop-section {
    text-align: center;
    margin-bottom: 16px;
}

.results-crop-image {
    width: 100%;
    max-height: 240px;
    object-fit: contain;
    border-radius: 12px;
    background: var(--bg-secondary);
}

.results-ensemble-hero {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    width: 100%;
}

.results-hero-inner {
    display: flex;
    align-items: center;
    gap: 16px;
}

.results-hero-crop {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 10px;
    flex-shrink: 0;
}

/* Reference ("stock") photo at the top of the Field Marks accordion body.
   Left-aligned so it reads as part of the content column (looks better than
   centered on wide desktop). Static: no tap-to-enlarge (already shown large
   enough, especially on phones). */
.results-stock-figure {
    margin: 0 0 14px 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.results-stock-img {
    width: 100%;
    max-width: 320px;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 10px;
    display: block;
}

.results-stock-caption {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-align: left;
    line-height: 1.3;
}

.results-hero-crop-multi {
    width: 60px;
    height: 60px;
}

.results-hero-crops-multi {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* Multi-photo hero: crops on top, text below */
.results-ensemble-hero:has(.results-hero-crops-multi) .results-hero-inner {
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.results-photo-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.results-photo-section {
    margin-top: 16px;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.results-photo-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.results-photo-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 8px;
}

.results-photo-header-text {
    display: flex;
    flex-direction: column;
}

.results-photo-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.results-photo-species {
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 500;
}

.results-hero-text {
    flex: 1;
    min-width: 0;
}

.results-species-name {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.results-confidence-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.results-confidence-pct {
    font-size: 1.25rem;
    font-weight: 600;
}

.results-confidence-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    border-radius: 14px;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

/* S&T Occurrence indicator */
.results-st-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.results-st-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.results-st-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

/* Field Marks Section */
.results-fieldmarks-section {
    margin: 12px 0;
}

.results-fieldmarks-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

.results-fieldmarks-btn:active {
    opacity: 0.8;
}

.results-fieldmarks-chevron {
    font-size: 1rem;
    transition: transform 0.2s;
}

.results-fieldmarks-body {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 10px 10px;
    background: var(--bg-secondary);
}

.results-fieldmarks-body.collapsed {
    display: none;
}

.fm-heading {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin: 0 0 6px 0;
    letter-spacing: 0.03em;
}

.fm-quick-id,
.fm-details,
.fm-voice,
.fm-confusion {
    margin-bottom: 12px;
}

.fm-quick-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.fm-quick-list li {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 4px 0;
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.4;
}

.fm-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 4px;
}

.fm-conf-high {
    background: #2ecc71;
}

.fm-conf-med {
    background: #f39c12;
}

.fm-conf-low {
    background: #7f8c8d;
}

.fm-dot {
    cursor: pointer;
}

.fm-tooltip {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.7rem;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: normal;
    max-width: min(280px, 80vw);
    overflow-wrap: break-word;
    word-break: break-word;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    animation: fm-tooltip-in 0.15s ease;
}

@keyframes fm-tooltip-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.fm-legend {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.fm-legend .fm-dot {
    width: 8px;
    height: 8px;
    margin-left: 6px;
}

.fm-table {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.fm-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.82rem;
    line-height: 1.4;
    padding: 3px 0;
}

.fm-feature {
    font-weight: 600;
    min-width: 70px;
    color: var(--text-secondary);
    text-transform: capitalize;
}

.fm-desc {
    color: var(--text-primary);
    flex: 1;
}

.fm-voice-line {
    font-size: 0.85rem;
    color: var(--text-primary);
    padding: 2px 0;
}

.fm-confusion-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.fm-confusion-list li {
    font-size: 0.82rem;
    color: var(--text-primary);
    padding: 4px 0;
    line-height: 1.4;
}

/* Decision Path */
.results-decision-path {
    margin-top: 8px;
    font-size: 0.82rem;
    color: var(--accent);
    font-weight: 500;
    font-style: italic;
}

/* Models Section — Tile Grid */
.results-models-section {
    margin-bottom: 16px;
}

.results-models-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

.results-models-btn:active {
    opacity: 0.8;
}

.results-models-chevron {
    font-size: 1rem;
    transition: transform 0.2s;
}

.results-models-body {
    margin-top: 10px;
}

.results-models-body.collapsed {
    display: none;
}

.results-section-title {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.results-model-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.results-tile-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.results-tile-row-single {
    grid-template-columns: 1fr;
}

.results-tile {
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 12px;
    min-width: 0;
}

.results-tile-deciding {
    border: 1.5px solid var(--accent);
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.2);
}

.results-tile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.results-tile-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.results-tile-tag {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.3px;
}
.results-tile-tag.tag-masked {
    background: rgba(76, 175, 80, 0.15);
    color: var(--accent);
}
.results-tile-tag.tag-unmasked {
    background: rgba(255, 167, 38, 0.15);
    color: var(--warning);
}
.results-tile-tag.tag-candidates {
    background: rgba(76, 175, 80, 0.15);
    color: var(--accent);
}

.results-tile-empty {
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: center;
    padding: 8px;
}

.results-tile-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.results-tile-pred {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.results-tile-pred-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.results-tile-species {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.results-tile-species.top-species {
    color: var(--text-primary);
    font-weight: 600;
}

.results-tile-pct {
    font-size: 0.75rem;
    color: var(--text-secondary);
    flex-shrink: 0;
    margin-left: 6px;
}

.results-tile-bar-container {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.results-tile-bar {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease;
}

.results-tile-bar.bar-green {
    background: var(--confidence-high);
}
.results-tile-bar.bar-yellow {
    background: var(--confidence-medium);
}
.results-tile-bar.bar-red {
    background: var(--confidence-low);
}

/* Mobile: stack tiles vertically */
@media (max-width: 500px) {
    .results-tile-row {
        grid-template-columns: 1fr;
    }
}

.results-pred-pct {
    flex: 0 0 auto;
    font-size: 0.75rem;
    color: var(--text-secondary);
    min-width: 42px;
    text-align: right;
}

/* Ensemble Highlight */
.results-ensemble-highlight {
    background: var(--bg-secondary);
    border: 2px solid var(--accent);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 16px;
}

.results-ensemble-highlight .results-models-section {
    margin-top: 12px;
}

.results-ensemble-highlight .results-trace-section {
    margin-top: 8px;
}

.results-ensemble-highlight-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent);
    margin-bottom: 6px;
    font-weight: 600;
}

.results-ensemble-highlight-value {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1rem;
}

.results-st-veto-badge {
    display: inline-block;
    background: #d32f2f;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    letter-spacing: 0.3px;
    vertical-align: middle;
    cursor: pointer;
    position: relative;
}

/* Decision Trace */
.results-trace-section {
    background: var(--bg-secondary);
    border-radius: 10px;
    margin-bottom: 16px;
    overflow: hidden;
}

.results-trace-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 48px;
    touch-action: manipulation;
}

.results-trace-header:active {
    background: var(--bg-tertiary);
}

.results-trace-body {
    padding: 0 14px 12px;
    transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.3s ease;
    max-height: 2000px;
    opacity: 1;
    overflow: visible;
}

.results-trace-body.collapsed {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.results-trace-row {
    display: flex;
    gap: 8px;
    padding: 4px 0;
    border-bottom: 1px solid var(--bg-tertiary);
    font-size: 0.8rem;
}

.results-trace-row:last-child {
    border-bottom: none;
}

.results-trace-key {
    color: var(--text-secondary);
    flex-shrink: 0;
    font-family: monospace;
}

.results-trace-value {
    color: var(--text-primary);
    word-break: break-word;
}

/* Bird AI Button */
.results-ask-ai-section {
    margin-bottom: 16px;
}

.results-ask-ai-btn.results-ask-ai-emphasized {
    background: var(--warning);
    animation: pulse-ask-ai 2s infinite;
}

@keyframes pulse-ask-ai {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 167, 38, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(255, 167, 38, 0); }
}

.ai-usage-counter {
    display: block;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 6px;
}

.ai-usage-counter.ai-usage-limit-reached {
    color: #e74c3c;
    font-weight: 600;
}

/* Compare Mode Placeholder */
.results-compare-container {
    min-height: 0;
    margin-bottom: 16px;
}

/* Back button in header */
.btn-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 8px;
    margin-right: 8px;
    min-height: 48px;
    touch-action: manipulation;
}

.btn-back:active {
    background: var(--bg-tertiary);
}

/* ===== UTILITIES ===== */
[hidden] {
    display: none !important;
}

/* Leaflet dark tile overrides */
.leaflet-container {
    background: var(--bg-secondary);
}


/* ===== IDENTIFY SCREEN — CAMERA & CAPTURE ===== */
.capture-section {
    margin-bottom: 16px;
}

.camera-preview {
    width: 100%;
    height: 100%;
    max-height: 300px;
    object-fit: cover;
    border-radius: 14px;
    touch-action: none;
}

.camera-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
    padding: 12px 0;
    position: relative;
}

.btn-shutter {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 4px solid #fff;
    background: transparent;
    cursor: pointer;
    position: relative;
}

.btn-shutter::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    right: 4px;
    bottom: 4px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.1s;
}

.btn-shutter:active::after {
    transform: scale(0.85);
}

.btn-camera-close {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes focusRingPulse {
    0% { transform: scale(1.2); opacity: 1; }
    50% { transform: scale(0.9); opacity: 0.8; }
    100% { transform: scale(1); opacity: 0; }
}

.capture-buttons {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.capture-buttons .btn {
    flex: 1;
    min-height: 44px;
    padding: 8px 12px;
    font-size: 0.85rem;
    gap: 6px;
}

.capture-buttons .btn svg {
    flex-shrink: 0;
}

/* ===== PHOTO THUMBNAILS ===== */
.photo-thumbnails {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.thumbnail {
    position: relative;
    width: 72px;
    border-radius: 8px;
    overflow: visible;
    border: 2px solid var(--accent);
}

.thumbnail img {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 6px;
}

.thumbnail-filename {
    display: block;
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 72px;
}

.thumbnail-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border: none;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* ===== CROP CONTAINER ===== */
.crop-container {
    overflow: hidden;
    position: relative;
    min-height: 200px;
}

.crop-container.crop-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    margin: -18px 0 0 -18px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.crop-container.crop-loading::before {
    content: 'Loading preview…';
    position: absolute;
    top: calc(50% + 30px);
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.crop-container img {
    display: block;
    max-width: 100%;
}

/* ===== LOCATION SECTION ===== */
.location-section {
    margin-top: 16px;
}

.location-section h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.location-mode-buttons {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.btn-sm {
    min-height: 36px;
    padding: 6px 14px;
    font-size: 0.8rem;
    border-radius: 8px;
}

.btn-mode {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.btn-mode.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.region-selector {
    margin-bottom: 10px;
}

.region-picker-trigger {
    width: 100%;
    min-height: 44px;
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
}

.region-picker-arrow {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.region-picker-overlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.region-picker-overlay[hidden] {
    display: none;
}

.region-picker-panel {
    background: var(--bg-primary);
    width: 100%;
    max-width: 500px;
    max-height: 70vh;
    border-radius: 16px 16px 0 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

@media (min-width: 900px) {
    .region-picker-trigger {
        display: none;
    }
    .region-picker-overlay:not([hidden]) {
        position: static;
        background: none;
        display: block;
    }
    .region-picker-panel {
        max-height: none;
        border-radius: 8px;
        border: 1px solid var(--border);
    }
    .region-picker-list {
        max-height: none;
        overflow-y: visible;
        padding-bottom: 0;
    }
    .region-picker-close {
        display: none;
    }
    .location-section {
        display: flex;
        flex-direction: column;
    }
    .location-section .region-picker-overlay {
        order: 10;
    }
}

.region-picker-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.region-picker-back {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--accent);
    cursor: pointer;
    padding: 0 8px 0 0;
    line-height: 1;
}

.region-picker-back[hidden] {
    display: none;
}

.region-picker-title {
    flex: 1;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.region-picker-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
}

.region-picker-list {
    overflow-y: auto;
    flex: 1;
    padding: 4px 0 60px;
    -webkit-overflow-scrolling: touch;
}

.region-picker-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 14px 16px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 0.95rem;
    text-align: left;
    cursor: pointer;
}

.region-picker-item:active {
    background: var(--bg-secondary);
}

.region-picker-item:last-child {
    border-bottom: none;
}

.region-picker-item.selected {
    background: var(--bg-secondary);
    color: var(--accent);
    font-weight: 600;
}

.region-picker-item-name {
    flex: 1;
}

.region-picker-item-count {
    color: var(--text-secondary);
    font-size: 0.82rem;
    margin-right: 8px;
}

.region-picker-item-arrow {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.location-search {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.search-input-wrapper {
    flex: 1;
    position: relative;
}

.location-search .setting-input {
    width: 100%;
    min-height: 40px;
    padding: 8px 32px 8px 12px;
    font-size: 0.9rem;
}

.search-clear-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary, #999);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 6px;
    line-height: 1;
    border-radius: 50%;
}

.search-clear-btn:hover {
    color: var(--text-primary, #eee);
    background: rgba(255, 255, 255, 0.1);
}

.location-search .setting-input.search-error {
    border-color: var(--danger, #e74c3c);
    box-shadow: 0 0 0 2px rgba(231, 76, 60, 0.3);
}

.location-search .setting-input.search-error::placeholder {
    color: var(--danger, #e74c3c);
}

.search-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    list-style: none;
    margin: 4px 0 0;
    padding: 0;
    background: var(--surface, #1e1e1e);
    border: 1px solid var(--border, #333);
    border-radius: 8px;
    max-height: 220px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.search-suggestions li {
    padding: 10px 12px;
    font-size: 0.85rem;
    color: var(--text-primary, #eee);
    cursor: pointer;
    border-bottom: 1px solid var(--border, #333);
    line-height: 1.3;
}

.search-suggestions li:last-child {
    border-bottom: none;
}

.search-suggestions li:hover,
.search-suggestions li:focus {
    background: var(--accent, #4a90d9);
    color: #fff;
}

.search-suggestions li .suggestion-secondary {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary, #999);
    margin-top: 2px;
}

.search-suggestions li:hover .suggestion-secondary,
.search-suggestions li:focus .suggestion-secondary {
    color: rgba(255, 255, 255, 0.8);
}

/* Map expanded mode (for tap-to-place) */
/* Map expanded mode (for tap-to-place) */

/* ===== TOGGLE HINT ===== */
.toggle-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 6px;
    font-style: italic;
}

/* ===== IDENTIFY BUTTON ===== */
.btn-identify {
    width: 100%;
    margin-top: 20px;
    min-height: 56px;
    font-size: 1.1rem;
    font-weight: 700;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 14px;
    letter-spacing: 0.5px;
}

.btn-identify:disabled {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: not-allowed;
}

.btn-identify:not(:disabled):active {
    transform: scale(0.97);
    background: var(--accent-dark);
}

.spinner-sm {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

.btn-identify-loading {
    display: inline-flex;
    align-items: center;
}


/* ===== Compare Mode ===== */
.compare-card {
    background: var(--bg-secondary);
    border: 1px solid var(--accent);
    border-radius: 12px;
    padding: 16px;
    margin: 16px 0;
}
.compare-card.compare-generic {
    border-color: #FFC107;
}
.compare-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.compare-icon {
    font-size: 20px;
}
.compare-title {
    font-size: 16px;
    font-weight: 600;
    color: #4CAF50;
}
.compare-key-mark {
    background: var(--theme);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-primary);
}
.compare-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.compare-col h4 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}
.compare-col-a h4 { color: #64B5F6; }
.compare-col-b h4 { color: #FFB74D; }
.compare-col ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.compare-col li {
    font-size: 12px;
    color: var(--text-primary);
    padding: 3px 0;
    line-height: 1.3;
}
.compare-col li::before {
    content: '• ';
    color: var(--text-secondary);
}
.compare-hint {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
}

/* ===== Desktop Layout (side by side) ===== */
@media (min-width: 900px) {
    /* Crop area: take full height of input panel on desktop */
    .id-input-panel .crop-area {
        display: flex;
        flex-direction: column;
        height: calc(100vh - 150px);
    }

    .id-input-panel .crop-area .crop-container {
        flex: 1;
        min-height: 0;
    }

    .id-input-panel .crop-area .crop-image {
        width: 100%;
        height: 100%;
        max-height: none;
        object-fit: contain;
    }

    .crop-image {
        max-height: calc(100vh - 150px);
    }

    #map {
        height: calc(100vh - 300px);
        min-height: 250px;
    }

    .map-container.map-expanded #map {
        height: 100%;
    }

    .map-container.map-expanded.map-fullscreen #map {
        height: 70vh;
    }

    .map-container.map-search-active #map {
        height: 100%;
    }
}

/* Tablet/Fold in landscape: wide but short viewport — cap map to prevent scroll */
@media (min-width: 768px) and (max-height: 750px) {
    #map {
        height: calc(100vh - 320px);
        min-height: 150px;
    }
    .map-container.map-expanded #map {
        height: calc(100vh - 320px);
    }
}

/* ===== Date Selector ===== */
.date-section {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 6px 0;
    padding: 0 4px;
}
.date-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}
.date-input {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 14px;
}
.date-input::-webkit-calendar-picker-indicator {
    filter: invert(0.8);
}
[data-theme="light"] .date-input::-webkit-calendar-picker-indicator {
    filter: none;
}
.date-source {
    font-size: 12px;
    color: var(--accent);
    font-style: italic;
}

.btn-today {
    background: none;
    border: 1px solid var(--border, #30363d);
    color: var(--text-secondary, #999);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    margin-left: 6px;
}

.btn-today:hover {
    border-color: var(--accent, #4a90d9);
    color: var(--text-primary, #e6edf3);
}


/* ===== HOME SCREEN (Pipeline Management) ===== */
.home-section {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
}
.home-section h3 {
    margin-bottom: 12px;
    font-size: 16px;
    color: var(--text-primary);
}
.home-server-status {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.home-server-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
}
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot.connected {
    background: var(--accent);
    box-shadow: 0 0 6px var(--accent);
}
.status-dot.disconnected {
    background: var(--danger);
}
.home-device-info {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Pipeline Controls */
.home-pipeline-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.pipeline-status {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.pipeline-state {
    font-weight: 600;
    font-size: 14px;
}
.pipeline-state.state-idle { color: var(--text-secondary); }
.pipeline-state.state-running { color: var(--warning); }
.pipeline-state.state-done { color: var(--accent); }
.pipeline-state.state-error { color: var(--danger); }
.pipeline-progress {
    font-size: 13px;
    color: var(--text-secondary);
    word-break: break-all;
    max-height: 80px;
    overflow-y: auto;
}

/* Config Editor */
.config-editor {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.config-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.config-field label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===== PWA INSTALL BANNER ===== */
.install-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.install-banner-text {
    flex: 1;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.btn-install-dismiss {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px 8px;
}

/* ===== CAMERA ZOOM ===== */
#camera-zoom-slider {
    width: calc(100% - 32px);
    margin: 8px 16px;
    height: 28px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}

#camera-zoom-slider::-webkit-slider-track {
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

#camera-zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent, #4a90d9);
    margin-top: -9px;
}

#camera-zoom-slider::-moz-range-track {
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

#camera-zoom-slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent, #4a90d9);
    border: none;
}

/* ===== HISTORY SCREEN ===== */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-entry {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
}

.history-entry:hover {
    background: var(--surface-hover, #2a2a2a);
}

.history-entry-thumb {
    width: 52px;
    height: 52px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.history-entry-info {
    flex: 1;
    min-width: 0;
}

.history-entry-species {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-entry-meta {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 3px;
}

.history-entry-confidence {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    flex-shrink: 0;
}

.history-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

#btn-clear-history {
    margin-top: 20px;
    width: 100%;
}

/* ===== BIRD AI LOADING ===== */
.askai-loading-initial {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-primary);
}

.askai-loading-initial p {
    margin-top: 16px;
    font-size: 1rem;
}

.askai-loading-initial .loading-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 8px;
}

.loading-dots {
    display: flex;
    gap: 6px;
}

.loading-dots span {
    width: 10px;
    height: 10px;
    background: var(--accent);
    border-radius: 50%;
    animation: dotPulse 1.4s infinite ease-in-out;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

.ai-error {
    color: var(--danger);
    padding: 20px;
    text-align: center;
}


/* ===== BIRD AI RESPONSE FORMATTING ===== */
.bubble-assistant h2.ai-h2,
.bubble-assistant h3.ai-h3,
.bubble-assistant h4.ai-h4 {
    color: var(--accent);
    margin: 16px 0 8px;
    font-weight: 600;
}

.bubble-assistant h2.ai-h2 { font-size: 1.1rem; }
.bubble-assistant h3.ai-h3 { font-size: 0.95rem; }
.bubble-assistant h4.ai-h4 { font-size: 0.88rem; }

.bubble-assistant h2.ai-h2:first-child,
.bubble-assistant h3.ai-h3:first-child {
    margin-top: 0;
}

.bubble-assistant p {
    margin: 6px 0;
    line-height: 1.5;
}

.bubble-assistant .ai-list {
    margin: 8px 0;
    padding-left: 20px;
}

.bubble-assistant .ai-list li {
    margin: 4px 0;
    line-height: 1.4;
}

.bubble-assistant .ai-spacer {
    height: 8px;
}

.bubble-assistant .ai-quote {
    border-left: 3px solid var(--accent);
    padding: 4px 12px;
    margin: 8px 0;
    color: var(--text-secondary);
    font-style: italic;
}

.bubble-assistant .ai-code-block {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 12px 14px;
    margin: 8px 0;
    overflow-x: auto;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-primary);
    white-space: pre;
}

.bubble-assistant .ai-inline-code {
    background: rgba(255, 255, 255, 0.1);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 0.85em;
}

.bubble-assistant .ai-list.ai-nested {
    margin: 2px 0 2px 16px;
    padding-left: 16px;
}

.bubble-assistant .pct-highlight {
    color: var(--accent);
    font-weight: 600;
}

.bubble-assistant .ai-table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 0.85rem;
    display: block;
    overflow-x: auto;
}

.bubble-assistant .ai-table th,
.bubble-assistant .ai-table td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
}

.bubble-assistant .ai-table th {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
}

.bubble-assistant .ai-table tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.bubble-assistant .ai-hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 12px 0;
}

.bubble-assistant strong {
    color: var(--text-primary);
    font-weight: 600;
}


/* ===== BIRD AI CONTAINER LAYOUT ===== */

/* Original ask-ai container layout */
.askai-container {
    margin: 0 auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-x: hidden;
}

@media (min-width: 900px) {
    .askai-container {
        padding: 24px 0;
    }
}

#ai-conversation {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 16px;
}

.askai-context-bar {
    font-size: 0.78rem;
    color: var(--text-secondary);
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 6px;
    line-height: 1.8;
}

.askai-context-bar .context-sep {
    margin: 0 4px;
    opacity: 0.5;
}

.bubble-assistant {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    font-size: 0.9rem;
    line-height: 1.6;
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: none;
    min-width: 0;
    align-self: stretch;
    overflow: hidden;
}

.bubble-user {
    background: var(--accent);
    color: #fff;
    border-radius: 12px;
    padding: 10px 16px;
    margin-bottom: 12px;
    margin-left: auto;
    max-width: 80%;
    width: fit-content;
    font-size: 0.9rem;
}

.askai-input-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 12px 0;
    margin-top: auto;
    border-top: 1px solid var(--border);
    position: sticky;
    bottom: 0;
    background: var(--bg-primary);
}

.ai-text-input {
    flex: 1;
    min-height: 38px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--text-secondary, #666);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.btn-done {
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
}

.btn-send-ai {
    background: var(--accent);
    border: none;
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
}

/* ===== RESULTS CONTEXT BAR ===== */
/* Uses .askai-context-bar class directly — no overrides needed */

.results-divider {
    border: none;
    border-top: 1px solid var(--text-secondary);
    margin: 4px 0 16px;
    opacity: 0.3;
}

.askai-container > .results-divider {
    margin: 4px 0 8px;
}

.results-ebird-warning {
    font-size: 0.8rem;
    color: #e67e22;
    margin-top: 6px;
    padding: 4px 0;
}

/* eBird-unavailable chip inside the context bar (both themes via --warning) */
.askai-context-bar .context-item.context-warn {
    color: var(--warning);
    font-weight: 600;
}

.bubble-assistant hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0;
    opacity: 0.5;
}

/* ===== FULL PHOTO VIEWER OVERLAY ===== */
.photo-viewer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.photo-viewer-overlay.active {
    opacity: 1;
}

.photo-viewer-close {
    position: absolute;
    top: 12px;
    right: 16px;
    z-index: 10001;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    font-size: 2rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}

.photo-viewer-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.photo-viewer-img {
    max-width: 95vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 4px;
    user-select: none;
    -webkit-user-select: none;
    /* We implement pinch/pan/double-tap zoom in JS (native pinch-zoom is
       unreliable inside a position:fixed overlay), so suppress the browser's
       own touch gestures on the image. */
    touch-action: none;
    transform-origin: center center;
    will-change: transform;
    cursor: zoom-in;
}

.photo-viewer-img.zoomed {
    cursor: grab;
    border-radius: 0;
}

.photo-viewer-img.zoomed:active {
    cursor: grabbing;
}

.photo-viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10001;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: #fff;
    font-size: 2.5rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s;
}

.photo-viewer-nav:hover {
    background: rgba(255, 255, 255, 0.25);
}

.photo-viewer-prev {
    left: 12px;
}

.photo-viewer-next {
    right: 12px;
}

.photo-viewer-dots {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 10001;
}

.photo-viewer-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}

.photo-viewer-dot.active {
    background: #fff;
    transform: scale(1.3);
}

/* ===== TAPPABLE CROP THUMBNAILS ===== */
.results-hero-crop-tappable {
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    position: relative;
}

.results-hero-crop-tappable:hover,
.results-hero-crop-tappable:focus {
    transform: scale(1.08);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.results-hero-crop-tappable:active {
    transform: scale(0.96);
}

.history-thumb-tappable {
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.history-thumb-tappable:hover,
.history-thumb-tappable:focus {
    transform: scale(1.1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}

.history-thumb-tappable:active {
    transform: scale(0.94);
}

/* Safe area for photo viewer close button on notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
    .photo-viewer-close {
        top: calc(12px + env(safe-area-inset-top));
    }
}

/* ===== EXTERNAL BIRD REFERENCE LINKS ===== */
.results-external-links {
    margin-top: 16px;
    padding: 0 4px;
}

.external-links-title {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 10px;
}

.external-links-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.external-link-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 20px;
    background: var(--bg-secondary);
    color: var(--text-primary) !important;
    text-decoration: none !important;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1px solid var(--border);
    transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.external-link-btn:hover,
.external-link-btn:focus {
    background: var(--bg-hover, rgba(255, 255, 255, 0.08));
    border-color: var(--primary);
    transform: translateY(-1px);
    text-decoration: none;
    color: var(--text-primary);
}

.external-link-btn:active {
    transform: scale(0.96);
}

.external-link-icon {
    font-size: 1rem;
    line-height: 1;
}

/* Merlin gets slight accent treatment */
.external-link-merlin {
    border-color: #f4a623;
}

.external-link-merlin:hover {
    border-color: #f4a623;
    background: rgba(244, 166, 35, 0.1);
}

.external-links-attribution {
    margin-top: 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.external-links-attribution a {
    color: var(--accent) !important;
    text-decoration: none !important;
}


/* ===== UNITS TOGGLE ===== */
.units-toggle-row {
    display: flex;
    gap: 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    width: fit-content;
}

.units-btn {
    padding: 10px 24px;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.units-btn:not(:last-child) {
    border-right: 1px solid var(--border);
}

.units-btn-active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

.units-btn:hover:not(.units-btn-active) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}


/* ===== SETTINGS PAGE ===== */
.settings-container {
    padding-bottom: 24px;
}

.settings-section {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.settings-subtitle {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 12px;
}

.settings-field {
    margin-bottom: 16px;
}

.settings-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.settings-helper {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
    opacity: 0.8;
}

.settings-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.settings-map-styles {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.settings-map-styles .btn-mode {
    font-size: 0.8rem;
    padding: 6px 12px;
}

.settings-dropdown {
    position: relative;
}

.settings-dropdown-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
}

.settings-dropdown-chevron {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.settings-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    z-index: 100;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.settings-dropdown-item {
    display: block;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
}

.settings-dropdown-item:hover,
.settings-dropdown-item:focus {
    background: var(--bg-hover, rgba(255,255,255,0.08));
}

.settings-dropdown-item.active {
    color: var(--accent);
    font-weight: 600;
}

.settings-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23999' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
    cursor: pointer;
}

select.settings-select {
    -webkit-appearance: none !important;
    appearance: none !important;
}

.settings-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.settings-credits {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.settings-credits p {
    margin: 6px 0;
}

.settings-credits a {
    color: var(--accent);
    text-decoration: none;
}

.settings-credits-disclaimer {
    font-style: italic;
    font-size: 0.72rem;
    margin-top: 12px !important;
    opacity: 0.8;
}

.settings-support-link {
    display: block;
    text-align: center;
    padding: 12px 20px;
    border-radius: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary) !important;
    text-decoration: none !important;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.settings-support-link:hover {
    background: var(--bg-hover, rgba(255, 255, 255, 0.08));
    border-color: var(--accent);
    color: var(--text-primary);
    text-decoration: none;
}

.settings-version {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 32px;
    opacity: 0.6;
}

.btn-save-settings {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: opacity 0.15s;
}

.btn-save-settings:hover {
    opacity: 0.9;
}

.btn-save-settings.saved {
    background: #4CAF50;
}

.btn-install-app {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--primary);
    border-radius: 8px;
    background: transparent;
    color: var(--primary);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-install-app:hover {
    background: var(--primary);
    color: #fff;
}

.input-with-toggle {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-with-toggle .settings-input {
    flex: 1;
}

.btn-toggle-visibility {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    color: var(--text-secondary);
    cursor: pointer;
}

.server-status {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #666;
}

.status-dot.connected {
    background: #4CAF50;
}

.status-dot.disconnected {
    background: #ef5350;
}

/* ===== GUIDE TAB ===== */
.guide-search-wrapper {
    padding: 0 0 12px 0;
    background: var(--bg-primary);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 0;
    position: sticky;
    top: 0;
    transition: transform 0.2s, opacity 0.2s;
}

.guide-search-wrapper.collapsed {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}

.guide-search-clear {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(calc(-50% - 6px));
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.guide-search-clear:active {
    color: var(--text-primary);
}


.guide-search-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    box-sizing: border-box;
}

.guide-search-input:focus {
    border-color: var(--accent);
}

.guide-sort-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 48px;
    background: var(--bg-primary);
    z-index: 9;
    transition: transform 0.2s, opacity 0.2s;
}

.guide-sort-buttons.collapsed {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}

.guide-sort-buttons .guide-filter-btn {
    margin-left: 0;
}

.guide-results {
    display: flex;
    flex-direction: column;
}

.guide-results[hidden] {
    display: none;
}

.guide-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: auto;
    margin-right: 8px;
    white-space: nowrap;
}

.guide-letter-header {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 10px 4px 4px;
    letter-spacing: 0.05em;
}

.guide-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 6px 12px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
    gap: 10px;
}

.guide-item-name {
    font-weight: 500;
    flex: 1;
}

.guide-item-thumb {
    width: 60px;
    height: 45px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.guide-item-thumb-empty {
    width: 60px;
    height: 45px;
    border-radius: 4px;
    flex-shrink: 0;
    background: var(--bg-secondary);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 55 40' fill='none'%3E%3Cpath d='M13 22c-1-3 0-6 2-8 2.5-2.5 6.5-4 11-4 3 0 6 .7 8.5 2 1.5-2.5 4-4 7-4 3.3 0 6 2.7 6 6 0 2.5-1.5 4.6-3.7 5.5.5.8.7 1.7.7 2.5 0 3.5-3.5 6.5-8.5 7.5-3 .6-6.5.5-10 0-4-.6-8-2.2-10.5-4.5-1.5-1.3-2.5-2.5-2.5-3z' fill='%239e9e9e' opacity='0.4'/%3E%3Cpath d='M44 14.5l5 1-5 1.5z' fill='%239e9e9e' opacity='0.45'/%3E%3Cpath d='M13 20l-5-3M13 20l-5 0M13 20l-5 3' stroke='%239e9e9e' stroke-width='2' stroke-linecap='round' opacity='0.35'/%3E%3Ccircle cx='39' cy='14' r='1.2' fill='%23666' opacity='0.6'/%3E%3Cpath d='M24 30l-1 6M29 30l-1 6' stroke='%239e9e9e' stroke-width='1.5' stroke-linecap='round' opacity='0.35'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 70%;
}

.guide-item:active {
    background: var(--bg-secondary);
}

.guide-item-name {
    font-weight: 500;
}

.guide-item-group {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 2px 8px;
    border-radius: 10px;
    cursor: pointer;
}

.guide-item-group:active {
    opacity: 0.7;
}

.guide-item-size {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-left: auto;
    white-space: nowrap;
}

.guide-sort-picker {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 100;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    padding: 4px;
    display: flex;
    flex-direction: column;
    min-width: 120px;
}

.guide-sort-option {
    padding: 10px 16px;
    border: none;
    background: none;
    color: var(--text-primary);
    text-align: left;
    font-size: 0.9rem;
    border-radius: 6px;
    cursor: pointer;
}

.guide-sort-option:hover, .guide-sort-option:active {
    background: var(--bg-secondary);
}

.guide-sort-option.active {
    color: var(--accent);
    font-weight: 600;
}

.guide-letter-header.guide-group-tap {
    cursor: pointer;
}

.guide-letter-header.guide-group-tap:active {
    opacity: 0.6;
}

.guide-filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    max-height: 50px;
    transition: opacity 0.2s, max-height 0.2s, padding 0.2s, margin 0.2s;
    overflow: hidden;
    flex-wrap: wrap;
}

.guide-filter-bar[hidden] {
    display: none;
}

.guide-filter-bar.collapsed {
    max-height: 0;
    overflow: hidden;
    padding: 0;
    margin: 0;
    opacity: 0;
}

.guide-filter-chip {
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
    padding: 3px 10px;
    border-radius: 12px;
}

.guide-filter-chip[hidden] {
    display: none !important;
}

.guide-filter-clear {
    background: none;
    border: none;
    font-size: 1rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 50%;
    line-height: 1;
}

.guide-filter-clear[hidden] {
    display: none !important;
}

.guide-filter-clear:active {
    background: var(--border);
}

/* Region picker items */
.guide-filter-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 1;
}

.guide-filter-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.guide-filter-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.guide-region-group {
    margin-bottom: 16px;
}

.guide-region-subgroup {
    margin-bottom: 4px;
}
.guide-region-subgroup .guide-region-group-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-primary);
    border-left: none;
    padding: 6px 12px 4px 8px;
}
.guide-region-subgroup .guide-region-group-selectable {
    border-left: none;
}
.guide-region-subgroup .guide-region-children {
    padding-left: 12px;
}

.guide-region-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.guide-region-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    padding: 8px 12px;
    cursor: pointer;
}

.guide-region-group-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent);
    padding: 8px 12px 4px;
    margin: 0;
    border-left: 3px solid var(--accent);
}

.guide-region-group-selectable {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-left: 3px solid var(--accent);
    cursor: pointer;
    border-radius: 0;
}

.guide-region-group-selectable:active {
    background: var(--bg-tertiary);
}

.guide-region-group-selectable.guide-region-active {
    background: var(--accent);
    color: #fff;
    border-left-color: #fff;
}

.guide-region-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 6px;
}

.guide-region-item:active {
    background: var(--bg-tertiary);
}

.guide-region-item.guide-region-active {
    background: var(--accent);
    color: #fff;
}

.guide-region-count {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.guide-region-active .guide-region-count {
    color: rgba(255,255,255,0.7);
}

/* Family picker overlay */
.guide-family-picker {
}

.guide-family-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 4px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}

.guide-picker-close {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
}

.guide-family-picker-list {
}

.guide-picker-item {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 10px;
    padding: 10px 12px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 0.88rem;
    text-align: left;
    cursor: pointer;
}

.guide-picker-item:active {
    background: var(--bg-secondary);
}

.guide-picker-item-active {
    background: var(--bg-secondary);
    font-weight: 600;
}

.guide-picker-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.guide-picker-name {
    flex: 1;
}

.guide-picker-count {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* ===== Compare view (Sibley-style two-panel) ===== */
.guide-compare {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.guide-compare-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 0 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.guide-compare-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Reuse .id-layout for the two panels. On phone it stacks (each its own scroll);
   on desktop (>=900px) it splits left/right. */
.guide-compare-layout {
    flex: 1;
    min-height: 0;
}

.guide-compare-panel {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    overflow-y: auto;
}

/* Phone (stacked): give each panel a bounded height so both scroll independently. */
@media (max-width: 899px) {
    .guide-compare-panel {
        max-height: 60vh;
    }
}

/* Desktop (split): each panel fills the grid cell and scrolls on its own. */
@media (min-width: 900px) {
    .guide-compare-panel {
        height: 100%;
        min-height: 0;
    }
    /* Panel B reuses .id-context-panel, which is display:flex/column for the
       Sound/Photo screens — that breaks the floated header image and leaves a
       gap before Quick ID. Force normal block flow for compare panels so both
       sides render identically. */
    .guide-compare-panel.id-context-panel {
        display: block;
    }
}

.guide-compare-change {
    /* normal-flow button in the panel bar — no image overlap */
}

.guide-compare-panel-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.guide-compare-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
}

.guide-compare-choose {
    background: none;
    border: 1px dashed var(--border);
    border-radius: 8px;
    color: var(--accent);
    font-weight: 600;
    padding: 12px 20px;
    cursor: pointer;
}

/* Detail topbar row: Back on the left, Compare on the right (no image overlap) */
.guide-detail-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

/* Compare button on the detail header */
.guide-compare-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 600;
    padding: 8px 0;
    cursor: pointer;
}

.guide-compare-btn:active {
    opacity: 0.7;
}

/* Compare picker as a centered modal overlay (obvious chooser, not inline flow) */
.guide-compare-picker {
    position: fixed;
    /* iOS Safari ignores the `inset` shorthand for fixed positioning — the
       element then auto-sizes and its top (checkbox/Filters/✕) overflows above
       the viewport. Use explicit longhand offsets so it fills the screen. */
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1200;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    padding: 16px;
    overflow: hidden;
}

@media (min-width: 900px) {
    .guide-compare-picker {
        /* two-value inset: 5vh (top/bottom) 50% (left/right) — longhand for iOS */
        top: 5vh;
        bottom: 5vh;
        left: 50%;
        right: 50%;
        transform: translateX(-50%);
        width: min(560px, 90vw);
        border: 1px solid var(--border);
        border-radius: 12px;
        box-shadow: 0 8px 32px rgba(0,0,0,0.4);
        max-height: 90vh;
    }
}

.guide-compare-picker[hidden] {
    display: none;
}

.guide-compare-picker .guide-family-picker-header {
    flex-wrap: wrap;
    gap: 8px;
}

.guide-compare-picker .guide-family-picker-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.guide-compare-showall {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}

.guide-compare-picker-search {
    padding: 4px 0 8px;
}

.guide-compare-picker-search .guide-search-input {
    width: 100%;
}

.guide-compare-pick-head {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    padding: 6px 4px;
    position: sticky;
    top: 0;
    background: var(--bg-primary);
}

.guide-compare-note {
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 0.82rem;
}

/* Floating search button (shows when scrolled) */
.guide-search-fab {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary, #2196f3);
    color: #fff;
    border: none;
    border-radius: 24px;
    padding: 10px 20px;
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    z-index: 90;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.guide-search-fab.visible {
    opacity: 1;
    pointer-events: auto;
}

.guide-search-fab:active {
    opacity: 0.8;
}

/* Alphabet scrubber */
.guide-alpha-scrubber {
    position: fixed;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 100;
    padding: 4px 2px;
    border-radius: 8px;
    background: rgba(0,0,0,0.03);
}

.guide-alpha-scrubber span {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 1.5px 6px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    line-height: 1.4;
}

.guide-alpha-scrubber span:active {
    color: var(--primary, #2196f3);
    font-weight: 700;
}

.guide-empty {
    color: var(--text-secondary);
    text-align: center;
    padding: 40px 20px;
    font-size: 0.9rem;
}

/* Guide Detail View */
.guide-detail {
    overflow-y: auto;
    position: relative;
}

/* Desktop prev/next arrows (hidden on mobile — swipe works there) */
.guide-nav-arrow {
    display: none;
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    z-index: 100;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s, background 0.2s;
}

.guide-nav-arrow:hover {
    opacity: 1;
    background: var(--bg-tertiary);
}

.guide-nav-prev {
    left: calc(20% - 72px);
}

.guide-nav-next {
    right: calc(20% - 72px);
}

@media (min-width: 900px) {
    .guide-nav-arrow {
        display: flex;
    }
}

.guide-back-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 600;
    padding: 8px 0;
    cursor: pointer;
}

.guide-back-btn:active {
    opacity: 0.7;
}

.guide-species-header {
    margin-bottom: 16px;
}

.guide-header-img {
    float: right;
    margin-left: 12px;
    margin-bottom: 8px;
    text-align: right;
}

.guide-header-img img {
    width: 180px;
    height: auto;
    border-radius: 8px;
    object-fit: cover;
}

.guide-photo-credit {
    display: block;
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-top: 2px;
    opacity: 0.7;
}

.guide-detail-img-tappable {
    cursor: pointer;
}

.guide-img-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.guide-img-overlay img {
    max-width: 90%;
    max-height: 85vh;
    border-radius: 8px;
    object-fit: contain;
}

.guide-img-overlay-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    padding: 8px;
    line-height: 1;
}

.guide-species-name {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0 0 2px 0;
}

.guide-scientific {
    font-style: italic;
    color: var(--text-secondary);
    margin: 0 0 2px 0;
    font-size: 0.85rem;
}

.guide-size {
    color: var(--text-secondary);
    margin: 0;
    font-size: 0.82rem;
}

.guide-meta {
    color: var(--text-secondary);
    margin: 4px 0 0;
    font-size: 0.78rem;
    font-style: italic;
}

.guide-section {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.guide-section:last-child {
    border-bottom: none;
}

.guide-external-links {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 4px 0;
}

.guide-external-btn {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 16px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 500;
}

.guide-external-btn:active {
    opacity: 0.7;
}

.guide-habitat-line {
    font-size: 0.85rem;
    color: var(--text-primary);
    padding: 2px 0;
    line-height: 1.4;
}

.guide-habitat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.guide-habitat-chip {
    font-size: 0.75rem;
    padding: 3px 8px;
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

/* "Sensitive species" chip — shown on results for eBird sensitive species, which
   are injected as always-available candidates (their locations are hidden), so a
   match doesn't imply a recent nearby sighting. See Settings -> How it works. */
.sensitive-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 20px;
    box-sizing: border-box;
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1;
    padding: 0 9px;
    border-radius: 10px;
    background: var(--chip-sensitive);
    color: #fff;
    vertical-align: middle;
    white-space: nowrap;
    cursor: pointer;
}

.guide-attribution {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-secondary);
    padding: 20px 0 8px;
    opacity: 0.7;
}

.guide-similar-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
}

.guide-similar-link:active {
    opacity: 0.7;
}

.guide-attribution a {
    color: var(--accent);
    text-decoration: none;
}

/* ===== WELCOME OVERLAY ===== */
.welcome-overlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 9999;
    background: var(--bg-primary);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.welcome-container {
    max-width: 420px;
    margin: 0 auto;
    padding: 40px 24px 60px;
}

.welcome-header {
    text-align: center;
    margin-bottom: 32px;
}

.welcome-icon {
    width: 72px;
    height: 72px;
    border-radius: 16px;
    margin-bottom: 12px;
}

.welcome-header h1 {
    font-size: 28px;
    margin: 0 0 8px;
    color: var(--text-primary, #e6edf3);
}

.welcome-subtitle {
    color: var(--text-secondary, #999);
    font-size: 14px;
    margin: 0;
}

.welcome-byline {
    color: var(--text-secondary, #999);
    font-size: 12px;
    margin: 6px 0 0;
    opacity: 0.7;
}

.welcome-section {
    margin-bottom: 28px;
}

.welcome-section h3 {
    color: var(--text-primary, #e6edf3);
    font-size: 16px;
    margin: 0 0 8px;
}

.welcome-section p {
    color: var(--text-secondary, #999);
    font-size: 14px;
    line-height: 1.5;
    margin: 0 0 12px;
}

.welcome-steps {
    color: var(--text-secondary, #999);
    font-size: 14px;
    line-height: 1.8;
    padding-left: 20px;
    margin: 0 0 16px;
}

.welcome-steps a {
    color: var(--accent, #4a90d9);
    text-decoration: none;
}

.welcome-form {
    margin-bottom: 28px;
}

.welcome-field {
    margin-bottom: 16px;
}

.welcome-field label {
    display: block;
    color: var(--text-secondary, #999);
    font-size: 13px;
    margin-bottom: 4px;
}

.welcome-field input {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-sizing: border-box;
}

.welcome-field input:focus {
    outline: none;
    border-color: var(--accent, #4a90d9);
}

.welcome-submit {
    width: 100%;
    margin-top: 8px;
}

.welcome-message {
    margin-top: 12px;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
}

.welcome-message-success {
    background: rgba(46, 204, 113, 0.1);
    color: #2ecc71;
    border: 1px solid rgba(46, 204, 113, 0.3);
}

.welcome-message-error {
    background: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
    border: 1px solid rgba(231, 76, 60, 0.3);
}

.welcome-existing {
    border-top: 1px solid var(--border, #30363d);
    padding-top: 24px;
}

.welcome-browse {
    margin-top: 24px;
    text-align: center;
}

.btn-ghost {
    background: none;
    border: 1px solid var(--border, #30363d);
    color: var(--text-secondary, #999);
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.btn-ghost:hover {
    border-color: var(--accent, #4a90d9);
    color: var(--text-primary, #e6edf3);
}

.welcome-skip {
    width: 100%;
    margin-top: 8px;
}


/* ===== MASKED INPUT (replaces type=password to avoid browser password prompts) ===== */
.masked-input {
    -webkit-text-security: disc;
    text-security: disc;
    font-family: monospace;
}

/* ===== GUIDE TOAST ===== */
.guide-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 9999;
    pointer-events: none;
}

.guide-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===== HELP PAGE ===== */
.help-section {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.help-section:last-child {
    border-bottom: none;
}
.help-section h2 {
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: var(--text-primary);
}
.help-section h3 {
    font-size: 0.95rem;
    margin-top: 14px;
    margin-bottom: 6px;
    color: var(--text-primary);
}
.help-section p {
    font-size: 0.88rem;
    line-height: 1.5;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.help-dl {
    margin: 8px 0;
}
.help-dl dt {
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text-primary);
    margin-top: 10px;
}
.help-dl dd {
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--text-secondary);
    margin-left: 0;
    margin-top: 2px;
}
.help-ul, .help-ol {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary);
    padding-left: 20px;
    margin: 8px 0;
}
.help-ul li, .help-ol li {
    margin-bottom: 4px;
}
.help-section a {
    color: var(--accent);
}
#screen-help .screen-content {
    overflow-y: auto;
}

/* ===== ADMIN PAGE ===== */
.admin-summary {
    display: flex;
    gap: 0.75rem;
    padding: 1rem;
}

.admin-stat-card {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--bg-tertiary);
    border-radius: 12px;
    padding: 1rem 0.75rem;
    text-align: center;
}

.admin-stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent);
}

.admin-stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.admin-updated {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 0 1rem 0.75rem;
}

.admin-user-list {
    padding: 0 1rem 1rem;
}

.admin-user-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--bg-tertiary);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.admin-user-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.admin-user-stats {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
}

.admin-badge {
    background: var(--bg-tertiary);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    color: var(--text-secondary);
}

.admin-badge.admin-low {
    background: #5c2a00;
    color: #ffaa44;
}

.admin-last-active {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.admin-loading {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}


/* ===== SOUND ID ===== */

.sound-view[hidden] { display: none !important; }

/* Context bar */
.sound-context-bar {
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sound-context-bar.sound-context-warning {
    background: rgba(255, 167, 38, 0.1);
    color: var(--warning);
}

/* === RECORD VIEW === */
.sound-record-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 4px 0 16px;
    user-select: none;
    -webkit-user-select: none;
}

.sound-input-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    width: 100%;
}

.sound-mic-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid var(--accent);
    background: var(--bg-secondary);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease, border-color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.sound-mic-btn:hover { background: var(--bg-tertiary); }
.sound-mic-btn:active { transform: scale(0.92); }

.sound-mic-btn.recording {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
    animation: sound-pulse 1.5s ease-in-out infinite;
}

@keyframes sound-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 83, 80, 0.4); }
    50% { box-shadow: 0 0 0 14px rgba(239, 83, 80, 0); }
}

.sound-live-canvas {
    width: 100%;
    height: 80px;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.sound-timer {
    font-size: 2rem;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    transition: color 0.3s;
}

.sound-timer-warning {
    color: var(--danger, #e53935);
    animation: timer-pulse 1s ease-in-out infinite;
}

@keyframes timer-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.sound-upload-label {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary) !important;
    text-decoration: none !important;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.sound-upload-label:hover { background: var(--bg-tertiary); border-color: var(--accent); }

.sound-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

.sound-filters {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

.sound-filter-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    -webkit-tap-highlight-color: transparent;
}

.sound-filter-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

.sound-filter-toggle input[type="checkbox"]:checked + .sound-filter-label {
    color: var(--text-primary);
}

.sound-record-controls {
    display: flex;
    gap: 12px;
    width: 100%;
    justify-content: center;
}

.sound-ctrl-btn {
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    border: 1px solid var(--border);
}

.sound-ctrl-submit {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.sound-ctrl-submit:active { opacity: 0.8; }

.sound-ctrl-discard {
    background: none;
    color: var(--text-secondary);
}

.sound-ctrl-discard:active { color: var(--danger); border-color: var(--danger); }

.sound-ctrl-restart {
    background: none;
    color: var(--warning);
    border-color: var(--warning);
}

.sound-ctrl-restart:active { opacity: 0.8; }

/* === PROCESSING VIEW === */
#sound-view-processing {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px 0;
}

.sound-processing-title {
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 500;
}

.sound-processing-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.sound-processing-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.4s ease;
    width: 0%;
}

.sound-model-checklist {
    width: 100%;
    max-width: 220px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sound-model-item {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sound-model-item.done { color: var(--accent); }
.sound-model-item.running { color: var(--warning); }

.sound-model-status {
    width: 18px;
    text-align: center;
    font-size: 0.9rem;
}

.sound-cancel-btn {
    margin-top: 16px;
    padding: 10px 24px;
    border: 1px solid var(--danger);
    border-radius: 8px;
    background: none;
    color: var(--danger);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.sound-cancel-btn:active { background: var(--danger); color: white; }

/* === RESULTS VIEW === */
#sound-results-wrap {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sound-waveform-wrap {
    position: relative;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 8px;
}

.sound-minimap-canvas {
    width: 100%;
    height: 24px;
    display: block;
    margin-bottom: 4px;
    border-radius: 4px;
}

.sound-waveform-scroll {
    position: relative;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.sound-play-btn {
    position: absolute;
    left: 8px;
    top: 32px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: white;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
    -webkit-tap-highlight-color: transparent;
}

.sound-play-btn:active { transform: scale(0.9); }

.sound-result-canvas {
    display: block;
    min-width: 100%;
    cursor: pointer;
}

.sound-waveform-time {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-secondary);
    padding-top: 2px;
}

.sound-waveform-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sound-time-readout {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.sound-hover-time {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    padding: 1px 5px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.68rem;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
    white-space: nowrap;
    z-index: 6;
}

.sound-viz-toggle {
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.sound-viz-toggle:hover { border-color: var(--accent); color: var(--text-primary); }

.sound-results-summary {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 2px 0;
}

.sound-reprocess-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    justify-content: center;
}

.sound-reprocess-controls #btn-reprocess {
    margin-left: 4px;
}

.sound-filtered-wrap {
    padding: 8px 16px 12px;
}

.sound-filtered-header {
    display: flex;
    justify-content: space-around;
    margin-bottom: 6px;
}

.sound-filtered-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
}

.sound-filtered-spectrograms {
    display: flex;
    gap: 8px;
}

.sound-filtered-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.sound-filtered-col canvas {
    width: 100%;
    height: 60px;
    border-radius: 6px;
    border: 1px solid var(--bg-tertiary);
    display: block;
}

.sound-play-mini {
    position: static;
    width: auto;
    height: auto;
    border-radius: 4px;
    font-size: 0.75rem;
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-primary);
    cursor: pointer;
}

.sound-play-mini:hover {
    background: var(--accent);
    color: white;
}

.sound-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-secondary);
}
.sound-empty-hint { font-size: 0.8rem; margin-top: 8px; opacity: 0.7; }

/* Species cards */
.sound-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.sound-card:hover { border-color: var(--accent); }
.sound-card.expanded { border-color: var(--accent); background: var(--bg-tertiary); }

.sound-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sound-card-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sound-card-conf {
    font-size: 0.85rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: auto;
}
.sound-card-conf.high { color: var(--confidence-high); background: rgba(76, 175, 80, 0.12); }
.sound-card-conf.medium { color: var(--confidence-medium); background: rgba(255, 167, 38, 0.12); }
.sound-card-conf.low { color: var(--confidence-low); background: rgba(239, 83, 80, 0.12); }

.sound-card-sub {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 3px;
}

/* Expanded card detail */
.sound-card-detail {
    margin-top: 10px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

.sound-chunks {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.sound-chunk-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    flex-wrap: wrap;
}

.sound-chunk-play {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}
.sound-chunk-play:active { background: var(--accent); color: white; }

.sound-chunk-time { color: var(--text-secondary); min-width: 48px; }
.sound-chunk-conf { font-weight: 600; color: var(--text-primary); }
.sound-chunk-agree { color: var(--text-secondary); }

.sound-chunk-expand-btn {
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 2px 4px;
}

.sound-chunk-wave {
    width: 100%;
    height: 150px;
    border-radius: 4px;
    display: block;
    margin-top: 4px;
}

.sound-chunk-models {
    width: 100%;
    padding: 4px 0 4px 32px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.sound-model-detail-row { padding: 1px 0; }

/* Per-model summary in expanded card */
.sound-model-summary {
    margin-bottom: 10px;
}
.sound-model-summary-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
}
.sound-model-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-primary);
    padding: 1px 0;
}

/* Links in expanded card */
.sound-card-links {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.sound-link-btn {
    padding: 6px 12px;
    border-radius: 6px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-primary) !important;
    text-decoration: none !important;
    font-size: 0.8rem;
    font-weight: 500;
}
.sound-link-btn:hover { border-color: var(--accent); }

/* New Recording button */
.sound-results-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}
.sound-new-btn, .sound-save-btn {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.sound-new-btn:hover, .sound-save-btn:hover { background: var(--bg-tertiary); border-color: var(--accent); }

/* ─── Streaming Sound ID ─────────────────────────────────────── */
#stream-results-wrap {
    margin-top: 12px;
    padding: 0 4px;
}
.stream-header {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}
.stream-species-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.stream-card {
    animation: streamFadeIn 0.3s ease;
}
.sound-card-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.sound-card-text {
    flex: 1;
    min-width: 0;
}
.sound-card-thumb {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}
.stream-card-thumb {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}
@keyframes streamFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── Photo Model Progress (WebSocket identify) ─────────────────── */
.photo-model-progress {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
}

.photo-progress-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    margin-top: 12px;
    margin-bottom: -8px;
}

.photo-model-item {
    font-size: 0.82rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s;
}

.photo-model-item.running {
    color: var(--warning, #f0ad4e);
}

.photo-model-item.done {
    color: var(--accent, #4caf50);
}

.photo-model-item .model-icon {
    width: 16px;
    text-align: center;
    font-size: 0.9rem;
}


/* ─── Candidate list inline expand in decision trace ────────────── */
.results-trace-candidates {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    opacity: 1;
}

.results-trace-candidates.collapsed {
    max-height: 0 !important;
    opacity: 0;
    margin: 0;
    padding: 0;
}

/* ============================================================================
   "What the models heard" — per-model, per-chunk raw predictions (Sound ID)
   Collapsed by default behind a single toggle (mirrors photo Model Predictions).
   ========================================================================== */
.sound-model-heard {
    margin-top: 16px;
}

.sound-heard-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

.sound-heard-btn:active {
    opacity: 0.8;
}

.sound-heard-chevron {
    font-size: 1rem;
    transition: transform 0.2s;
}

.sound-heard-body {
    margin-top: 10px;
}

.sound-heard-body.collapsed {
    display: none;
}

.sound-heard-note {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 10px;
}

/* Legend: model -> color */
.sound-heard-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
    margin-bottom: 10px;
}
.sound-heard-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    color: var(--text-secondary);
}
.sound-heard-swatch {
    width: 11px;
    height: 11px;
    border-radius: 3px;
    display: inline-block;
}

/* Per-model colors (work in both themes) */
.model-birdnet24 { background: #4c9be8; }
.model-birdnet30 { background: #9b6dde; }
.model-perch_calibrated { background: #e6a23c; }
.model-convnext { background: #48b98a; }

/* Horizontal scroller: the whole model-thoughts area scrolls as a group,
   while the label column (image/name/confidence) stays frozen (sticky). */
.sound-heard-scroll {
    overflow-x: auto;
    /* When overflow-x is `auto`, the browser forces the (otherwise `visible`)
       vertical axis to `auto` too. The inline popover is position:absolute and
       pokes above/below the timeline, so without vertical room it would trigger
       a spurious vertical scrollbar. Reserve room for the popover with padding
       and clip the vertical axis so it never scrolls. */
    overflow-y: clip;
    padding-top: 52px;
    margin-top: -52px;
    /* Bottom: no padding/negative-margin here. The horizontal scrollbar renders
       at this element's bottom edge, so any bottom padding+negative-margin trick
       forced a choice between "big gap" and "scrollbar overlaps the buttons"
       (the scrollbar lives inside that padding). Instead the popover's `.below`
       render room is placed on .sound-heard-inner (inside the scroll viewport,
       doesn't move the scrollbar). Scrollbar now sits at the true content bottom
       and the button row follows in normal flow. */
    -webkit-overflow-scrolling: touch;
}
.sound-heard-inner {
    /* --lane-w and --label-w are set from JS after mount */
    --lane-w: 100%;
    --label-w: 150px;
    display: inline-block;
    min-width: 100%;
    /* Small cushion below the bottom time-axis footer. The footer (margin:6px)
       already sits below the last lane, and the `.below` popover anchors to the
       timeline list (which ends above the footer), so only a little extra room
       is needed — a large value here just becomes dead gap when the clip is
       short enough that there's no horizontal scrollbar. */
    padding-bottom: 8px;
}

/* Detection timeline: one row per bird, shared time axis, 4 model lanes */
.sound-heard-timeline {
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
}

.sound-heard-trow {
    display: flex;
    align-items: stretch;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.sound-heard-trow:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

/* Left label column — FROZEN via sticky while lanes scroll under it */
.sound-heard-tlabel {
    position: sticky;
    left: 0;
    z-index: 2;
    flex: 0 0 var(--label-w);
    width: var(--label-w);
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    background: var(--bg-primary);
    padding-right: 6px;
    cursor: pointer;
}
.sound-heard-tthumb {
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    object-fit: cover;
}
.sound-heard-tname {
    flex: 1 1 auto;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.sound-heard-tpeak {
    flex: 0 0 auto;
    font-size: 0.72rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.sound-heard-tpeak.tier-high { color: var(--confidence-high); }
.sound-heard-tpeak.tier-medium { color: var(--confidence-medium); }
.sound-heard-tpeak.tier-low { color: var(--confidence-low); }

/* Right: stacked model lanes, sized to the scaled recording width */
.sound-heard-lanes {
    flex: 0 0 var(--lane-w);
    width: var(--lane-w);
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.sound-heard-lane {
    position: relative;
    height: 7px;
    border-radius: 3px;
    background: var(--bg-secondary);
    overflow: hidden;
}
.sound-heard-blk {
    position: absolute;
    top: 0;
    bottom: 0;
    border-radius: 2px;
    min-width: 6px;
    cursor: pointer;
}
.sound-heard-blk.selected {
    outline: 2px solid var(--text-primary);
    outline-offset: 1px;
    opacity: 1 !important;
}

/* Time axis strip: frozen spacer (matches label) + scaled track */
.sound-heard-axis {
    display: flex;
    gap: 8px;
    margin: 6px 0;
    font-size: 0.66rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}
.sound-heard-axis-spacer {
    position: sticky;
    left: 0;
    flex: 0 0 var(--label-w);
    width: var(--label-w);
    background: var(--bg-primary);
    z-index: 2;
}
.sound-heard-axis-track {
    flex: 0 0 var(--lane-w);
    width: var(--lane-w);
    display: flex;
    justify-content: space-between;
}

/* Inline popover: appears right at the tapped block */
.sound-heard-pop {
    position: absolute;
    z-index: 5;
    transform: translate(-50%, -100%);
    max-width: 240px;
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--text-primary);
    color: var(--bg-primary);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    gap: 1px;
    pointer-events: none;
    white-space: nowrap;
}
.sound-heard-pop.below {
    transform: translate(-50%, 0);
}
.sound-heard-pop::after {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    top: 100%;
    border-top-color: var(--text-primary);
}
.sound-heard-pop.below::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: var(--text-primary);
}
.sound-heard-pop-name {
    font-size: 0.8rem;
    font-weight: 700;
}
.sound-heard-pop-meta {
    font-size: 0.74rem;
    opacity: 0.85;
    font-variant-numeric: tabular-nums;
}

