:root {
    --paper:      #faf7f2;
    --paper-dark: #f0ebe0;
    --ink:        #1c1a16;
    --ink-mid:    #4a443a;
    --ink-light:  #8a8070;
    --green:      #2d6a4f;
    --green-light:#40916c;
    --green-bg:   #d8f3dc;
    --gold:       #b5832a;
    --gold-light: #f4e3c0;
    --rule:       #d6cfc4;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(180deg, var(--paper-dark) 0%, var(--paper) 100%);
    color: var(--ink);
    min-height: 100vh;
}

/* ── TOP BAR ──────────────────────────────────────────── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--green);
    color: #fff;
    box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}

.topbar-inner {
    max-width: 860px;
    margin: 0 auto;
    padding: 0.9rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.2rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    flex-shrink: 0;
}

.brand-icon { font-size: 1.8rem; line-height: 1; }

.brand-title {
    font-family: 'Lora', serif;
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.2;
    color: #fff;
}

.brand-sub {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.65);
    letter-spacing: 0.3px;
}

.search-box {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 8px;
    padding: 0.55rem 1rem;
    transition: background 0.2s, border-color 0.2s;
}
.search-box:focus-within {
    background: rgba(255,255,255,0.25);
    border-color: rgba(255,255,255,0.5);
}
.search-box > svg { color: rgba(255,255,255,0.7); flex-shrink: 0; }

.search-box input {
    background: none;
    border: none;
    outline: none;
    color: #fff;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    width: 100%;
}
.search-box input::placeholder { color: rgba(255,255,255,0.55); }

.search-clear {
    display: none;
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    transition: color 0.15s;
    flex-shrink: 0;
    line-height: 0;
}
.search-clear:hover { color: #fff; }
.search-clear.visible { display: inline-flex; }
.search-clear:focus-visible { outline: 2px solid rgba(255,255,255,0.7); outline-offset: 2px; }

/* ── BACK BUTTON ──────────────────────────────────────── */
.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.45rem 0.75rem;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.25);
    background: rgba(255,255,255,0.1);
    transition: background 0.2s, border-color 0.2s, color 0.2s;
    flex-shrink: 0;
    white-space: nowrap;
}
.back-btn:hover {
    background: rgba(255,255,255,0.2);
    border-color: rgba(255,255,255,0.4);
    color: #fff;
}
.back-btn svg { flex-shrink: 0; }

@media (max-width: 480px) {
    .back-btn span { display: none; }
    .back-btn { padding: 0.45rem; }
}

/* ── PILL BAR ─────────────────────────────────────────── */
.pill-bar {
    position: sticky;
    top: 60px;
    z-index: 90;
    background: var(--paper);
    border-bottom: 1px solid var(--rule);
    overflow: hidden;
}

.pills {
    max-width: 860px;
    margin: 0 auto;
    padding: 0.55rem 1.5rem;
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    scrollbar-width: none;
}
.pills::-webkit-scrollbar { display: none; }

.pill {
    padding: 0.3rem 0.9rem;
    border-radius: 50px;
    border: 1.5px solid var(--rule);
    background: transparent;
    color: var(--ink-light);
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.pill:hover {
    border-color: var(--green);
    color: var(--green);
}
.pill:focus-visible {
    outline: 2px solid var(--green);
    outline-offset: 2px;
}
.pill.active {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
    font-weight: 600;
}
.pill.active:focus-visible {
    outline-color: #fff;
}

/* ── HERO COUNT ────────────────────────────────────────── */
.hero-count {
    max-width: 860px;
    margin: 0 auto;
    padding: 2rem 1.5rem 0.5rem;
    text-align: center;
}

.hero-number {
    display: block;
    font-family: 'Lora', serif;
    font-size: 3.5rem;
    font-weight: 700;
    color: var(--green);
    line-height: 1;
    letter-spacing: -1px;
}

.hero-label {
    display: block;
    font-size: 0.8rem;
    color: var(--ink-light);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 0.3rem;
}

/* ── BOOK ─────────────────────────────────────────────── */
.book {
    max-width: 860px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem 4rem;
}

/* ── FAMILY SECTION ───────────────────────────────────── */
.family-section { margin-bottom: 2rem; }

.family-heading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--green);
}

