:root {
    color-scheme: light only;
    --portal-canvas: #f4f6f5;
    --portal-surface: #fffefd;
    --portal-surface-soft: #f8e9df;
    --portal-ink: #24363a;
    --portal-muted: #667276;
    --portal-line: #dedfda;
    --portal-accent: #bd501f;
    --portal-accent-dark: #914018;
    --portal-sidebar-width: 264px;
}

html,
html[data-theme="study"] {
    color-scheme: light only !important;
    background: var(--portal-canvas);
}

body.portal-shell-ready {
    min-width: 320px;
    min-height: 100dvh;
    padding-left: var(--portal-sidebar-width);
    padding-bottom: 0 !important;
    background: var(--portal-canvas);
    color: var(--portal-ink);
}

.portal-shell-ready .app-top-tabs-wrap {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1000;
    display: flex;
    width: var(--portal-sidebar-width);
    max-width: none;
    height: 100dvh;
    flex-direction: column;
    margin: 0;
    border: 0;
    border-right: 1px solid var(--portal-line);
    background: rgba(255, 254, 253, 0.98);
    padding: 22px 16px 18px;
    box-shadow: none;
}

.portal-brand {
    display: flex;
    min-height: 70px;
    align-items: center;
    border-radius: 12px;
    padding: 5px 8px;
    text-decoration: none;
}

.portal-brand:hover,
.portal-brand:focus-visible {
    background: var(--portal-surface-soft);
    outline: none;
}

.portal-brand img {
    display: block;
    width: 214px;
    height: auto;
}

.portal-shell-ready .app-top-tabs {
    display: flex;
    min-height: 0;
    flex: 1;
    flex-direction: column;
    gap: 4px;
    margin-top: 20px;
    overflow-x: hidden;
    overflow-y: auto;
    border-radius: 0;
    background: transparent;
    padding: 0 2px;
    box-shadow: none;
}

.portal-shell-ready .app-top-tab {
    display: flex;
    width: 100%;
    min-width: 0;
    min-height: 46px;
    flex: none;
    justify-content: flex-start;
    border: 1px solid transparent;
    border-radius: 11px;
    background: transparent;
    color: var(--portal-ink);
    padding: 10px 13px;
    box-shadow: none;
    font-size: 0.94rem;
    font-weight: 700;
    text-align: left;
}

.portal-shell-ready .app-top-tab:hover,
.portal-shell-ready .app-top-tab:focus-visible {
    border-color: transparent;
    background: var(--portal-surface-soft);
    color: var(--portal-accent-dark);
    outline: 3px solid rgba(189, 80, 31, 0.18);
    outline-offset: 1px;
}

.portal-shell-ready .app-top-tab.active {
    border-color: #efd4c2;
    background: var(--portal-surface-soft);
    color: var(--portal-accent-dark);
    box-shadow: inset 3px 0 0 var(--portal-accent);
}

.portal-language-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-top: auto;
    border: 1px solid var(--portal-line);
    border-radius: 10px;
    background: var(--portal-surface);
    padding: 4px;
}

.portal-language-button {
    min-height: 36px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--portal-muted);
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 800;
}

.portal-language-button[aria-pressed="true"] {
    background: var(--portal-ink);
    color: #fffaf7;
}

.portal-mobile-menu,
.portal-drawer-close,
.portal-drawer-scrim {
    display: none;
}

.portal-shell-ready > .container,
.portal-shell-ready > .aichat-wrap,
.portal-shell-ready > .shop-shell,
.portal-shell-ready > .profile-container,
.portal-shell-ready > #app {
    width: min(1120px, 100%);
    max-width: 1120px;
}

.portal-shell-ready > .profile-container {
    width: min(760px, 100%);
    max-width: 760px;
}

.portal-shell-ready[data-portal-home="daily"] .practice-library-shell,
.portal-shell-ready[data-portal-home="daily"] .hsk-selection-container,
.portal-shell-ready[data-portal-home="daily"] #study-selection-container,
.portal-shell-ready[data-portal-home="daily"] #level-dashboard {
    display: none !important;
}

.portal-shell-ready[data-portal-home="practice"] #start-screen {
    display: none !important;
}

.portal-shell-ready .hsk-selection-container {
    margin-top: 0 !important;
    border-top: 0 !important;
    padding-top: 0 !important;
}

.portal-shell-ready .hsk-version-toggle {
    border: 1px solid var(--portal-line);
    border-radius: 18px;
    background: var(--portal-surface);
    padding: 10px;
    box-shadow: 0 12px 30px rgba(86, 62, 45, 0.07);
}

.portal-shell-ready .version-btn {
    border: 1px solid transparent;
    border-radius: 10px;
    color: var(--portal-ink);
    padding: 10px 20px;
}

.portal-shell-ready .version-btn.active {
    border-color: var(--portal-accent);
    background: var(--portal-accent);
    color: #fffaf7;
    box-shadow: 0 7px 16px rgba(145, 64, 24, 0.18);
}

