@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Nunito:wght@400;600;700;800&display=swap');

/* ===== RESET & VARIABLES ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg-color: #F0F4FF;
    --card-bg: #FFFFFF;
    --text-dark: #2D3748;
    --text-light: #718096;
    --accent: #667eea;
    --accent2: #764ba2;
}

body {
    font-family: 'Nunito', sans-serif;
    background: var(--bg-color);
    color: var(--text-dark);
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ===== HEADER ===== */
.header {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    position: relative;
    z-index: 1000;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    font-family: 'Fredoka One', cursive;
    font-size: 28px;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 32px;
    animation: pulse 2s ease-in-out infinite;
}

.header-subtitle {
    color: rgba(255,255,255,0.85);
    font-size: 14px;
    font-weight: 600;
}

.live-badge {
    background: #48BB78;
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 800;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    animation: glow 2s ease-in-out infinite;
}

.live-dot {
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
    animation: blink 1s ease-in-out infinite;
}

/* ===== ACTIVATE BUTTON ===== */
.activate-btn {
    background: linear-gradient(135deg, #F6AD55, #ED8936);
    color: #ffffff;
    border: none;
    padding: 8px 18px;
    border-radius: 20px;
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 12px rgba(237, 137, 54, 0.45);
    animation: glowOrange 2s ease-in-out infinite;
}

.activate-btn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 4px 18px rgba(237, 137, 54, 0.6);
}

@keyframes glowOrange {
    0%, 100% { box-shadow: 0 2px 12px rgba(237, 137, 54, 0.45); }
    50% { box-shadow: 0 4px 20px rgba(237, 137, 54, 0.65); }
}

/* ===== LAYOUT ===== */
.app-container {
    display: grid;
    grid-template-columns: 360px 1fr;
    flex: 1;
    min-height: 0;
}

/* ===== SIDEBAR ===== */
.sidebar {
    background: var(--card-bg);
    overflow-y: auto;
    border-right: 1px solid #E2E8F0;
    padding: 0;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: #CBD5E0; border-radius: 3px; }

/* ===== ANIMAL CARDS (data-driven via --c, --grad, --cbg) ===== */
.animal-card {
    padding: 18px 20px;
    border-bottom: 1px solid #EDF2F7;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.animal-card::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    background: var(--c, #667eea);
    transition: width 0.3s ease;
}

@media (hover: hover) {
    .animal-card:hover { background: #F7FAFC; }
    .animal-card:hover::before { width: 6px; }
}
.animal-card.active { background: var(--cbg, #EBF4FF); }
.animal-card.active::before { width: 6px; }

.card-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
}

.animal-avatar {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    position: relative;
    background: var(--grad, linear-gradient(135deg, #a78bfa, #7c3aed));
}

.tracking-ping {
    position: absolute;
    top: -2px; right: -2px;
    width: 14px; height: 14px;
    background: #48BB78;
    border-radius: 50%;
    border: 2px solid white;
    animation: ping 2s ease-in-out infinite;
}

.animal-info h3 {
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 2px;
}

.animal-species {
    font-size: 13px;
    color: var(--text-light);
    font-weight: 600;
}

.card-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}

.stat {
    background: #F7FAFC;
    padding: 8px 10px;
    border-radius: 10px;
    text-align: center;
}

.stat-label {
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-light);
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 14px;
    font-weight: 800;
    margin-top: 2px;
    color: var(--c, var(--text-dark));
}

.animal-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    background: var(--cbg, #EBF4FF);
    color: var(--c, var(--accent));
}

/* Meet Button */
.card-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.map-btn, .meet-btn {
    flex: 1;
    padding: 8px;
    border: 2px dashed #CBD5E0;
    border-radius: 10px;
    background: transparent;
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-light);
}

@media (hover: hover) {
    .map-btn:hover, .meet-btn:hover {
        transform: translateY(-1px);
        border-color: var(--c, #667eea);
        color: var(--c, #667eea);
        background: var(--cbg, #EBF4FF);
    }
}

.map-btn {
    border-style: solid;
    background: var(--cbg, #EBF4FF);
    color: var(--c, #667eea);
    border-color: var(--cbg2, #DDD6FE);
}

/* ===== FIELD NOTE SECTION ===== */
.field-note-section {
    padding: 18px 20px;
    border-bottom: 1px solid #EDF2F7;
}

.field-note-card {
    background: #FFFFF0;
    border: 2px solid #F6E05E;
    border-radius: 16px;
    padding: 16px;
    position: relative;
}

.field-note-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.field-note-badge {
    background: #48BB78;
    color: white;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.5px;
}

/* ===== SPEAK (READ ALOUD) BUTTON ===== */
.speak-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(102, 126, 234, 0.12);
    cursor: pointer;
    font-size: 16px;
    padding: 0;
    transition: all 0.2s ease;
    vertical-align: middle;
    margin-left: 6px;
    flex-shrink: 0;
}
.speak-btn.speaking {
    background: rgba(102, 126, 234, 0.25);
    animation: speakPulse 1.2s ease-in-out infinite;
}
@media (hover: hover) {
    .speak-btn:hover {
        background: rgba(102, 126, 234, 0.25);
        transform: scale(1.1);
    }
}
.speak-btn-lg {
    width: 36px;
    height: 36px;
    font-size: 18px;
}
@keyframes speakPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.3); }
    50% { box-shadow: 0 0 0 8px rgba(102, 126, 234, 0); }
}

/* Share button — matches speak-btn style */
.share-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(102, 126, 234, 0.12);
    cursor: pointer;
    font-size: 16px;
    padding: 0;
    transition: all 0.2s ease;
    vertical-align: middle;
    margin-left: 6px;
    flex-shrink: 0;
}
@media (hover: hover) {
    .share-btn:hover {
        background: rgba(102, 126, 234, 0.25);
        transform: scale(1.1);
    }
}
.share-btn-lg {
    width: 36px;
    height: 36px;
    font-size: 18px;
}

/* Share CTA in field note */
.fn-share-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid #EDF2F7;
}
.fn-share-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: 2px solid #667eea;
    border-radius: 20px;
    background: transparent;
    color: #667eea;
    font-family: 'Nunito', sans-serif;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}
.fn-share-btn:hover {
    background: #667eea;
    color: white;
    transform: translateY(-1px);
}

/* Mobile field note action bar */
.fn-action-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid #EDF2F7;
}
.fn-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 16px;
    border: 1.5px solid #E2E8F0;
    border-radius: 20px;
    background: white;
    color: #4A5568;
    font-family: 'Nunito', sans-serif;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}
