/*==============================
    全域變數
===============================*/
/* Light Mode - Stronger Specificity */
html.light-mode {
    --bg-color: #F8F9FA !important;
    --text-color: #212529 !important;
    --link-color: #0D6EFD !important;
    --hover-color: #0A58CA !important;
    --border-color: #DEE2E6 !important;
    --content-bg: #FFFFFF !important;
    --button-bg: #E9ECEF !important;
    --button-hover-bg: #DDE0E3 !important;
    --navbar-bg: #FFFFFF !important;
    --navbar-hover-bg: #F8F9FA !important;
    --category-bg: #F1F3F5 !important;
    --category-text: #212529 !important;

    --toc-bg: #F8F9FA !important;
    --toc-border: #DEE2E6 !important;
}

/* Base Variables */
:root {
    --bg-color: #181818;
    --text-color: #EAEAEA;
    --link-color: #315885;
    --hover-color: #357ABD;
    --border-color: #292929;
    --content-bg: #202020;
    --button-bg: #333333;
    --button-hover-bg: #444444;
    --navbar-bg: #101010;
    --navbar-hover-bg: #222222;
    --category-bg: #252525;
    --category-text: #EAEAEA;
    --site-container-max-width: 1200px;
    /* 文章主區最大寬度 */

    /* Table of Contents */
    --toc-bg: #202020;
    --toc-border: #292929;
}

/*==============================
    全站基本樣式
===============================*/
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
    line-height: 1.8;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background-color 0.3s ease, color 0.3s ease;
    padding-top: 60px;
}

a {
    color: var(--link-color);
    text-decoration: none;
    font-weight: bold;
    transition: color 0.3s ease;
}

a:hover {
    color: var(--hover-color);
    text-decoration: underline;
}

p {
    text-align: justify;
    padding: 10px 0;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: "Noto Serif TC", "Microsoft JhengHei", serif;
    color: var(--text-color);
    text-align: left;
    transition: color 0.3s ease;
}

section h2 {
    font-size: 2rem;
    font-weight: bold;
    color: var(--text-color);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 3px solid var(--border-color);
    padding-bottom: 5px;
    margin-bottom: 20px;
    transition: border-bottom 0.3s ease;
}

section h2:hover {
    border-bottom: 3px solid var(--hover-color);
}

ul {
    padding-left: 20px;
}

li {
    margin-bottom: 5px;
}

hr {
    border: none;
    height: 2px;
    background-color: var(--border-color);
    margin: 20px 0;
}

/*==============================
    主要容器與導覽列
===============================*/
.container {
    max-width: var(--site-container-max-width);
    width: 100%;
    margin: 50px auto;
    background-color: var(--content-bg);
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    transition: background-color 0.3s ease;
}

.navbar {
    width: 100%;
    background-color: var(--navbar-bg);
    padding: 10px 0;
    text-align: center;
    border-bottom: 2px solid var(--border-color);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 999;
}

.navbar-container {
    display: flex;
    justify-content: center;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.navbar ul {
    display: flex;
    justify-content: center;
    list-style: none;
    margin: 0;
    padding: 0;
    width: 100%;
}

.navbar ul li {
    margin: 0 20px;
}

/* Base Navbar Link Styles */
.navbar ul li a {
    color: var(--link-color);
    font-size: 1.2em;
    font-weight: bold;
    padding: 10px 15px;
    border-radius: 5px;
    transition: background-color 0.3s ease, color 0.3s ease;
    display: block;
    /* Ensure full area is clickable */
}

/* --- Dropdown Menu Styles --- */
.navbar ul li {
    position: static;
    /* Anchor for dropdown - CHANGED to static so dropdown spans full navbar width */
}

.dropdown-menu {
    /* display: none; REPLACED with visibility for transition */
    display: grid;
    visibility: hidden;
    opacity: 0;
    transition: all 0.3s ease;

    position: absolute;
    top: 100%;
    left: 0;
    /* Full width */
    width: 100%;
    transform: none;
    /* Remove centering transform */

    background-color: var(--navbar-bg);
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);

    z-index: 1000;
    padding: 30px;

    /* Center grid content effectively via constraints or just letting it flow */
    /* Grid Layout - Auto fit for mega menu feel */
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;

    /* Optional: Limit content width inside the full-width bar */
    padding-left: max(30px, calc(50% - 600px));
    padding-right: max(30px, calc(50% - 600px));
}

