:root {
    --side-menu-width: 240px;
    --header-height: 0px;

    /* ライトモード色設定 */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-elevated: #ffffff;
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --text-on-dark: #ffffff;
    --header-bg: #2c3e50;
    --header-bg-hover: #34495e;
    --border-color: #e0e0e0;
    --input-bg: #ffffff;
    --link-color: #3498db;
    --link-hover: #2980b9;
    --success-color: #4caf50;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;
    --shadow-color: rgba(0, 0, 0, 0.1);
}

[data-theme='dark'] {
    /* ダークモード色設定 */
    --bg-primary: #1a1a1a;
    --bg-secondary: #252525;
    --bg-elevated: #2d2d2d;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a0a0;
    --text-on-dark: #ffffff;
    --header-bg: #0d0d0d;
    --header-bg-hover: #1f1f1f;
    --border-color: #404040;
    --input-bg: #2d2d2d;
    --link-color: #5dade2;
    --link-hover: #85c1e9;
    --success-color: #66bb6a;
    --danger-color: #ef5350;
    --warning-color: #ffa726;
    --shadow-color: rgba(0, 0, 0, 0.5);
}

/* テーマ切り替え時の滑らかなトランジション */
* {
    transition:
        background-color 0.3s ease,
        color 0.3s ease,
        border-color 0.3s ease;
}

body {
    margin: 0;
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

/* メインコンテンツのスタイル */
#content-container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
    min-height: 100vh;
}

/* ヘッダーのスタイル */
/* sticky は親要素を sticky 範囲とするため、<header> ではなく header-container に適用する
   （aside.side-menu は position: fixed で flow から外れているため sticky の妨げにならない）。
   z-index は モバイル時のオーバーレイ(1000)・ドロワー(1001) より前面で操作可能に保つため 1100。 */
#header-container {
    position: sticky;
    top: 0;
    z-index: 1100;
}

#header-title-area {
    background-color: var(--header-bg);
    padding: 0.75rem 1.5rem;
    box-shadow: 0 2px 4px var(--shadow-color);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-title {
    color: var(--text-on-dark);
    margin: 0;
    font-size: 1.8rem;
    font-weight: bold;
    text-align: start;
    flex: 1;
}

/* フッターのスタイル */
footer {
    background-color: var(--header-bg);
    color: var(--text-on-dark);
    padding: 2rem 1rem;
    width: 100%;
    box-shadow: 0 -2px 4px var(--shadow-color);
    margin-top: auto;
    box-sizing: border-box;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
}

.footer-share {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.footer-share-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 1rem 0;
    text-align: center;
    color: var(--text-on-dark);
}

.footer-share-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.share-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-on-dark);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
    background-color: transparent;
}

.share-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.share-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.share-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.share-x {
    background-color: #000000;
    border: 1px solid #333333;
}

.share-x:hover {
    background-color: #1a1a1a;
}

.share-facebook {
    background-color: #1877f2;
}

.share-facebook:hover {
    background-color: #166fe5;
}

.share-line {
    background-color: #00b900;
}

.share-line:hover {
    background-color: #00a000;
}

.share-copy {
    background-color: var(--text-secondary);
    border: 1px solid #95a5a6;
}

.share-copy:hover {
    background-color: var(--text-secondary);
}

.footer-links {
    text-align: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.footer-link {
    color: var(--text-on-dark);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.3s ease;
    padding: 0.5rem 1rem;
    display: inline-block;
}

.footer-link:hover {
    color: #ecf0f1;
    text-decoration: underline;
}

.footer-copyright {
    text-align: center;
}

.copyright {
    margin: 0;
    font-size: 0.9rem;
    text-align: center;
    color: rgba(255, 255, 255, 0.8);
    /* ダークモード対応は別途 */
}

.app-version {
    display: block;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
    text-align: center;
    margin-top: 0.25rem;
}

/* サイドメニュー（共通） */
.side-menu {
    background-color: var(--header-bg);
    overflow-y: auto;
    box-sizing: border-box;
}

.side-menu-header {
    display: none;
}

/* ナビゲーションエリアのスタイル */
.header-nav {
    width: 100%;
}

.nav-list {
    display: flex;
    flex-direction: column;
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-item {
    margin: 0;
    width: 100%;
    border-bottom: 1px solid var(--header-bg-hover);
}

.nav-item:last-child {
    border-bottom: none;
}

.nav-item a {
    color: var(--text-on-dark);
    text-decoration: none;
    font-size: 1rem;
    padding: 1rem 1.2rem;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
}

.menu-item-icon {
    width: 18px;
    height: 18px;
    margin-right: 0.6rem;
    flex-shrink: 0;
}

.nav-item a:hover {
    color: var(--link-color);
    background-color: var(--header-bg-hover);
}

/* ボタンエリア */
#header-btn-area {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex-shrink: 0;
    gap: 0.5rem;
}

#header-btn-area button#auth-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    background-color: var(--link-color);
    color: var(--text-on-dark);
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

#header-btn-area button#auth-btn:hover {
    background-color: var(--link-hover);
}

/* テーマ切り替えトグルスイッチ */
.theme-toggle-switch {
    position: relative;
    display: inline-block;
    width: 56px;
    height: 28px;
    cursor: pointer;
    flex-shrink: 0;
}

.theme-toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.theme-toggle-slider {
    position: absolute;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 28px;
    transition:
        background-color 0.3s ease,
        border-color 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 6px;
    box-sizing: border-box;
}

.theme-toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    left: 2px;
    top: 50%;
    transform: translateY(-50%);
    background-color: #ffffff;
    border-radius: 50%;
    transition:
        transform 0.3s ease,
        background-color 0.3s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    z-index: 1;
}

