/* ==========================================================================
   1. 基礎設定與變數 (Core Variables & Reset)
   ========================================================================== */
:root { 
    --bg-color: #050505; 
    --text-primary: #ffffff; 
    --text-secondary: #cccccc; 
    --accent-1: #818cf8; 
    --accent-2: #ec4899; 
    --accent-3: #8b5cf6; 
    --glass-bg: rgba(255, 255, 255, 0.03); 
    --glass-border: rgba(255, 255, 255, 0.08); 
    --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37); 
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { 
    height: 100%; 
    overflow: hidden; 
    font-family: 'Noto Sans TC', 'Outfit', sans-serif; 
    background-color: var(--bg-color); 
    color: var(--text-primary); 
    line-height: 1.6; 
}

/* ==========================================================================
   2. 背景氛圍與裝飾 (Background Elements)
   ========================================================================== */
.bg-elements { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; z-index: -1; pointer-events: none; }

.glow { position: absolute; width: 600px; height: 600px; border-radius: 50%; filter: blur(120px); opacity: 0.15; animation: float 20s infinite ease-in-out alternate; }
.glow-1 { top: -10%; left: -10%; background: radial-gradient(circle, var(--accent-1), transparent 70%); }
.glow-2 { bottom: -20%; right: -10%; background: radial-gradient(circle, var(--accent-2), transparent 70%); }

@keyframes float { 0% { transform: translate3d(0, 0, 0); } 100% { transform: translate3d(50px, 30px, 0); } }

/* ==========================================================================
   3. 佈局核心 (Main Layout & Grid System)
   ========================================================================== */
.main-layout { display: flex; width: 100vw; height: 100vh; padding: 3rem; gap: 3rem; align-items: center; justify-content: flex-start; }

.portal-grid { 
    flex-grow: 1; 
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    grid-template-rows: auto; 
    gap: 1.5rem; 
    max-height: 85vh; 
    overflow-y: auto; 
    padding-right: 15px; 
    align-content: start; 
    padding: 3.8px 0 0 0;
}

/* 網格滾動條樣式 */
.portal-grid::-webkit-scrollbar { width: 4px; }
.portal-grid::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 10px; }

/* 比例分配 */
.card-size-2 { grid-column: span 2; width: 100%; }
.card-size-1 { grid-column: span 1; width: 100%; }

/* ==========================================================================
   4. 側邊欄 (Sidebar & Personal Info)
   ========================================================================== */
.sidebar { opacity: 0; transition: opacity 0.5s ease; }

/* --- 初始中央狀態 --- */
.sidebar.initial-center { 
    opacity: 1; position: fixed; top: 50%; left: 50%; 
    transform: translate(-50%, -50%) scale(1.3); 
    text-align: center; z-index: 1000; 
    display: flex; flex-direction: column; align-items: center; 
    transition: transform 1.2s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.5s ease; 
}

/* --- 歸位橫向狀態 --- */
.sidebar.active-left { 
    flex-shrink: 0; opacity: 1 !important; position: sticky !important; top: 3rem; 
    width: 420px; max-height: 95vh; background: var(--glass-bg); 
    border: 1px solid var(--glass-border); border-radius: 32px; padding: 1.5rem; 
    overflow: hidden; display: flex !important; flex-direction: row !important; 
    flex-wrap: wrap; align-items: center !important; gap: 0.9rem; 
    backdrop-filter: blur(20px); 
    transition: transform 1.2s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease; 
}

.sidebar.active-left .intro-content { flex: 1; text-align: left !important; display: flex; flex-direction: column; align-items: flex-start; min-width: 200px; }

/* --- 側邊欄內部元件 --- */
.avatar-wrapper { width: 100px; height: 100px; border-radius: 24px; overflow: hidden; background: #1a1a1a; transition: all 1s ease; flex-shrink: 0; }
.sidebar.active-left .avatar-wrapper { width: 80px; height: 80px; }
.avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }

.main-title { font-size: 3rem; font-weight: 900; transition: font-size 1s ease; }
.sidebar.active-left .main-title { font-size: 2.2rem; }

.text-gradient { 
    background: linear-gradient(135deg, var(--accent-1), var(--accent-3)) !important; 
    -webkit-background-clip: text !important; background-clip: text !important; 
    -webkit-text-fill-color: transparent !important; display: inline-block; 
    -webkit-box-decoration-break: clone; box-decoration-break: clone; 
}

