/* ========== RESET ========== */
:root {
    --app-height: 100vh;
}

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

html,
body {
    background: #0a0a0f;
    overflow: hidden;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: #e0e0e0;
    width: 100%;
    min-height: var(--app-height);
}

/* ========== PHASER CANVAS ========== */
#game-container {
    position: fixed;
    inset: 0;
    height: var(--app-height);
    z-index: 1;
}
#game-container canvas {
    display: block;
}

#loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: rgba(10, 10, 15, 0.92);
    color: #d8ffe8;
    transition: opacity 0.25s ease;
}

#loading-overlay.hidden {
    display: none;
}

@media (max-width: 900px) and (orientation: portrait) {
    #loading-overlay.initial-loading {
        display: none;
    }
}

.loading-sprout {
    font-size: 2.6rem;
    transform-origin: center bottom;
    animation: sprout-grow 1.1s ease-in-out infinite alternate;
}

.loading-copy {
    font-size: 0.95rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #8cf7bc;
}

@keyframes sprout-grow {
    from { transform: scale(0.82) translateY(6px); opacity: 0.7; }
    to { transform: scale(1.08) translateY(-2px); opacity: 1; }
}

#mobile-scene-fallback {
    position: fixed;
    inset: 0;
    z-index: 2;
    background: #0a0a0f;
    overflow: hidden;
}

#mobile-scene-fallback.hidden {
    display: none;
}

#mobile-scene-strip {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    cursor: grab;
}

.fallback-world {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    will-change: transform;
}

.fallback-zone {
    position: absolute;
    top: 0;
    height: var(--app-height);
    overflow: hidden;
    background: #0a0a0f;
}

.fallback-zone-bg {
    position: absolute;
    left: 0;
    bottom: 0;
    width: auto;
    height: 100%;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}

.fallback-zone-label {
    display: none;
}

.fallback-sprite-layer {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    will-change: transform;
}

.fallback-camera-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 6;
}

#mobile-scene-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 7;
}

.fallback-sprite {
    position: absolute;
    transform-origin: center bottom;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
    display: block;
}

.fallback-plant {
    z-index: 3;
}

.fallback-fox {
    z-index: 4;
}

#mobile-scene-hint {
    display: none;
}

/* ========== TRACKER PANEL ========== */
#ui-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 320px;
    height: var(--app-height);
    z-index: 50;
    background: linear-gradient(90deg, rgba(15,8,3,0.97) 0%, rgba(15,8,3,0.88) 100%);
    border-right: 1px solid rgba(74, 222, 128, 0.25);
    transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
}
#ui-overlay.hidden { transform: translateX(-320px); }

#tracker-panel {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 36px;
    min-height: var(--app-height);
    justify-content: center;
}

@media (max-width: 768px) {
    #tracker-panel {
        gap: 20px;
        justify-content: flex-start;
        padding-top: 32px;
    }
}

