/* === 液態玻璃動畫變數 === */
@property --angle-1 {
    syntax: "<angle>";
    inherits: false;
    initial-value: -75deg;
}

@property --angle-2 {
    syntax: "<angle>";
    inherits: false;
    initial-value: -45deg;
}

:root {
    /* 🌙 Dark Mode - 科技黑 */
    --color-background: #0F0F1B;
    --color-text-primary: #ffffff;
    --color-text-secondary: rgba(255, 255, 255, 0.7);
    --color-glass-bg: rgba(255, 255, 255, 0.03);
    --color-glass-border: rgba(255, 255, 255, 0.1);
    --color-glass-hover: rgba(255, 255, 255, 0.08);
    --color-input-bg: rgba(0, 0, 0, 0.4);
    --color-accent: #a7a7d1;
    --color-accent-hover: rgba(167, 167, 209, 0.2);
    --color-heart: #ff4757;

    /* 液態按鈕專屬變數 */
    --color-button-shadow-1: rgba(0, 0, 0, 0.05);
    --color-button-shadow-2: rgba(255, 255, 255, 0.5);
    --color-button-shadow-3: rgba(0, 0, 0, 0.2);
    --color-button-shadow-4: rgba(255, 255, 255, 0.2);
    --anim--hover-time: 400ms;
    --anim--hover-ease: cubic-bezier(0.25, 1, 0.5, 1);

    --sidebar-width: 260px;
}

body.light-mode {
    /* ☕ Light Mode - 溫暖拿鐵 */
    --color-background: #F7F4EF;
    --color-text-primary: #3E2723;
    --color-text-secondary: #795C54;
    --color-glass-bg: rgba(255, 255, 255, 0.6);
    --color-glass-border: rgba(111, 78, 55, 0.15);
    --color-glass-hover: rgba(255, 255, 255, 0.9);
    --color-input-bg: rgba(255, 255, 255, 0.8);
    --color-accent: #6F4E37;
    --color-accent-hover: rgba(111, 78, 55, 0.1);
    --color-heart: #D84315;

    /* 液態按鈕淺色變數 */
    --color-button-shadow-1: rgba(255, 255, 255, 0.8);
    --color-button-shadow-2: rgba(0, 0, 0, 0.1);
    --color-button-shadow-3: rgba(0, 0, 0, 0.05);
    --color-button-shadow-4: rgba(255, 255, 255, 0.5);
}

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

html,
body {
    height: 100%;
    overflow: hidden;
    font-family: "Inter", "Noto Sans TC", sans-serif;
}

body {
    background-color: var(--color-background);
    background-image: url('https://github.com/chunsheng612/FunFun.AI-Website/blob/main/ai-tools-bg-black.png?raw=true');
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    color: var(--color-text-primary);
    transition: background-color 0.5s ease, color 0.5s ease, background-image 0.5s ease;
}

body.light-mode {
    background-image: url('https://github.com/chunsheng612/FunFun.AI-Website/blob/main/ai-tools-bg-light.png?raw=true');
}

#tsparticles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
}

/* === Animations === */
@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(25px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes heartBounce {
    0% {
        transform: scale(1);
    }

    40% {
        transform: scale(1.35);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* === App Layout === */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: relative;
    z-index: 1;
}

.glass-panel {
    background-color: var(--color-glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--color-glass-border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    transition: background-color 0.4s ease, border-color 0.4s ease;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    margin: 16px 0 16px 16px;
    border-radius: 20px;
    overflow-y: auto;
    padding: 24px 12px;
    transition: width 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), margin 0.4s ease, opacity 0.3s ease;
    z-index: 100;
    scrollbar-width: none;
}

.sidebar::-webkit-scrollbar {
    display: none;
}

.sidebar.collapsed-desktop {
    width: 0;
    margin: 0;
    padding: 0;
    opacity: 0;
    border: none;
    pointer-events: none;
}

.nav-section-title {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    margin: 16px 0 8px 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    text-align: left;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
    margin-bottom: 4px;
}

.nav-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 0.2s;
}

.nav-btn:hover {
    background: var(--color-glass-hover);
    color: var(--color-text-primary);
    transform: translateX(4px);
}

.nav-btn.active {
    background: var(--color-accent);
    color: #fff;
    font-weight: 600;
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

body.light-mode .nav-btn.active {
    color: var(--color-bg-base);
}

/* --- Main Content Area --- */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* --- Topbar --- */
.topbar {
    height: 68px;
    margin: 16px 16px 0 16px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    gap: 24px;
    flex-shrink: 0;
    position: relative;
}

.brand-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.hamburger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--color-text-primary);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: all 0.2s;
    margin-left: -4px;
}

