/* --- 全域設定 --- */
:root {
    --bg-dark: #0f172a;
    --bg-side: #1e293b;
    --accent: #38bdf8;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --glass: rgba(255, 255, 255, 0.03);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --header-height: 75px; /* 定義頁首高度變數 */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- 頁首區塊 --- */
header {
    height: var(--header-height);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    /* justify-content: space-between;  <-- 修改這裡 */
    padding: 0 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 100;
    position: relative; /* 確保 z-index 生效 */
}

/* 新增：手機版漢堡選單按鈕樣式 */
.mobile-menu-btn {
    display: none; /* 預設隱藏，手機版才顯示 */
    flex-direction: column;
    justify-content: space-around;
    width: 30px;
    height: 25px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 101; /* 比側邊欄高 */
    margin-right: 20px;
}

.mobile-menu-btn span {
    width: 100%;
    height: 3px;
    background-color: var(--text-main);
    border-radius: 10px;
    transition: var(--transition);
}

/* 漢堡按鈕變成 X 的動畫效果 */
.mobile-menu-btn.open span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 6px);
}
.mobile-menu-btn.open span:nth-child(2) {
    opacity: 0;
}
.mobile-menu-btn.open span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -6px);
}


.logo {
    font-size: 1.4rem;
    font-weight: 800;
    background: linear-gradient(to right, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 1px;
    /* width: 150px;  <-- 移除固定寬度 */
    text-decoration: none;
    color: inherit;
    display: inline-block;
    margin-right: auto; /* 讓 Logo 靠左，標題靠右 */
}

.page-title {
    text-align: right; /* 標題靠右對齊 */
}

.header-user-zone {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-right: 18px;
    padding: 8px 14px;
    border-radius: 14px;
    border: 1px solid rgba(56, 189, 248, 0.35);
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.92));
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.18), inset 0 0 18px rgba(129, 140, 248, 0.08);
}

.header-user-label {
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.header-user-name {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    background: linear-gradient(90deg, #67e8f9 0%, #38bdf8 30%, #a78bfa 65%, #f472b6 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.6));
    animation: user-name-glow 2.2s ease-in-out infinite alternate;
}

.header-logout-btn {
    border: 1px solid rgba(248, 113, 113, 0.5);
    background: rgba(127, 29, 29, 0.25);
    color: #fecaca;
    border-radius: 10px;
    font-size: 0.82rem;
    font-weight: 700;
    padding: 4px 10px;
    cursor: pointer;
    transition: var(--transition);
}

.header-logout-btn:hover {
    background: rgba(153, 27, 27, 0.45);
    color: #fee2e2;
}

@keyframes user-name-glow {
    from {
        filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.45));
    }
    to {
        filter: drop-shadow(0 0 16px rgba(236, 72, 153, 0.7));
    }
}

.title-top {
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: 3px;
    color: var(--text-main);
}

.title-bottom {
    font-size: 0.85rem;
    color: var(--accent);
    letter-spacing: 5px;
    margin-top: 2px;
}

/* .header-placeholder { width: 150px; } <-- 移除 */

/* --- 主區域佈局 --- */
.main-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative; /* 為遮罩層定位 */
}

/* 新增：遮罩層樣式 */
.menu-overlay {
    display: none; /* 預設隱藏 */
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: 100%;
    height: calc(100% - var(--header-height));
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 98; /* 在側邊欄之下，內容之上 */
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.menu-overlay.show {
    display: block;
    opacity: 1;
}


/* --- 側邊欄 --- */
aside {
    width: 280px;
    background: var(--bg-side);
    padding: 20px;
    overflow-y: auto;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    transition: var(--transition); /* 添加過渡效果 */
    z-index: 99; /* 確保在手機版時浮在內容上 */
}

/* 手機版樣式 (螢幕寬度小於 768px) */
@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex; /* 顯示漢堡按鈕 */
    }

    .page-title {
        display: none; /* 手機版隱藏完整標題，節省空間 */
    }

    .header-user-zone {
        margin-left: auto;
        margin-right: 0;
        padding: 6px 10px;
        gap: 8px;
    }

    .header-user-label {
        display: none;
    }

    .header-user-name {
        font-size: 0.95rem;
        max-width: 120px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .header-logout-btn {
        padding: 4px 8px;
        font-size: 0.78rem;
    }

    aside {
        position: fixed;
        top: var(--header-height);
        left: 0;
        height: calc(100% - var(--header-height));
        transform: translateX(-100%); /* 預設隱藏在左側螢幕外 */
        width: 80%; /* 手機版寬度設為 80% */
        max-width: 300px;
        border-right: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: 5px 0 15px rgba(0,0,0,0.3);
    }

    /* 選單開啟時的狀態 */
    aside.show {
        transform: translateX(0); /* 滑入螢幕 */
    }

    main {
        padding: 20px; /* 減少手機版內容的內距 */
    }

    .content-card {
        padding: 25px; /* 減少手機版卡片的內距 */
    }

    .home-hero-header {
        flex-direction: column;
    }

    .home-status-pill {
        min-width: 100%;
        white-space: normal;
    }

    .home-info-grid {
        grid-template-columns: 1fr;
    }
}