/* ========== HEADER ========== */
.tracker-header { text-align: center; }
.tracker-header h1 {
    font-size: 1.3rem;
    background: linear-gradient(135deg, #07F986, #07F986);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
    font-family: 'SF Mono', monospace;
}
.beta { font-size: 0.45em; color: #888; vertical-align: super; -webkit-text-fill-color: #888; }
.tagline { color: #888; font-size: 0.8rem; font-style: italic; }

/* ========== TRACKING DATA ========== */
#tracking-data {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ========== COUNTER ========== */
.glasses-display {
    font-size: 2.8rem;
    font-weight: bold;
    color: #07F986;
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: 6px;
}
.sep { color: #888; font-size: 0.5em; }
.pct { text-align: center; font-size: 1.1rem; color: #07F986; }

#reservoir-display {
    text-align: center;
    color: #60a5fa;
    font-size: 0.95rem;
}

/* ========== PROGRESS ========== */
.progress-wrap {
    width: 100%;
    height: 10px;
    background: rgba(255,255,255,0.08);
    border-radius: 5px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #07F986, #07F986);
    border-radius: 5px;
    width: 0%;
    transition: width 0.4s ease;
}

/* ========== CONTROLS ========== */
.controls {
    display: flex;
    gap: 12px;
    justify-content: center;
}
.btn {
    border: none; cursor: pointer;
    border-radius: 30px;
    font-size: 1rem;
    transition: transform 0.15s, opacity 0.15s;
    display: flex; align-items: center; justify-content: center;
}
.btn:hover { transform: scale(1.06); }
.btn:active { transform: scale(0.95); }
.btn:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-remove {
    width: 48px; height: 48px;
    border-radius: 50%;
    background: rgba(255,255,255,0.08);
    color: #e0e0e0;
    font-size: 1.2rem;
}
.btn-add {
    flex: 1;
    height: 48px;
    background: rgba(8, 8, 12, 0.92);
    border: 1px solid rgba(7, 249, 134, 0.35);
    color: #07F986;
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
}

/* ========== STATS ========== */
.stats {
    display: flex;
    justify-content: space-around;
    padding: 12px 8px;
    background: rgba(255,255,255,0.04);
    border-radius: 12px;
    border: 1px solid rgba(74,222,128,0.12);
}
.stat { text-align: center; }
.stat-val { font-size: 1.4rem; font-weight: bold; color: #ffaa00; }
.stat-lbl { font-size: 0.7rem; color: #888; margin-top: 2px; }

/* ========== TREES BOX ========== */
#trees-box {
    padding: 12px 16px;
    background: rgba(255,255,255,0.04);
    border-radius: 12px;
    border: 1px solid rgba(74,222,128,0.12);
    color: #888;
    font-size: 0.7rem;
}
#trees-box .tree-progress-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    color: #b8c2b5;
    font-size: 0.68rem;
    letter-spacing: 0.02em;
}
#trees-box .tree-progress-wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
#trees-box .tree-progress-track {
    position: relative;
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(74,222,128,0.16);
}
#trees-box .tree-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: inherit;
    background: linear-gradient(90deg, #07F986 0%, #7dffb6 100%);
    box-shadow: 0 0 16px rgba(7, 249, 134, 0.28);
    transition: width 0.25s ease;
}
#trees-box .tree-progress-emoji {
    font-size: 1rem;
    line-height: 1;
}
#trees-box .trees-summary {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
}
#trees-box #trees-planted {
    display: inline;
    font-weight: bold;
    font-size: 1.4rem;
    color: #07F986;
}
#debug-box {
    display: none;
    margin-top: 10px;
    padding: 10px 12px;
    background: rgba(7, 10, 14, 0.72);
    border: 1px solid rgba(110, 231, 255, 0.22);
    border-radius: 10px;
    color: #9cc7d4;
    font: 11px/1.45 monospace;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ========== TREE CELEBRATION ========== */
#tree-celebration,
#lizard-unlock,
#woodpecker-unlock,
#jerboa-unlock,
#roadrunner-unlock,
#hummingbird-unlock,
#mercat-unlock,
#sandcat-unlock,
#scorpion-unlock,
#oryx-unlock,
#goldeneagle-unlock {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(3, 12, 12, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(12px);
    animation: celebFadeIn 0.4s ease;
}
#tree-celebration.hidden,
#lizard-unlock.hidden,
#woodpecker-unlock.hidden,
#jerboa-unlock.hidden,
#roadrunner-unlock.hidden,
#hummingbird-unlock.hidden,
#mercat-unlock.hidden,
#sandcat-unlock.hidden,
#scorpion-unlock.hidden,
#oryx-unlock.hidden,
#goldeneagle-unlock.hidden { display: none; }

.lizard-unlock-img {
    width: 100%;
    max-height: 55vh;
    object-fit: contain;
    object-position: bottom;
    transform: scaleX(-1);
}
.woodpecker-unlock-img,
.animal-unlock-img {
    width: 100%;
    max-height: 55vh;
    object-fit: contain;
    object-position: bottom;
}
#sandcat-unlock .animal-unlock-img {
    object-fit: contain;
    object-position: bottom;
    max-height: 60vh;
    transform: translateY(-20px);
}
#scorpion-unlock .animal-unlock-img {
    transform: scaleX(-1);
}
#oryx-unlock .animal-unlock-img {
    max-height: 68vh;
    object-position: center;
}
.roadrunner-unlock-img {
    width: 100%;
    max-height: 55vh;
    object-fit: contain;
    object-position: bottom;
    filter: drop-shadow(0 24px 28px rgba(0, 0, 0, 0.28));
}
.hummingbird-unlock-img {
    width: 100%;
    max-height: 55vh;
    object-fit: contain;
    object-position: center;
    filter: drop-shadow(0 24px 28px rgba(0, 0, 0, 0.28));
}
.mercat-unlock-img {
    width: 100%;
    max-height: 55vh;
    object-fit: contain;
    object-position: bottom;
    filter: drop-shadow(0 24px 28px rgba(0, 0, 0, 0.28));
}
.goldeneagle-unlock-img {
    width: 100%;
    max-height: 52vh;
    object-fit: contain;
    object-position: center;
    filter: drop-shadow(0 24px 28px rgba(0, 0, 0, 0.28));
}
#woodpecker-unlock .celebration-img-wrap {
    padding-bottom: 20px;
}
#jerboa-unlock .celebration-img-wrap,
#roadrunner-unlock .celebration-img-wrap,
#hummingbird-unlock .celebration-img-wrap,
#mercat-unlock .celebration-img-wrap,
#goldeneagle-unlock .celebration-img-wrap {
    padding-bottom: 20px;
}
#hummingbird-unlock .celebration-img-wrap {
    align-items: center;
}