.practice-mode-toggle {
    display: grid;
    width: min(760px, 100%);
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    border: 1px solid var(--portal-line);
    border-radius: 18px;
    background: var(--portal-surface);
    margin: 14px auto 0;
    padding: 10px;
    box-shadow: 0 12px 30px rgba(86, 62, 45, 0.07);
}

.practice-mode-toggle.hidden {
    display: none !important;
}

.practice-mode-btn {
    min-height: 52px;
    border: 1px solid var(--portal-line);
    border-radius: 11px;
    background: #f8f8f7;
    color: var(--portal-ink);
    cursor: pointer;
    padding: 10px 14px;
    font-weight: 750;
}

.practice-mode-btn.active,
.practice-mode-btn[aria-pressed="true"] {
    border-color: var(--portal-accent);
    background: var(--portal-surface-soft);
    color: var(--portal-accent-dark);
    box-shadow: inset 3px 0 0 var(--portal-accent);
}

.selection-skill-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin: 0 auto 22px;
    border-bottom: 1px solid var(--portal-line);
    padding-bottom: 13px;
}

.selection-skill-tab {
    min-height: 40px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: var(--portal-muted);
    cursor: pointer;
    padding: 8px 13px;
    font-weight: 740;
}

.selection-skill-tab.active,
.selection-skill-tab[aria-pressed="true"] {
    border-color: var(--portal-line);
    background: var(--portal-surface-soft);
    color: var(--portal-accent-dark);
}

@media (max-width: 820px) {
    body.portal-menu-open {
        overflow: hidden;
    }

    body.portal-shell-ready {
        padding-top: 68px;
        padding-left: 0;
    }

    .portal-shell-ready .app-top-tabs-wrap {
        inset: 0 0 auto 0;
        width: 100%;
        height: 68px;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        border-right: 0;
        border-bottom: 1px solid var(--portal-line);
        padding: 8px 14px;
    }

    .portal-brand {
        min-height: 0;
        width: 174px;
        padding: 3px 5px;
    }

    .portal-brand img {
        width: 164px;
    }

    .portal-mobile-menu,
    .portal-drawer-close {
        display: grid;
        width: 44px;
        height: 44px;
        place-items: center;
        border: 0;
        border-radius: 10px;
        background: transparent;
        color: var(--portal-ink);
        cursor: pointer;
    }

    .portal-mobile-menu::before {
        width: 21px;
        height: 14px;
        border-top: 2px solid currentColor;
        border-bottom: 2px solid currentColor;
        box-shadow: inset 0 6px 0 -4px currentColor;
        content: "";
    }

    .portal-drawer-close {
        align-self: flex-end;
        margin: 4px 4px 12px;
        font-size: 1.45rem;
    }

    .portal-shell-ready .app-top-tabs {
        position: fixed;
        inset: 0 0 0 auto;
        z-index: 1002;
        width: min(86vw, 330px);
        height: 100dvh;
        margin: 0;
        transform: translateX(102%);
        border-left: 1px solid var(--portal-line);
        background: var(--portal-surface);
        padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
        box-shadow: -18px 0 42px rgba(39, 49, 51, 0.14);
        transition: transform 180ms ease;
    }

    .portal-menu-open .app-top-tabs {
        transform: translateX(0);
    }

    .portal-language-switch {
        margin-top: auto;
    }

    .portal-drawer-scrim {
        position: fixed;
        inset: 0;
        z-index: 1001;
        display: block;
        visibility: hidden;
        border: 0;
        background: rgba(27, 35, 37, 0.36);
        opacity: 0;
        transition: opacity 180ms ease, visibility 180ms ease;
    }

    .portal-menu-open .portal-drawer-scrim {
        visibility: visible;
        opacity: 1;
    }

    .practice-mode-toggle {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .portal-shell-ready > .container,
    .portal-shell-ready > .aichat-wrap,
    .portal-shell-ready > .shop-shell,
    .portal-shell-ready > .profile-container {
        padding-right: 14px;
        padding-left: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .portal-shell-ready .app-top-tabs,
    .portal-drawer-scrim {
        transition: none;
    }
}

.portal-logout {
    flex: none;
    width: 100%;
    min-height: 46px;
    margin-top: 12px;
    padding: 12px 13px;
    border: 0;
    border-top: 1px solid var(--portal-line);
    border-radius: 0 0 10px 10px;
    background: transparent;
    color: var(--portal-accent-dark);
    font: inherit;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}
.portal-logout[hidden] { display: none !important; }
.portal-logout:hover, .portal-logout:focus-visible { background: var(--portal-surface-soft); }
.portal-logout:focus-visible { outline: 2px solid var(--portal-accent); outline-offset: -2px; }
/* Only the store is a guest navigation destination; member links wait for server verification. */
html:not([data-portal-access="member"]) .app-top-tabs .app-top-tab:not([data-i18n="tab.shop"]) { display:none!important; }