.family-heading h2 {
    font-family: 'Lora', serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--green);
    letter-spacing: 0.3px;
}

.family-count {
    font-size: 0.75rem;
    color: var(--ink-light);
    background: var(--paper-dark);
    border: 1px solid var(--rule);
    border-radius: 50px;
    padding: 0.1rem 0.6rem;
}

/* ── BIRD ENTRY ───────────────────────────────────────── */
.bird-entry {
    display: grid;
    grid-template-columns: 2rem 56px 1fr;
    gap: 0 0.6rem;
    padding: 0.7rem 0.5rem;
    border-bottom: 1px solid var(--rule);
    transition: background 0.15s, box-shadow 0.15s;
    border-radius: 6px;
}

.bird-entry:hover {
    background: var(--paper);
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.bird-num {
    font-family: 'Lora', serif;
    font-size: 0.78rem;
    color: var(--ink-light);
    padding-top: 0.25rem;
    text-align: right;
    user-select: none;
}

/* ── THUMBNAIL ────────────────────────────────────────── */
.bird-thumb {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--paper-dark);
    border: 1px solid var(--rule);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.bird-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 0.3s;
}

.bird-thumb-img:not([src]) { opacity: 0; }
.bird-thumb-img[src] { opacity: 1; }

/* Shimmer loading */
.bird-thumb.loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255,255,255,0.35) 50%,
        transparent 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.2s ease-in-out infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Failed state – subtle silence */
.bird-thumb.failed { opacity: 0.35; }

/* ── CONTENT ──────────────────────────────────────────── */
.bird-content {}

.bird-names {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.5rem 0.8rem;
    margin-bottom: 0.25rem;
}

.bird-english {
    font-family: 'Lora', serif;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.3;
}

.bird-scientific {
    font-family: 'Lora', serif;
    font-style: italic;
    font-size: 0.85rem;
    color: var(--ink-light);
}

.bird-nepali {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gold);
    background: var(--gold-light);
    padding: 0.1rem 0.55rem;
    border-radius: 4px;
    white-space: nowrap;
}

.bird-detail {
    font-size: 0.85rem;
    color: var(--ink-mid);
    line-height: 1.55;
}

/* ── EMPTY STATE ──────────────────────────────────────── */
.empty {
    text-align: center;
    padding: 5rem 2rem;
    color: var(--ink-light);
}
.empty svg { opacity: 0.35; margin-bottom: 0.75rem; }
.empty p { font-size: 1rem; }

