/* Header */
.header {
    background-color: var(--primary-teal);
    padding: 15px 0;
    color: #fff;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 1000;
}

.header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
}

.logo img {
    height: 27px;
    width: auto;
    max-width: none;
    /* Prevent potential 100% width override */
}

.nav>ul {
    display: flex;
    align-items: center;
    gap: 30px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav li {
    position: relative;
}

.nav a,
.nav .nav-link-text {
    font-size: 0.9rem;
    color: #fff;
    opacity: 0.9;
    text-decoration: none;
    display: block;
    padding: 5px 0;
}

/* 語言切換（下拉選單，沿用 .dropdown 行為） */
.nav .lang-switch .dropdown-content .lang-active {
    color: var(--primary-teal);
    font-weight: 700;
}

@media (min-width: 769px) {
    .nav .lang-switch {
        margin-left: 18px;
    }

    /* 觸發鈕：外框 + 向下箭頭，明示為可展開的下拉 */
    .nav .lang-switch>.nav-link-text {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 5px 12px;
        line-height: 1.4;
        border: 1px solid rgba(255, 255, 255, 0.55);
        border-radius: 4px;
        transition: border-color 0.3s ease;
    }

    .nav .lang-switch>.nav-link-text::after {
        content: '\f107';
        /* FontAwesome angle-down */
        font-family: "Font Awesome 6 Free";
        font-weight: 900;
        font-size: 0.75rem;
        transition: transform 0.3s ease;
    }

    /* hover：外框變實（視覺回饋） */
    .nav .lang-switch:hover>.nav-link-text,
    .nav .lang-switch.active>.nav-link-text {
        border-color: #fff;
        text-decoration: none;
    }

    /* 展開時（.active）箭頭翻轉 */
    .nav .lang-switch.active>.nav-link-text::after {
        transform: rotate(180deg);
    }

    /* 改為「點擊才展開」：取消 hover 自動開，僅 .active 時顯示 */
    .nav .lang-switch:hover>.dropdown-content {
        display: none;
    }

    .nav .lang-switch.active>.dropdown-content {
        display: block;
    }

    /* 下拉選單靠右對齊 + 與按鈕保留間隔 */
    .nav .lang-switch .dropdown-content {
        left: auto;
        right: 0;
        top: calc(100% + 10px);
        min-width: 110px;
    }
}

@media (min-width: 769px) {

    .nav a:hover,
    .nav .nav-link-text:hover,
    .nav li.active>a,
    .nav li.active>.nav-link-text {
        opacity: 1;
        text-decoration: underline;
        text-underline-offset: 5px;
        /* Optional: adds some space */
    }
}

/* Dropdown Styles */
.dropdown-content {
    display: none;
    position: absolute;
    background-color: #fff;
    min-width: 120px;
    /* Reduced from 140px */
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
    z-index: 1;
    top: 100%;
    left: 0;
    padding: 10px 0;
    border-radius: 4px;
}

@media (min-width: 769px) {
    .dropdown:hover .dropdown-content {
        display: block;
    }
}

.dropdown-content li {
    display: block;
}

.dropdown-content a {
    color: #333;
    padding: 10px 15px;
    /* Reduced horizontal padding */
    text-decoration: none;
    display: block;
    font-size: 0.9rem;
    white-space: nowrap;
    text-align: left;
    /* Align text left */
}

@media (min-width: 769px) {
    .dropdown-content a:hover {
        background-color: #f1f1f1;
        color: var(--primary-teal);
        text-decoration: none;
    }
}

.hamburger {
    display: none;
    cursor: pointer;
    /* 確保觸控目標 ≥ 44×44 (iOS HIG) */
    padding: 12px;
    margin: -12px;
}

.hamburger span {
    display: block;
    width: 25px;
    height: 2px;
    background-color: #fff;
    margin: 5px 0;
    transition: 0.3s;
}

.mobile-logo,
.mobile-socials,
.mobile-copyright {
    display: none !important;
}

/* Mobile Header & Menu */
@media (max-width: 768px) {
    .header {
        padding: 15px 0;
        z-index: 3000;
        /* Ensure header/menu stays above back-to-top button (z:1000) */
    }

    .hamburger {
        display: block;
        z-index: 2000;
        /* Ensure above overlay */
        position: relative;
    }

    .nav {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background-color: var(--primary-teal);
        flex-direction: column;
        justify-content: flex-start;
        padding-top: 0;
        padding-left: 20px;
        padding-right: 20px;
        padding-bottom: 0px;
        transform: translateX(100%);
        z-index: 1999;
        overflow-y: auto;
        /* Hide by default to prevent flash during resize */
        visibility: hidden;
        opacity: 0;
    }

    /* Only apply transition when explicitly enabled (via JS) */
    .nav.nav-transitioning {
        transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out, visibility 0s;
    }

    /* Disable transition during resize */
    .resize-animation-stopper .nav {
        transition: none !important;
    }

    .nav.active {
        transform: translateX(0);
        visibility: visible;
        opacity: 1;
    }

    .mobile-logo {
        display: block !important;
        width: 55px;
        /* Logo width */
        margin-bottom: 40px;
        padding: 0;
        /* Remove generic nav a padding */
    }

    .mobile-logo img {
        width: 100%;
        display: block;
    }

    .nav>ul {
        flex-direction: column;
        gap: 0;
        width: 100%;
        /* margin-bottom remove for auto push from socials */
    }

    .nav>ul>li {
        width: 100%;
        border-bottom: 1px solid #fff;
        /* White divider */
        margin: 0;
    }

    .nav a,
    .nav .nav-link-text {
        font-size: 1.1rem;
        padding: 20px 0;
        color: #fff;
        display: block;
        font-family: 'Noto Sans JP', sans-serif;
        text-decoration: none;
        position: relative;
        /* Context for arrow */
    }

    .nav a:hover,
    .nav .nav-link-text:hover {
        color: #fff;
        /* Keep white on hover */
        text-decoration: none;
    }

    /* Dropdown Arrow for Mobile */
    .nav .dropdown>a::after,
    .nav .dropdown>.nav-link-text::after {
        content: '\f107';
        /* FontAwesome angle-down */
        font-family: "Font Awesome 6 Free";
        font-weight: 900;
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        transition: transform 0.3s;
    }

    /* Reset/Disable Hover Rotation on Mobile */
    .dropdown:hover>a::after,
    .dropdown:hover>.nav-link-text::after {
        transform: translateY(-50%);
    }

    /* Rotate ONLY when Active */
    .dropdown.active>a::after,
    .dropdown.active>.nav-link-text::after {
        transform: translateY(-50%) rotate(180deg);
    }

    /* Keep text white when active */
    .dropdown.active>a,
    .dropdown.active>.nav-link-text {
        color: #fff !important;
    }

    /* Submenus in Mobile */
    .dropdown-content {
        position: static;
        background-color: transparent;
        box-shadow: none;
        padding-left: 20px;
        padding-top: 0;
        padding-bottom: 10px;
        display: none;
        /* Hidden by default */
        min-width: 100%;
        border-radius: 0;
    }

    /* Disable CSS hover display on mobile, rely on JS 'active' class */
    .dropdown:hover .dropdown-content {
        display: none;
    }

    .dropdown.active .dropdown-content {
        display: block !important;
    }

    .dropdown-content a {
        padding: 10px 0;
        color: #fff;
        /* White text */
    }

    .dropdown-content a:hover {
        color: #fff;
        /* Keep white on hover */
        background-color: transparent;
    }

    /* Mobile Social Icons */
    .mobile-socials {
        display: flex !important;
        justify-content: center;
        width: 100%;
        gap: 40px;
        margin-top: auto;
        padding-top: 30px;
        padding-bottom: 10px;
    }

    .mobile-socials a {
        display: block;
        flex: 0 0 auto;
        /* Auto width */
        text-align: center;
        padding: 0;
        font-size: 1.5rem;
        color: #fff;
        opacity: 0.8;
    }

    .mobile-socials a:hover {
        opacity: 0.8;
        color: #fff;
    }

    .mobile-copyright {
        display: block !important;
        text-align: center;
        color: #fff;
        font-size: 0.75rem;
        width: 100%;
        padding: 15px 0 10px 0;
        border-top: 1px solid rgba(255, 255, 255, 0.2);
        opacity: 0.8;
    }

    /* Hamburger Animation */
    .hamburger.active span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }

    .hamburger.active span:nth-child(2) {
        opacity: 0;
    }

    .hamburger.active span:nth-child(3) {
        transform: rotate(-45deg) translate(5px, -5px);
    }
}