.fn-action-btn:active {
    background: #F7FAFC;
    transform: scale(0.97);
}

/* Share toast notification */
.share-toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #2D3748;
    color: white;
    padding: 12px 24px;
    border-radius: 12px;
    font-family: 'Nunito', sans-serif;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    z-index: 99999;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}
.share-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Profile share button */
.profile-share-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    border: 2px solid white;
    border-radius: 20px;
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(4px);
    color: white;
    font-family: 'Nunito', sans-serif;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 10px;
}
.profile-share-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: translateY(-1px);
}

/* PWA Install Banner */
.pwa-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #E2E8F0;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.1);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    z-index: 9998;
    transform: translateY(100%);
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-family: 'Nunito', sans-serif;
}
.pwa-install-banner.visible {
    transform: translateY(0);
}
.pwa-install-banner .pwa-icon {
    font-size: 36px;
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}
.pwa-install-banner .pwa-text {
    flex: 1;
    min-width: 0;
}
.pwa-install-banner .pwa-title {
    font-weight: 800;
    font-size: 15px;
    color: #1A202C;
    line-height: 1.2;
}
.pwa-install-banner .pwa-sub {
    font-size: 12px;
    color: #718096;
    margin-top: 2px;
    line-height: 1.3;
}
.pwa-install-banner .pwa-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.pwa-install-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    font-family: 'Nunito', sans-serif;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}
.pwa-install-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
}
.pwa-dismiss-btn {
    padding: 8px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #A0AEC0;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1;
}
.pwa-dismiss-btn:hover {
    background: #F7FAFC;
    color: #4A5568;
}
.pwa-ios-hint {
    font-size: 12px;
    color: #4A5568;
    line-height: 1.5;
    margin-top: 4px;
}
.pwa-ios-hint strong {
    color: #1A202C;
}
@media (max-width: 600px) {
    .pwa-install-banner {
        padding: 14px 16px;
        gap: 10px;
    }
    .pwa-install-banner .pwa-icon {
        width: 40px;
        height: 40px;
        font-size: 28px;
        border-radius: 10px;
    }
    .pwa-install-banner .pwa-title { font-size: 14px; }
    .pwa-install-btn { padding: 8px 16px; font-size: 13px; }
}

.field-note-title {
    font-family: 'Fredoka One', cursive;
    font-size: 16px;
    margin-bottom: 8px;
    color: var(--text-dark);
}

.field-note-body {
    font-size: 13px;
    line-height: 1.7;
    color: #4A5568;
    font-weight: 600;
    margin-bottom: 10px;
}

/* Legacy field-note-fact (kept for compat) */
.field-note-fact {
    font-size: 12px;
    font-weight: 700;
    color: #B7791F;
    background: #FEFCE8;
    padding: 8px 12px;
    border-radius: 10px;
    margin-bottom: 8px;
}
.field-note-fact::before { content: '💡 '; }

/* ===== EMOJI STORY STRIP — visual summary for pre-readers ===== */
.fn-emoji-strip {
    font-size: 28px;
    text-align: center;
    letter-spacing: 6px;
    padding: 8px 0 4px;
    line-height: 1.3;
}

/* ===== "DID YOU KNOW?" EDUCATIONAL CALLOUT ===== */
.fn-did-you-know {
    background: linear-gradient(135deg, #FEFCE8, #FFF8E1);
    border: 2px solid #F6E05E;
    border-radius: 12px;
    padding: 10px 14px;
    margin-top: 8px;
    margin-bottom: 6px;
}
.fn-dyk-label {
    font-family: 'Fredoka One', cursive;
    font-size: 12px;
    color: #B7791F;
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}
.fn-dyk-text {
    font-size: 12px;
    font-weight: 700;
    color: #975A16;
    line-height: 1.5;
}

/* ===== "LAST SIGNAL" — makes it feel alive ===== */
.fn-last-seen {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-light);
    text-align: right;
    padding-top: 4px;
    opacity: 0.7;
}

.field-note-region {
    font-size: 11px;
    color: var(--text-light);
    font-weight: 700;
}

/* ===== ADVENTURE LOG ===== */
.adventure-section {
    padding: 18px 20px;
    border-bottom: 1px solid #EDF2F7;
}

.section-title {
    font-family: 'Fredoka One', cursive;
    font-size: 16px;
    color: var(--text-dark);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.log-entry {
    display: flex;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid #F7FAFC;
    animation: fadeIn 0.5s ease;
}
.log-entry:last-child { border-bottom: none; }

.log-time {
    font-size: 11px;
    color: var(--text-light);
    font-weight: 700;
    min-width: 50px;
    padding-top: 2px;
}
.log-icon { font-size: 18px; }
.log-text {
    font-size: 13px;
    color: var(--text-dark);
    font-weight: 600;
    line-height: 1.4;
}
.log-animal { font-weight: 800; }

/* ===== MAP ===== */
.map-container { position: relative; }
#map { width: 100%; height: 100%; }

.leaflet-popup-content-wrapper {
    border-radius: 16px !important;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15) !important;
    padding: 0 !important;
}
.leaflet-popup-content { margin: 0 !important; min-width: 220px; }

.popup-content { padding: 16px; text-align: center; }
.popup-emoji { font-size: 40px; margin-bottom: 8px; }
.popup-name { font-family: 'Fredoka One', cursive; font-size: 20px; margin-bottom: 4px; }
.popup-species { font-size: 13px; color: var(--text-light); font-weight: 600; margin-bottom: 10px; }
.popup-location {
    font-size: 12px;
    color: var(--text-dark);
    font-weight: 700;
    background: #F7FAFC;
    padding: 8px;
    border-radius: 8px;
}

/* Map Markers (inline grad/color from JS) */
.animal-marker { background: none; border: none; }
.marker-inner { position: relative; width: 48px; height: 48px; }
.marker-icon {
    width: 48px; height: 48px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 26px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.25);
    border: 3px solid white;
    position: relative; z-index: 2;
    transition: transform 0.3s ease;
}
.marker-icon:hover { transform: scale(1.15); }