/* ── MODAL ─────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}
.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: #fff;
    border-radius: 14px;
    max-width: 480px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    transform: translateY(24px) scale(0.95);
    transition: transform 0.25s ease-out;
    position: relative;
}
.modal-overlay.open .modal {
    transform: translateY(0) scale(1);
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(0,0,0,0.45);
    border: none;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s;
}
.modal-close:hover { background: rgba(0,0,0,0.65); }
.modal-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.modal-body {
    display: flex;
    flex-direction: column;
}

.modal-img-wrap {
    width: 100%;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    border-radius: 14px 14px 0 0;
    background: var(--paper-dark);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    transition: opacity 0.3s;
}
.modal-img[src] { opacity: 1; }
.modal-img:not([src]) { opacity: 0; }

.modal-info {
    padding: 1.25rem 1.5rem 1.5rem;
}

.modal-names {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem 0.8rem;
    margin-bottom: 0.5rem;
}

.modal-english {
    font-family: 'Lora', serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.3;
}

.modal-scientific {
    font-family: 'Lora', serif;
    font-style: italic;
    font-size: 0.9rem;
    color: var(--ink-light);
}

.modal-nepali {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gold);
    background: var(--gold-light);
    padding: 0.15rem 0.6rem;
    border-radius: 4px;
    white-space: nowrap;
}

.modal-family {
    font-size: 0.8rem;
    color: var(--green);
    font-weight: 600;
    margin-bottom: 0.75rem;
    letter-spacing: 0.3px;
}

.modal-detail {
    font-size: 0.95rem;
    color: var(--ink-mid);
    line-height: 1.65;
}

@media (max-width: 540px) {
    .modal { max-width: 100%; max-height: 90vh; margin: 0.5rem; }
    .modal-info { padding: 1rem 1.25rem 1.25rem; }
    .modal-english { font-size: 1.15rem; }
}

@media print {
    .modal-overlay { display: none; }
}

/* ── WHATSAPP BUTTON ──────────────────────────────────── */
.whatsapp-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 50;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #25D366;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(37, 211, 102, 0.35);
    transition: transform 0.25s, box-shadow 0.25s;
    text-decoration: none;
    animation: wa-appear 0.4s ease-out both;
    animation-delay: 1s;
}
.whatsapp-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(37, 211, 102, 0.45);
}
.whatsapp-btn:focus-visible {
    outline: 3px solid #25D366;
    outline-offset: 3px;
}
.whatsapp-btn svg {
    width: 28px;
    height: 28px;
}
.wa-tooltip {
    display: none;
}
@media (hover: hover) {
    .whatsapp-btn:hover .wa-tooltip {
        display: block;
        position: absolute;
        right: 60px;
        background: #fff;
        color: #075E54;
        padding: 6px 14px;
        border-radius: 8px;
        font-size: 0.8rem;
        font-family: 'Inter', sans-serif;
        font-weight: 500;
        white-space: nowrap;
        box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        pointer-events: none;
    }
    .whatsapp-btn:hover .wa-tooltip::after {
        content: '';
        position: absolute;
        right: -5px;
        top: 50%;
        transform: translateY(-50%);
        border: 5px solid transparent;
        border-left-color: #fff;
    }
}
@keyframes wa-appear {
    from { opacity: 0; transform: translateY(12px) scale(0.9); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 540px) {
    .whatsapp-btn {
        bottom: 16px;
        right: 16px;
        width: 48px;
        height: 48px;
    }
    .whatsapp-btn svg { width: 24px; height: 24px; }
}

@media print {
    .whatsapp-btn { display: none; }
}

/* ── FOOTER ───────────────────────────────────────────── */
.foot {
    text-align: center;
    padding: 1.5rem;
    font-size: 0.78rem;
    color: var(--ink-light);
    border-top: 1px solid var(--rule);
    background: var(--paper);
}

/* ── MOBILE ───────────────────────────────────────────── */
@media (max-width: 540px) {
    .topbar-inner {
        flex-wrap: wrap;
        gap: 0.6rem;
        padding: 0.6rem 1rem;
    }
    .brand-title { font-size: 0.95rem; }
    .brand-sub { display: none; }
    .search-box { order: 3; width: 100%; }

    .pills { padding: 0.55rem 1rem; }

    .book { padding: 1rem 1rem 3rem; }

    .bird-entry {
        grid-template-columns: 1.6rem 48px 1fr;
        gap: 0 0.5rem;
        padding: 0.6rem 0.4rem;
    }
    .bird-thumb {
        width: 48px;
        height: 48px;
    }
    .bird-english { font-size: 0.95rem; }
    .bird-scientific { font-size: 0.8rem; }
    .bird-detail { font-size: 0.8rem; }
    .bird-nepali { font-size: 0.75rem; }
    .hero-number { font-size: 2.5rem; }
    .hero-count { padding: 1.5rem 1rem 0.25rem; }
}

@media (max-width: 380px) {
    .topbar-inner { padding: 0.5rem 0.75rem; gap: 0.4rem; }
    .brand-title { font-size: 0.85rem; }
    .brand-icon { font-size: 1.4rem; }
    .bird-english { font-size: 0.9rem; }
    .bird-entry { padding: 0.5rem 0.3rem; }
}

/* ── PRINT ────────────────────────────────────────────── */
@media print {
    .topbar, .pill-bar, .hero-count, .foot { display: none; }
    .book { max-width: 100%; padding: 0.5in; }
    .bird-entry {
        break-inside: avoid;
        page-break-inside: avoid;
        border-bottom: 1px solid #ccc;
        grid-template-columns: 40px 1fr;
    }
    .bird-num { display: none; }
    .bird-thumb { width: 40px; height: 40px; border: 1px solid #ccc; }
    .bird-english { font-size: 11pt; }
    .bird-scientific { font-size: 9pt; }
    .bird-detail { font-size: 8pt; color: #444; }
    .bird-nepali { font-size: 8pt; }
}
