/* ===== ChemistryTimes — Sidebar + Iframe Layout Shell ===== */

/* --- Language Toggle --- */
.lang-en { display: none; }
.lang-zh-tw { display: inline; }
body[data-lang="en"] .lang-en { display: inline; }
body[data-lang="en"] .lang-zh-tw { display: none; }

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Greyscale tokens */
    --tabc-grey-100: #ffffff;
    --tabc-grey-200: #f2f2f2;
    --tabc-grey-300: #e9e9e9;
    --tabc-grey-400: #dddddd;
    --tabc-grey-500: #aaaaaa;
    --tabc-grey-600: #777777;
    --tabc-grey-700: #555555;
    --tabc-grey-800: #333333;
    --tabc-grey-900: #080808;
    --tabc-dark-blue-800: #112f82;

    /* Semantic */
    --bg-primary: #f9f8f6;
    --bg-card: #ffffff;
    --text-primary: var(--tabc-grey-800);
    --text-secondary: var(--tabc-grey-700);
    --text-muted: var(--tabc-grey-500);
    --border-color: var(--tabc-grey-400);
    --border-heavy: var(--tabc-grey-900);
    --accent: var(--tabc-grey-900);
    --link-color: var(--tabc-dark-blue-800);

    /* Typography */
    --font-primary: 'Huninn', 'Noto Sans TC', sans-serif;

    /* Layout */
    --content-max: 960px;
}

/* --- Dark Theme --- */
[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-card: #242424;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-muted: #777777;
    --border-color: #333333;
    --border-heavy: #e0e0e0;
    --accent: #e0e0e0;
    --link-color: #6ca4d9;
    --tabc-grey-100: #1a1a1a;
    --tabc-grey-200: #242424;
    --tabc-grey-300: #333333;
    --tabc-grey-400: #444444;
    --tabc-grey-500: #777777;
    --tabc-grey-600: #999999;
    --tabc-grey-700: #b0b0b0;
    --tabc-grey-800: #e0e0e0;
    --tabc-grey-900: #f0f0f0;
}

/* Dark theme — overrides for elements not using CSS variables */
[data-theme="dark"] .welcome-icon svg {
    stroke: #555555;
}

[data-theme="dark"] .mobile-sidebar-toggle {
    background: var(--bg-card);
    border-color: var(--border-color);
}

[data-theme="dark"] .mobile-sidebar-toggle span {
    background: var(--text-muted);
}

[data-theme="dark"] .mobile-overlay.open {
    background: rgba(0, 0, 0, 0.6);
}

/* --- View Transition (dark mode ripple) --- */
::view-transition-old(root),
::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}

/* --- Iframe Theme Mask --- */
.iframe-theme-mask {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.1s;
}

.iframe-theme-mask.active {
    opacity: 1;
}

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-primary);
    font-size: 16px;
    font-weight: 400;
    color: var(--text-primary);
    background: var(--bg-primary);
    line-height: 1.7;
    min-height: 100vh;
    overflow: hidden;
}