@keyframes celebFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes celebSlideUp {
    from { opacity: 0; transform: translateY(24px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.celebration-close {
    position: absolute;
    top: 14px;
    right: 16px;
    background: rgba(255,255,255,0.07);
    border: none;
    color: #888;
    font-size: 1rem;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    z-index: 1;
}
.celebration-close:hover { background: rgba(255,255,255,0.15); color: #fff; }

.celebration-inner {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    max-width: 700px;
    width: 92%;
    max-height: 90vh;
    background: linear-gradient(135deg, #060f0e 0%, #0a1a14 100%);
    border-radius: 24px;
    border: 1px solid rgba(240, 168, 48, 0.3);
    box-shadow: 0 0 80px rgba(240, 168, 48, 0.08), 0 0 30px rgba(46, 196, 182, 0.1);
    overflow: hidden;
    animation: celebSlideUp 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.celebration-img-wrap {
    flex: 0 0 48%;
    background: linear-gradient(180deg, #0d1f1a 0%, #061410 100%);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 24px 16px 0;
    border-right: 1px solid rgba(240, 168, 48, 0.12);
}
#celebration-img {
    width: 100%;
    max-height: 55vh;
    object-fit: contain;
    object-position: bottom;
}

.celebration-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 36px 32px;
    gap: 14px;
}
.celebration-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(240, 168, 48, 0.12);
    border: 1px solid rgba(240, 168, 48, 0.35);
    color: #f0a830;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 5px 14px;
    border-radius: 20px;
    width: fit-content;
    letter-spacing: 0.04em;
}
.celebration-text h2 {
    font-size: 1.5rem;
    color: #f0e8d0;
    line-height: 1.2;
    margin: 0;
}
.celebration-species {
    color: #2ec4b6;
    font-size: 0.82rem;
    margin: 0;
}
.celebration-body {
    color: #9ab8b0;
    font-size: 0.83rem;
    line-height: 1.7;
    margin: 0;
}
.celebration-btn {
    margin-top: 8px;
    align-self: flex-start;
    display: inline-block;
    background: linear-gradient(135deg, #2ec4b6, #1aa99d);
    color: #000;
    border: none;
    padding: 11px 32px;
    border-radius: 30px;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.15s, box-shadow 0.15s;
    font-family: 'SF Mono', 'Fira Code', monospace;
}
.celebration-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(46, 196, 182, 0.4);
}

@media (max-width: 600px) {
    .celebration-inner {
        flex-direction: column;
        width: min(96vw, 420px);
        max-height: min(88vh, 760px);
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .celebration-img-wrap { flex: 0 0 auto; padding: 20px 20px 0; border-right: none; border-bottom: 1px solid rgba(240,168,48,0.12); }
    #celebration-img,
    .lizard-unlock-img,
    .woodpecker-unlock-img,
    .animal-unlock-img,
    .roadrunner-unlock-img,
    .hummingbird-unlock-img,
    .mercat-unlock-img,
    .goldeneagle-unlock-img { max-height: 28vh; }
    .roadrunner-unlock-img { width: min(100%, 240px); }
    .celebration-text { padding: 20px 18px 18px; gap: 10px; }
    .celebration-text h2 { font-size: 1.2rem; }
    .celebration-body { font-size: 0.78rem; line-height: 1.55; }
    .celebration-btn { width: 100%; text-align: center; padding: 11px 18px; }
    .celebration-close { top: 10px; right: 10px; }
}

/* Mobile portrait: stack vertically, scroll */
@media (max-width: 600px) {
    #tree-celebration,
    #lizard-unlock,
    #woodpecker-unlock,
    #jerboa-unlock,
    #roadrunner-unlock,
    #hummingbird-unlock,
    #sandcat-unlock,
    #scorpion-unlock,
    #oryx-unlock,
    #goldeneagle-unlock {
        align-items: flex-start;
        padding-top: max(8px, env(safe-area-inset-top));
        padding-bottom: max(16px, env(safe-area-inset-bottom));
        overflow-y: auto;
    }
    #sandcat-unlock .celebration-inner,
    #scorpion-unlock .celebration-inner,
    #oryx-unlock .celebration-inner,
    #lizard-unlock .celebration-inner,
    #woodpecker-unlock .celebration-inner,
    #jerboa-unlock .celebration-inner {
        width: min(98vw, 440px);
        max-height: none;
    }
    #sandcat-unlock .celebration-img-wrap,
    #scorpion-unlock .celebration-img-wrap,
    #oryx-unlock .celebration-img-wrap {
        padding: 12px 16px 0;
        min-height: 220px;
    }
    #sandcat-unlock .animal-unlock-img,
    #scorpion-unlock .animal-unlock-img,
    #oryx-unlock .animal-unlock-img {
        max-height: 30vh;
        transform: none;
    }
    #sandcat-unlock .celebration-text,
    #scorpion-unlock .celebration-text,
    #oryx-unlock .celebration-text {
        padding: 16px 20px 18px;
        gap: 8px;
    }
}