.hamburger-btn:hover {
    background: var(--color-accent-hover);
}

.hamburger-btn svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    fill: none;
}

.brand-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    transition: transform 0.3s;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.brand-area:hover .brand-avatar {
    transform: scale(1.05) rotate(-2deg);
}

.brand-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text-primary);
    letter-spacing: 0.5px;
}

/* Search Area */
.search-container {
    flex: 1;
    max-width: 400px;
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--color-text-secondary);
    pointer-events: none;
}

#search-input {
    width: 100%;
    background: var(--color-input-bg);
    border: 1px solid var(--color-glass-border);
    border-radius: 99px;
    padding: 10px 36px 10px 40px;
    color: var(--color-text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    font-family: inherit;
}

#search-input:focus {
    border-color: var(--color-accent);
    width: 105%;
    box-shadow: 0 0 0 3px var(--color-accent-hover);
}

#search-input::placeholder {
    color: var(--color-text-secondary);
    opacity: 0.7;
}

.clear-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    display: none;
    padding: 4px;
    font-size: 14px;
    transition: transform 0.2s;
}

.clear-btn:hover {
    color: var(--color-text-primary);
    transform: translateY(-50%) scale(1.2);
}

.mobile-search-btn,
.mobile-search-back {
    display: none;
    background: transparent;
    border: none;
    color: var(--color-text-primary);
    cursor: pointer;
    padding: 8px;
}

.mobile-search-btn svg,
.mobile-search-back svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 登入按鈕 */
.auth-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--color-input-bg);
    border: 1px solid var(--color-glass-border);
    padding: 6px 14px;
    border-radius: 99px;
    color: var(--color-text-primary);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    backdrop-filter: blur(12px);
}

.auth-btn:hover {
    background: var(--color-accent-hover);
    border-color: var(--color-accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.auth-btn img {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: none;
    object-fit: cover;
}

.auth-btn span {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
}

.icon-btn {
    background: var(--color-input-bg);
    border: 1px solid var(--color-glass-border);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-primary);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.icon-btn:hover {
    background: var(--color-accent-hover);
    border-color: var(--color-accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* --- Content Area --- */
.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
}

.content-area::-webkit-scrollbar {
    width: 6px;
}

.content-area::-webkit-scrollbar-track {
    background: transparent;
}

.content-area::-webkit-scrollbar-thumb {
    background: var(--color-glass-border);
    border-radius: 3px;
}

.section-header {
    margin-bottom: 24px;
    padding-left: 4px;
}

.section-title {
    font-size: 1.35rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--color-text-primary);
}

.section-title svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

/* --- Tool Grid & Cards --- */
.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    gap: 20px;
    padding-bottom: 20px;
    flex: 1;
    align-content: start;
}

.tool-card {
    background: var(--color-glass-bg);
    border: 1px solid var(--color-glass-border);
    border-radius: 20px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    transition: border-color 0.3s ease, background 0.3s ease, transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.3s ease;
    opacity: 0;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.tool-card.hidden {
    display: none !important;
}

.tool-card:hover {
    border-color: var(--color-accent);
    background: var(--color-glass-hover);
    transform: translateY(-6px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
}

.card-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding-right: 28px;
}

.card-icon {
    color: var(--color-accent);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-input-bg);
    padding: 8px;
    border-radius: 12px;
    border: 1px solid var(--color-glass-border);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.card-icon svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.tool-card:hover .card-icon {
    transform: scale(1.1) rotate(-3deg);
}

.tool-name {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.35;
    margin-top: 2px;
    color: var(--color-text-primary);
}

.tool-description {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: auto;
    min-height: 2.8rem;
}

/* Heart Favorite Button */
.fav-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--color-text-secondary);
    padding: 4px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.4;
    z-index: 10;
}