.marker-ripple {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 48px; height: 48px;
    border-radius: 50%;
    z-index: 1;
    animation: ripple 3s ease-out infinite;
}

/* ===== MAP OVERLAY BUTTONS ===== */
.map-overlay {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 1000;
}

.overlay-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 25px;
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    color: white;
}
.overlay-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}
.overlay-btn.all { background: linear-gradient(135deg, var(--accent), var(--accent2)); }
.overlay-btn.trail-btn { background: linear-gradient(135deg, #68D391, #48BB78); }
.trail-btn.active {
    background: linear-gradient(135deg, #48BB78, #38A169);
    box-shadow: 0 0 0 3px rgba(72,187,120,0.4), 0 4px 15px rgba(0,0,0,0.15);
}

/* ===== FUN FACTS TICKER ===== */
.fun-facts-bar {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    color: white;
    padding: 8px 0;
    overflow: hidden;
    position: relative;
}
.facts-track {
    display: flex;
    animation: scroll 30s linear infinite;
    white-space: nowrap;
}
.fact-item {
    padding: 0 40px;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}

/* ===== PROFILE MODAL ===== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(4px);
}
.modal-overlay.active { opacity: 1; pointer-events: all; }

.profile-modal {
    background: white;
    border-radius: 24px;
    width: 520px;
    max-width: 92vw;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: 0 25px 60px rgba(0,0,0,0.3);
    transform: translateY(30px) scale(0.95);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-overlay.active .profile-modal { transform: translateY(0) scale(1); }
.profile-modal::-webkit-scrollbar { width: 6px; }
.profile-modal::-webkit-scrollbar-thumb { background: #CBD5E0; border-radius: 3px; }

.profile-hero {
    padding: 32px 28px 24px;
    text-align: center;
    position: relative;
    border-radius: 24px 24px 0 0;
}

.profile-close {
    position: absolute;
    top: 16px; right: 16px;
    width: 36px; height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.8);
    font-size: 18px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.profile-close:hover { background: white; transform: scale(1.1); }

.profile-avatar {
    width: 90px; height: 90px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 48px;
    margin: 0 auto 16px;
    border: 4px solid white;
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.profile-name {
    font-family: 'Fredoka One', cursive;
    font-size: 28px;
    margin-bottom: 4px;
}

.profile-species-line {
    font-size: 15px;
    color: var(--text-light);
    font-weight: 700;
    margin-bottom: 12px;
}

.profile-traits {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.trait-badge {
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 800;
    background: rgba(255,255,255,0.7);
    backdrop-filter: blur(4px);
}

.profile-body { padding: 24px 28px 28px; }
.profile-section { margin-bottom: 22px; }
.profile-section:last-child { margin-bottom: 0; }

.profile-section-title {
    font-family: 'Fredoka One', cursive;
    font-size: 17px;
    color: var(--text-dark);
    margin-bottom: 10px;
    display: flex; align-items: center; gap: 8px;
}

.backstory-text {
    font-size: 14px;
    line-height: 1.7;
    color: #4A5568;
    font-weight: 600;
    background: #F7FAFC;
    padding: 14px 16px;
    border-radius: 14px;
    border-left: 4px solid #E2E8F0;
}

/* Quick Facts */
.quick-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quick-fact { background: #F7FAFC; padding: 10px 12px; border-radius: 12px; text-align: center; }
.quick-fact-label {
    font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
    font-weight: 700; color: var(--text-light); margin-bottom: 4px;
}
.quick-fact-value { font-size: 14px; font-weight: 800; }

/* Family Tree */
.family-tree { display: flex; flex-direction: column; gap: 10px; }
.family-row { display: flex; gap: 10px; flex-wrap: wrap; }
.family-row.parents { justify-content: center; }
.family-row.siblings { justify-content: center; }
.family-connector { text-align: center; color: #CBD5E0; font-size: 18px; line-height: 1; }

.family-member {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px;
    background: #F7FAFC;
    border-radius: 14px;
    flex: 0 1 auto;
    min-width: 0;
    transition: all 0.2s ease;
}
.family-member:hover { background: #EDF2F7; transform: translateY(-1px); }
.family-member.self { border: 2px dashed #CBD5E0; }

.family-emoji { font-size: 28px; flex-shrink: 0; }
.family-details { min-width: 0; }
.family-name { font-weight: 800; font-size: 14px; color: var(--text-dark); }
.family-role { font-size: 11px; color: var(--text-light); font-weight: 700; }
.family-desc { font-size: 11px; color: #A0AEC0; font-weight: 600; font-style: italic; }

/* ===== WIZARD ===== */
.wizard-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 3000;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(6px);
}
.wizard-overlay.active { opacity: 1; pointer-events: all; }

.wizard-modal {
    background: white;
    border-radius: 28px;
    width: 580px;
    max-width: 94vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 30px 80px rgba(0,0,0,0.35);
    transform: translateY(30px) scale(0.95);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.wizard-overlay.active .wizard-modal { transform: translateY(0) scale(1); }
.wizard-modal::-webkit-scrollbar { width: 6px; }
.wizard-modal::-webkit-scrollbar-thumb { background: #CBD5E0; border-radius: 3px; }

.wizard-header { padding: 28px 28px 0; text-align: center; }

.wizard-close {
    position: absolute;
    top: 16px; right: 16px;
    width: 36px; height: 36px;
    border-radius: 50%; border: none;
    background: #F7FAFC; font-size: 18px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s ease; z-index: 10;
}
.wizard-close:hover { background: #EDF2F7; transform: scale(1.1); }

.wizard-step-indicator { display: flex; justify-content: center; gap: 8px; margin-bottom: 20px; }
.step-dot {
    width: 10px; height: 10px;
    border-radius: 50%; background: #E2E8F0;
    transition: all 0.3s ease;
}
.step-dot.active { background: linear-gradient(135deg, var(--accent), var(--accent2)); width: 28px; border-radius: 5px; }
.step-dot.completed { background: #48BB78; }

.wizard-body { padding: 20px 28px 28px; position: relative; }
.wizard-step { display: none; animation: fadeIn 0.4s ease; }
.wizard-step.active { display: block; }

.wizard-title {
    font-family: 'Fredoka One', cursive;
    font-size: 24px; color: var(--text-dark);
    margin-bottom: 6px; text-align: center;
}
.wizard-subtitle {
    font-size: 14px; color: var(--text-light);
    font-weight: 600; text-align: center; margin-bottom: 24px;
}

/* Scan Step */
.scan-area { display: flex; flex-direction: column; align-items: center; padding: 30px 0; }
.tag-icon { font-size: 80px; margin-bottom: 20px; animation: float 3s ease-in-out infinite; }
.scan-ring {
    width: 160px; height: 160px;
    border-radius: 50%; border: 4px dashed var(--accent);
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 24px; animation: spinSlow 8s linear infinite;
    position: relative;
}
.scan-ring .tag-icon { animation: none; }
.scan-btn {
    padding: 14px 36px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: white; border: none; border-radius: 16px;
    font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 16px;
    cursor: pointer; transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}
.scan-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5); }
.scan-detected { display: none; flex-direction: column; align-items: center; gap: 10px; }
.scan-detected.show { display: flex; animation: fadeIn 0.5s ease; }
.scan-checkmark {
    width: 60px; height: 60px; border-radius: 50%;
    background: #48BB78;
    display: flex; align-items: center; justify-content: center;
    font-size: 30px; color: white;
    animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.scan-detected-text { font-weight: 800; font-size: 18px; color: #48BB78; }

/* Reconnect */
.reconnect-section { margin-top: 20px; text-align: center; }
.reconnect-link {
    font-size: 13px; color: var(--accent); font-weight: 700;
    cursor: pointer; text-decoration: underline;
}
.reconnect-link:hover { color: var(--accent2); }
.reconnect-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.reconnect-item {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 18px; border-radius: 14px;
    border: 2px solid #EDF2F7; background: white;
    cursor: pointer; transition: all 0.2s ease;
}
@media (hover: hover) {
    .reconnect-item:hover { border-color: var(--accent); background: #F7FAFC; transform: translateY(-1px); }
}
.reconnect-item-emoji { font-size: 32px; }
.reconnect-item-name { font-weight: 800; font-size: 15px; }
.reconnect-item-species { font-size: 12px; color: var(--text-light); font-weight: 600; }

/* Species Grid */
.species-grid {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 10px; max-height: 380px; overflow-y: auto; padding: 4px;
}
.species-grid::-webkit-scrollbar { width: 5px; }
.species-grid::-webkit-scrollbar-thumb { background: #CBD5E0; border-radius: 3px; }
.species-option {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 14px 8px; border-radius: 16px;
    border: 2px solid #EDF2F7; cursor: pointer;
    transition: all 0.2s ease; background: white;
    -webkit-tap-highlight-color: transparent; /* prevent blue flash on mobile scroll */
    -webkit-touch-callout: none;
    user-select: none;
}
@media (hover: hover) {
    .species-option:hover { border-color: var(--accent); background: #F7FAFC; transform: translateY(-2px); }
}
.species-option.selected {
    border-color: var(--accent); background: #EBF4FF;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}
.species-emoji { font-size: 42px; }
.species-label { font-size: 10px; font-weight: 800; color: var(--text-light); text-align: center; line-height: 1.2; }

/* Name Input */
.name-input-area { text-align: center; padding: 20px 0; }
.name-preview-emoji { font-size: 64px; margin-bottom: 16px; }
.name-input {
    width: 100%; max-width: 320px;
    padding: 14px 20px; border: 3px solid #E2E8F0;
    border-radius: 16px; font-family: 'Nunito', sans-serif;
    font-size: 20px; font-weight: 800; text-align: center;
    color: var(--text-dark); outline: none;
    transition: border-color 0.3s ease;
}
.name-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15); }
.name-input::placeholder { color: #CBD5E0; font-weight: 600; }
.name-suggestions-label {
    font-size: 12px; font-weight: 700; color: var(--text-light);
    margin-top: 16px; margin-bottom: 6px; text-align: center;
}
.name-suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.name-suggestion {
    padding: 6px 14px; border-radius: 20px;
    border: 2px solid #EDF2F7; background: white;
    font-size: 13px; font-weight: 700; color: var(--text-light);
    cursor: pointer; transition: all 0.2s ease;
}
.name-suggestion.selected {
    border-color: var(--accent); background: var(--accent); color: white;
}
@media (hover: hover) {
    .name-suggestion:hover { border-color: var(--accent); color: var(--accent); background: #EBF4FF; }
    .name-suggestion.selected:hover { color: white; background: var(--accent); }
}

/* Personality Picker — Categorized */
.personality-categories-scroll {
    max-height: 45vh;
    overflow-y: auto;
    padding: 4px 0;
    -webkit-overflow-scrolling: touch;
}
.trait-category {
    margin-bottom: 14px;
}
.trait-category-label {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    padding-left: 4px;
}
.trait-category-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.personality-grid { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 10px 0; }
.personality-chip {
    padding: 7px 14px; border-radius: 20px;
    border: 2px solid #EDF2F7; background: white;
    font-size: 13px; font-weight: 700; color: var(--text-dark);
    cursor: pointer; transition: all 0.2s ease; user-select: none;
}
@media (hover: hover) {
    .personality-chip:hover { border-color: var(--accent); transform: translateY(-1px); }
}
.personality-chip.selected {
    border-color: var(--accent); background: var(--accent); color: white;
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

/* Selected traits preview */
.selected-traits-preview {
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    color: var(--accent);
    padding: 8px 16px;
    margin-bottom: 8px;
    background: rgba(102, 126, 234, 0.08);
    border-radius: 12px;
    line-height: 1.4;
}

.personality-count {
    text-align: center; font-size: 13px; font-weight: 700;
    color: var(--text-light); margin-top: 10px;
    padding: 6px 0;
    position: sticky; bottom: 0; background: white;
}

/* Generating Animation */
.generating-area { text-align: center; padding: 40px 0; }
.generating-spinner {
    width: 80px; height: 80px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    display: flex; align-items: center; justify-content: center;
    font-size: 40px; margin: 0 auto 24px;
    animation: pulse 1.5s ease-in-out infinite;
}
.generating-steps { list-style: none; text-align: left; max-width: 300px; margin: 0 auto; }
.generating-steps li {
    padding: 8px 0; font-weight: 700; font-size: 14px;
    color: #CBD5E0; display: flex; align-items: center; gap: 10px;
    transition: color 0.3s ease;
}
.generating-steps li.done { color: #48BB78; }
.generating-steps li.active { color: var(--accent); }

.gen-check {
    width: 22px; height: 22px; border-radius: 50%;
    border: 2px solid currentColor;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; flex-shrink: 0;
}
.gen-check.done { background: #48BB78; border-color: #48BB78; color: white; }
.gen-check.active { border-color: var(--accent); animation: pulse 1s ease-in-out infinite; }

/* Wizard Navigation */
.wizard-nav { display: flex; justify-content: space-between; padding: 20px 28px 24px; gap: 12px; }
.wizard-nav-btn {
    padding: 12px 28px; border-radius: 14px;
    font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 15px;
    cursor: pointer; transition: all 0.3s ease; border: none;
}
.wizard-nav-btn:hover { transform: translateY(-1px); }
.wizard-nav-btn.secondary { background: #EDF2F7; color: var(--text-light); }
.wizard-nav-btn.secondary:hover { background: #E2E8F0; }
.wizard-nav-btn.primary {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: white; box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}
.wizard-nav-btn.primary:hover { box-shadow: 0 6px 18px rgba(102, 126, 234, 0.4); }
.wizard-nav-btn.primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.wizard-nav-btn.success {
    background: linear-gradient(135deg, #48BB78, #38A169);
    color: white; box-shadow: 0 4px 12px rgba(72, 187, 120, 0.3);
}
.wizard-nav-btn.success:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ===== ANIMATIONS ===== */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}
@keyframes glow {
    0%, 100% { box-shadow: 0 0 8px rgba(72, 187, 120, 0.4); }
    50% { box-shadow: 0 0 16px rgba(72, 187, 120, 0.7); }
}
@keyframes glowGold {
    0%, 100% { box-shadow: 0 2px 10px rgba(236, 201, 75, 0.4); }
    50% { box-shadow: 0 4px 20px rgba(236, 201, 75, 0.7); }
}
@keyframes glowPurple {
    0%, 100% { box-shadow: 0 2px 10px rgba(102, 126, 234, 0.4); }
    50% { box-shadow: 0 4px 20px rgba(102, 126, 234, 0.7); }
}
@keyframes ping {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(72,187,120,0.4); }
    50% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(72,187,120,0); }
}
@keyframes ripple {
    0% { width: 48px; height: 48px; opacity: 1; }
    100% { width: 100px; height: 100px; opacity: 0; }
}
@keyframes scroll {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}
@keyframes spinSlow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
@keyframes popIn {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

/* ===== WELCOME HERO OVERLAY ===== */
.welcome-hero {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.6s ease, transform 0.6s ease;
}
.welcome-hero.dismissed {
    opacity: 0;
    transform: scale(1.05);
    pointer-events: none;
}
.welcome-hero.hidden { display: none; }

.welcome-bg {
    position: absolute;
    inset: 0;
    background: linear-gradient(150deg, #1a1a2e 0%, #16213e 25%, #0f3460 50%, #533483 75%, #7c3aed 100%);
    z-index: 0;
}
.welcome-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 30% 20%, rgba(102,126,234,0.3) 0%, transparent 60%),
                radial-gradient(ellipse at 70% 80%, rgba(118,75,162,0.3) 0%, transparent 60%);
}

.welcome-content {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 40px 24px;
    max-width: 480px;
    width: 100%;
}

.welcome-floating-emojis {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}

.welcome-float-emoji {
    position: absolute;
    font-size: 48px;
    opacity: 0;
    animation: welcomeFloat 6s ease-in-out infinite;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,0.3));
}

.welcome-text {
    position: relative;
    z-index: 1;
}

.welcome-logo {
    font-family: 'Fredoka One', cursive;
    font-size: 22px;
    color: rgba(255,255,255,0.6);
    margin-bottom: 20px;
    letter-spacing: 1px;
}

.welcome-headline {
    font-family: 'Fredoka One', cursive;
    font-size: 36px;
    color: white;
    line-height: 1.2;
    margin-bottom: 16px;
    text-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.welcome-sub {
    font-size: 18px;
    color: rgba(255,255,255,0.8);
    font-weight: 600;
    margin-bottom: 40px;
}

.welcome-cta {
    background: linear-gradient(135deg, #F6E05E, #ECC94B);
    color: #744210;
    border: none;
    padding: 16px 36px;
    border-radius: 50px;
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(236, 201, 75, 0.5);
    transition: all 0.3s ease;
    animation: welcomeCtaPulse 2s ease-in-out infinite;
    position: relative;
    z-index: 1;
}
.welcome-cta:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 30px rgba(236, 201, 75, 0.7);
}

.welcome-hint {
    margin-top: 16px;
    font-size: 13px;
    color: rgba(255,255,255,0.4);
    font-weight: 600;
    position: relative;
    z-index: 1;
}

@keyframes welcomeFloat {
    0%   { opacity: 0; transform: translateY(100vh) rotate(0deg) scale(0.8); }
    10%  { opacity: 0.7; }
    50%  { opacity: 0.9; transform: translateY(30vh) rotate(15deg) scale(1.1); }
    90%  { opacity: 0.5; }
    100% { opacity: 0; transform: translateY(-20vh) rotate(-10deg) scale(0.9); }
}

@keyframes welcomeCtaPulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(236, 201, 75, 0.5); }
    50% { box-shadow: 0 4px 30px rgba(236, 201, 75, 0.8), 0 0 60px rgba(236, 201, 75, 0.3); }
}

/* ===== SPARKLE BURST ON MAP MARKER ===== */
.marker-sparkle {
    position: absolute;
    top: 50%; left: 50%;
    width: 80px; height: 80px;
    margin-left: -40px;
    margin-top: -40px;
    pointer-events: none;
    z-index: 3;
}

.sparkle-particle {
    position: absolute;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #F6E05E;
    top: 50%; left: 50%;
    animation: sparkleBurst 0.8s ease-out forwards;
}

.sparkle-particle:nth-child(1)  { --sx: -20px; --sy: -30px; animation-delay: 0s; background: #F6E05E; }
.sparkle-particle:nth-child(2)  { --sx:  25px; --sy: -25px; animation-delay: 0.05s; background: #FC8181; }
.sparkle-particle:nth-child(3)  { --sx:  30px; --sy:  10px; animation-delay: 0.1s; background: #68D391; }
.sparkle-particle:nth-child(4)  { --sx: -25px; --sy:  20px; animation-delay: 0.15s; background: #63B3ED; }
.sparkle-particle:nth-child(5)  { --sx:   0px; --sy: -35px; animation-delay: 0.05s; background: #B794F4; }
.sparkle-particle:nth-child(6)  { --sx:  15px; --sy:  28px; animation-delay: 0.1s; background: #F6AD55; }
.sparkle-particle:nth-child(7)  { --sx: -30px; --sy:   5px; animation-delay: 0s; background: #FEB2B2; }
.sparkle-particle:nth-child(8)  { --sx:  10px; --sy: -20px; animation-delay: 0.08s; background: #9AE6B4; }

.sparkle-star {
    position: absolute;
    top: 50%; left: 50%;
    font-size: 16px;
    animation: sparkleStarBurst 0.9s ease-out forwards;
}
.sparkle-star:nth-child(9)  { --sx: -18px; --sy: -28px; animation-delay: 0s; }
.sparkle-star:nth-child(10) { --sx:  22px; --sy: -18px; animation-delay: 0.06s; }
.sparkle-star:nth-child(11) { --sx:  28px; --sy:  15px; animation-delay: 0.12s; }
.sparkle-star:nth-child(12) { --sx: -22px; --sy:  22px; animation-delay: 0.04s; }

@keyframes sparkleBurst {
    0% { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--sx), var(--sy)) scale(0); opacity: 0; }
}

@keyframes sparkleStarBurst {
    0% { transform: translate(0, 0) scale(0.5) rotate(0deg); opacity: 1; }
    50% { opacity: 1; }
    100% { transform: translate(var(--sx), var(--sy)) scale(1.2) rotate(180deg); opacity: 0; }
}

/* Ring burst */
.marker-ring-burst {
    position: absolute;
    top: 50%; left: 50%;
    width: 10px; height: 10px;
    margin-left: -5px; margin-top: -5px;
    border-radius: 50%;
    border: 3px solid var(--c, #F6E05E);
    pointer-events: none;
    z-index: 3;
    animation: ringBurst 0.7s ease-out forwards;
}

@keyframes ringBurst {
    0% { width: 10px; height: 10px; margin-left: -5px; margin-top: -5px; opacity: 1; border-width: 3px; }
    100% { width: 80px; height: 80px; margin-left: -40px; margin-top: -40px; opacity: 0; border-width: 1px; }
}

/* ===== RESPONSIVE — MOBILE ===== */
@media (max-width: 768px) {
    body { height: 100vh; height: 100dvh; /* dvh: iOS 15.4+; vh fallback for older */ }

    /* ---- iOS safe areas ---- */
    .header {
        padding: 8px 12px;
        padding-top: max(8px, env(safe-area-inset-top));
    }
    .sidebar {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* Header: single-line compact toolbar */
    .logo { font-size: 18px; gap: 4px; }
    .logo-icon { font-size: 18px; }
    .header-subtitle { display: none; }
    .header-right { gap: 6px; }
    .activate-btn { padding: 4px 10px; font-size: 10px; gap: 3px; }
    .live-badge { padding: 3px 8px; font-size: 9px; gap: 4px; }
    .live-dot { width: 6px; height: 6px; }

    /* Fun facts ticker: smaller */
    .fun-facts-bar { padding: 5px 0; }
    .fact-item { font-size: 11px; padding: 0 24px; }

    /* Main layout: map fills screen, sidebar is a bottom sheet */
    .app-container {
        display: flex;
        flex-direction: column;
        position: relative;
    }

    .map-container {
        flex: 1;
        order: 1;
        min-height: 0;
    }

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

    /* Map overlay: sits above the collapsed bottom sheet */
    .map-overlay {
        bottom: 150px;
        gap: 8px;
        transition: bottom 0.35s ease;
    }
    /* When detail-view is active, push overlay above the taller sheet */
    .sidebar.detail-view ~ .map-container .map-overlay {
        bottom: calc(45dvh + 10px);
    }
    .overlay-btn { padding: 8px 14px; font-size: 12px; gap: 4px; }

    /* ---- Sidebar → Bottom Sheet ---- */
    .sidebar {
        order: 2;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1500;
        border-right: none;
        border-top: none;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -4px 30px rgba(0,0,0,0.15);
        max-height: 75vh;   /* fallback */
        max-height: 75dvh;
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        overflow: hidden;
        display: flex;
        flex-direction: column;
        background: var(--card-bg);
    }

    /* Collapsed: show only the drag handle + compact card strip */
    .sidebar.collapsed {
        transform: translateY(calc(100% - 140px));
    }

    /* Detail view: field note replaces card strip, capped height so marker stays visible */
    .sidebar.detail-view {
        max-height: 45vh;   /* fallback */
        max-height: 45dvh;  /* iOS 15.4+ */
    }
    .sidebar.detail-view #animalCards { display: none; }
    /* In browse mode (no detail-view), hide the inner scrollable content on mobile */
    .sidebar:not(.detail-view) .sidebar-inner { display: none; }

    /* Drag handle — visible tap/swipe target */
    .sidebar::before {
        content: '';
        display: block;
        width: 40px;
        height: 5px;
        background: #CBD5E0;
        border-radius: 3px;
        margin: 10px auto 6px;
        flex-shrink: 0;
        cursor: grab;
    }

    .sidebar-inner {
        overflow-y: auto;
        flex: 1;
        min-height: 0;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain; /* prevent iOS rubber-band pulling entire page */
    }

    /* ---- Animal cards: horizontal scroll strip ---- */
    #animalCards {
        display: flex;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        gap: 0;
        padding-bottom: 2px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-shrink: 0;
    }
    #animalCards::-webkit-scrollbar { display: none; }

    .animal-card {
        min-width: 260px;
        max-width: 300px;
        flex-shrink: 0;
        scroll-snap-align: start;
        border-bottom: none;
        border-right: 1px solid #EDF2F7;
        padding: 10px 14px;
    }
    .animal-card:last-child { border-right: none; }
    .animal-card::before { display: none; }

    .card-header { margin-bottom: 6px; gap: 10px; }
    .animal-avatar { width: 44px; height: 44px; font-size: 24px; border-radius: 12px; }
    .animal-info h3 { font-size: 16px; }
    .animal-species { font-size: 12px; }

    .card-stats { gap: 4px; margin-bottom: 6px; }
    .stat { padding: 4px 6px; }
    .stat-label { font-size: 9px; }
    .stat-value { font-size: 11px; }

    .animal-status { padding: 5px 10px; font-size: 11px; }
    .card-actions { gap: 6px; margin-top: 6px; }
    .map-btn, .meet-btn { padding: 8px 5px; font-size: 11px; min-height: 36px; } /* larger touch target */

    /* ---- Back button in detail view ---- */
    .fn-back {
        display: flex;
        align-items: center;
        gap: 4px;
        font-size: 13px;
        font-weight: 700;
        color: var(--accent, #667eea);
        padding: 6px 0 2px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    /* ---- Field Note: clean "postcard" style ---- */
    .field-note-section {
        padding: 10px 12px;
        border-top: none;
    }
    .field-note-card {
        padding: 14px;
        border-radius: 14px;
    }
    .field-note-title { font-size: 15px; margin-bottom: 6px; }
    .field-note-body { font-size: 13px; line-height: 1.6; margin-bottom: 8px; }
    .field-note-fact { font-size: 11px; padding: 6px 10px; margin-bottom: 0; }
    .fn-did-you-know { padding: 8px 12px; margin-top: 6px; }
    .fn-dyk-label { font-size: 11px; }
    .fn-dyk-text { font-size: 11px; }

    /* Postcard header — compact row with name + location */
    .fn-postcard-header {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 6px;
        margin-bottom: 6px;
    }
    .fn-postcard-from {
        font-weight: 800;
        font-size: 14px;
        color: var(--text-dark);
    }
    .fn-postcard-location {
        font-size: 11px;
        color: var(--text-light);
        font-weight: 700;
    }
    .fn-profile-link {
        margin-left: auto;
        font-size: 12px;
        font-weight: 800;
        color: var(--accent, #667eea);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        white-space: nowrap;
    }

    /* ---- Adventure log ---- */
    .adventure-section { padding: 12px 14px; }
    .log-entry { padding: 6px 0; }
    .log-text { font-size: 12px; }

    /* ---- Wizard: slide-up sheet on mobile ---- */
    .wizard-modal {
        width: 100%;
        max-width: 100vw;
        max-height: 96vh;
        max-height: 96dvh;
        border-radius: 20px 20px 0 0;
        margin-top: auto;
    }
    .wizard-overlay.active { align-items: flex-end; }
    .wizard-body { padding: 16px 20px 20px; }
    .wizard-nav {
        padding: 16px 20px;
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
    .species-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .species-emoji { font-size: 36px; }
    .species-label { font-size: 9px; color: var(--text-light); }
    .species-option { padding: 12px 6px; }
    .fn-emoji-strip { font-size: 24px; letter-spacing: 4px; padding: 6px 0 2px; }
    .scan-ring { width: 120px; height: 120px; }
    .tag-icon { font-size: 60px; }
    .name-input { font-size: 18px; padding: 12px 16px; }
    .personality-chip { padding: 6px 12px; font-size: 12px; }

    /* ---- Profile modal: slide-up sheet ---- */
    .profile-modal {
        width: 100%;
        max-width: 100vw;
        max-height: 96vh;
        max-height: 96dvh;
        border-radius: 20px 20px 0 0;
    }
    .modal-overlay.active { align-items: flex-end; }
    .profile-hero { padding: 24px 20px 18px; }
    .profile-body {
        padding: 18px 20px;
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }
    .profile-avatar { width: 70px; height: 70px; font-size: 36px; }
    .profile-name { font-size: 24px; }
    .quick-facts { grid-template-columns: 1fr 1fr; gap: 6px; }
    .family-member { padding: 8px 10px; }
    .family-emoji { font-size: 22px; }
    .family-name { font-size: 13px; }
    .backstory-text { font-size: 13px; padding: 10px 12px; }

    /* ---- Welcome hero: mobile tweaks ---- */
    .welcome-headline { font-size: 28px; }
    .welcome-sub { font-size: 15px; margin-bottom: 32px; }
    .welcome-cta { padding: 14px 28px; font-size: 16px; }
    .welcome-float-emoji { font-size: 36px; }
    .welcome-logo { font-size: 18px; margin-bottom: 16px; }

    /* ---- Map attribution: compact on mobile ---- */
    .leaflet-control-attribution {
        font-size: 8px !important;
        padding: 1px 4px !important;
        background: rgba(255,255,255,0.6) !important;
    }

    /* ---- Map markers: smaller on mobile ---- */
    .marker-inner { width: 40px; height: 40px; }
    .marker-icon { width: 40px; height: 40px; font-size: 22px; border-width: 2px; }
    .marker-ripple { width: 40px; height: 40px; }

    /* ---- Map popups: narrower ---- */
    .leaflet-popup-content { min-width: 180px; }
    .popup-emoji { font-size: 32px; }
    .popup-name { font-size: 17px; }
    .popup-location { font-size: 11px; }
}

/* ===================================================================
   BUSINESS FEATURES — Streaks, Resting, Teasers, Passport, Upgrade
   =================================================================== */

/* ===== STREAK BADGE ===== */
.streak-badge {
    font-size: 11px;
    font-weight: 800;
    margin-left: 4px;
    white-space: nowrap;
}

/* ===== RESTING MAP MARKERS ===== */
.marker-resting {
    opacity: 0.4;
    filter: grayscale(50%);
}

/* ===== CARD TEASER (story preview) ===== */
.card-teaser {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    padding: 4px 12px 2px;
    line-height: 1.4;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* ===== RESTING STATE ===== */
.animal-card.resting {
    opacity: 0.6;
    filter: grayscale(30%);
}
.animal-card.resting .card-header {
    opacity: 0.8;
}
.resting-avatar {
    position: relative;
}
.resting-avatar::after {
    content: '💤';
    position: absolute;
    top: -4px;
    right: -4px;
    font-size: 14px;
}
.resting-message {
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-light);
    padding: 8px 12px;
}
.resting-cta {
    text-align: center;
    padding: 4px 12px 8px;
}
.wake-btn {
    background: linear-gradient(135deg, #F6E05E, #ECC94B);
    color: #744210;
    border: none;
    border-radius: 12px;
    padding: 8px 20px;
    font-family: 'Nunito', sans-serif;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
}
@media (hover: hover) {
    .wake-btn:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(236, 201, 75, 0.4);
    }
}

/* ===== RESTING FIELD NOTE ===== */
.resting-field-note {
    text-align: center;
    padding: 24px 16px;
}
.resting-fn-title {
    font-family: 'Fredoka One', cursive;
    font-size: 18px;
    color: var(--text-dark);
    margin-bottom: 8px;
}
.resting-fn-body {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    line-height: 1.6;
    margin-bottom: 16px;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}
.wake-btn-lg {
    background: linear-gradient(135deg, #F6E05E, #ECC94B);
    color: #744210;
    border: none;
    border-radius: 16px;
    padding: 12px 28px;
    font-family: 'Nunito', sans-serif;
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-block;
}
@media (hover: hover) {
    .wake-btn-lg:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 16px rgba(236, 201, 75, 0.5);
    }
}
.resting-fn-or {
    font-size: 12px;
    font-weight: 700;
    color: #CBD5E0;
    margin: 10px 0;
}
.upgrade-btn-sm {
    background: none;
    border: 2px solid var(--accent);
    color: var(--accent);
    border-radius: 12px;
    padding: 8px 20px;
    font-family: 'Nunito', sans-serif;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
}
@media (hover: hover) {
    .upgrade-btn-sm:hover {
        background: var(--accent);
        color: white;
    }
}

/* ===== PROFILE STREAK ===== */
.profile-streak {
    font-family: 'Fredoka One', cursive;
    font-size: 14px;
    margin-top: 6px;
    opacity: 0.9;
}

/* ===== EXPLORER BADGE ===== */
.explorer-badge {
    font-size: 10px;
    font-weight: 800;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 2px 8px;
    border-radius: 8px;
    margin-left: 8px;
    vertical-align: middle;
    letter-spacing: 0.5px;
}

/* ===== REGION PASSPORT ===== */
.passport-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}
.passport-stamp {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #F0FFF4;
    border: 2px solid #C6F6D5;
    border-radius: 12px;
    padding: 6px 12px;
    transition: transform 0.2s ease;
}
.passport-stamp-emoji {
    font-size: 18px;
}
.passport-stamp-label {
    font-size: 11px;
    font-weight: 700;
    color: #276749;
}
.passport-count {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-light);
    text-align: center;
}
.passport-empty {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    text-align: center;
    padding: 16px;
    line-height: 1.6;
}
.passport-locked {
    text-align: center;
    padding: 16px;
    background: #F7FAFC;
    border-radius: 12px;
    border: 2px dashed #E2E8F0;
}
.passport-locked-text {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    line-height: 1.6;
    margin-bottom: 12px;
}

/* ===== UPGRADE MODAL ===== */
.upgrade-modal {
    background: white;
    border-radius: 24px;
    max-width: 420px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    position: relative;
}
.upgrade-modal-inner {
    padding: 32px 24px;
}
.upgrade-header {
    text-align: center;
    margin-bottom: 24px;
}
.upgrade-title {
    font-family: 'Fredoka One', cursive;
    font-size: 24px;
    color: var(--text-dark);
    margin-bottom: 8px;
}
.upgrade-subtitle {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-light);
    line-height: 1.5;
}

/* Swap section */
.swap-section {
    margin-bottom: 16px;
}
.swap-label {
    font-size: 13px;
    font-weight: 800;
    color: var(--text-dark);
    margin-bottom: 10px;
}
.swap-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.swap-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 2px solid #EDF2F7;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}
@media (hover: hover) {
    .swap-item:hover {
        border-color: var(--accent);
        background: #F7FAFC;
    }
}
.swap-emoji { font-size: 24px; }
.swap-name {
    font-size: 14px;
    font-weight: 800;
    color: var(--text-dark);
    flex: 1;
}
.swap-arrow {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-light);
}

/* Divider */
.upgrade-divider {
    text-align: center;
    margin: 16px 0;
    position: relative;
}
.upgrade-divider::before {
    content: '';
    position: absolute;
    left: 0; right: 0; top: 50%;
    height: 1px;
    background: #E2E8F0;
}
.upgrade-divider span {
    position: relative;
    background: white;
    padding: 0 12px;
    font-size: 12px;
    font-weight: 700;
    color: #CBD5E0;
}

/* CTA section */
.upgrade-cta-section {
    text-align: center;
}
.upgrade-benefits {
    text-align: left;
    margin-bottom: 20px;
}
.upgrade-benefit {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    padding: 6px 0;
    line-height: 1.4;
}
/* Plan toggle (monthly vs annual) */
.plan-toggle {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin: 16px 0;
}
.plan-option {
    flex: 1;
    max-width: 150px;
    border: 2px solid #E2E8F0;
    border-radius: 14px;
    padding: 14px 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    background: white;
}
.plan-option.selected {
    border-color: #667eea;
    background: linear-gradient(135deg, rgba(102,126,234,0.08), rgba(118,75,162,0.08));
    box-shadow: 0 0 0 1px #667eea;
}
.plan-option:not(.selected):active {
    transform: scale(0.97);
}
.plan-price {
    font-family: 'Fredoka One', cursive;
    font-size: 20px;
    color: #2D3748;
}
.plan-label {
    font-size: 12px;
    font-weight: 700;
    color: #718096;
    margin-top: 2px;
}
.plan-badge {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #48BB78, #38A169);
    color: white;
    font-size: 10px;
    font-weight: 800;
    padding: 2px 10px;
    border-radius: 20px;
    white-space: nowrap;
}

.upgrade-btn {
    display: inline-block;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 16px;
    padding: 14px 32px;
    font-family: 'Nunito', sans-serif;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    max-width: 320px;
}
@media (hover: hover) {
    .upgrade-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    }
}
.upgrade-note {
    font-size: 11px;
    font-weight: 700;
    color: #A0AEC0;
    margin-top: 8px;
}

/* ===== SETTINGS ===== */
.settings-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.settings-btn:hover {
    background: rgba(255,255,255,0.3);
}

.settings-modal {
    background: white;
    border-radius: 24px;
    padding: 28px;
    max-width: 440px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.settings-section h3 {
    font-family: 'Fredoka One', cursive;
    font-size: 16px;
    margin-bottom: 8px;
    color: var(--text-dark);
}

.settings-action-btn {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 12px;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: transform 0.2s, box-shadow 0.2s;
}
.settings-action-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102,126,234,0.3);
}