/* Mobile landscape: keep row layout, fill full width, shrink fonts */
@media (max-height: 520px) and (orientation: landscape) {
    #tree-celebration,
    #lizard-unlock,
    #woodpecker-unlock,
    #jerboa-unlock,
    #roadrunner-unlock,
    #hummingbird-unlock,
    #sandcat-unlock,
    #scorpion-unlock,
    #oryx-unlock,
    #goldeneagle-unlock {
        align-items: center;
        padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
        overflow-y: auto;
    }
    #tree-celebration .celebration-inner,
    #lizard-unlock .celebration-inner,
    #woodpecker-unlock .celebration-inner,
    #jerboa-unlock .celebration-inner,
    #roadrunner-unlock .celebration-inner,
    #hummingbird-unlock .celebration-inner,
    #sandcat-unlock .celebration-inner,
    #scorpion-unlock .celebration-inner,
    #oryx-unlock .celebration-inner,
    #goldeneagle-unlock .celebration-inner {
        flex-direction: row;
        width: 96vw;
        max-width: none;
        max-height: 94vh;
        overflow: hidden;
    }
    #tree-celebration .celebration-img-wrap,
    #lizard-unlock .celebration-img-wrap,
    #woodpecker-unlock .celebration-img-wrap,
    #jerboa-unlock .celebration-img-wrap,
    #roadrunner-unlock .celebration-img-wrap,
    #hummingbird-unlock .celebration-img-wrap,
    #sandcat-unlock .celebration-img-wrap,
    #scorpion-unlock .celebration-img-wrap,
    #oryx-unlock .celebration-img-wrap,
    #goldeneagle-unlock .celebration-img-wrap {
        flex: 0 0 38%;
        padding: 10px 12px;
        border-right: 1px solid rgba(240,168,48,0.12);
        border-bottom: none;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    #celebration-img,
    .lizard-unlock-img,
    .woodpecker-unlock-img,
    .animal-unlock-img,
    .roadrunner-unlock-img,
    .hummingbird-unlock-img,
    .goldeneagle-unlock-img {
        max-height: 88vh;
        width: 100%;
        transform: none;
    }
    #sandcat-unlock .animal-unlock-img {
        transform: none;
    }
    #scorpion-unlock .animal-unlock-img {
        transform: scaleX(-1);
    }
    .celebration-text {
        flex: 1;
        overflow-y: auto;
        padding: 12px 16px 12px;
        gap: 6px;
    }
    .celebration-text h2 { font-size: 1rem; line-height: 1.2; }
    .celebration-badge { font-size: 0.72rem; }
    .celebration-species { font-size: 0.68rem; }
    .celebration-body { font-size: 0.7rem; line-height: 1.4; }
    .celebration-btn { padding: 8px 20px; font-size: 0.8rem; }
    .celebration-close { top: 8px; right: 8px; width: 28px; height: 28px; font-size: 0.85rem; }
}