.badge { font-size: 0.75rem; letter-spacing: 2px; color: var(--accent-1); margin-bottom: 0.5rem; text-transform: uppercase; }
.tagline { font-size: 0.9rem; color: var(--text-secondary); }

/* --- 自我介紹與標籤 --- */
.bio-details { width: 100%; margin-top: 1rem; display: none; opacity: 0; text-align: left !important; }
.sidebar.active-left.run-scan .bio-details { display: block; animation: scanMask 1.5s cubic-bezier(0.19, 1, 0.22, 1) forwards; }

.bio-quote { font-style: italic; color: var(--accent-1); font-size: 0.9rem; margin-bottom: 1rem; border-left: 2px solid var(--accent-1); padding-left: 10px; }
.bio-description { font-size: 0.95rem; color: var(--text-secondary); line-height: 1.8; margin-bottom: 1.5rem; }
.bio-list { list-style: none; padding-top: 1rem; border-top: 1px solid var(--glass-border); }
.bio-list li { margin-bottom: 0.8rem; font-size: 0.9rem; }

.skill-tags { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; }
.tag { background: rgba(99, 102, 241, 0.1); border: 1px solid rgba(99, 102, 241, 0.2); color: var(--accent-1); padding: 2px 10px; border-radius: 6px; font-size: 0.75rem; font-weight: 700; }

/* ==========================================================================
   5. 聯絡通道 (Contact Stack)
   ========================================================================== */
.contact-stack { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--glass-border); }
.contact-stack small { color: var(--accent-1); display: block; margin-bottom: 1.2rem; font-weight: 700; font-size: 0.75rem; letter-spacing: 2px; text-transform: uppercase; }
.contact-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px 10px; }