.menu-trigger {
    width: 100%;
    padding: 12px 15px;
    background: var(--glass);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 12px;
    color: var(--text-main);
    text-align: left;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    font-weight: 600;
    margin-bottom: 5px;
}

.menu-group.active .submenu { max-height: 200px; margin-bottom: 15px; }

.submenu {
    max-height: 0;
    overflow: hidden;
    transition: var(--transition);
    list-style: none;
    padding-left: 10px;
}

.submenu li {
    padding: 8px 15px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9rem;
    transition: 0.2s;
}

.submenu li:hover, .submenu li.active-item {
    color: var(--accent);
    background: rgba(56, 189, 248, 0.1);
}

/* --- 內容與圖片 --- */
main {
    flex: 1;
    padding: 40px;
    overflow-y: auto;
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
}

.content-card {
    max-width: 800px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 25px;
    padding: 40px;
    animation: fadeIn 0.5s ease;
}

.home-hero-card {
    max-width: 960px;
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.92), rgba(15, 23, 42, 0.88));
    box-shadow: 0 24px 60px rgba(2, 6, 23, 0.28);
}

.home-hero-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    margin-bottom: 28px;
}

.home-hero-subtitle {
    margin-top: 12px;
    color: var(--text-muted);
    line-height: 1.85;
    font-size: 1rem;
}

.home-status-pill {
    min-width: 220px;
    padding: 12px 16px;
    border-radius: 999px;
    border: 1px solid rgba(56, 189, 248, 0.25);
    background: rgba(56, 189, 248, 0.08);
    color: var(--text-main);
    font-size: 0.95rem;
    text-align: center;
    white-space: nowrap;
}

.home-info-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.home-info-block {
    padding: 22px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.home-info-block h3 {
    margin-bottom: 14px;
    font-size: 1.05rem;
    color: #dbeafe;
}

.home-feature-list {
    list-style: none;
    display: grid;
    gap: 12px;
}

.home-feature-list li {
    position: relative;
    padding-left: 18px;
    line-height: 1.8;
    color: var(--text-main);
}

.home-feature-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 12px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: linear-gradient(135deg, #38bdf8, #818cf8);
}

.home-note-box {
    margin-top: 24px;
    padding: 20px 22px;
    border-radius: 18px;
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.16);
}

.home-note-box strong {
    display: inline-block;
    margin-bottom: 8px;
    color: #e0f2fe;
}

.home-note-box p {
    color: var(--text-main);
    line-height: 1.8;
}