@media (max-width: 600px) {
    #roadrunner-unlock .celebration-inner,
    #hummingbird-unlock .celebration-inner,
    #mercat-unlock .celebration-inner,
    #goldeneagle-unlock .celebration-inner {
        width: min(98vw, 440px);
    }
    #roadrunner-unlock .roadrunner-unlock-img,
    #hummingbird-unlock .hummingbird-unlock-img,
    #mercat-unlock .mercat-unlock-img,
    #goldeneagle-unlock .goldeneagle-unlock-img {
        width: min(100%, 285px);
        height: 230px;
        max-height: none;
    }
    #roadrunner-unlock .celebration-img-wrap,
    #hummingbird-unlock .celebration-img-wrap,
    #mercat-unlock .celebration-img-wrap,
    #goldeneagle-unlock .celebration-img-wrap {
        min-height: 260px;
        padding-top: 30px;
    }
    #hummingbird-unlock .hummingbird-unlock-img {
        width: min(100%, 320px);
        height: 270px;
    }
}

@media (max-height: 520px) and (min-width: 601px) {
    #roadrunner-unlock,
    #hummingbird-unlock,
    #mercat-unlock,
    #goldeneagle-unlock {
        justify-content: center;
    }
    #roadrunner-unlock .celebration-inner,
    #hummingbird-unlock .celebration-inner,
    #mercat-unlock .celebration-inner,
    #goldeneagle-unlock .celebration-inner {
        flex-direction: row;
        width: min(94vw, 1120px);
        max-height: calc(100vh - 18px);
    }
    #roadrunner-unlock .celebration-img-wrap,
    #hummingbird-unlock .celebration-img-wrap,
    #mercat-unlock .celebration-img-wrap,
    #goldeneagle-unlock .celebration-img-wrap {
        flex: 0 0 44%;
        padding: 14px 18px 0;
        border-right: 1px solid rgba(240,168,48,0.12);
        border-bottom: none;
    }
    #roadrunner-unlock .roadrunner-unlock-img,
    #hummingbird-unlock .hummingbird-unlock-img,
    #mercat-unlock .mercat-unlock-img,
    #goldeneagle-unlock .goldeneagle-unlock-img {
        width: min(100%, 390px);
        max-height: 52vh;
    }
    #hummingbird-unlock .hummingbird-unlock-img {
        width: min(100%, 320px);
        max-height: 44vh;
    }
    #roadrunner-unlock .celebration-text,
    #hummingbird-unlock .celebration-text,
    #mercat-unlock .celebration-text,
    #goldeneagle-unlock .celebration-text {
        padding: 14px 30px;
        gap: 7px;
    }
    #roadrunner-unlock .celebration-text h2,
    #hummingbird-unlock .celebration-text h2,
    #mercat-unlock .celebration-text h2,
    #goldeneagle-unlock .celebration-text h2 { font-size: 1.18rem; }
    #roadrunner-unlock .celebration-species,
    #hummingbird-unlock .celebration-species,
    #mercat-unlock .celebration-species,
    #goldeneagle-unlock .celebration-species { font-size: 0.74rem; }
    #roadrunner-unlock .celebration-body,
    #hummingbird-unlock .celebration-body,
    #mercat-unlock .celebration-body,
    #goldeneagle-unlock .celebration-body {
        font-size: 0.68rem;
        line-height: 1.34;
    }
    #roadrunner-unlock .celebration-btn,
    #hummingbird-unlock .celebration-btn,
    #mercat-unlock .celebration-btn,
    #goldeneagle-unlock .celebration-btn {
        margin-top: 4px;
        padding: 9px 24px;
    }
}

/* ========== AUTH ========== */
#auth-container {
    margin-top: 8px;
    margin-bottom: 8px;
}

/* ========== TOGGLE TAB ========== */
#toggle-tab {
    position: fixed;
    top: 25%;
    left: 320px;
    transform: translateY(-50%);
    width: 44px; height: 56px;
    background: rgba(10,10,15,0.95);
    border: 1px solid rgba(74,222,128,0.3);
    border-left: none;
    border-radius: 0 12px 12px 0;
    color: #07F986;
    font-size: 1.3rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: left 0.45s cubic-bezier(0.4, 0, 0.2, 1), background 0.2s;
    box-shadow: 4px 0 16px rgba(0,0,0,0.5);
    z-index: 200;
}
#toggle-tab.panel-hidden { left: 0; }
#toggle-tab:hover { background: rgba(74,222,128,0.2); }