/* --- Navbar (56px) --- */
.navbar {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    position: relative;
    z-index: 100;
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.navbar-center {
    display: flex;
    align-items: center;
    gap: 8px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.navbar-brand {
    font-family: var(--font-primary);
    font-size: 22px;
    color: var(--text-primary);
    letter-spacing: 0.3px;
}

.navbar-sub {
    font-family: var(--font-primary);
    font-size: 14px;
    color: var(--text-muted);
    letter-spacing: 2px;
}

.navbar-date,
.navbar-issue {
    font-family: var(--font-primary);
    font-size: 12px;
    color: var(--text-muted);
}

.navbar-divider {
    display: inline-block;
    width: 1px;
    height: 14px;
    background: var(--border-color);
}

/* --- Toggle Buttons (theme + lang) --- */
.theme-toggle,
.lang-toggle {
    border: none;
    border-radius: 3px;
    padding: 6px 10px;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-primary);
    font-size: 12px;
    color: var(--text-muted);
    transition: color 0.15s ease, background 0.15s ease;
}

.theme-toggle svg,
.lang-toggle svg {
    stroke: var(--text-muted);
    transition: stroke 0.15s ease;
}

.theme-toggle:hover,
.lang-toggle:hover {
    color: var(--text-primary);
    background: var(--tabc-grey-200);
}

.theme-toggle:hover svg,
.lang-toggle:hover svg {
    stroke: var(--text-primary);
}

.lang-label {
    font-weight: 400;
    letter-spacing: 0.5px;
}

/* --- Layout (sidebar + content) --- */
.layout {
    display: flex;
    height: calc(100vh - 56px - 37px);
}

/* --- Sidebar (260px, collapsible) --- */
.sidebar {
    width: 260px;
    min-width: 260px;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    transition: width 0.2s, min-width 0.2s;
    position: relative;
}

.sidebar.collapsed {
    width: 36px;
    min-width: 36px;
    overflow: hidden;
}

.sidebar.collapsed .sidebar-header-content,
.sidebar.collapsed .sidebar-list-container,
.sidebar.collapsed .sidebar-footer,
.sidebar.collapsed .sidebar-header {
    display: none;
}

.sidebar.collapsed .sidebar-collapsed-content {
    display: flex;
}

.sidebar-header {
    font-family: var(--font-primary);
    font-size: 14px;
    color: var(--text-muted);
    letter-spacing: 1.5px;
    padding: 12px 24px;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-collapse-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-collapse-btn:hover {
    color: var(--text-secondary);
}

/* --- Sidebar List --- */
.sidebar-list-container {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.sidebar-list {
    height: 100%;
    overflow-y: auto;
    scrollbar-width: thin;
}

.sidebar-list::-webkit-scrollbar {
    width: 4px;
}

.sidebar-list::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-list::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 2px;
}

/* --- Article Items (in sidebar) --- */
.article-item {
    padding: 10px 24px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: all 0.15s;
}

.article-item:hover {
    background: var(--bg-card);
}

.article-item.active {
    background: var(--bg-card);
    border-left-color: var(--link-color);
}

.article-item-title {
    font-family: var(--font-primary);
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.article-item.active .article-item-title {
    color: var(--accent);
}

.article-item-date {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.article-item-empty {
    padding: 40px 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* --- Scroll Fade Indicators --- */
.scroll-fade-top,
.scroll-fade-bottom {
    position: absolute;
    left: 0;
    width: 100%;
    pointer-events: none;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.2s;
}

.scroll-fade-top {
    top: 0;
    height: 50px;
    background: linear-gradient(to bottom, var(--bg-primary), transparent);
}

.scroll-fade-bottom {
    bottom: 0;
    height: 70px;
    background: linear-gradient(to top, var(--bg-primary), transparent);
}

.scroll-fade-top.visible,
.scroll-fade-bottom.visible {
    opacity: 1;
}

/* --- Sidebar Footer (pet tank) --- */
.sidebar-footer {
    padding: 12px 24px 1px;
    display: flex;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.pet-tank-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.pet-flashlight-area {
    display: none;
    position: relative;
    flex-shrink: 0;
    width: 32px;
    height: 91px;
    align-items: center;
    justify-content: flex-end;
    margin-left: -28px;
    opacity: 0;
    transition: opacity 0.8s ease;
}

[data-theme="dark"] .pet-flashlight-area {
    display: flex;
}

[data-theme="dark"] .pet-flashlight-area.ready {
    opacity: 1;
}

.pet-flashlight {
    border: none;
    background: none;
    cursor: pointer;
    padding: 0;
    color: #444;
    transition: color 0.4s, filter 0.4s;
    position: relative;
    z-index: 3;
}

.pet-flashlight:hover {
    color: #666;
}

/* Beam — arc glow from flashlight head toward pet tank */
.pet-light-beam {
    position: absolute;
    left: 28px;
    top: -20px;
    width: 170px;
    height: 130px;
    pointer-events: none;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.5s;
}

/* Lights ON — icon glows warm */
[data-theme="dark"] .pet-tank-wrapper.lights-on .pet-flashlight {
    color: #f5f0e0;
    filter: drop-shadow(0 0 5px rgba(255, 250, 220, 0.8))
            drop-shadow(0 0 15px rgba(255, 245, 200, 0.4));
}

[data-theme="dark"] .pet-tank-wrapper.lights-on .pet-light-beam {
    opacity: 1;
}

/* Narrow beam — focused cone from flashlight to pet tank */
[data-theme="dark"] .pet-tank-wrapper.lights-on .pet-light-beam::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 160px;
    height: 130px;
    background:
        /* Tight narrow beam */
        radial-gradient(
            ellipse 55% 18% at 8% 50%,
            rgba(255, 252, 240, 0.50) 0%,
            rgba(255, 250, 230, 0.20) 40%,
            rgba(255, 248, 220, 0.05) 70%,
            transparent 100%
        ),
        /* Wider soft spill */
        radial-gradient(
            ellipse 50% 30% at 8% 50%,
            rgba(255, 250, 225, 0.15) 0%,
            rgba(255, 248, 215, 0.05) 50%,
            transparent 100%
        );
    filter: blur(5px);
}

/* Bright hotspot — emission point at flashlight head */
[data-theme="dark"] .pet-tank-wrapper.lights-on .pet-light-beam::after {
    content: '';
    position: absolute;
    left: -3px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 10px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 248, 0.9) 0%, rgba(255, 250, 235, 0.3) 50%, transparent 80%);
    filter: blur(2px);
}

[data-theme="dark"] .pet-tank {
    opacity: 0.55;
    filter: brightness(0.85);
    transition: opacity 0.6s ease, filter 0.6s ease;
    mask-image: linear-gradient(to right, transparent, rgba(0,0,0,0.35) 25%, rgba(0,0,0,0.35) 75%, transparent),
                linear-gradient(to bottom, transparent, rgba(0,0,0,0.35) 25%, rgba(0,0,0,0.35) 75%, transparent);
    mask-composite: intersect;
    -webkit-mask-image: linear-gradient(to right, transparent, rgba(0,0,0,0.35) 25%, rgba(0,0,0,0.35) 75%, transparent),
                        linear-gradient(to bottom, transparent, rgba(0,0,0,0.35) 25%, rgba(0,0,0,0.35) 75%, transparent);
    -webkit-mask-composite: source-in;
}

/* Lights on — smooth transition to visible */
[data-theme="dark"] .pet-tank.lights-on {
    opacity: 1;
    filter: none;
    mask-image:
        /* Upper half of beam — tighter on left, expands right-upward */
        radial-gradient(ellipse 80% 40% at 35% 55%, black 0%, rgba(0,0,0,0.5) 35%, rgba(0,0,0,0.06) 65%, transparent 85%),
        /* Lower half of beam — wider, expands right-downward */
        radial-gradient(ellipse 90% 55% at 45% 45%, black 0%, rgba(0,0,0,0.4) 30%, rgba(0,0,0,0.06) 60%, transparent 85%),
        /* Base silhouette */
        linear-gradient(to right, transparent, rgba(0,0,0,0.35) 30%, rgba(0,0,0,0.35) 70%, transparent),
        linear-gradient(to bottom, transparent, rgba(0,0,0,0.35) 30%, rgba(0,0,0,0.35) 70%, transparent);
    mask-composite: add, add, intersect;
    -webkit-mask-image:
        radial-gradient(ellipse 80% 40% at 35% 55%, black 0%, rgba(0,0,0,0.5) 35%, rgba(0,0,0,0.06) 65%, transparent 85%),
        radial-gradient(ellipse 90% 55% at 45% 45%, black 0%, rgba(0,0,0,0.4) 30%, rgba(0,0,0,0.06) 60%, transparent 85%),
        linear-gradient(to right, transparent, rgba(0,0,0,0.35) 30%, rgba(0,0,0,0.35) 70%, transparent),
        linear-gradient(to bottom, transparent, rgba(0,0,0,0.35) 30%, rgba(0,0,0,0.35) 70%, transparent);
    -webkit-mask-composite: source-over, source-over, source-in;
}

/* --- Sidebar Collapsed State --- */
.sidebar-collapsed-content {
    display: none;
    flex-direction: column;
    align-items: center;
    padding-top: 12px;
}

.sidebar-collapsed-label {
    writing-mode: vertical-rl;
    font-family: var(--font-primary);
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: 2px;
    margin-top: 16px;
}

/* --- Pet Tank --- */
.pet-tank {
    width: 120px;
    height: 91px;
    overflow: hidden;
    background: var(--bg-primary);
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32'%3E%3Ctext y='24' font-size='24'%3E%F0%9F%8C%BB%3C/text%3E%3C/svg%3E") 16 16, pointer;
}

.pet-tank iframe {
    margin: -1.5px;
    width: calc(100% + 3.5px);
    height: calc(100% + 3px);
}

/* --- Content Area --- */
.content {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: var(--bg-primary);
}

/* --- Welcome Screen --- */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 16px;
}

.welcome-icon svg {
    width: 48px;
    height: 48px;
}

.welcome-title {
    font-family: var(--font-primary);
    font-size: 24px;
    color: var(--text-primary);
}

.welcome-sub {
    font-family: var(--font-primary);
    font-size: 13px;
    color: var(--text-muted);
    letter-spacing: 1.5px;
}

.welcome-hint {
    font-family: var(--font-primary);
    font-size: 14px;
    color: var(--text-muted);
}

/* --- Article Frame (iframe) --- */
.article-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: none;
}

.article-frame.visible {
    display: block;
}

/* --- Footer --- */
.footer {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 8px 32px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.footer span {
    font-family: var(--font-primary);
    font-size: 11px;
    color: var(--text-muted);
}

/* --- Loading / Spinner --- */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--tabc-grey-300);
    border-top-color: var(--tabc-grey-700);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Mobile Sidebar Toggle --- */
.mobile-sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 48px;
    right: 24px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border-radius: 3px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.mobile-sidebar-toggle span {
    display: block;
    width: 16px;
    height: 1.5px;
    background: #999;
    border-radius: 1px;
}

.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 250;
}

.mobile-overlay.open {
    display: block;
}

/* --- Responsive: Mobile <= 768px --- */
@media (max-width: 768px) {
    .navbar-left {
        display: none;
    }

    .navbar-center {
        position: static;
        transform: none;
    }

    .navbar {
        justify-content: center;
        gap: 16px;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 300;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        border-right: 1px solid var(--border-color);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
    }

    .mobile-sidebar-toggle {
        display: flex;
    }

    .pet-tank {
        display: none;
    }

    .sidebar-footer {
        display: none;
    }

    .footer {
        flex-direction: column;
        gap: 4px;
    }
}

@media (max-width: 375px) {
    .navbar {
        padding: 0 16px;
    }
}
