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

:root {
    --primary: #f2a7b5;
    --primary-dark: #d88a99;
    --accent: #d4af37;
    --bg: #fff9f5;
    --text: #2d2d2d;
    --text-light: #666666;
    --white: #ffffff;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    --glass: rgba(255, 255, 255, 0.85);
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Noto Sans TC', 'Inter', sans-serif;
    scroll-behavior: smooth;
}

h1, h2, h3, h4 {
    font-family: 'Playfair Display', 'Noto Sans TC', serif;
}

/* Header 與 footer 的「Glow Makeup.」原本是 h1／h2，等於每一頁的 H1 都是品牌名而不是
   頁面主題。改成連結與一般區塊後，標題字體不再由上面那條規則套用，靠這個 class 維持原樣。 */
.brand-logo {
    font-family: 'Playfair Display', 'Noto Sans TC', serif;
}

/* Header & Nav Fixes */
header {
    height: 96px; /* Fixed height for consistency */
    display: flex;
    align-items: center;
}

nav {
    display: flex;
    align-items: center;
    height: 100%;
}

.nav-link {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 5px;
    margin-bottom: -2px; /* Visual adjustment for the underline */
}

.dropdown-parent {
    display: flex;
    align-items: center;
    height: 100%;
}

/* 簡單分類下拉（保養專欄）專用：讓 .dropdown-menu 的 absolute 定位以這個連結本身為基準置中，
   不能直接加在 .dropdown-parent 上，因為 mega-menu 也共用這個 class，且需要以 header 為基準鋪滿整寬 */
.simple-dropdown {
    position: relative;
}

/* Ensure underlined links align */
.nav-link {
    position: relative;
    transition: color 0.3s ease;
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: 30px; /* Align underline within the fixed header height */
    left: 0;
    width: 0;
    height: 2px;
    background: var(--primary);
    transition: width 0.3s ease;
}

.nav-link:hover::after {
    width: 100%;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(0); /* Removed jumpy translateY */
    background: white;
    min-width: 200px;
    border-radius: 15px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.1);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    padding: 15px 0;
    z-index: 100;
}

.dropdown-parent:hover .dropdown-menu {
    opacity: 1;
    visibility: visible;
}

.dropdown-item {
    padding: 12px 25px;
    display: block;
    text-decoration: none;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 700;
}

.dropdown-item:hover {
    background: var(--bg);
    color: var(--primary);
}