/* Show dropdown on hover */
.navbar ul li:hover .dropdown-menu {
    visibility: visible;
    opacity: 1;
}

.dropdown-menu li {
    margin: 0;
    width: auto;
    /* Reset width */
}

.dropdown-menu li a {
    font-size: 1rem;
    /* Smaller font for sub-items */
    padding: 10px 20px;
    white-space: nowrap;
    color: var(--text-color);
    /* Default text color in dropdown */
}

.dropdown-menu li a:hover {
    background-color: var(--navbar-hover-bg);
    color: var(--hover-color);
}

.navbar ul li a:hover {
    color: var(--hover-color);
    background-color: var(--navbar-hover-bg);
}

.site-name h1 {
    margin: 0;
    color: var(--text-color);
}

.hamburger {
    display: none;
}

/*==============================
    按鈕與其他元件
===============================*/
button {
    background: var(--button-bg);
    color: var(--text-color);
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

button:hover {
    background: var(--button-hover-bg);
    transform: scale(1.05);
}

/* 分類標籤 */
.category-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    padding: 20px;
}

.category-item {
    background: var(--category-bg);
    color: var(--category-text);
    padding: 5px 10px;
    border-radius: 5px;
    transition: transform 0.2s ease, background-color 0.3s ease;
}

.category-item:hover {
    transform: scale(1.1);
    background: var(--hover-color);
    color: #101010;
    text-decoration: none;
}

.category-item .count {
    font-size: 0.85em;
    opacity: 0.8;
    margin-left: 5px;
}

/*==============================
    響應式調整
===============================*/
@media (max-width: 768px) {

    /* ⭐ 保留 fixed 位置，不再覆寫成 relative */
    .navbar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 999;
    }

    .hamburger {
        display: block;
        cursor: pointer;
        padding: 10px;
        background: none;
        border: none;
        color: var(--text-color);
        font-size: 1.5em;

        /* 固定定位後，這個位置才能正確 */
        position: absolute;
        top: 10px;
        right: 20px;
    }

    .navbar ul {
        display: none;
        position: absolute;

        /* 固定後選單仍會在下方展開 */
        top: 100%;
        left: 0;

        width: 100%;
        background-color: var(--navbar-bg);
        flex-direction: column;
        text-align: center;
        padding: 15px 0;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    }

    .navbar ul.active {
        display: flex;
    }

    .navbar ul li {
        margin: 10px 0;
    }

    .container {
        max-width: 90%;
        margin: 80px auto 30px;
        /* ⭐ 增加上方距離避免被 navbar 壓住 */
        padding: 25px;
    }

    p {
        padding: 0 15px;
    }

    /* Fix Mobile Dropdown */
    .navbar ul li {
        width: 100%;
        /* Full width items */
        margin: 0;
    }

    .navbar ul li a {
        padding: 15px;
        border-bottom: 1px solid var(--border-color);
        display: block;
    }

    /* Dropdown in mobile: Static position to push content down */
    /* Dropdown in mobile: Static position to push content down */
    .dropdown-menu {
        position: static;
        transform: none;
        box-shadow: none;
        border: none;
        background-color: var(--navbar-hover-bg);
        /* Slightly distinct background */
        text-align: center;
        width: 100%;
        display: none;
        /* Still hidden by default */

        /* Reset visibility/opacity for mobile since we use display:none/block here */
        visibility: visible;
        opacity: 1;

        /* Reset Grid for Mobile */
        grid-template-columns: 1fr;
        gap: 0;
        padding: 0;
    }

    .navbar ul li:hover .dropdown-menu {
        display: block;
    }

    /* Ensure dropdown links are visible in mobile */
    .dropdown-menu li a {
        padding: 10px;
        font-size: 0.95em;
        border-bottom: none;
        /* Remove border for sub-items */
    }

    /* Toggle Button visibility */
    #theme-toggle {
        width: 80%;
        margin: 10px auto;
        display: block;
    }
}