.tool-card:hover .fav-btn {
    opacity: 1;
}

.fav-btn svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    transition: all 0.2s;
}

.fav-btn:hover {
    color: var(--color-heart);
    background: rgba(255, 71, 87, 0.1);
}

.fav-btn.active {
    color: var(--color-heart);
    opacity: 1;
}

.fav-btn.active svg {
    fill: currentColor;
    stroke: currentColor;
    animation: heartBounce 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* === 🏆 完美回歸：液態玻璃按鈕 (強制置左、不拉長) === */
.card-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
    justify-content: flex-start;
}

.button-wrap {
    flex: 0 0 calc(50% - 5px);
    min-width: 0;
    position: relative;
    z-index: 2;
    border-radius: 999vw;
    background: transparent;
    pointer-events: none;
}

.button-wrap button {
    --border-width: 2px;
    all: unset;
    cursor: pointer;
    position: relative;
    pointer-events: auto;
    z-index: 3;
    background: linear-gradient(-75deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.05));
    border-radius: 999vw;
    box-shadow: inset 0 0.125em 0.125em var(--color-button-shadow-1), inset 0 -0.125em 0.125em var(--color-button-shadow-2), 0 0.25em 0.125em -0.125em var(--color-button-shadow-3), 0 0 0.1em 0.25em inset var(--color-button-shadow-4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: transform var(--anim--hover-time) var(--anim--hover-ease);
    display: flex;
    justify-content: center;
    width: 100%;
    height: 100%;
}

body.light-mode .button-wrap button {
    background: linear-gradient(-75deg, rgba(0, 0, 0, 0.02), rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.02));
}

.button-wrap button:hover {
    transform: scale(0.97);
}

.button-wrap button:active {
    transform: scale(0.94);
    background: linear-gradient(-75deg, rgba(150, 120, 255, 0.1), rgba(180, 150, 255, 0.3), rgba(150, 120, 255, 0.1));
}

.button-wrap button span {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    font-size: 0.85rem;
    line-height: 1.25;
    color: var(--color-text-primary);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    padding: 0.7em 0.8em;
    width: 100%;
    text-align: center;
    white-space: normal;
    word-break: keep-all;
}

body.light-mode .button-wrap button span {
    text-shadow: none;
    font-weight: 600;
}

.button-wrap button span::after {
    content: "";
    display: block;
    position: absolute;
    z-index: 1;
    width: calc(100% - var(--border-width));
    height: calc(100% - var(--border-width));
    top: calc(0% + var(--border-width) / 2);
    left: calc(0% + var(--border-width) / 2);
    box-sizing: border-box;
    border-radius: 999vw;
    overflow: clip;
    background: linear-gradient(var(--angle-2), rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.4) 40% 50%, rgba(255, 255, 255, 0) 55%);
    mix-blend-mode: screen;
    pointer-events: none;
    background-size: 200% 200%;
    background-position: 0% 50%;
    transition: background-position calc(var(--anim--hover-time) * 1.25) var(--anim--hover-ease), --angle-2 calc(var(--anim--hover-time) * 1.25) var(--anim--hover-ease);
}

body.light-mode .button-wrap button span::after {
    mix-blend-mode: normal;
    background: linear-gradient(var(--angle-2), rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.6) 40% 50%, rgba(255, 255, 255, 0) 55%);
}