@media (min-width: 901px) {
    body.loading-active #toggle-tab,
    body.loading-active #herbarium-tab {
        display: none !important;
    }

    body.loading-active #ui-overlay {
        display: none !important;
    }

    body.loading-active #placement-editor {
        display: none !important;
    }
}

/* ========== MOBILE ========== */
@media (max-width: 768px) {
    #ui-overlay { width: 100vw; }
    #ui-overlay.hidden { transform: translateX(-100vw); }
    #toggle-tab { display: none; }
    #tracker-panel {
        gap: 14px;
        padding-top: 24px;
        padding-bottom: 16px;
        min-height: auto;
    }
    #tracking-data { gap: 14px; }
    .stats { padding: 10px 6px; }
    #trees-box { padding: 10px 14px; }
    #trees-box .tree-progress-head { font-size: 0.64rem; }
    #trees-box .trees-summary { font-size: 0.68rem; }
    #trees-box #trees-planted { font-size: 1.2rem; }
}
@media (max-width: 900px) and (orientation: portrait) {
    #mobile-scene-fallback {
        display: none !important;
    }

    #ui-overlay {
        display: block !important;
        transform: translateX(0) !important;
    }
    #toggle-tab {
        display: none !important;
    }
}
@media (max-width: 900px) and (orientation: landscape) {
    #game-container {
        display: block !important;
    }

    #ui-overlay { display: none !important; }
    #toggle-tab { display: none !important; }
}

body[data-viewport-orientation="portrait"] #mobile-scene-fallback {
    display: none !important;
}

body[data-viewport-orientation="portrait"] #ui-overlay {
    display: block !important;
    transform: translateX(0) !important;
}

body[data-viewport-orientation="portrait"] #toggle-tab {
    display: none !important;
}

body[data-viewport-orientation="landscape"] #game-container {
    display: block !important;
}

@media (max-width: 900px) {
    body[data-viewport-orientation="landscape"] #ui-overlay,
    body[data-viewport-orientation="landscape"] #toggle-tab {
        display: none !important;
    }
}

@media (min-width: 901px) {
    body[data-viewport-orientation="landscape"] #ui-overlay {
        display: block !important;
    }

    body[data-viewport-orientation="landscape"] #toggle-tab {
        display: flex !important;
    }
}

/* ========== SAGE DIALOGUE PANEL ========== */
#sage-dialogue {
    position: fixed;
    top: max(16px, env(safe-area-inset-top));
    left: 0;
    right: 0;
    z-index: 450;
    padding: 0 16px 0 16px;
    display: flex;
    justify-content: center;
    animation: celebFadeIn 0.3s ease;
}
#sage-dialogue.hidden { display: none; }

.sage-dialogue-inner {
    width: 100%;
    max-width: 640px;
    background: linear-gradient(135deg, rgba(6,15,14,0.96) 0%, rgba(10,26,20,0.96) 100%);
    border: 1px solid rgba(240,168,48,0.3);
    border-radius: 12px 12px 16px 16px;
    padding: 16px 20px 14px;
    backdrop-filter: blur(12px);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 -4px 32px rgba(0,0,0,0.4);
}

.sage-dialogue-speaker {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(240,168,48,0.85);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.sage-dialogue-text {
    font-size: 0.95rem;
    line-height: 1.55;
    color: rgba(255,255,255,0.92);
    margin: 0;
}

.sage-dialogue-hint {
    font-size: 0.65rem;
    color: rgba(255,255,255,0.3);
    text-align: right;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

@media (max-height: 520px) and (orientation: landscape) {
    .sage-dialogue-inner {
        padding: 10px 16px 10px;
        gap: 5px;
        max-width: 560px;
    }
    .sage-dialogue-text { font-size: 0.82rem; line-height: 1.4; }
}

/* Mobile landscape: move dialogue to bottom so it doesn't cover Sage */
@media (max-width: 900px) and (orientation: landscape) {
    #sage-dialogue {
        top: auto;
        bottom: max(8px, env(safe-area-inset-bottom));
        padding: 0 12px;
    }
}
body[data-viewport-orientation="landscape"] #sage-dialogue {
    top: auto;
    bottom: max(8px, env(safe-area-inset-bottom));
    padding: 0 12px;
}


/* ========================================
   HERBARIUM
   ======================================== */