/* Search Bar Styling */
.search-container {
    background: #f5f5f5;
    border-radius: 30px;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    width: 200px;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.search-container:focus-within {
    width: 280px;
    background: white;
    border-color: var(--primary);
    box-shadow: 0 5px 15px rgba(242, 167, 181, 0.2);
}

.search-input {
    background: transparent;
    border: none;
    outline: none;
    margin-left: 10px;
    font-size: 0.85rem;
    width: 100%;
    color: var(--text);
}

/* Animations */
@keyframes marquee { 0% { transform: translateX(100%); } 100% { transform: translateX(-100%); } }
.animate-marquee { display: inline-block; white-space: nowrap; animation: marquee 30s linear infinite; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
.animate-fade-in { animation: fadeIn 0.4s ease-out forwards; }

.slider-container { height: 380px; position: relative; overflow: hidden; }
.slider-track { display: flex; transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1); height: 100%; }
.slide { min-width: 100%; height: 100%; background-size: cover; background-position: center; position: relative; }

/* Voting */
.battle-bar-a { background: var(--primary); transition: width 1s ease; }
.battle-bar-b { background: var(--accent); transition: width 1s ease; }

/* Article Feed：手機直排、圖片全寬；平板以上才左右並排、圖片固定尺寸縮圖 */
.article-list-item { display: flex; flex-direction: column; gap: 16px; padding: 24px 0; border-bottom: 1px solid rgba(0,0,0,0.05); }
.article-list-img { width: 100%; height: auto; aspect-ratio: 3 / 2; border-radius: 20px; object-fit: cover; flex-shrink: 0; }

@media (min-width: 640px) {
    .article-list-item { flex-direction: row; gap: 30px; padding: 30px 0; }
    .article-list-img { width: 240px; height: 160px; aspect-ratio: auto; }
}

/* Category Hero */
.category-hero { padding: 100px 0; text-align: center; background: linear-gradient(135deg, #f2a7b5 0%, #d4af37 100%); color: white; margin-bottom: 50px; }

/* Home Quiz Specifics */
.home-quiz-container {
    background: white;
    border-radius: 40px;
    padding: 60px;
    box-shadow: 0 30px 60px rgba(242, 167, 181, 0.1);
    border: 1px solid rgba(242, 167, 181, 0.1);
}

/* 選中的問卷卡片：用 !important 蓋掉卡片本身的 border-gray-100，
   避免跟 Tailwind CDN 動態產生的 border-[#f2a7b5] 同優先權互相蓋掉，
   點擊後顏色沒有真的固定下來、使用者以為自己沒選到的問題 */
.option-card.selected {
    border-color: #f2a7b5 !important;
    background-color: #fff5f7;
}

/* Sentiment Panels */
.sentiment-panel {
    background: white;
    border-radius: 24px;
    padding: 12px;
    width: 100%;
    box-shadow: 0 4px 20px rgba(0,0,0,0.03);
    border: 1px solid rgba(242, 167, 181, 0.1);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 400px;
    transition: all 0.3s ease;
}

/* 殘酷擂台版面：手機上「左/右指數分析」併排在中間對戰卡下方，桌機維持左-中-右三欄一排 */
.battle-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
        "center center"
        "left right";
    gap: 12px;
}

.battle-layout > #sentiment-left { grid-area: left; }
.battle-layout > #sentiment-right { grid-area: right; }
.battle-layout > #battle-center { grid-area: center; }

@media (min-width: 1024px) {
    .battle-layout {
        grid-template-columns: 260px 1fr 260px;
        grid-template-areas: "left center right";
        gap: 2rem;
    }
    .sentiment-panel {
        width: 260px;
        padding: 20px;
        gap: 15px;
    }
}

.sentiment-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(242, 167, 181, 0.2);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.sentiment-chart {
    width: 100%;
    border-radius: 15px;
}

.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.tag-cloud .sentiment-tag {
    flex-shrink: 0;
}

.sentiment-tag {
    background: #f8f8f8;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 700;
    white-space: nowrap;
    transition: transform 0.2s ease;
}

.sentiment-tag:hover {
    transform: scale(1.1);
    background: var(--bg);
}

.tag-pro { color: var(--primary-dark); }
.tag-con { color: #888; }

/* Mega Menu */
.mega-menu {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(242, 167, 181, 0.2);
    box-shadow: 0 15px 40px rgba(0,0,0,0.08);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    transform: translateY(-10px);
    z-index: 100;
}

.dropdown-parent:hover .mega-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.mega-menu-inner {
    display: flex;
    padding: 40px 20px;
    gap: 60px;
    max-width: 80rem; /* max-w-7xl */
    margin: 0 auto;
}

.mega-types {
    width: 180px;
    border-right: 1px solid rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.mega-type-item {
    padding: 12px 20px;
    cursor: pointer;
    border-radius: 12px;
    font-weight: 800;
    color: var(--text-light);
    transition: all 0.2s ease;
}

.mega-type-item:hover, .mega-type-item.active {
    background: var(--bg);
    color: var(--primary);
    transform: translateX(5px);
}

.mega-content {
    flex-grow: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 40px;
    align-content: start;
}

.mega-category {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mega-category-title {
    font-weight: 900;
    color: var(--text);
    border-bottom: 2px solid var(--primary);
    padding-bottom: 8px;
    margin-bottom: 8px;
    display: inline-block;
}

.mega-subcategory {
    color: var(--text-light);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    padding-left: 0;
}

.mega-subcategory:hover {
    color: var(--primary);
    padding-left: 5px;
}

/* Mobile nav drawer */
.mobile-nav-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease;
    z-index: 90;
}

.mobile-nav-overlay.open {
    opacity: 1;
    visibility: visible;
}

.mobile-nav {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 82%;
    max-width: 320px;
    background: #fff9f5;
    z-index: 100;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

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

.mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid rgba(242, 167, 181, 0.15);
    position: sticky;
    top: 0;
    background: #fff9f5;
}

.mobile-nav-title {
    font-weight: 900;
    font-size: 1.1rem;
    color: var(--primary);
}

.mobile-nav-close {
    font-size: 1.75rem;
    line-height: 1;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 0 4px;
}

.mobile-nav-list {
    display: block;
    height: auto;
    padding: 8px 0 40px;
}

.mobile-nav-link {
    display: block;
    padding: 14px 20px;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text);
    border-bottom: 1px solid rgba(45, 45, 45, 0.06);
}

.mobile-nav-parent {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    font-weight: 700;
    font-size: 1.05rem;
    border-bottom: 1px solid rgba(45, 45, 45, 0.06);
    cursor: pointer;
    color: var(--text);
}

.mobile-nav-parent .mobile-nav-caret {
    display: inline-block;
    transition: transform 0.2s ease;
    font-size: 0.8rem;
    color: var(--primary);
    flex-shrink: 0;
    margin-left: 8px;
}

.mobile-nav-parent.expanded .mobile-nav-caret {
    transform: rotate(180deg);
}

.mobile-nav-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: rgba(242, 167, 181, 0.05);
}

.mobile-nav-submenu.expanded {
    max-height: 3000px;
}

.mobile-nav-sub-item {
    display: block;
    padding: 10px 20px 10px 36px;
    font-size: 0.95rem;
    color: var(--text-light);
}

.mobile-nav-type-label {
    padding: 12px 20px 4px 32px;
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: 0.03em;
}

.mobile-nav-cat-label {
    padding: 6px 20px 2px 32px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-light);
}

body.mobile-nav-open {
    overflow: hidden;
}

/* 熱門榜單：類別分頁籤，橫向捲動並隱藏捲軸 */
.ranking-tabs {
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
}
.ranking-tabs::-webkit-scrollbar {
    display: none;
}
.ranking-tab-btn {
    outline: none;
}
.ranking-tab-btn:focus-visible {
    outline: 2px solid rgba(242, 167, 181, 0.5);
    outline-offset: 2px;
    border-radius: 4px;
}
/* 分頁籤數量多，桌機用左右箭頭捲動；左右加漸層淡出，暗示還有更多分類可滑 */
.ranking-tabs-wrap::before,
.ranking-tabs-wrap::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 12px;
    width: 40px;
    pointer-events: none;
    z-index: 1;
}
.ranking-tabs-wrap::before {
    left: 0;
    background: linear-gradient(to right, #fff9f5, transparent);
}
.ranking-tabs-wrap::after {
    right: 0;
    background: linear-gradient(to left, #fff9f5, transparent);
}
.ranking-tabs-arrow {
    position: absolute;
    top: -6px;
    bottom: 12px;
    width: 36px;
    z-index: 2;
    align-items: center;
    justify-content: center;
    color: #f2a7b5;
    font-size: 0.8rem;
    background: transparent;
    border: none;
    cursor: pointer;
}
.ranking-tabs-arrow-left {
    left: -8px;
    justify-content: flex-start;
}
.ranking-tabs-arrow-right {
    right: -8px;
    justify-content: flex-end;
}
.ranking-tabs-arrow:hover {
    color: #e05a47;
}

/* 新品快報：手機版預設只顯示前 6 個品牌，點「查看全部」才展開其餘品項 */
#new-products-grid.np-collapsed .new-product-extra {
    display: none;
}
@media (min-width: 768px) {
    #new-products-grid.np-collapsed .new-product-extra {
        display: flex;
    }
}