.button-wrap button:hover span::after {
    background-position: 25% 50%;
}

.button-wrap button::after {
    content: "";
    position: absolute;
    z-index: 1;
    inset: 0;
    border-radius: 999vw;
    width: calc(100% + var(--border-width));
    height: calc(100% + var(--border-width));
    top: calc(0% - var(--border-width) / 2);
    left: calc(0% - var(--border-width) / 2);
    padding: var(--border-width);
    box-sizing: border-box;
    background: conic-gradient(from var(--angle-1) at 50% 50%, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 5% 40%, rgba(0, 0, 0, 0.5) 50%, rgba(0, 0, 0, 0) 60% 95%, rgba(0, 0, 0, 0.5)), linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5));
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask-composite: exclude;
    transition: all var(--anim--hover-time) var(--anim--hover-ease), --angle-1 500ms ease;
    box-shadow: inset 0 0 0 calc(var(--border-width) / 2) rgba(255, 255, 255, 0.5);
}

body.light-mode .button-wrap button::after {
    background: conic-gradient(from var(--angle-1) at 50% 50%, rgba(111, 78, 55, 0.2), rgba(0, 0, 0, 0) 5% 40%, rgba(111, 78, 55, 0.2) 50%, rgba(0, 0, 0, 0) 60% 95%, rgba(111, 78, 55, 0.2)), linear-gradient(180deg, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.1));
    box-shadow: inset 0 0 0 calc(var(--border-width) / 2) rgba(111, 78, 55, 0.2);
}

.button-wrap button:hover::after {
    --angle-1: -125deg;
}

/* --- Footer Info Area --- */
.main-footer {
    margin-top: 32px;
    padding: 24px;
    border-top: 1px solid var(--color-glass-border);
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-radius: 20px;
    margin-bottom: 20px;
    animation: fadeIn 1s ease forwards;
}

.footer-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.footer-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-top: 2px;
    stroke: var(--color-text-primary);
    fill: none;
    stroke-width: 2;
}

.footer-link {
    color: var(--color-text-primary);
    text-decoration: underline;
    text-decoration-color: var(--color-glass-border);
    transition: all 0.2s;
}

.footer-link:hover {
    text-decoration-color: var(--color-accent);
    color: var(--color-accent);
}

/* --- Mobile Responsive --- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 95;
    opacity: 0;
    transition: opacity 0.3s;
}

@media (max-width: 900px) {
    .brand-title {
        display: none;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: calc(100vh - 24px);
        transform: translateX(-120%);
        margin: 12px;
        width: 260px;
        background: var(--color-background);
        border: 1px solid var(--color-glass-border);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }

    .topbar {
        margin: 12px;
        height: 60px;
        padding: 0 16px;
        gap: 12px;
    }

    .search-container {
        display: none;
        position: absolute;
        inset: 0;
        padding: 0 16px;
        background: var(--color-background);
        border-radius: 20px;
        border: 1px solid var(--color-glass-border);
        z-index: 10;
        align-items: center;
        gap: 10px;
    }

    .search-container.mobile-active {
        display: flex;
        animation: fadeIn 0.2s ease;
    }

    .search-container .search-icon {
        left: 44px;
    }

    #search-input {
        padding-left: 36px;
        background: transparent;
        border: none;
        box-shadow: none !important;
    }

    .mobile-search-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-left: auto;
        background: transparent;
        border: none;
        color: var(--color-text-primary);
        cursor: pointer;
        padding: 8px;
    }

    .mobile-search-back {
        display: block;
        padding: 4px;
        flex-shrink: 0;
        background: transparent;
        border: none;
        color: var(--color-text-primary);
        cursor: pointer;
    }

    .mobile-search-btn svg,
    .mobile-search-back svg {
        width: 22px;
        height: 22px;
        stroke: currentColor;
        fill: none;
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .clear-btn {
        right: 16px;
    }

    .content-area {
        padding: 16px 12px;
    }

    .tool-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}
