/* ═══════════════════════════════════════════════════════════════════════
   Igeouz — app-style mobile shell for the Study Workspace
   - Bottom tab bar (rendered by js/study-shell.js on phones/tablets)
   - App-style home on study.html (hero, shortcuts, AI card, subjects)
   Desktop layouts are untouched: everything here lives inside media queries.
   ═══════════════════════════════════════════════════════════════════════ */

.study-tabbar { display: none; }

/* ─── Bottom tab bar (whenever the sidebar is a drawer) ─── */
@media (max-width: 1024px) {
    body.has-app-tabs {
        --app-tabs-h: 64px;
        --app-tabs-gap: 10px;
    }

    body.has-app-tabs:not(.app-tabs-hidden) .study-main {
        padding-bottom: calc(var(--app-tabs-h) + var(--app-tabs-gap) + 18px + env(safe-area-inset-bottom, 0px));
    }

    /* The dashboard already carries launcher clearance; the tab bar padding above covers it now. */
    body.has-app-tabs:not(.app-tabs-hidden) .study-dashboard {
        padding-bottom: 28px;
    }

    /* The "Menu" tab opens the drawer, so the topbar hamburger is redundant. */
    body.has-app-tabs:not(.app-tabs-hidden) .study-topbar__hamburger {
        display: none;
    }

    /* Geobek assistant page: the chat column is sized to the viewport, so keep the
       composer above the tab bar. */
    body.has-app-tabs:not(.app-tabs-hidden) .study-assistant-container {
        height: calc(100dvh - 160px - var(--app-tabs-h) - var(--app-tabs-gap) - 16px - env(safe-area-inset-bottom, 0px));
    }

    body.has-app-tabs:not(.app-tabs-hidden) .geobek-launcher {
        bottom: calc(var(--app-tabs-h) + var(--app-tabs-gap) + 18px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .study-tabbar {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: calc(var(--app-tabs-gap, 10px) + env(safe-area-inset-bottom, 0px));
        height: var(--app-tabs-h, 64px);
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        align-items: center;
        gap: 2px;
        padding: 6px;
        border-radius: 24px;
        background: color-mix(in srgb, var(--bg-surface) 88%, transparent);
        -webkit-backdrop-filter: blur(18px) saturate(1.4);
        backdrop-filter: blur(18px) saturate(1.4);
        border: 1px solid var(--border-glass);
        box-shadow: 0 14px 36px rgba(2, 6, 23, 0.32), 0 2px 6px rgba(2, 6, 23, 0.12);
        z-index: 80;
    }

    @supports not (background: color-mix(in srgb, red 50%, blue)) {
        .study-tabbar { background: var(--bg-surface); }
    }

    .study-tabbar__item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        height: 52px;
        min-width: 0;
        padding: 0 2px;
        border: 0;
        border-radius: 17px;
        background: transparent;
        color: var(--text-muted);
        font-family: inherit;
        font-size: 0.66rem;
        font-weight: 700;
        letter-spacing: 0.01em;
        line-height: 1;
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
    }

    .study-tabbar__item span {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .study-tabbar__item i {
        font-size: 1.4rem;
        line-height: 1;
    }

    .study-tabbar__item:active {
        transform: scale(0.94);
    }

    .study-tabbar__item.is-active,
    .study-tabbar__item.is-open {
        color: #10b981;
        background: rgba(16, 185, 129, 0.14);
    }

    /* Hidden while a game round owns the screen (StudyShell.setTabBarHidden). */
    body.app-tabs-hidden .study-tabbar { display: none; }

    /* Slide away while the on-screen keyboard is up so it does not float mid-screen. */
    .study-tabbar { transition: transform 0.2s ease, opacity 0.2s ease; }
    body.app-keyboard-open .study-tabbar {
        transform: translateY(160%);
        opacity: 0;
        pointer-events: none;
    }

    /* World map: keep its bottom-anchored controls and sheets above the bar. */
    body.wm-page.has-app-tabs:not(.app-tabs-hidden) .wm-controls {
        bottom: calc(24px + var(--app-tabs-h) + var(--app-tabs-gap) + env(safe-area-inset-bottom, 0px));
    }
    body.wm-page.has-app-tabs:not(.app-tabs-hidden) .wm-stat-legend,
    body.wm-page.has-app-tabs:not(.app-tabs-hidden) .wm-layer-legend {
        bottom: calc(20px + var(--app-tabs-h) + var(--app-tabs-gap) + env(safe-area-inset-bottom, 0px));
    }

    .study-tabbar__item.is-active i::before {
        font-weight: 700;
    }
}

@media (max-width: 768px) {
    /* World map bottom sheets (country profile, layers) sit above the bar. */
    body.wm-page.has-app-tabs:not(.app-tabs-hidden) .wm-panel {
        bottom: calc(var(--app-tabs-h) + var(--app-tabs-gap) + env(safe-area-inset-bottom, 0px));
        height: min(60vh, calc(100dvh - 190px));
    }
    body.wm-page.has-app-tabs:not(.app-tabs-hidden) .wm-settings {
        bottom: calc(var(--app-tabs-h) + var(--app-tabs-gap) + env(safe-area-inset-bottom, 0px));
        height: min(80dvh, 660px);
        max-height: min(80dvh, 660px);
    }
    body.wm-page.has-app-tabs:not(.app-tabs-hidden) .wm-layer-legend {
        bottom: auto;
    }
    /* Lesson video mini-player docks above the bar. */
    body.has-app-tabs:not(.app-tabs-hidden) .learn-video-container.is-docked {
        bottom: calc(24px + var(--app-tabs-h) + var(--app-tabs-gap) + env(safe-area-inset-bottom, 0px));
    }
    body.has-app-tabs:not(.app-tabs-hidden) .study-assistant-container {
        height: calc(100dvh - 120px - var(--app-tabs-h) - var(--app-tabs-gap) - 16px - env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 640px) {
    body.has-app-tabs:not(.app-tabs-hidden) .study-assistant-container {
        height: calc(100dvh - 92px - var(--app-tabs-h) - var(--app-tabs-gap) - 16px - env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 360px) {
    .study-tabbar__item { font-size: 0.6rem; }
    .study-tabbar__item i { font-size: 1.3rem; }
}

/* ─── App-style home (study.html) ─── */
.app-home { display: none; }

@media (max-width: 768px) {
    .app-home {
        display: block;
        margin-bottom: 22px;
    }

    /* The desktop expedition hero is replaced by the app hero on phones. */
    .app-home ~ .dash-expedition {
        display: none;
    }

    /* Hero */
    .app-hero {
        position: relative;
        overflow: hidden;
        border-radius: 26px;
        padding: 18px 18px 14px;
        color: #fff;
        background:
            radial-gradient(circle at 100% 0%, rgba(255, 255, 255, 0.16), transparent 42%),
            linear-gradient(135deg, #065f46 0%, #047857 48%, #0e7490 100%);
        box-shadow: 0 18px 40px rgba(4, 120, 87, 0.28), 0 6px 0 -2px #064e3b;
    }

    .app-hero__row {
        display: flex;
        align-items: center;
        gap: 14px;
    }

    .app-hero__mascot {
        flex-shrink: 0;
        width: 92px;
        height: 92px;
        object-fit: contain;
        filter: drop-shadow(0 10px 18px rgba(2, 6, 23, 0.35));
    }

    .app-hero__body {
        flex: 1;
        min-width: 0;
    }

    .app-hero__greet {
        display: block;
        font-size: 0.8rem;
        font-weight: 600;
        color: rgba(255, 255, 255, 0.82);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .app-hero__title-row {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-top: 2px;
        min-width: 0;
    }

    .app-hero__title {
        font-family: var(--font-heading);
        font-size: 1.28rem;
        font-weight: 800;
        line-height: 1.15;
        margin: 0;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-hero__level {
        flex-shrink: 0;
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 4px 9px;
        border-radius: 999px;
        background: #fbbf24;
        color: #422006;
        font-size: 0.7rem;
        font-weight: 800;
        white-space: nowrap;
    }

    .app-hero__bar {
        height: 9px;
        margin-top: 10px;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.22);
        overflow: hidden;
    }

    .app-hero__bar span {
        display: block;
        height: 100%;
        width: 0%;
        border-radius: inherit;
        background: linear-gradient(90deg, #a7f3d0, #fbbf24);
        transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
    }

    .app-hero__meta {
        margin: 7px 0 0;
        font-size: 0.76rem;
        color: rgba(255, 255, 255, 0.86);
    }

    .app-hero__meta strong { color: #fff; }

    .app-hero__stats {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-top: 14px;
    }

    .app-stat {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 12px;
        border-radius: 18px;
        background: rgba(255, 255, 255, 0.14);
        border: 1px solid rgba(255, 255, 255, 0.18);
        color: #fff;
        text-decoration: none;
        min-width: 0;
        -webkit-tap-highlight-color: transparent;
    }

    .app-stat__icon {
        flex-shrink: 0;
        width: 40px;
        height: 40px;
        border-radius: 13px;
        display: grid;
        place-items: center;
        font-size: 1.35rem;
        background: #fff;
    }

    .app-stat--streak .app-stat__icon { color: #f97316; }
    .app-stat--coins .app-stat__icon { color: #d97706; }

    .app-stat__body {
        display: flex;
        flex-direction: column;
        min-width: 0;
    }

    .app-stat__body strong {
        font-family: var(--font-heading);
        font-size: 1.05rem;
        font-weight: 800;
        line-height: 1.1;
        white-space: nowrap;
    }

    .app-stat__body span {
        font-size: 0.7rem;
        color: rgba(255, 255, 255, 0.82);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .app-stat > .ph {
        margin-left: auto;
        opacity: 0.7;
    }

    /* Shortcuts ("stories") row */
    .app-stories {
        display: flex;
        gap: 6px;
        margin: 18px -16px 0;
        padding: 4px 16px 6px;
        overflow-x: auto;
        scroll-snap-type: x proximity;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .app-stories::-webkit-scrollbar { display: none; }

    .app-story {
        flex: 0 0 82px;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 7px;
        text-decoration: none;
        color: var(--text-primary);
        scroll-snap-align: start;
        -webkit-tap-highlight-color: transparent;
    }

    .app-story__ring {
        width: 68px;
        height: 68px;
        border-radius: 50%;
        padding: 3px;
        background: conic-gradient(from 210deg, #10b981, #06b6d4, #8b5cf6, #f59e0b, #10b981);
        box-shadow: 0 8px 18px rgba(2, 6, 23, 0.18);
    }

    .app-story__icon {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        border: 3px solid var(--bg-dark);
        display: grid;
        place-items: center;
        font-size: 1.65rem;
        color: #fff;
        background: var(--app-story-bg, linear-gradient(135deg, #10b981, #047857));
    }

    .app-story__icon img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        object-fit: cover;
    }

    .app-story__label {
        max-width: 82px;
        font-size: 0.72rem;
        font-weight: 600;
        text-align: center;
        line-height: 1.15;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-story--academy   .app-story__icon { --app-story-bg: linear-gradient(135deg, #34d399, #047857); }
    .app-story--exams     .app-story__icon { --app-story-bg: linear-gradient(135deg, #60a5fa, #1d4ed8); }
    .app-story--games     .app-story__icon { --app-story-bg: linear-gradient(135deg, #f472b6, #be185d); }
    .app-story--map       .app-story__icon { --app-story-bg: linear-gradient(135deg, #22d3ee, #0e7490); }
    .app-story--dictionary .app-story__icon { --app-story-bg: linear-gradient(135deg, #fbbf24, #b45309); }
    .app-story--flashcards .app-story__icon { --app-story-bg: linear-gradient(135deg, #a78bfa, #6d28d9); }
    .app-story--problems  .app-story__icon { --app-story-bg: linear-gradient(135deg, #fb923c, #c2410c); }
    .app-story--notebook  .app-story__icon { --app-story-bg: linear-gradient(135deg, #f87171, #b91c1c); }
    .app-story--library   .app-story__icon { --app-story-bg: linear-gradient(135deg, #94a3b8, #334155); }
    .app-story--plan      .app-story__icon { --app-story-bg: linear-gradient(135deg, #2dd4bf, #0f766e); }

    /* AI tutor card */
    .app-ai-card {
        display: flex;
        align-items: center;
        gap: 14px;
        width: 100%;
        margin-top: 14px;
        padding: 14px 16px;
        border-radius: 22px;
        border: 1px solid var(--border-glass);
        background: var(--bg-surface);
        color: var(--text-primary);
        text-align: left;
        font-family: inherit;
        cursor: pointer;
        box-shadow: 0 10px 26px rgba(2, 6, 23, 0.12);
        -webkit-tap-highlight-color: transparent;
    }

    .app-ai-card__icon {
        flex-shrink: 0;
        width: 52px;
        height: 52px;
        border-radius: 16px;
        display: grid;
        place-items: center;
        background: rgba(16, 185, 129, 0.12);
        overflow: hidden;
    }

    .app-ai-card__icon img {
        width: 44px;
        height: 44px;
        object-fit: contain;
    }

    .app-ai-card__body { flex: 1; min-width: 0; }

    .app-ai-card__body strong {
        display: block;
        font-family: var(--font-heading);
        font-size: 1.02rem;
        font-weight: 800;
    }

    .app-ai-card__body span {
        display: block;
        margin-top: 2px;
        font-size: 0.8rem;
        color: var(--text-muted);
    }

    .app-ai-card > .ph { color: var(--text-muted); }

    /* Subjects */
    .app-subjects { margin-top: 22px; }

    .app-subjects__head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        margin-bottom: 12px;
    }

    .app-subjects__head h2 {
        margin: 0;
        font-family: var(--font-heading);
        font-size: 1.35rem;
        font-weight: 800;
    }

    .app-subjects__link {
        display: inline-flex;
        align-items: center;
        gap: 2px;
        font-size: 0.9rem;
        font-weight: 700;
        color: #10b981;
        text-decoration: none;
    }

    .app-subjects__grid {
        display: grid;
        gap: 12px;
    }

    .app-subject {
        position: relative;
        display: flex;
        align-items: center;
        gap: 14px;
        padding: 16px;
        border-radius: 24px;
        text-decoration: none;
        color: var(--text-primary);
        border: 1px solid var(--border-glass);
        background: var(--bg-surface);
        overflow: hidden;
        box-shadow: 0 10px 26px rgba(2, 6, 23, 0.1);
        -webkit-tap-highlight-color: transparent;
    }

    .app-subject::after {
        content: '';
        position: absolute;
        right: -30px;
        top: -30px;
        width: 120px;
        height: 120px;
        border-radius: 50%;
        background: var(--app-subject-accent, #10b981);
        opacity: 0.16;
        pointer-events: none;
    }

    .app-subject--human    { --app-subject-accent: #f59e0b; }
    .app-subject--physical { --app-subject-accent: #06b6d4; }

    .app-subject__ring {
        --p: 0;
        flex-shrink: 0;
        width: 68px;
        height: 68px;
        border-radius: 50%;
        display: grid;
        place-items: center;
        background: conic-gradient(var(--app-subject-accent) calc(var(--p) * 1%), var(--border-glass) 0);
    }

    .app-subject__ring span {
        width: 54px;
        height: 54px;
        border-radius: 50%;
        display: grid;
        place-items: center;
        background: var(--bg-surface);
        font-family: var(--font-heading);
        font-size: 0.95rem;
        font-weight: 800;
        color: var(--app-subject-accent);
    }

    .app-subject__body { flex: 1; min-width: 0; }

    .app-subject__body strong {
        display: block;
        font-family: var(--font-heading);
        font-size: 1.08rem;
        font-weight: 800;
        line-height: 1.2;
    }

    .app-subject__body span {
        display: block;
        margin-top: 3px;
        font-size: 0.8rem;
        color: var(--text-muted);
    }

    .app-subject__badge {
        display: inline-flex;
        margin-top: 8px;
        padding: 3px 9px;
        border-radius: 999px;
        font-size: 0.68rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--app-subject-accent);
        background: color-mix(in srgb, var(--app-subject-accent) 14%, transparent);
    }

    .app-subject > .ph {
        color: var(--text-muted);
        position: relative;
        z-index: 1;
    }

    .app-subject.is-locked {
        opacity: 0.78;
    }
}