/*==============================
    Cusdis 留言區
===============================*/
/* 只保留同寬＆自動撐開，不強制高度 */
.comment-wrapper {
    margin-top: 40px;
}

/* （1）外層框線、同寬 */
#cusdis_thread {
    width: 100%;
    background-color: var(--content-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    margin-top: 40px;
    /* 跟文章區隔開 */
}

/* （2）直接針對 iframe 本身，用 !important 強制覆寫 */
#cusdis_thread iframe {
    display: block !important;
    width: 100% !important;
    min-height: 1600px !important;
    /* 一打開就是 1600px，也能再往下自動延展 */
    height: auto !important;
    border: none !important;
}

/*==============================
    New Components (Reading Time, Breadcrumbs, TOC)
===============================*/

/* 1. Breadcrumbs */
.breadcrumbs {
    font-size: 0.9em;
    color: var(--text-color);
    margin-bottom: 20px;
    opacity: 0.8;
}

.breadcrumbs a {
    color: var(--link-color);
}

.breadcrumbs span {
    margin: 0 5px;
}

/* 2. Reading Time */
.reading-time {
    font-size: 0.9rem;
    color: var(--text-color);
    opacity: 0.7;
    margin-left: 15px;
    display: inline-block;
}

/* 3. Table of Contents */
.toc-container {
    background-color: var(--toc-bg);
    border: 1px solid var(--toc-border);
    padding: 20px;
    margin-bottom: 30px;
    border-radius: 8px;
}

.toc-title {
    font-weight: bold;
    font-size: 1.2rem;
    margin-top: 0;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 5px;
    color: var(--text-color);
}

#toc ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

#toc ul li {
    margin-bottom: 5px;
}

#toc a {
    text-decoration: none;
    color: var(--link-color);
    font-size: 0.95rem;
}

#toc a:hover {
    text-decoration: underline;
    color: var(--hover-color);
}

/* TOC Indentation for H3 calls */
#toc ul ul {
    padding-left: 20px;
}

/* Post Navigation (Prev/Next) Enhancements */
.post-navigation {
    display: flex;
    justify-content: space-between;
    margin-top: 40px;
    gap: 20px;
}

.post-navigation a {
    flex: 1;
    padding: 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-align: center;
    transition: all 0.3s ease;
    background: var(--content-bg);
    color: var(--text-color);
}