.theme-toggle-switch input:checked + .theme-toggle-slider {
    background-color: rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.2);
}

.theme-toggle-switch input:checked + .theme-toggle-slider::before {
    transform: translate(28px, -50%);
    background-color: #f0f0f0;
}

.theme-toggle-switch input:focus-visible + .theme-toggle-slider {
    outline: 2px solid var(--link-color);
    outline-offset: 2px;
}

.theme-toggle-icon {
    font-size: 14px;
    line-height: 1;
    z-index: 0;
    user-select: none;
}

.theme-toggle-icon-sun {
    color: #f1c40f;
}

.theme-toggle-icon-moon {
    color: #ecf0f1;
}

.header-logo {
    width: 45px;
    height: 45px;
    margin-bottom: -12px;
}

/* プロフィールアイコンとドロップダウン */
.profile-menu-container {
    position: relative;
}

.profile-icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
    background-color: var(--link-color);
    color: var(--text-on-dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 0;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.profile-icon-btn:hover {
    border-color: var(--text-on-dark);
    transform: scale(1.05);
}

.profile-icon-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: bold;
    text-transform: uppercase;
}

.profile-icon-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.profile-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px var(--shadow-color);
    list-style: none;
    padding: 0.4rem 0;
    margin: 0;
    z-index: 1100;
    display: none;
}

.profile-dropdown.show {
    display: block;
}

.profile-dropdown li {
    margin: 0;
    padding: 0;
}

.profile-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.7rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    background: none;
    border: none;
    text-align: left;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    box-sizing: border-box;
    font-family: inherit;
}

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

.profile-dropdown-item-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* モバイルメニューボタン（デフォルトでは非表示） */
.mobile-only {
    display: none;
}

#mobile-menu-button {
    display: none;
    background-color: transparent;
    color: var(--text-on-dark);
    border: none;
    padding: 0.4rem 0.8rem;
    text-align: center;
    cursor: pointer;
    font-size: 1.6rem;
    line-height: 1;
    flex-shrink: 0;
    transition: background-color 0.3s ease;
    border-radius: 4px;
}

#mobile-menu-button:hover {
    background-color: var(--header-bg-hover);
}

/* サイドメニューオーバーレイ（モバイル時のみ表示） */
#side-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

#side-menu-overlay.show {
    display: block;
}

/* PC用：サイドメニュー常時表示（ヘッダー下から） */
@media screen and (min-width: 769px) {
    .side-menu {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        width: var(--side-menu-width);
        background-color: var(--bg-primary);
        border-right: 1px solid var(--border-color);
        z-index: 100;
    }

    .side-menu .nav-item {
        border-bottom: 1px solid var(--bg-secondary);
    }

    .side-menu .nav-item a {
        color: var(--text-primary);
    }

    .side-menu .nav-item a:hover {
        color: var(--link-color);
        background-color: var(--bg-secondary);
    }

    /* コンテンツはサイドメニューを除いた残り領域内で中央寄せ。
       画面幅 ≤ 1200px ではサイドメニュー直右に左寄せ、それ以上では (100vw - 1200px) / 2 だけ
       右にずらして実質的に「残り領域の中央」に配置する。 */
    #content-container {
        max-width: calc(1200px - var(--side-menu-width));
        margin-left: calc(var(--side-menu-width) + max(0px, (100vw - 1200px) / 2));
        margin-right: auto;
    }

    /* footer は全幅表示。サイドメニューの底辺は JS でフッター上端まで縮める（initializeSideMenuFooterClamp） */
}

/* スマートフォン向け */
@media screen and (max-width: 768px) {
    #header-title-area {
        padding: 0.6rem 0.75rem;
        gap: 0.5rem;
    }

    .header-title {
        font-size: 1.2rem;
        flex: 1;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .header-logo {
        width: 32px;
        height: 32px;
        margin-bottom: -8px;
    }

    footer {
        padding: 1.5rem 0.8rem;
    }

    .footer-share {
        margin-bottom: 1rem;
        padding-bottom: 1rem;
    }

    .footer-share-title {
        font-size: 0.9rem;
    }

    .footer-share-buttons {
        gap: 0.75rem;
    }

    .share-btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    .share-text {
        display: none;
    }

    .share-icon {
        font-size: 1.1rem;
    }

    .copyright {
        font-size: 0.8rem;
    }

    /* モバイルメニューボタン */
    #mobile-menu-button {
        display: block;
    }

    .mobile-only {
        display: inline-flex;
    }

    /* サイドメニュードロワー（ヘッダーの下から表示）。
       ヘッダー(#header-container z-index:1100) の下のレイヤーで動作するため、
       メニュー内のリンクは押せる、メニュー外（オーバーレイ部分）クリックで閉じる挙動を維持。 */
    .side-menu {
        position: fixed;
        top: var(--header-height);
        bottom: 0;
        left: -300px;
        width: 260px;
        background-color: var(--header-bg);
        z-index: 1001;
        transition: left 0.3s ease;
    }

    .side-menu.show {
        left: 0;
    }

    /* サイドメニュー内ヘッダー */
    .side-menu-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 1rem 1rem 1rem 1.2rem;
        background-color: var(--header-bg);
        border-bottom: 1px solid var(--header-bg-hover);
        flex-shrink: 0;
    }

    .side-menu-title {
        color: var(--text-on-dark);
        font-weight: bold;
        font-size: 1rem;
    }

    #side-menu-close {
        background: none;
        border: none;
        color: var(--text-on-dark);
        font-size: 1.4rem;
        cursor: pointer;
        line-height: 1;
        padding: 0.2rem 0.4rem;
        border-radius: 4px;
        transition: background-color 0.2s;
    }

    #side-menu-close:hover {
        background-color: var(--header-bg-hover);
    }
}
