/* ============================================================
   阿偉的物理 x AI 實驗室 — 全局品牌樣式
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700;900&display=swap');

/* ── CSS 品牌變數 ── */
:root {
    --brand-primary:   #657954;
    --brand-dark:      #4a5e3a;
    --bg-light:        #F8FAFC;
    --text-main:       #1E293B;
    --text-muted:      #64748B;
    --action-blue:     #3B82F6;
    --border-color:    #E2E8F0;
    --navbar-height:   60px;
    --shadow-navbar:   0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-card:     0 2px 10px rgba(0, 0, 0, 0.05);
    --radius-card:     14px;
}

/* ── 全局重置 ── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;   /* App Shell：body 不捲動，iframe 內部自行捲動 */
    font-family: 'Noto Sans TC', sans-serif;
    background-color: var(--bg-light);
    color: var(--text-main);
}

/* ── App Shell 骨架 ── */
.app-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

/* ── Navbar ── */
.navbar {
    flex-shrink: 0;
    height: var(--navbar-height);
    background: #ffffff;
    box-shadow: var(--shadow-navbar);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
}

.navbar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--brand-primary);
    font-weight: 900;
    font-size: 1rem;
    letter-spacing: 0.3px;
    transition: opacity 0.2s;
    white-space: nowrap;
}

.navbar-logo:hover {
    opacity: 0.75;
}

.navbar-logo .logo-icon {
    font-size: 1.4rem;
    line-height: 1;
}

/* ── Navigation Links ── */
.nav-links {
    display: flex;
    align-items: center;
    gap: 28px;
    list-style: none;
    margin-left: auto;
    margin-right: 24px;
}

.nav-links > li {
    position: relative;
    height: var(--navbar-height);
    display: flex;
    align-items: center;
}

.nav-links a {
    text-decoration: none;
    color: var(--text-main);
    font-size: 0.95rem;
    font-weight: 700;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.nav-links a:hover, .nav-links li:hover > a {
    color: var(--brand-primary);
}

.caret {
    font-size: 0.65rem;
    transform: translateY(1px);
    color: var(--text-muted);
}

/* ── Dropdown Menu ── */
.dropdown-menu {
    position: absolute;
    top: 96%;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    background: #ffffff;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    list-style: none;
    min-width: 240px;
    padding: 10px 0;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 200;
}

.nav-links li:hover .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.dropdown-menu li {
    width: 100%;
    height: auto;
    display: block;
}

.dropdown-menu a {
    padding: 12px 24px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-main);
    display: block;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.dropdown-menu a:hover {
    background: var(--bg-light);
    color: var(--brand-primary);
}

.mobile-toggle {
    display: none;
    background: transparent;
    border: none;
    font-size: 1.6rem;
    color: var(--brand-primary);
    cursor: pointer;
    padding: 2px 6px;
    margin-left: 4px;
    transition: transform 0.2s;
}

.mobile-toggle:active {
    transform: scale(0.9);
}

@media (max-width: 1000px) {
    .mobile-toggle {
        display: block;
    }

    .nav-links {
        position: fixed;
        top: var(--navbar-height);
        right: -100%;
        width: 260px;
        height: calc(100vh - var(--navbar-height));
        background: #ffffff;
        flex-direction: column;
        align-items: flex-start;
        padding: 12px 0;
        gap: 0;
        box-shadow: -4px 0 15px rgba(0,0,0,0.08);
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 999;
        margin: 0;
        overflow-y: auto;
    }

    .nav-links.nav-open {
        right: 0;
    }

    .nav-links > li {
        width: 100%;
        height: auto;
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    .nav-links a {
        display: flex;
        justify-content: space-between; /* push caret to right edge */
        align-items: center;
        padding: 16px 24px;
        width: 100%;
        border-bottom: 1px inset rgba(0,0,0,0.05);
        border-radius: 0;
        font-size: 1.05rem;
    }

    /* Override Desktop Hover Dropdown */
    .dropdown-menu,
    .nav-links li:hover .dropdown-menu,
    .nav-links > li.dropdown-open .dropdown-menu {
        position: static !important;
        left: auto !important;
        right: auto !important;
        transform: none !important;
        box-shadow: none !important;
        border: none !important;
        border-radius: 0;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        opacity: 1;
        visibility: visible;
        background: #F8FAFC;
    }

    .dropdown-menu {
        display: none; /* Accordion default closed */
    }

    .nav-links > li.dropdown-open .dropdown-menu {
        display: block; /* Accordion open */
    }

    .caret {
        padding: 4px 12px;
        margin-right: -12px;
        font-size: 0.9rem;
    }

    .dropdown-menu a {
        padding: 12px 24px 12px 2.5rem !important; /* Indented for sub-menu hierarchy */
        font-size: 0.95rem;
        font-weight: 400;
        border-bottom: 1px solid var(--border-color);
        color: var(--text-muted);
        display: block !important;
        white-space: normal !important;
        line-height: 1.4;
        width: 100% !important;
        margin: 0 !important;
    }
}

/* ── Search Overlay ── */
.search-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: none;
    flex-direction: column;
    align-items: center;
    padding-top: 8vh;
    opacity: 0;
    transition: opacity 0.3s;
}

.search-overlay.active {
    display: flex;
    opacity: 1;
}

.search-container {
    width: 90%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.search-header {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
}

.search-input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    background: #ffffff;
    border-radius: 16px;
    padding: 12px 24px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.search-icon {
    font-size: 1.5rem;
    color: var(--text-muted);
    margin-right: 12px;
}

.search-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 1.3rem;
    font-family: inherit;
    color: var(--text-main);
}
.search-input::placeholder { color: #cbd5e1; }

.search-close {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.search-close:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.05);
}

.search-results-label {
    color: #94a3b8;
    font-size: 1rem;
    padding-left: 8px;
}

.search-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
    max-height: 60vh;
    overflow-y: auto;
    padding-bottom: 40px;
}

.search-results::-webkit-scrollbar { width: 6px; }
.search-results::-webkit-scrollbar-track { background: transparent; }
.search-results::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
}

.search-card {
    background: #ffffff;
    border-radius: 12px;
    padding: 16px;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: transform 0.2s, box-shadow 0.2s;
    border-bottom: 3px solid transparent;
}
.search-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}

.search-card-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
}
.search-card-category {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--brand-primary);
    background: var(--bg-light);
    padding: 4px 8px;
    border-radius: 6px;
    align-self: flex-start;
}
.search-card-tags {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 預留按鈕樣式 */
.navbar-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.navbar-btn:hover {
    background: var(--bg-light);
    color: var(--brand-primary);
    border-color: var(--brand-primary);
}

/* ── Content Area ── */
.content-area {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.content-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}
/* ── Loading Bar ── */
#page-loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0%;
    background: linear-gradient(90deg, var(--brand-primary), var(--action-blue));
    z-index: 99999;
    transition: width 0.3s ease, opacity 0.3s ease;
    opacity: 0;
    border-radius: 0 2px 2px 0;
    box-shadow: 0 0 8px rgba(101, 121, 84, 0.5);
}

#page-loading-bar.loading {
    opacity: 1;
}