/* --- Herbarium side tab --- */
#herbarium-tab {
    position: fixed;
    top: calc(25% + 68px);
    left: 320px;
    transform: translateY(-50%);
    width: 44px; height: 56px;
    background: rgba(10,8,4,0.95);
    border: 1px solid rgba(180,140,80,0.35);
    border-left: none;
    border-radius: 0 12px 12px 0;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: left 0.45s cubic-bezier(0.4,0,0.2,1), background 0.2s;
    box-shadow: 4px 0 16px rgba(0,0,0,0.5);
    z-index: 350;
}
#herbarium-tab.panel-hidden { left: 0; }
#herbarium-tab:hover { background: rgba(180,140,80,0.15); }

/* Hidden on portrait mobile — access via in-panel button only */
@media (max-width: 900px) and (orientation: portrait) { #herbarium-tab { display: none !important; } }
body[data-viewport-orientation="portrait"] #herbarium-tab { display: none !important; }

/* Mobile landscape only: tab sits at left edge (no tracker panel) */
@media (max-width: 900px) and (orientation: landscape) {
    #herbarium-tab { left: 0; }
    #herbarium-tab.panel-hidden { left: 0; }
}
@media (max-width: 900px) {
    body[data-viewport-orientation="landscape"] #herbarium-tab { left: 0; }
    body[data-viewport-orientation="landscape"] #herbarium-tab.panel-hidden { left: 0; }
}

/* Sound toggle — bottom right */
#sound-toggle {
    position: fixed;
    bottom: 20px;
    right: 16px;
    width: 40px; height: 40px;
    background: rgba(10,8,4,0.82);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 50%;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 12px rgba(0,0,0,0.45);
    z-index: 400;
    transition: background 0.2s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}
#sound-toggle:hover { background: rgba(40,35,20,0.92); transform: scale(1.08); }
body.loading-active #sound-toggle { display: none; }
/* Sound only in landscape — hide on portrait where tracker covers the screen */
@media (orientation: portrait) { #sound-toggle { display: none !important; } }
body[data-viewport-orientation="portrait"] #sound-toggle { display: none !important; }

/* Mobile portrait: in-panel trigger button */
#herbarium-mobile-btn {
    display: none;
    width: 100%;
    padding: 12px 16px;
    background: rgba(180,140,80,0.1);
    border: 1px solid rgba(180,140,80,0.3);
    border-radius: 10px;
    color: #c8a06a;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background 0.2s;
}
#herbarium-mobile-btn:hover { background: rgba(180,140,80,0.2); }
@media (max-width: 768px) { #herbarium-mobile-btn.herbarium-visible { display: block; } }
body[data-viewport-orientation="portrait"] #herbarium-mobile-btn.herbarium-visible { display: block !important; }
body[data-viewport-orientation="landscape"] #herbarium-mobile-btn { display: none !important; }

/* --- Herbarium full-screen overlay --- */
#herbarium-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw;
    height: var(--app-height, 100vh);
    z-index: 300;
    transform: translateX(-100vw);
    transition: transform 0.45s cubic-bezier(0.4,0,0.2,1);
    pointer-events: none;
    display: flex;
    align-items: stretch;
    background: #1a0f05;
}
#herbarium-overlay.open {
    transform: translateX(0);
    pointer-events: auto;
}

/* Close button */
.herbarium-close {
    position: absolute;
    top: 16px; right: 16px;
    width: 40px; height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(180,140,80,0.4);
    background: rgba(20,12,4,0.85);
    color: #c8a06a;
    font-size: 1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    z-index: 10;
    transition: background 0.2s;
}

/* Slideshow nav arrows */
.herbarium-nav {
    position: absolute;
    top: 50%; transform: translateY(-50%);
    width: 28px; height: 44px;
    background: rgba(20,12,4,0.35);
    border: 1px solid rgba(180,140,80,0.2);
    color: rgba(200,160,106,0.7);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    display: none; /* shown via JS when multiple pages exist */
    align-items: center; justify-content: center;
    z-index: 10;
    transition: background 0.2s, color 0.2s;
}
.herbarium-nav:hover { background: rgba(20,12,4,0.7); color: #c8a06a; }
.herbarium-prev { left: 0; border-left: none; border-radius: 0 6px 6px 0; }
.herbarium-next { right: 0; border-right: none; border-radius: 6px 0 0 6px; }
.herbarium-close:hover { background: rgba(180,140,80,0.2); }

/* --- Book layout: image centered in full overlay --- */
.herbarium-book {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#herbarium-page-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}