.contact-card { display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; transition: transform 0.3s ease; }
.contact-card:hover { transform: translateY(-3px); }
.contact-card i { font-size: 1.4rem; color: #666666; margin-bottom: 6px; transition: all 0.3s ease; }
.contact-card span { font-size: 0.65rem; color: #666666; font-weight: 500; transition: color 0.3s ease; }
.contact-card:hover i { color: var(--text-primary); filter: drop-shadow(0 0 8px var(--accent-1)); }
.contact-card:hover span { color: var(--text-primary); }

/* ==========================================================================
   6. 卡片通用樣式 (Portal Card Base)
   ========================================================================== */
.portal-card { 
    background: var(--glass-bg); border: 1px solid var(--glass-border); 
    border-radius: 24px; padding: 2rem; text-decoration: none; 
    color: inherit; transition: 0.3s ease; backdrop-filter: blur(10px); 
}

.portal-card:hover { transform: translateY(-3.5px); border-color: var(--accent-1); box-shadow: var(--card-shadow); }

.contents-hidden { opacity: 0; transform: translateY(20px); pointer-events: none; }
.contents-show { opacity: 1; transform: translateY(0); pointer-events: auto; transition: 0.8s ease; }

/* ==========================================================================
   7. 監控儀表板 (Monitor Dashboard - 5 欄位)
   ========================================================================== */
.monitor-dashboard { width: 100%; max-width: none !important; padding: 0.8rem; display: flex; flex-direction: column; justify-content: center; }
.monitor-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1rem; align-items: start; text-align: center; width: 100%; }
.monitor-header { font-size: 0.7rem; font-weight: 900; color: var(--text-secondary); letter-spacing: 1px; margin-bottom: 10px; }

.monitor-avatar-wrapper { width: 60px; height: 60px; margin: 0 auto 10px; border-radius: 50%; padding: 3px; border: 1px solid var(--glass-border); background: rgba(0, 0, 0, 0.2); }
.monitor-avatar { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

.monitor-info { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 0.8rem; margin-top: 5px; }

/* 燈號特效 */
.status-led { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.led-online { background: #2ecc71; box-shadow: 0 0 8px #2ecc71; animation: led-pulse-green 2s infinite; }
.led-offline { background: #95a5a6; }
.led-location { background: var(--accent-1); box-shadow: 0 0 8px var(--accent-1); animation: led-pulse-blue 3s infinite; }
.led-steps { background: #f39c12; box-shadow: 0 0 8px #f39c12; animation: led-pulse-orange 2.5s infinite; }
.led-low-battery { animation: led-blink-red 1s infinite; }

/* 電池元件 */
.battery-container { width: 100%; height: 50px; display: flex; align-items: center; justify-content: center; position: relative; }
.battery-body { width: 22px; height: 38px; border: 2px solid #555; border-radius: 4px; position: relative; padding: 2px; background: rgba(0, 0, 0, 0.3); }
.battery-cap { width: 10px; height: 4px; background: #555; position: absolute; top: -6px; left: 50%; transform: translateX(-50%); border-radius: 2px 2px 0 0; }
.battery-level { width: 100%; background: #2ecc71; position: absolute; bottom: 2px; left: 0; transition: height 0.5s ease; border-radius: 1px; }
.charging-icon { position: absolute; color: #ffffff; font-size: 0.8rem; z-index: 10; filter: drop-shadow(0 0 5px rgba(241, 196, 15, 0.8)); }

/* ==========================================================================
   8. 天氣與部落格細節 (Weather & Blog Units)
   ========================================================================== */
.weather-dashboard-card { display: flex; flex-direction: column; justify-content: center; min-height: 180px; padding: 0.8rem; }
.weather-mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; width: 100%; margin: auto 0; }
.mini-weather-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.03); }
.mini-city-name { font-size: 0.9rem; min-width: 50px; }
.mini-city-temp { font-family: 'Outfit', sans-serif; font-size: 1rem; font-weight: 700; color: var(--accent-1); }
.mini-city-icon { font-size: 0.9rem; color: var(--text-secondary); }

/* --- 部落格單元樣式 --- */
.blog-columns-inner { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; width: 100%; }
.blog-unit { display: flex; align-items: center; gap: 12px; background: rgba(255, 255, 255, 0.03); padding: 12px; border-radius: 16px; text-decoration: none; color: inherit; transition: all 0.3s ease; border: 1px solid transparent; }
.blog-unit:hover { background: rgba(255, 255, 255, 0.06); border-color: var(--accent-1); transform: scale(1.02); }

.blog-identity { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 0 0 90px; min-width: 90px; }
.blog-img-wrapper { width: 70px; height: 70px; border-radius: 10px; overflow: hidden; border: 1px solid var(--glass-border); margin-bottom: 6px; }
.blog-img-wrapper img { width: 100%; height: 100%; object-fit: cover; }
.blog-identity h4 { font-size: 0.95rem; color: var(--accent-1); margin: 0; text-align: center; white-space: nowrap; width: 100%; overflow: hidden; text-overflow: ellipsis; }

.blog-desc-side { flex: 1; display: flex; flex-direction: column; justify-content: center; border-left: 1px solid var(--glass-border); padding-left: 10px; }
.blog-desc-side p { font-size: 0.95rem; color: var(--text-secondary); line-height: 1.4; margin: 2px; white-space: nowrap; }

/* ==========================================================================
   9. 三位一體切換與自動輪播 (Trinity Carousel)
   ========================================================================== */
.card-trinity { display: flex; flex-direction: column; gap: 15px; padding: 1.2rem !important; min-height: 250px; }
.trinity-controls { display: flex; gap: 10px; border-bottom: 1px solid var(--glass-border); padding-bottom: 10px; flex-shrink: 0; }

.t-btn { background: transparent; border: 1px solid var(--glass-border); color: var(--text-secondary); padding: 5px 12px; font-size: 0.85rem; font-family: 'Outfit', sans-serif; cursor: pointer; transition: 0.3s; border-radius: 4px; }
.t-btn.active { border-color: var(--accent-1); color: var(--accent-1); background: rgba(129, 140, 248, 0.1); box-shadow: 0 0 10px rgba(129, 140, 248, 0.2); }

.trinity-display { position: relative; height: 110px; overflow: hidden; flex-grow: 1; display: flex; align-items: center; justify-content: center; }
.blog-group { display: none; flex-direction: column; width: 100%; }
.blog-group.active { display: flex; }

.sub-item { display: none; gap: 38px; text-decoration: none; color: inherit; width: 100%; align-items: center; }
.sub-item.active { display: flex; animation: fadin-up 0.5s cubic-bezier(0.19, 1, 0.22, 1) forwards; }

.preview-img { flex: 0 0 225px; height: 150px; border-radius: 12px; overflow: hidden; border: 1px solid var(--glass-border); }
.preview-img img { width: 100%; height: 100%; object-fit: cover; }

.preview-text { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.p-cat { font-size: 0.6rem; color: var(--accent-1); font-weight: 700; letter-spacing: 1px; }
.preview-text h4 { font-size: 1.1rem; color: #fff; margin: 4px 0; line-height: 1.2; }
.preview-text p { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.4; display: -webkit-box; word-break: break-all; -webkit-box-orient: vertical; overflow: hidden; }

/* ==========================================================================
   10. 最新動態卡片 (Recent Activity Roll)
   ========================================================================== */
.activity-card { display: flex; flex-direction: column; padding: 1rem !important; height: 100%; overflow: hidden; }
.activity-window { flex-grow: 1; overflow: hidden; position: relative; margin-top: 10px; height: 180px; }
.activity-list { display: flex; flex-direction: column; gap: 8px; transition: transform 0.6s cubic-bezier(0.19, 1, 0.22, 1); }

.activity-item { height: 38px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 10px; background: rgba(255, 255, 255, 0.03); border-left: 2px solid transparent; text-decoration: none; color: var(--text-primary); transition: all 0.3s ease; }
.activity-item:hover { background: rgba(255, 255, 255, 0.08); border-left: 2px solid var(--accent-1); transform: translateX(4px); }

.activity-info { display: flex; align-items: center; gap: 10px; overflow: hidden; }
.activity-tag { font-size: 0.6rem; padding: 2px 6px; border-radius: 3px; font-weight: bold; flex-shrink: 0; font-family: 'Courier New', monospace; min-width: 35px; text-align: center; }
.tag-dev { background: #3498db; color: white; }
.tag-fix { background: #f39c12; color: white; }
.tag-life { background: #9b59b6; color: white; }
.tag-app { background: #2ecc71; color: white; }

.activity-title { font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.9; }
.activity-arrow { font-size: 0.7rem; opacity: 0.3; transition: transform 0.3s ease, opacity 0.3s ease; }
.activity-item:hover .activity-arrow { opacity: 1; transform: translateX(2px); color: var(--accent-1); }
.activity-footer { font-size: 0.6rem; opacity: 0.2; margin-top: auto; padding-top: 10px; text-align: right; letter-spacing: 1px; }

/* --- 歷史日誌字幕機專屬 --- */
.card-blog { display: flex; flex-direction: column; height: 220px; max-height: 220px; overflow: hidden; position: relative; }
.log-marquee-viewport { flex: 1; overflow: hidden; position: relative; height: 140px; mask-image: linear-gradient(transparent, black 15%, black 85%, transparent); -webkit-mask-image: linear-gradient(transparent, black 15%, black 85%, transparent); }
.log-marquee-content { display: flex; flex-direction: column; position: absolute; width: 100%; top: 0; left: 0; animation: scrollLog 20s linear infinite; }
.log-marquee-content:hover { animation-play-state: paused; }
.log-item { padding: 12px 0; border-bottom: 1px dashed rgba(255, 255, 255, 0.05); display: flex; flex-direction: column; gap: 4px; width: 100%; }
.log-title { font-size: 0.85rem; font-weight: 700; color: var(--accent-3); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.log-title .v-num { color: var(--accent-1); font-size: 0.7rem; background: rgba(139, 92, 246, 0.1); padding: 0 5px; border-radius: 4px; }
.log-title .date { color: var(--text-secondary); font-size: 0.7rem; font-weight: normal; }
.log-detail { font-size: 0.8rem; color: #ffffff; opacity: 0.9; padding-left: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ==========================================================================
   11. 動畫定義 (Animations)
   ========================================================================== */
@keyframes scanMask { 0% { opacity: 0; clip-path: inset(0 0 100% 0); } 100% { opacity: 1; clip-path: inset(0 0 0 0); } }
@keyframes dissolveOut { 0% { opacity: 1; filter: blur(0px); transform: translate(-50%, -50%) scale(1.3); } 100% { opacity: 0; filter: blur(20px); transform: translate(-50%, -50%) scale(1.1); } }
@keyframes fadin-up { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
@keyframes led-pulse-green { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.4; transform: scale(1.2); } }
@keyframes led-pulse-blue { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.8); } }
@keyframes led-pulse-orange { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.5); transform: scale(1.1); } }
@keyframes led-blink-red { 0%, 100% { opacity: 1; background: #ff4757; box-shadow: 0 0 8px #ff4757; } 50% { opacity: 0.3; background: #222; box-shadow: none; } }
@keyframes flash { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes scrollLog { 0% { transform: translateY(0); } 100% { transform: translateY(-50%); } }

.sidebar.run-dissolve { animation: dissolveOut 1.0s forwards; }
.sidebar.active-left.run-scan { animation: scanMask 1.5s cubic-bezier(0.19, 1, 0.22, 1) forwards; }
.pulse-dot { width: 6px; height: 6px; background: #ff4757; border-radius: 50%; margin-left: 8px; display: inline-block; box-shadow: 0 0 8px #ff4757; animation: flash 1.5s infinite; }

/* ==========================================================================
   12. 響應式佈局 (Responsive Design) - Witt3C 專屬優化
   ========================================================================== */

/* --- [1] 平板與小螢幕筆電 (1200px 以下) --- */
@media (max-width: 1200px) {
    .main-layout {
        padding: 2rem;
        gap: 2rem;
    }
    
    .sidebar.active-left {
        width: 350px; /* 縮小側邊欄寬度給右側空間 */
    }

    .portal-grid {
        grid-template-columns: 1fr; /* 右側網格改為單欄，避免卡片太擠 */
    }

    .card-size-2 {
        grid-column: span 1;
    }
}

/* --- [2] 平板直向與大手機 (1024px 以下) --- */
@media (max-width: 1024px) {
    html, body {
        overflow: auto; /* 恢復滾動 */
    }

    .main-layout {
        flex-direction: column; /* 改為上下佈局 */
        height: auto;
        padding: 1.5rem;
        justify-content: flex-start;
        align-items: center;
    }

    .sidebar.active-left {
        width: 100%; /* 側邊欄全寬 */
        max-height: none;
        position: relative !important;
        top: 0;
        margin-bottom: 1.5rem;
        padding: 2rem;
    }

    .portal-grid {
        width: 100%;
        max-height: none;
        overflow: visible;
        padding-right: 0;
    }
}


/* ==========================================================================
   手機版強力修復包 (768px 以下全屏優化)
   ========================================================================== */
@media (max-width: 768px) {
    /* 1. 基礎容器重整：防止左右晃動 (Horizontal Scroll) */
    html, body {
        overflow-x: hidden; 
        width: 100%;
        height: auto;
    }

    .main-layout {
        display: block; /* 取消 flex，改用區塊排版 */
        padding: 1rem;  /* 縮小邊距，留給內容空間 */
        width: 100%;
    }

    /* 2. 側邊欄 (Sidebar) 手機化 */
    .sidebar.active-left {
        width: 100% !important;
        position: relative !important;
        top: 0 !important;
        margin-bottom: 1.5rem;
        border-radius: 20px;
        padding: 1.2rem;
        flex-direction: column !important; /* 強制垂直排版 */
        align-items: center !important;
    }

    .sidebar.active-left .intro-content {
        text-align: center !important;
        align-items: center;
        min-width: 0;
        width: 100%;
    }

    .sidebar.active-left .main-title {
        font-size: 1.8rem;
    }

    /* 3. 網格系統 (Grid) 強制單欄 */
    .portal-grid {
        display: block; /* 手機版不建議用 grid，改用 block 最穩 */
        padding-right: 0;
    }

    .portal-card {
        width: 100%;
        margin-bottom: 1.2rem; /* 卡片間距 */
        padding: 1.2rem !important; /* 縮小內距，避免內容被擠扁 */
    }

    /* 4. 監控面板 (Monitor Dashboard) 修復 - 改為 2 欄 */
    .monitor-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr); /* 手機版 2 欄最剛好 */
        gap: 0.8rem;
    }

    .monitor-avatar-wrapper {
        width: 50px;
        height: 50px;
    }

    /* 5. 三部落格介紹 (Blog Units) - 強制垂直排列 */
    .blog-columns-inner {
        display: block;
    }

    .blog-unit {
        margin-bottom: 0.8rem;
        width: 100%;
    }

    .blog-identity {
        flex: 0 0 70px; /* 縮小左側頭像寬度 */
        min-width: 70px;
    }

    /* 6. 最新文章預覽 (Trinity Display) - 這是最容易破版的地方 */
    .trinity-display {
        height: auto;
        min-height: 300px;
    }

    .sub-item {
        flex-direction: column; /* 圖片在上，文字在下 */
        align-items: center;
        gap: 10px;
    }

    .preview-img {
        width: 100%; /* 圖片撐滿 */
        height: 150px;
        flex: none;
    }

    .preview-text {
        width: 100%;
        text-align: left;
    }

    .preview-text h4 {
        font-size: 1rem;
        white-space: normal; /* 允許標題換行 */
    }

    /* 7. 更新日誌 (System Log) - 防止文字溢出 */
    .log-item {
        white-space: normal;
    }

    .log-detail {
        white-space: normal; /* 允許日誌細節換行，否則手機會看不到尾端 */
        display: block;
    }

    /* 8. 聯絡資訊 (Contact Grid) - 4 欄改 3 欄 */
    .contact-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px 5px;
    }
}