.post-navigation a:hover {
    border-color: var(--hover-color);
    color: var(--hover-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.prev-post::before {
    content: "上一篇：";
    display: block;
    font-size: 0.8em;
    opacity: 0.7;
    margin-bottom: 5px;
}

.next-post::before {
    content: "下一篇：";
    display: block;
    font-size: 0.8em;
    opacity: 0.7;
    margin-bottom: 5px;
}

/*==============================
    頁尾
===============================*/
footer {
    width: 100%;
    background-color: var(--navbar-bg);
    color: var(--text-color);
    text-align: center;
    padding: 20px 0;
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

/*==============================
    Sidebar & Two-Column Layout
===============================*/
.layout-flex {
    display: flex;
    gap: 40px;
    align-items: flex-start;
    /* For Sticky Sidebar */
}

.post-content {
    flex: 3;
    max-width: 750px;
    /* Golden reading width */
    min-width: 0;
    /* Prevent flex overflow */
}

/* Sidebar Styles */
.sidebar {
    flex: 1;
    max-width: 350px;
    min-width: 300px;
    position: sticky;
    top: 100px;
    /* Sticky effect when scrolling */
}

.sidebar-widget {
    background-color: var(--navbar-bg);
    /* Use Navbar bg for slight contrast or just container bg */
    border: 1px solid var(--border-color);
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.widget-title {
    font-size: 1.2rem;
    font-weight: bold;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 15px;
    margin-top: 0;
}

/* Popular Posts Widget */
.post-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.post-list li {
    margin-bottom: 15px;
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 10px;
}

.post-list li:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.post-list a {
    display: block;
    font-weight: normal;
}

.post-list .post-title {
    font-weight: bold;
    font-size: 1rem;
    color: var(--text-color);
    margin-bottom: 5px;
    transition: color 0.3s ease;
}

.post-list a:hover .post-title {
    color: var(--hover-color);
}

.post-list .post-date {
    font-size: 0.85rem;
    color: var(--text-color);
    opacity: 0.6;
}

/* Tag Cloud Widget */
.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.tag-pill {
    background-color: var(--button-bg);
    color: var(--text-color);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    text-decoration: none;
    font-weight: normal;
    border: 1px solid transparent;
}

.tag-pill:hover {
    background-color: var(--hover-color);
    color: #fff;
    transform: translateY(-2px);
    text-decoration: none;
}

.tag-pill .count {
    font-size: 0.8em;
    opacity: 0.7;
    margin-left: 3px;
}

/* Responsive Sidebar adjustments */
@media (max-width: 992px) {
    .layout-flex {
        flex-direction: column;
    }

    .post-content {
        max-width: 100%;
        /* Full width on mobile/tablet */
    }

    .sidebar {
        width: 100%;
        max-width: 100%;
        position: static;
        margin-top: 40px;
    }

    .tag-cloud {
        justify-content: center;
    }
}

/*==============================
    Name Switcher Replaced Text
===============================*/
.replaced-name {
    background-color: rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 2px 4px;
    border-radius: 4px;
    font-weight: bold;
    transition: background-color 0.3s ease, color 0.3s ease;
}


html.light-mode .replaced-name {
    background-color: #e2e6ea;
    color: #212529;
}

/*==============================
    Name Switcher Component
===============================*/
.name-switcher-container {
    background-color: var(--navbar-bg);
    /* Use navbar or category bg for subtle contrast */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 30px;
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.name-switcher-summary {
    cursor: pointer;
    font-weight: bold;
    color: var(--link-color);
    /* Make it look interactive */
    transition: color 0.3s ease;
}

.name-switcher-summary:hover {
    color: var(--hover-color);
}

.name-switcher-desc {
    font-size: 0.9em;
    color: var(--text-color);
    opacity: 0.8;
    margin-bottom: 15px;
    margin-top: 10px;
}

.name-switcher-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    margin-bottom: 15px;
}

.name-switcher-group {
    flex: 1;
    min-width: 140px;
}

.name-switcher-label {
    display: block;
    font-size: 0.85em;
    margin-bottom: 5px;
    color: var(--text-color);
    opacity: 0.9;
}

.name-switcher-input {
    width: 100%;
    padding: 8px 12px;
    background-color: var(--content-bg);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    color: var(--text-color);
    transition: border-color 0.3s ease;
}

.name-switcher-input:focus {
    outline: none;
    border-color: var(--link-color);
}

.name-switcher-input[readonly] {
    background-color: var(--button-bg);
    /* Use a darker/different bg to indicate disabled/readonly */
    opacity: 0.7;
    cursor: default;
}

.name-switcher-arrow {
    flex: 0 0 auto;
    padding-top: 20px;
    /* Align with input */
    color: var(--text-color);
    opacity: 0.5;
}

.name-switcher-actions {
    text-align: right;
    margin-top: 20px;
}

.name-switcher-btn {
    /* Inherits from global button style but customized if needed */
    margin-left: 10px;
}
/*==============================
    Code Block Styling (Added for Fix)
==============================*/
pre {
    background-color: var(--category-bg);
    color: var(--text-color);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    white-space: pre-wrap;       /* Wrap text to prevent overflow */
    word-wrap: break-word;       /* Legacy support */
    overflow-wrap: break-word;   /* Standard */
    margin: 20px 0;
    font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
    font-size: 0.95em;
    line-height: 1.6;
    box-shadow: inset 0 1px 4px rgba(0,0,0,0.05);
}

code {
    font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
    background-color: var(--button-bg); /* Inline code bg */
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* Override inline style for code blocks */
pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
    color: inherit;
}