/* 最新文章：橫向滑動輪播，卡片數量不影響區塊高度（手機用手勢滑，桌機可點箭頭） */
.article-carousel {
    display: flex;
    gap: 32px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
}

.article-carousel::-webkit-scrollbar {
    display: none;
}

.article-carousel .article-card {
    flex: 0 0 auto;
    width: 78vw;
    max-width: 320px;
    scroll-snap-align: start;
}

@media (min-width: 640px) {
    .article-carousel .article-card {
        width: calc(50% - 16px);
        max-width: none;
    }
}

@media (min-width: 1024px) {
    .article-carousel .article-card {
        width: calc(20% - 26px);
    }
}

/* 完整成分列表：手機版改為連續文字排列
   成分名稱常常很長（例如 Bis-Behenyl/Isostearyl/Phytosteryl Dimer Dilinoleyl Dimer
   Dilinoleate），在藥丸標籤裡會換成兩三行、每顆標籤都被撐高，整段列表在手機上長到
   難以捲動。改成 INCI 標示慣用的頓號連續排列，高度大幅縮短，連結與可點擊性不變。
   桌機維持原本的藥丸樣式不受影響。 */
@media (max-width: 767px) {
    #ingredients-list {
        display: block;
        line-height: 2;
        word-break: break-word;
    }
    #ingredients-list > a {
        display: inline;
        padding: 0;
        border: 0;
        background: none;
        border-radius: 0;
        color: #6b7280;
    }
    #ingredients-list > a:not(:last-child)::after {
        content: "、";
        color: #c9c9c9;
    }
    #ingredients-list > a:hover {
        background: none;
        color: #f2a7b5;
    }
}