.preview-container {
    margin-top: 25px;
    border-radius: 15px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.preview-img {
    width: 100%;
    display: block;
}

/* --- 頁尾 --- */
footer {
    height: 65px;
    background: #020617;
    text-align: center;
    padding: 10px;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 101; /* 確保頁尾在最上層 */
    position: relative;
}

/* Notice style for emphasis */
.notice { color: #c00; font-weight: 800; }

.editor-panel {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.upload-btn {
    display: inline-block;
    width: fit-content;
    padding: 10px 18px;
    border-radius: 10px;
    border: 1px solid rgba(56, 189, 248, 0.6);
    background: rgba(56, 189, 248, 0.12);
    color: var(--text-main);
    cursor: pointer;
    transition: 0.2s ease;
}

.upload-btn:hover {
    background: rgba(56, 189, 248, 0.2);
}

.upload-btn.is-disabled {
    background: rgba(148, 163, 184, 0.2);
    border-color: rgba(148, 163, 184, 0.35);
    color: rgba(241, 245, 249, 0.7);
    cursor: not-allowed;
    pointer-events: none;
}

.editor-file-input {
    display: none;
}

.editor-textarea {
    width: 100%;
    min-height: 140px;
    resize: vertical;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.4);
    background: rgba(15, 23, 42, 0.85);
    color: var(--text-main);
    padding: 12px 14px;
    outline: none;
}

.editor-textarea:focus {
    border-color: var(--accent);
}

.editor-subtitle {
    margin: 6px 0 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.chest-slider-wrap {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chest-slider-label {
    color: var(--text-main);
    font-weight: 600;
}

.chest-slider {
    width: 100%;
    accent-color: var(--accent);
    cursor: pointer;
}

.editor-submit-btn {
    width: fit-content;
    padding: 10px 22px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #082f49;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s ease;
}

.editor-submit-btn:hover {
    filter: brightness(1.08);
}

.editor-submit-btn.is-resubmit {
    background: linear-gradient(135deg, #f59e0b, #f97316);
    color: #fff7ed;
}

.editor-submit-btn:disabled {
    background: rgba(148, 163, 184, 0.45);
    color: rgba(241, 245, 249, 0.85);
    cursor: not-allowed;
    filter: none;
}

.editor-action-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.editor-cancel-btn {
    width: fit-content;
    padding: 10px 22px;
    border: 1px solid rgba(248, 113, 113, 0.7);
    border-radius: 10px;
    background: rgba(127, 29, 29, 0.35);
    color: #fee2e2;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s ease;
}

.editor-cancel-btn:hover:not(.hidden) {
    background: rgba(127, 29, 29, 0.55);
}

.editor-top-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.editor-clear-btn {
    width: fit-content;
    padding: 10px 22px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.9);
    color: var(--text-main);
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s ease;
}

.editor-clear-btn:hover:not(.hidden) {
    background: rgba(148, 163, 184, 0.2);
}

.editor-clear-btn:disabled,
.editor-clear-btn.is-disabled {
    background: rgba(148, 163, 184, 0.2);
    border-color: rgba(148, 163, 184, 0.35);
    color: rgba(241, 245, 249, 0.7);
    cursor: not-allowed;
}

.editor-download-btn {
    width: fit-content;
    padding: 10px 22px;
    border: 1px solid rgba(56, 189, 248, 0.6);
    border-radius: 10px;
    background: rgba(56, 189, 248, 0.15);
    color: var(--text-main);
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9rem;
    transition: 0.2s ease;
}

.editor-download-btn:hover:not(.hidden) {
    background: rgba(56, 189, 248, 0.28);
}

/* --- 滑桿比對 --- */
.compare-slider-wrapper {
    position: relative;
    width: 100%;
    max-width: 700px;
    margin: 0 auto;
    border-radius: 12px;
    overflow: hidden;
    user-select: none;
    line-height: 0;
}

/* 結果圖：in-flow，撐起包裹層高度 */
.compare-img-after {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 12px;
}

/* 原圖：絕對定位覆蓋，用 clip-path 裁切右側 */
.compare-img-before {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    clip-path: inset(0 50% 0 0);
    border-right: 2px solid rgba(255, 255, 255, 0.9);
    z-index: 2;
}

.compare-line {
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    transform: translateX(-50%);
    pointer-events: none;
}

.compare-line::before {
    content: '◀ ▶';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.92);
    color: #0f172a;
    font-size: 0.7rem;
    font-weight: 800;
    padding: 4px 7px;
    border-radius: 20px;
    white-space: nowrap;
    pointer-events: none;
}

.compare-range {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: ew-resize;
    z-index: 10;
    margin: 0;
}

.compare-label {
    position: absolute;
    bottom: 10px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 0.75rem;
    padding: 3px 10px;
    border-radius: 20px;
    pointer-events: none;
    z-index: 5;
}

.compare-label-left  { left: 10px; }
.compare-label-right { right: 10px; }

.server-status {
    display: block;
    color: var(--text-main);
    font-size: 0.95rem;
}

/* === 任務進度徽章 === */
.task-progress-badge {
    display: inline-block;
    margin: 8px 0 4px;
    border-radius: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.task-progress-badge.is-loading {
    font-size: 0.95rem;
    padding: 5px 16px;
    color: #a5b4fc;
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(165, 180, 252, 0.35);
    animation: badge-loading-glow 2s ease-in-out infinite;
}

.task-progress-badge.is-loading::before {
    content: '⚙';
    display: inline-block;
    margin-right: 6px;
    animation: badge-spin 2s linear infinite;
}

@keyframes badge-loading-glow {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
        opacity: 1;
    }
    50% {
        box-shadow: 0 0 18px 4px rgba(99, 102, 241, 0.25);
        opacity: 0.82;
    }
}

@keyframes badge-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.task-progress-badge.is-progress {
    font-size: 2rem;
    padding: 2px 4px;
    background: linear-gradient(135deg, #818cf8 0%, #a855f7 45%, #ec4899 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: badge-progress-pulse 1.4s ease-in-out infinite alternate;
}

@keyframes badge-progress-pulse {
    from {
        filter: drop-shadow(0 0 5px rgba(99, 102, 241, 0.65));
        transform: scale(1);
    }
    to {
        filter: drop-shadow(0 0 14px rgba(168, 85, 247, 0.9));
        transform: scale(1.04);
    }
}

.hidden {
    display: none;
}

.image-preview-container {
    min-height: 100px;
    border-radius: 12px;
    border: 1px dashed rgba(148, 163, 184, 0.5);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-image {
    max-width: 100%;
    max-height: 400px;
    border-radius: 10px;
    object-fit: contain;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}