/* 成分列表收合（僅手機版；桌機空間夠，一律全展開） */
@media (max-width: 767px) {
    #ingredients-list.ing-collapsed {
        max-height: 11em;
        overflow: hidden;
        -webkit-mask-image: linear-gradient(to bottom, #000 70%, transparent 100%);
        mask-image: linear-gradient(to bottom, #000 70%, transparent 100%);
    }
    #ingredients-toggle { display: block; }
}
@media (min-width: 768px) {
    #ingredients-list.ing-collapsed { max-height: none; overflow: visible; }
    #ingredients-toggle { display: none !important; }
}

/* 站內搜尋結果面板 */
.search-container { position: relative; }
.search-results {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    /* 搜尋框位在 header 最右側，面板必須靠右展開，否則會溢出視窗右緣 */
    right: 0;
    left: auto;
    width: max(320px, 100%);
    max-height: min(70vh, 460px);
    overflow-y: auto;
    background: #fff;
    border: 1px solid rgba(242, 167, 181, 0.25);
    border-radius: 20px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
    padding: 8px;
    z-index: 60;
    text-align: left;
}
.search-results.is-open { display: block; }
.search-group {
    font-size: 0.7rem;
    font-weight: 900;
    color: #9ca3af;
    letter-spacing: 0.08em;
    padding: 8px 10px 4px;
}
.search-result {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 14px;
    transition: background 0.15s ease;
}
.search-result:hover,
.search-result.is-active { background: rgba(242, 167, 181, 0.12); }
.search-result img {
    width: 38px;
    height: 38px;
    object-fit: contain;
    border-radius: 10px;
    background: #fff9f5;
    flex-shrink: 0;
}
.search-result-text { display: flex; flex-direction: column; min-width: 0; }
.search-result-name {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.search-result-meta { font-size: 0.7rem; color: #9ca3af; }
.search-empty { padding: 16px 12px; font-size: 0.8rem; color: #9ca3af; text-align: center; }

@media (max-width: 767px) {
    /* 手機版頭部空間窄：搜尋框容器的右緣離視窗右側還有漢堡按鈕的寬度，若用 absolute
       靠右對齊，面板左緣會溢出畫面。改用 fixed 貼齊視窗左右內距，寬度自動吃滿。
       top 用 sticky header 的高度（實測 96px）再留 8px 間距。 */
    .search-results {
        position: fixed;
        top: 104px;
        left: 12px;
        right: 12px;
        width: auto;
        max-height: calc(100vh - 120px);
    }
}
