/* =================================================================
 * app.css
 * Roomnis アプリ固有スタイル
 * レイアウト・サイドバー・投稿カード・モーダル・
 * コンポーズ・絵文字ピッカー・アバターエフェクト・設定ページ
 * ================================================================= */

/* ========== SIDEBAR ========== */
        /* ---- サイドバーリサイズカード (pinned時のみ) ---- */
        body.has-bottom-nav .sidebar-resize-card { display: none !important; }

        /* ハンドル帯: 右ボーダー上の当たり判定 */
        .sidebar-resize-handle {
            position: absolute;
            top: 0; right: 0;
            width: 8px; height: 100%;
            cursor: col-resize;
            z-index: 201;
            display: none;
        }
        .sidebar.pinned .sidebar-resize-handle { display: block; }

        /* カード本体: ハンドルホバーで表示 */
        .sidebar-resize-card {
            position: absolute;
            right: 0;
            top: 50%;
            transform: translate(50%, -50%);
            z-index: 200;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.15s;
            display: none;
        }
        .sidebar.pinned .sidebar-resize-card { display: block; }
        /* ハンドルホバー → カード表示 */
        .sidebar-resize-handle:hover ~ .sidebar-resize-card,
        .sidebar-resize-card:hover,
        .sidebar-resize-handle.dragging ~ .sidebar-resize-card { opacity: 1; pointer-events: auto; }

        .sidebar-card-inner {
            display: flex;
            flex-direction: row;
            align-items: center;
            background: var(--bg-surface);
            border: 1px solid var(--border-color);
            border-radius: 9999px;
            padding: 3px 5px;
            gap: 1px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.10);
        }
        .sidebar-card-btn {
            width: 28px; height: 28px;
            border-radius: 50%;
            border: none;
            background: transparent;
            color: var(--text-secondary);
            display: flex; align-items: center; justify-content: center;
            font-size: 16px; font-weight: 600; line-height: 1;
            transition: background 0.13s, color 0.13s;
            user-select: none;
            padding: 0;
            cursor: col-resize;
        }
        .sidebar-card-btn:hover { background: var(--accent-bg); color: var(--accent-primary); }
        .sidebar-card-btn:active { transform: scale(0.88); }
        .sidebar-card-btn.reset-btn { cursor: pointer; font-size: 15px; }

        /* カードにホバーで ↺ 付きに切り替え */
        .sidebar-resize-card .card-no-reset   { display: flex; }
        .sidebar-resize-card .card-with-reset { display: none; }
        .sidebar-resize-card:hover .card-no-reset   { display: none; }
        .sidebar-resize-card:hover .card-with-reset { display: flex; }

        .sidebar {
            width: var(--sidebar-collapsed);
            background-color: var(--bg-sidebar);
            border-right: 1px solid var(--border-color);
            height: 100vh;
            padding: 1.25rem 0;
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
            z-index: 50;
            overflow: visible;
            position: relative;
            transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
            flex-shrink: 0;
        }

        body:not(.has-bottom-nav):not(.force-mobile-ui) .sidebar:hover,
        .sidebar.menu-open, .sidebar.pinned { width: var(--sidebar-expanded); }
        /* サイドバー固定時はホバー幅変化を抑制 */
        .sidebar.pinned { transition: none; }
        .sidebar:not(.pinned) { transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1); }

        .logo-container {
            display: flex;
            align-items: center;
            justify-content: flex-start;
            height: 80px;
            padding: 0 8px;
            margin-bottom: 0;
            gap: 0.75rem;
            color: var(--accent-primary);
            font-weight: 700;
            font-size: 1.4rem;
            white-space: nowrap;
            overflow: hidden;
        }
        body:not(.has-bottom-nav):not(.force-mobile-ui) .sidebar:hover .logo-container,
        .sidebar.menu-open .logo-container,
        .sidebar.pinned .logo-container {
            padding: 0 1.25rem;
        }

        .logo-container svg { flex-shrink: 0; width: 28px; height: 28px; }

        /* 折りたたみ時のアイコン：absoluteでサイドバー右端に配置 */
        .logo-container {
            position: relative;
        }
        .logo-container img.logo-icon {
            position: absolute;
            right: 8px;
            top: 50%;
            transform: translateY(-50%) scale(1);
            height: 56px;
            width: 56px;
            object-fit: contain;
            flex-shrink: 0;
            opacity: 1;
            transition: right 0.35s cubic-bezier(0.4,0,0.2,1), opacity 0.15s ease, transform 0.35s cubic-bezier(0.4,0,0.2,1);
            pointer-events: none;
        }
        /* 展開時：icon.pngを中央付近へ移動しつつ拡大→フェードアウト */
        body:not(.has-bottom-nav):not(.force-mobile-ui) .sidebar:hover .logo-container img.logo-icon,
        .sidebar.menu-open .logo-container img.logo-icon,
        .sidebar.pinned .logo-container img.logo-icon {
            right: calc(50% - 28px);
            opacity: 0;
            transform: translateY(-50%) scale(1.3);
        }

        /* 展開時のバナー */
        .logo-container img.logo-banner {
            position: absolute;
            left: 1.25rem;
            top: 50%;
            transform: translateY(-50%) scale(1);
            transform-origin: left center;
            height: 100px;
            width: auto;
            max-width: 220px;
            object-fit: contain;
            opacity: 1;
            pointer-events: auto;
            transition: opacity 0.25s ease 0.15s, transform 0.35s cubic-bezier(0.4,0,0.2,1) 0.1s;
        }
        /* 折りたたみ時はbanner.pngをscaleで隠す */
        .sidebar:not(:hover):not(.menu-open):not(.pinned) .logo-container img.logo-banner {
            opacity: 0;
            transform: translateY(-50%) scale(0.75);
            pointer-events: none;
            transition: opacity 0.15s ease 0s, transform 0.35s cubic-bezier(0.4,0,0.2,1) 0s;
        }

        .nav-label {
            overflow: hidden;
            max-width: 0;
            opacity: 0;
            white-space: nowrap;
            transition: max-width 0.35s cubic-bezier(0.4,0,0.2,1), opacity 0.2s ease 0s;
            pointer-events: none;
        }

        body:not(.has-bottom-nav):not(.force-mobile-ui) .sidebar:hover .nav-label, .sidebar.menu-open .nav-label, .sidebar.pinned .nav-label {
            max-width: 200px;
            opacity: 1;
            transition: max-width 0.35s cubic-bezier(0.4,0,0.2,1), opacity 0.2s ease 0.1s;
            pointer-events: auto;
        }

        .nav-menu {
            display: flex;
            flex-direction: column;
            gap: 0.25rem;
            padding: 0;
            transition: padding 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        }

        body:not(.has-bottom-nav):not(.force-mobile-ui) .sidebar:hover .nav-menu, .sidebar.menu-open .nav-menu, .sidebar.pinned .nav-menu {
            padding: 0 1.5rem;
        }

        .nav-item {
            display: flex;
            align-items: center;
            gap: 0.875rem;
            padding: 0.75rem;
            padding-left: 24px;
            border-radius: var(--border-radius-full);
            color: var(--text-secondary);
            font-weight: 500;
            font-size: 1rem;
            transition: background-color var(--transition-speed) ease,
                        color var(--transition-speed) ease,
                        padding-left 0.35s cubic-bezier(0.4,0,0.2,1);
            cursor: pointer;
            border: none;
            background: transparent;
            text-align: left;
            width: 100%;
            white-space: nowrap;
            text-decoration: none;
        }

        body:not(.has-bottom-nav):not(.force-mobile-ui) .sidebar:hover .nav-item, .sidebar.menu-open .nav-item, .sidebar.pinned .nav-item {
            padding-left: 0.75rem;
        }

        .nav-item svg { width: 24px; height: 24px; flex-shrink: 0; }
        .anim-icon-wrap {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 24px;
            height: 24px;
            flex-shrink: 0;
        }
        .nav-item icon-home,
        .nav-item icon-squarepen,
        .nav-item icon-user {
            display: block;
            line-height: 0;
        }
        .nav-item { position: relative; }
        .nav-item::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 12px;
            width: 48px;
            height: 48px;
            transform: translateY(-50%);
            border-radius: 50%;
            background-color: transparent;
            transition: background-color var(--transition-speed) ease,
                        opacity 0.35s cubic-bezier(0.4,0,0.2,1);
            z-index: 0;
            pointer-events: none;
        }
        .nav-item:hover::before  { background-color: var(--nav-hover-bg, var(--accent-bg)); }
        .nav-item.active::before { background-color: var(--nav-hover-bg, var(--accent-bg)); }

        /* 展開時は本体backgroundに切り替え。::beforeをサイズ変化させるとアニメーション中に円が歪むため */
        body:not(.has-bottom-nav):not(.force-mobile-ui) .sidebar:hover .nav-item::before, .sidebar.menu-open .nav-item::before, .sidebar.pinned .nav-item::before { opacity: 0; }
        body:not(.has-bottom-nav):not(.force-mobile-ui) .sidebar:hover .nav-item:hover, .sidebar.menu-open .nav-item:hover, .sidebar.pinned .nav-item:hover  { background-color: var(--nav-hover-bg, var(--accent-bg)); }
        body:not(.has-bottom-nav):not(.force-mobile-ui) .sidebar:hover .nav-item.active, .sidebar.menu-open .nav-item.active, .sidebar.pinned .nav-item.active { background-color: var(--nav-hover-bg, var(--accent-bg)); }

        .nav-item > * { position: relative; z-index: 1; }

        .nav-item:hover { color: var(--accent-hover); }
        .nav-item.active { color: var(--accent-hover); font-weight: 700; }

        .btn-post-action {
            margin: 0.5rem 0.75rem 0;
            background-color: var(--accent-primary);
            color: white;
            border: none;
            padding: 0.75rem;
            border-radius: var(--border-radius-full);
            font-weight: 600;
            font-size: 1rem;
            cursor: pointer;
            transition: background-color var(--transition-speed) ease;
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 0.5rem;
            white-space: nowrap;
            overflow: hidden;
        }

        .btn-post-action:hover { background-color: var(--accent-hover); }
        .btn-post-action svg { width: 20px; height: 20px; flex-shrink: 0; }

        .user-profile-mini {
            margin-top: auto;
            display: flex;
            align-items: center;
            gap: 0.75rem;
            padding: 0.5rem 0.75rem;
            border-radius: var(--border-radius-full);
            cursor: pointer;
            transition: background-color var(--transition-speed) ease;
            white-space: nowrap;
            overflow: hidden;
        }

        .user-profile-mini:hover { background-color: var(--bg-main); }

        .avatar-sm {
            width: 40px; height: 40px;
            border-radius: 50%;
            background-color: var(--border-color);
            object-fit: cover;
            flex-shrink: 0;
        }
        .avatar-sm[src]:not([src=""]) {
            animation: avatar-fadein 0.2s ease;
        }
        @keyframes avatar-fadein {
            from { opacity: 0; }
            to   { opacity: 1; }
        }
        .profile-avatar-large {
            background-color: var(--border-color);
        }
        .avatar-xs {
            background-color: var(--border-color);
        }
        /* 投稿アイコン エフェクトラッパー */
        .post-avatar-wrap {
            position: relative;
            width: 40px;
            height: 40px;
            flex-shrink: 0;
            overflow: visible;
        }
        .post-avatar-wrap .avatar-sm {
            position: relative;
            z-index: 1;
        }
        .post-avatar-effect-canvas {
            position: absolute;
            inset: -6px;
            width: calc(100% + 12px);
            height: calc(100% + 12px);
            pointer-events: none;
            mix-blend-mode: screen;
            z-index: 2;
        }

        /* ========== MAIN CONTENT ========== */
        /*
         * --header-height: ヘッダーの実高さ。
         * page-section の top オフセットと page-header の min-height を
         * この変数で一元管理する。変更するときはここだけ触ればよい。
         */
        :root { --header-height: 60px; }

        .main-content {
            flex: 1;
            min-width: 0;
            border-right: 1px solid var(--border-color);
            background-color: var(--bg-surface);
            height: 100vh;
            overflow-y: auto;
            overflow-x: clip;
            position: relative;
            scrollbar-gutter: stable;
        }

        /* ========== PAGE HEADER ========== */
        /*
         * ヘッダーは main-content 内の先頭に置いたまま
         * position:sticky で固定する。
         * page-section は全状態で position:absolute なので
         * ヘッダーとのフロー競合は発生しない。
         */
        .page-header {
            position: sticky;
            top: 0;
            /* main-content の padding-top 内に収まるよう
               margin-top で padding 分を打ち消してヘッダーを先頭に戻す */
            z-index: 20; /* page-section アニメーション最大値(10)より上 */
            background: var(--header-bg);
            backdrop-filter: blur(24px) saturate(1.8);
            -webkit-backdrop-filter: blur(24px) saturate(1.8);
            border-bottom: 1px solid var(--header-border);
            box-shadow: var(--header-shadow);
            padding: 1rem 1.5rem;
            font-size: 1.25rem;
            display: flex;
            align-items: center;
            font-weight: 700;
            gap: 1rem;
            min-height: var(--header-height);
            flex-shrink: 0;
        }

        .page-header-inner {
            display: flex;
            align-items: center;
            gap: 1rem;
            width: 100%;
        }

        /* ========== PAGE TRANSITION ========== */
        /*
         * 【ガタつき根絶の核心】
         * page-section を「常に position:absolute; top: var(--header-height)」に固定し、
         * active 時も relative に戻さない。
         * これにより active ↔ アニメーションクラス切り替え時に
         * position も top も一切変わらず、Y座標ジャンプが発生しない。
         *
         * スクロール高さは main-content の padding-top + min-height で確保する。
         */
        .page-section {
            display: none;
            position: absolute;
            top: var(--header-height); left: 0;
            width: 100%;
            min-height: calc(100vh - var(--header-height));
            background: var(--bg-surface);
            z-index: 1;
        }
        /* モバイルボトムナビ分のスクロール末尾余白 */
        body.has-bottom-nav .page-section {
            padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
        }
        body.has-bottom-nav.floating-nav .page-section {
            padding-bottom: calc(108px + env(safe-area-inset-bottom, 0px));
        }
        .page-section.active {
            display: block;
            /* position/top は変えない → ガタつきなし */
            z-index: 2;
        }
        #dm-chat { flex-direction: column; min-height: 0; }
        #dm-chat.active { display: flex !important; }

        .page-section.nav-slide-in {
            display: block !important;
            z-index: 10;
            animation: navSlideIn 0.42s var(--nav-curve) forwards;
        }
        .page-section.nav-dim {
            display: block !important;
            z-index: 1;
            animation: navDim 0.42s var(--nav-curve) forwards;
        }
        .page-section.nav-slide-out {
            display: block !important;
            z-index: 10;
            animation: navSlideOut 0.42s var(--nav-curve) forwards;
        }
        .page-section.nav-undim {
            display: block !important;
            z-index: 1;
            animation: navUndim 0.42s var(--nav-curve) forwards;
        }
        .page-section.nav-fade-in {
            display: block !important;
            z-index: 2;
            animation: navFadeIn 0.2s ease forwards;
        }
        #dm-chat.nav-slide-in,
        #dm-chat.nav-slide-out,
        #dm-chat.nav-dim,
        #dm-chat.nav-undim,
        #dm-chat.nav-fade-in { display: flex !important; }

        @keyframes navSlideIn {
            from { transform: translateX(100%); }
            to   { transform: translateX(0); }
        }
        @keyframes navSlideOut {
            from { transform: translateX(0); }
            to   { transform: translateX(100%); }
        }
        @keyframes navDim {
            from { transform: translateX(0);    opacity: 1;   filter: brightness(1); }
            to   { transform: translateX(-20%); opacity: 0.9; filter: brightness(0.8); }
        }
        @keyframes navUndim {
            from { transform: translateX(-20%); opacity: 0.9; filter: brightness(0.8); }
            to   { transform: translateX(0);    opacity: 1;   filter: brightness(1); }
        }
        /* 左方向タブ切り替え用 */
        .page-section.nav-slide-in-left {
            display: block !important;
            z-index: 10;
            animation: navSlideInLeft 0.42s var(--nav-curve) forwards;
        }
        .page-section.nav-dim-left {
            display: block !important;
            z-index: 1;
            animation: navDimLeft 0.42s var(--nav-curve) forwards;
        }
        #dm-chat.nav-slide-in-left,
        #dm-chat.nav-dim-left { display: flex !important; }

        @keyframes navSlideInLeft {
            from { transform: translateX(-100%); }
            to   { transform: translateX(0); }
        }
        @keyframes navDimLeft {
            from { transform: translateX(0);   opacity: 1;   filter: brightness(1); }
            to   { transform: translateX(20%); opacity: 0.9; filter: brightness(0.8); }
        }
        @keyframes navFadeIn {
            from { opacity: 0; transform: translateY(4px); }
            to   { opacity: 1; transform: translateY(0); }
        }
        :root { --nav-curve: cubic-bezier(0.32, 0.72, 0, 1); }

        /* ========== THREAD INNER ANIMATIONS ========== */
        @keyframes threadSlideUpIn {
            from { opacity: 0; transform: translateY(-32px); }
            to   { opacity: 1; transform: translateY(0); }
        }
        @keyframes threadSlideDownIn {
            from { opacity: 0; transform: translateY(32px); }
            to   { opacity: 1; transform: translateY(0); }
        }
        @keyframes threadSlideUpOut {
            from { opacity: 1; transform: translateY(0); }
            to   { opacity: 0; transform: translateY(-32px); }
        }
        @keyframes threadSlideDownOut {
            from { opacity: 1; transform: translateY(0); }
            to   { opacity: 0; transform: translateY(32px); }
        }
        .thread-slide-up-in       { animation: threadSlideUpIn   0.28s var(--nav-curve) both; }
        .thread-slide-down-in     { animation: threadSlideDownIn 0.28s var(--nav-curve) both; }
        .thread-slide-up-in-d     { animation: threadSlideUpIn   0.28s var(--nav-curve) 0.05s both; }
        .thread-slide-down-in-d   { animation: threadSlideDownIn 0.28s var(--nav-curve) 0.05s both; }
        .thread-slide-up-out      { animation: threadSlideUpOut   0.2s ease both; }
        .thread-slide-down-out    { animation: threadSlideDownOut 0.2s ease both; }

        /* ========== COMPOSE ========== */
        .compose-area {
            padding: 1.5rem;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            gap: 1rem;
            transition: background-color var(--transition-speed) ease;
        }

        .compose-area:focus-within { background-color: var(--bg-main); }

        .compose-input-wrapper { flex: 1; position: relative; }
        .compose-input-wrapper.drag-over-img {
            border: 2px dashed var(--accent-primary) !important;
            border-radius: var(--border-radius-md);
            background: rgba(66,133,244,0.08) !important;
        }

        .compose-input {
            width: 100%;
            border: none;
            resize: none;
            font-size: 1.1rem;
            line-height: 1.6;
            padding: 0.5rem 0;
            outline: none;
            background: transparent;
            min-height: 60px;
            color: transparent;
            caret-color: var(--text-primary);
            position: relative;
            z-index: 2;
        }

        .compose-preview {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            font-size: 1.1rem;
            line-height: 1.6;
            padding: 0.5rem 0;
            min-height: 60px;
            pointer-events: none;
            white-space: pre-wrap;
            word-break: break-word;
            color: var(--text-primary);
            z-index: 3;
            font-family: inherit;
        }

        /* マークアップ記号を灰色に */
        .compose-preview .mk-sym { color: var(--text-muted); }

        .compose-input::placeholder { color: var(--text-muted); }

        .compose-actions {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: 1rem;
            border-top: 1px solid var(--border-color);
            padding-top: 1rem;
        }

        .action-icons { display: flex; gap: 0.5rem; }

        .icon-btn {
            background: transparent;
            border: none;
            color: var(--accent-primary);
            width: 36px; height: 36px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all var(--transition-speed) ease;
        }

        .icon-btn:hover { background-color: var(--accent-bg); transform: scale(1.1); }

        .btn-submit {
            background-color: var(--accent-primary);
            color: white;
            border: none;
            padding: 0.5rem 1.5rem;
            border-radius: var(--border-radius-full);
            font-weight: 600;
            cursor: pointer;
            transition: background-color var(--transition-speed) ease;
        }

        .btn-submit:hover:not(:disabled) { background-color: var(--accent-hover); }
        .btn-submit:disabled { opacity: 0.5; cursor: not-allowed; }

        /* ========== POST ITEMS ========== */
        .post-item {
            padding: 1.5rem;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            flex-wrap: wrap;
            gap: 0 1rem;
            transition: background-color var(--transition-speed) ease;
            cursor: pointer;
        }
        .post-item .repost-label {
            width: 100%;
            flex-basis: 100%;
            margin-bottom: 0.25rem;
        }

        .post-item:hover { background-color: var(--bg-main); }
        .post-content { flex: 1; }

        .post-header {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            margin-bottom: 0.25rem;
            position: relative;
        }

        .post-author-name { font-weight: 700; color: var(--text-primary); }
        .post-author-handle, .post-time { color: var(--text-secondary); font-size: 0.9rem; }

        .post-text {
            color: var(--text-primary);
            margin-bottom: 0.75rem;
            word-break: break-word;
            white-space: pre-wrap;
        }

        /* 長文フェード */
        .post-text-wrap {
            position: relative;
        }
        .post-text-wrap.is-collapsed .post-text {
            overflow: hidden;
        }
        .post-text-wrap.is-collapsed::after {
            content: '';
            position: absolute;
            bottom: 28px;
            left: 0;
            right: 0;
            height: 60px;
            background: linear-gradient(to bottom, transparent, var(--bg-surface));
            pointer-events: none;
        }
        .post-expand-btn {
            display: block;
            width: 100%;
            padding: 0.3rem 0;
            border: none;
            background: none;
            color: var(--accent-primary);
            font-size: 0.85rem;
            font-weight: 600;
            cursor: pointer;
            text-align: left;
        }
        .post-text-wrap .post-text {
            transition: max-height 0.45s cubic-bezier(0.4, 0, 0.2, 1);
        }
        .post-text-wrap.is-collapsed .post-text {
            max-height: 200px;
        }
        .post-text-wrap:not(.is-collapsed) .post-text {
            max-height: 10000px;
        }
        /* フェードオーバーレイ */
        .post-text-wrap.is-collapsed::after {
            transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
            opacity: 1;
        }
        .post-text-wrap:not(.is-collapsed)::after {
            opacity: 0;
            pointer-events: none;
        }
        /* chevronをrotateX立体回転 */
        .expand-arrow {
            display: inline-block;
            transform: rotateX(0deg) translateY(0px);
            transition: transform 0.45s cubic-bezier(0.34, 1.3, 0.64, 1);
            transform-origin: center center;
            perspective: 300px;
        }
        .post-expand-btn.is-expanded .expand-arrow {
            transform: rotateX(180deg) translateY(-2px);
        }

        /* ページロードスピナー */
        #page-loading-overlay {
            position: fixed;
            inset: 0;
            z-index: 999999;
            background: var(--bg-main, #fff);
            display: flex;
            align-items: center;
            justify-content: center;
            transition: opacity 0.3s ease;
        }
        #page-loading-overlay.hidden {
            opacity: 0;
            pointer-events: none;
        }

        .post-media {
            width: 100%;
            max-height: 400px;
            border-radius: var(--border-radius-md);
            object-fit: cover;
            margin-bottom: 0.75rem;
            border: 1px solid var(--border-color);
        }

        /* 投稿画像グリッド */
        .post-imgs {
            display: grid;
            gap: 4px;
            margin-bottom: 0.75rem;
            border-radius: 6px;
            overflow: hidden;
            width: 100%;
            max-width: 420px;
        }
        .post-imgs.imgs-1 { grid-template-columns: 1fr; }
        .post-imgs.imgs-2 { grid-template-columns: 1fr 1fr; }
        .post-imgs.imgs-3 { grid-template-columns: 1fr 1fr; }
        .post-imgs.imgs-3 .post-img-wrap:first-child { grid-column: 1 / -1; }

        /* imgをwrapperで包んでaspect-ratioで高さを制御 */
        .post-img-wrap {
            position: relative;
            width: 100%;
            overflow: hidden;
            border: 1px solid var(--border-color);
            border-radius: 6px;
        }
        .post-imgs.imgs-1 .post-img-wrap { height: 260px; }
        .post-imgs.imgs-2 .post-img-wrap { height: 180px; }
        .post-imgs.imgs-3 .post-img-wrap { height: 150px; }
        .post-imgs.imgs-3 .post-img-wrap:first-child { height: 180px; }

        /* 投稿詳細画面では大きく表示 */
        #thread .post-imgs { max-width: 480px; }
        #thread .post-imgs.imgs-1 .post-img-wrap { height: 300px; }
        #thread .post-imgs.imgs-2 .post-img-wrap { height: 200px; }
        #thread .post-imgs.imgs-3 .post-img-wrap { height: 170px; }
        #thread .post-imgs.imgs-3 .post-img-wrap:first-child { height: 200px; }

        .post-img {
            position: absolute;
            inset: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
            display: block;
            cursor: zoom-in;
        }

        /* 投稿フォームの画像プレビュー */
        .compose-img-preview {
            display: flex;
            gap: 6px;
            flex-wrap: wrap;
            margin-top: 8px;
        }
        .compose-img-item {
            position: relative;
            width: 80px;
            height: 80px;
        }
        .compose-img-item img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            border-radius: 8px;
            border: 1px solid var(--border-color);
        }
        .compose-img-remove {
            position: absolute;
            top: -6px;
            right: -6px;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background: var(--text-primary);
            color: var(--bg-main);
            border: none;
            cursor: pointer;
            font-size: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            line-height: 1;
        }
        /* 圧縮中スピナーオーバーレイ */
        .compose-img-spinner {
            position: absolute;
            inset: 0;
            border-radius: 8px;
            background: rgba(0,0,0,0.45);
            display: flex;
            align-items: center;
            justify-content: center;
            pointer-events: none;
        }
        .compose-img-spinner canvas {
            width: 48px !important;
            height: 48px !important;
        }

        .post-interactions {
            display: flex;
            justify-content: space-between;
            max-width: 400px;
            color: var(--text-secondary);
        }

        /* ダーク時のインタラクションボタン */
        [data-theme="dark"] .interaction-btn {
            color: var(--text-secondary);
        }
        [data-theme="dark"] .interaction-btn:hover {
            background: var(--bg-main);
        }
        [data-theme="dark"] .sk {
            background: linear-gradient(90deg, var(--border-color) 25%, #1e293b 50%, var(--border-color) 75%);
            background-size: 800px 100%;
        }

        .interaction-btn {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            background: transparent;
            border: none;
            color: inherit;
            cursor: pointer;
            font-size: 0.9rem;
            transition: color var(--transition-speed) ease;
            padding: 0.5rem;
            border-radius: var(--border-radius-full);
        }

        /* ========== POST MENU (3点ドット) ========== */
        .post-menu-btn {
            margin-left: auto;
            background: none;
            border: none;
            cursor: pointer;
            color: var(--text-muted);
            padding: 0.2rem 0.35rem;
            border-radius: var(--border-radius-full);
            display: flex;
            align-items: center;
            opacity: 0;
            transition: opacity 0.15s, background 0.15s, color 0.15s;
        }
        .post-item:hover .post-menu-btn { opacity: 1; }
        .post-menu-btn:hover { background: var(--accent-bg); color: var(--accent-primary); }
        .post-menu-btn svg { width: 16px; height: 16px; }

        .post-menu-dropdown {
            position: absolute;
            right: 0;
            top: 100%;
            background: var(--bg-surface);
            border: 1px solid var(--border-color);
            border-radius: 0.75rem;
            box-shadow: 0 8px 24px rgba(0,0,0,0.12);
            z-index: 50;
            min-width: 140px;
            overflow: hidden;
            animation: dropdownFadeIn 0.15s ease;
        }
        @keyframes dropdownFadeIn {
            from { opacity: 0; transform: translateY(-6px) scale(0.97); }
            to   { opacity: 1; transform: translateY(0)  scale(1); }
        }
        .post-menu-dropdown button {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            width: 100%;
            padding: 0.65rem 1rem;
            background: none;
            border: none;
            cursor: pointer;
            font-size: 0.9rem;
            font-weight: 500;
            color: var(--text-primary);
            transition: background 0.15s;
            text-align: left;
        }
        .post-menu-dropdown button:hover { background: var(--bg-main); }
        .post-menu-dropdown button.danger { color: #ef4444; }
        .post-menu-dropdown button svg { width: 15px; height: 15px; flex-shrink: 0; }

        /* ========== 投稿編集モーダル ========== */
        #edit-post-modal .modal-inner {
            background: var(--bg-surface);
            border-radius: 1rem;
            padding: 1.5rem;
            width: 90%;
            max-width: 520px;
        }

        .ripple { background: color-mix(in srgb, var(--text-primary) 18%, transparent); }
        .interaction-btn svg { width: 18px; height: 18px; transition: transform var(--transition-speed) var(--transition-bounce); }
        .interaction-btn:hover { background-color: var(--accent-bg); color: var(--accent-primary); }
        .interaction-btn:hover svg { transform: scale(1.2); }
        .interaction-btn.like:hover { color: #ef4444; background-color: color-mix(in srgb, #ef4444 12%, transparent); }
        .interaction-btn.like.liked { color: #ef4444; }
        .interaction-btn.like.liked svg { fill: #ef4444; }

        .trend-item {
            padding: 1.25rem 1.5rem;
            border-bottom: 1px solid var(--border-color);
            transition: background-color var(--transition-speed) ease;
            cursor: pointer;
        }

        .trend-item:hover { background-color: var(--bg-main); }
        .trend-category { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.25rem; }
        .trend-title { font-weight: 700; font-size: 1.1rem; margin-bottom: 0.25rem; }
        .trend-stats { font-size: 0.9rem; color: var(--text-secondary); }

        .profile-header-area { border-bottom: 1px solid var(--border-color); }
        .profile-cover { height: 150px; background-image: linear-gradient(120deg, #a1c4fd 0%, #c2e9fb 100%); }

        .profile-info-section { padding: 1.5rem; position: relative; padding-top: 4rem; }


        /* アバターホバーオーバーレイ */
        .profile-avatar-wrapper {
            position: absolute;
            top: -60px;
            width: 120px;
            height: 120px;
            cursor: pointer;
            overflow: visible;
        }
        .profile-avatar-wrapper .profile-avatar-large {
            position: static;
            top: auto;
            width: 100%;
            height: 100%;
        }
        /* エフェクトキャンバス（アバターリングとして重なる） */
        .profile-effect-canvas {
            position: absolute;
            inset: -18px;
            width: calc(100% + 36px);
            height: calc(100% + 36px);
            pointer-events: none;
            z-index: 2;
            border-radius: 50%;
            mix-blend-mode: screen;
        }
        .profile-avatar-overlay {
            position: absolute;
            inset: 0;
            border-radius: 50%;
            background: rgba(0,0,0,0.45);
            display: flex;
            align-items: center;
            justify-content: center;
            opacity: 0;
            transition: opacity 0.2s;
        }
        .profile-avatar-wrapper:hover .profile-avatar-overlay { opacity: 1; }
        .profile-avatar-overlay svg { color: #fff; width: 28px; height: 28px; }

        /* アバター変更モーダル */
        #avatar-modal {
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.5);
            z-index: 1001;
            display: flex;
            align-items: center;
            justify-content: center;
            opacity: 0;
            visibility: hidden;
            pointer-events: none;
            transition: opacity 0.35s var(--ease-out-smooth),
                        visibility 0.35s var(--ease-out-smooth);
            will-change: opacity, visibility;
        }
        #avatar-modal.open {
            opacity: 1;
            visibility: visible;
            pointer-events: auto;
        }
        #avatar-modal .avatar-modal-inner {
            transform: scale(1.25);
            opacity: 0;
            transition: transform 0.35s var(--ease-out-smooth),
                        opacity 0.35s var(--ease-out-smooth);
            will-change: transform, opacity;
        }
        #avatar-modal.open .avatar-modal-inner {
            transform: scale(1);
            opacity: 1;
        }
        #avatar-modal.is-closing {
            opacity: 0;
            visibility: hidden;
            pointer-events: none;
            transition: opacity 0.28s var(--ease-out-smooth),
                        visibility 0.28s var(--ease-out-smooth);
        }
        #avatar-modal.is-closing .avatar-modal-inner {
            transform: scale(1.25);
            opacity: 0;
            transition: transform 0.28s var(--ease-out-smooth),
                        opacity 0.28s var(--ease-out-smooth);
        }
        .avatar-modal-inner {
            background: var(--bg-surface);
            border-radius: 1rem;
            padding: 1.5rem;
            width: 90%;
            max-width: 400px;
            text-align: center;
        }
        .avatar-preview-wrap {
            width: 120px;
            height: 120px;
            border-radius: 50%;
            overflow: hidden;
            margin: 1rem auto;
            border: 3px solid var(--border-color);
        }
        .avatar-preview-wrap img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .avatar-drop-zone {
            border: 2px dashed var(--border-color);
            border-radius: 0.75rem;
            padding: 1.5rem;
            margin: 1rem 0;
            cursor: pointer;
            transition: border-color 0.2s, background 0.2s;
            color: var(--text-muted);
            font-size: 0.9rem;
        }
        .avatar-drop-zone:hover, .avatar-drop-zone.drag-over {
            border-color: var(--accent-primary);
            background: rgba(59,130,246,0.05);
        }
        .avatar-modal-actions {
            display: flex;
            gap: 0.5rem;
            justify-content: flex-end;
            margin-top: 1rem;
        }

        /* ---- アバターモーダル タブ ---- */
        .avatar-modal-tabs {
            display: flex;
            gap: 0;
            border-bottom: 1px solid var(--border-color);
            margin-bottom: 1rem;
        }
        .avatar-modal-tab {
            flex: 1;
            padding: 0.55rem 0.5rem;
            font-size: 0.88rem;
            font-weight: 600;
            border: none;
            background: none;
            cursor: pointer;
            color: var(--text-secondary);
            border-bottom: 2px solid transparent;
            margin-bottom: -1px;
            transition: color 0.18s, border-color 0.18s;
        }
        .avatar-modal-tab.active {
            color: var(--accent-primary);
            border-bottom-color: var(--accent-primary);
        }
        .avatar-modal-tab-pane { display: none; }
        .avatar-modal-tab-pane.active { display: block; }

        /* ---- エフェクト選択カード ---- */
        .effect-option-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 0.75rem;
            margin: 0.75rem 0;
        }
        .effect-option-card {
            border: 2px solid var(--border-color);
            border-radius: 0.875rem;
            padding: 0.75rem 0.5rem 0.6rem;
            cursor: pointer;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 0.5rem;
            transition: border-color 0.18s, background 0.18s;
            background: var(--bg-main);
            font-size: 0.82rem;
            font-weight: 600;
            color: var(--text-secondary);
            user-select: none;
        }
        .effect-option-card:hover {
            border-color: var(--accent-primary);
            background: var(--accent-bg);
        }
        .effect-option-card.selected {
            border-color: var(--accent-primary);
            background: var(--accent-bg);
            color: var(--accent-primary);
        }
        .effect-option-card .effect-thumb {
            width: 72px;
            height: 72px;
            border-radius: 50%;
            overflow: visible;
            position: relative;
            flex-shrink: 0;
        }
        .effect-option-card .effect-thumb img {
            width: 72px;
            height: 72px;
            border-radius: 50%;
            object-fit: cover;
            display: block;
        }
        .effect-thumb-canvas {
            position: absolute;
            inset: -14px;
            width: calc(100% + 28px);
            height: calc(100% + 28px);
            pointer-events: none;
            mix-blend-mode: screen;
        }
        .effect-none-thumb {
            width: 72px;
            height: 72px;
            border-radius: 50%;
            background: var(--border-color);
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--text-muted);
        }
        .avatar-modal-inner {
            max-width: 440px !important;
        }

        /* ---- PC横長レイアウト（エフェクトタブ時） ---- */
        @media (min-width: 640px) {
            .avatar-modal-inner.effect-tab-active {
                max-width: 780px !important;
            }
            #avatar-tab-effect .effect-tab-body {
                display: flex;
                gap: 1.5rem;
                align-items: flex-start;
            }
            /* 左：大プレビュー */
            .effect-large-preview {
                flex-shrink: 0;
                display: flex;
                flex-direction: column;
                align-items: center;
                gap: 0.75rem;
                width: 160px;
            }
            .effect-large-preview-thumb {
                position: relative;
                width: 120px;
                height: 120px;
                flex-shrink: 0;
            }
            .effect-large-preview-thumb img {
                width: 120px;
                height: 120px;
                border-radius: 50%;
                object-fit: cover;
                display: block;
            }
            .effect-large-preview-canvas {
                position: absolute;
                inset: -18px;
                width: calc(100% + 36px);
                height: calc(100% + 36px);
                pointer-events: none;
                mix-blend-mode: screen;
            }
            .effect-large-preview-label {
                font-size: 0.82rem;
                font-weight: 700;
                color: var(--accent-primary);
                text-align: center;
            }
            /* 右：カードグリッド */
            #avatar-tab-effect .effect-option-grid {
                flex: 1;
                grid-template-columns: repeat(4, 1fr);
                margin: 0;
                overflow-y: auto;
                max-height: 320px;
            }
        }
        /* SP：大プレビューは非表示 */
        .effect-large-preview { display: none; }
        @media (min-width: 640px) {
            .effect-large-preview { display: flex; }
        }

        .profile-avatar-large {
            width: 120px; height: 120px;
            border-radius: 50%;
            border: 4px solid var(--bg-surface);
            background-color: var(--border-color);
            position: absolute;
            top: -60px;
            object-fit: cover;
        }

        .profile-actions { display: flex; justify-content: flex-end; margin-bottom: 1rem; }

        .btn-edit-profile {
            background: transparent;
            border: 1px solid var(--border-color);
            padding: 0.5rem 1rem;
            border-radius: var(--border-radius-full);
            font-weight: 600;
            cursor: pointer;
            transition: all var(--transition-speed) ease;
        }

        .btn-edit-profile:hover { background-color: var(--bg-main); }
        .btn-follow {
            background: var(--text-primary);
            color: var(--bg-surface);
            border: none;
            padding: 0.5rem 1.2rem;
            border-radius: var(--border-radius-full);
            font-weight: 700;
            font-size: 0.9rem;
            cursor: pointer;
            transition: opacity 0.15s;
        }
        .btn-follow:hover { opacity: 0.85; }
        .btn-follow.following {
            background: transparent;
            color: var(--text-primary);
            border: 1px solid var(--border-color);
        }
        .btn-follow.following:hover {
            background: rgba(239,68,68,0.1);
            color: #ef4444;
            border-color: #ef4444;
        }

        .profile-main-row {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            gap: 1rem;
            margin-bottom: 0.75rem;
        }
        .profile-name-block { flex: 1; min-width: 0; }
        .profile-side-info {
            display: flex;
            flex-direction: column;
            align-items: flex-end;
            gap: 0.4rem;
            flex-shrink: 0;
        }
        .profile-side-info .profile-meta { margin: 0; }
        .profile-side-info .profile-stats { gap: 1rem; }
        .profile-name { font-size: 1.5rem; font-weight: 800; }
        .profile-handle { color: var(--text-secondary); margin-bottom: 1rem; }
        .profile-bio {
            margin-bottom: 1rem;
            max-height: calc(1.6em * 4);
            overflow-y: auto;
            line-height: 1.6;
        }
        .profile-stats { display: flex; gap: 1.5rem; }
        .stat-group { display: flex; gap: 0.25rem; font-size: 0.9rem; }
        .stat-value { font-weight: 700; color: var(--text-primary); }
        .stat-label { color: var(--text-secondary); }

        /* PC でモバイルUIを強制する */
        body.force-mobile-ui .app-container { flex-direction: column; }
        body.force-mobile-ui .sidebar {
            position: fixed !important;
            bottom: 0 !important; top: auto !important;
            width: 100% !important;
            height: 76px !important;
            flex-direction: row !important;
            border-top: 1px solid rgba(148, 163, 184, 0.55) !important;
            border-left: none !important;
            border-right: none !important;
            border-bottom: none !important;
            padding: 0 !important;
            justify-content: space-around !important;
            background-color: rgba(255, 255, 255, 0.08) !important;
            backdrop-filter: blur(28px) !important;
            -webkit-backdrop-filter: blur(28px) !important;
            box-shadow: none !important;
            z-index: 100 !important;
            overflow: hidden !important;
            transition: none !important;
        }
        body.force-mobile-ui .logo-container,
        body.force-mobile-ui .user-profile-mini,
        body.force-mobile-ui .btn-post-action { display: none !important; }
        body.force-mobile-ui .nav-menu { flex-direction: row !important; width: 100% !important; justify-content: space-around !important; padding: 0 !important; }
        body.force-mobile-ui .nav-label { display: none !important; }
        body.force-mobile-ui .nav-item { padding: 0.5rem !important; width: auto !important; background: transparent !important; }
        body.force-mobile-ui .nav-item::before { display: none !important; }
        body.force-mobile-ui .main-content { max-width: 100% !important; border-right: none !important; padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important; }
        body.force-mobile-ui .mobile-fab { display: flex !important; position: fixed; bottom: 96px; right: 20px; width: 56px; height: 56px; border-radius: 50%; background-color: var(--accent-primary); color: white; align-items: center; justify-content: center; box-shadow: 0 4px 12px rgba(59,130,246,0.3); border: none; z-index: 90; }
        body.force-mobile-ui.floating-nav .sidebar { width: calc(100% - 2rem) !important; left: 1rem !important; bottom: 0.75rem !important; border-radius: 9999px !important; border: 1px solid rgba(148, 163, 184, 0.55) !important; height: 72px !important; box-shadow: none !important; }
        body.force-mobile-ui.floating-nav .main-content { padding-bottom: calc(108px + env(safe-area-inset-bottom, 0px)) !important; }
        body.force-mobile-ui.floating-nav .mobile-fab { bottom: 108px !important; }

        @media (max-width: 640px) {
            .app-container { flex-direction: column; }

            .sidebar {
                position: fixed;
                bottom: 0; top: auto;
                width: 100% !important;
                height: 76px;
                flex-direction: row;
                border-top: 1px solid rgba(148, 163, 184, 0.55);
                border-left: none;
                border-right: none;
                border-bottom: none;
                padding: 0;
                justify-content: space-around;
                background-color: rgba(255, 255, 255, 0.08);
                backdrop-filter: blur(28px);
                -webkit-backdrop-filter: blur(28px);
                box-shadow: none;
                z-index: 100;
                overflow: hidden;
                transition: border-top-color 0.1s linear, border-color 0.1s linear;
            }

            .logo-container, .user-profile-mini, .btn-post-action { display: none; }
            .nav-menu { flex-direction: row; width: 100%; justify-content: space-around; padding: 0; }
            .nav-label { display: none; }
            .nav-item { padding: 0.5rem; width: auto; background: transparent !important; }
            .nav-item:hover { background: transparent !important; color: var(--text-secondary); }
            .nav-item.active { background: transparent; color: var(--accent-primary); }
            .nav-item::before { display: none; }
            .main-content { max-width: 100%; border-right: none; padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }

            /* フローティングボトムナビ */
            .sidebar.floating {
                width: calc(100% - 2rem) !important;
                left: 1rem;
                bottom: 0.75rem;
                border-radius: 9999px;
                border: 1px solid rgba(148, 163, 184, 0.55);
                height: 72px;
                box-shadow: none;
            }
            body.floating-nav .main-content { padding-bottom: calc(108px + env(safe-area-inset-bottom, 0px)); }
            body.floating-nav .mobile-fab   { bottom: 108px; }

            .mobile-fab {
                display: flex !important;
                position: fixed;
                bottom: 96px; right: 20px;
                width: 56px; height: 56px;
                border-radius: 50%;
                background-color: var(--accent-primary);
                color: white;
                align-items: center;
                justify-content: center;
                box-shadow: 0 4px 12px rgba(59,130,246,0.3);
                border: none;
                z-index: 90;
            }

            /* 設定サイドインデックス */
        .settings-side-index {
            position: sticky;
            top: calc(var(--header-height) + 1rem);
            padding: 0.5rem 0;
        }
        .settings-side-link {
            display: flex;
            align-items: center;
            padding: 0.6rem 0.875rem;
            border-radius: 0.75rem;
            font-size: 0.875rem;
            font-weight: 500;
            color: var(--text-secondary);
            cursor: pointer;
            transition: background 0.15s, color 0.15s;
            user-select: none;
            line-height: 1.4;
            margin-bottom: 2px;
        }
        .settings-side-link:hover {
            background: var(--bg-main);
            color: var(--text-primary);
        }
        .settings-side-link.active {
            background: var(--accent-bg);
            color: var(--accent-primary);
            font-weight: 600;
        }

        /* 設定ページ: モバイル対応 */
            #settings .settings-row { padding: 0.875rem 1rem; }
            #settings > div { padding-bottom: env(safe-area-inset-bottom, 0px); }

            /* 絵文字ピッカー: モバイルでは画面下部に固定 */
            #emoji-picker-popup.mobile-picker {
                position: fixed !important;
                left: 0 !important;
                right: 0 !important;
                bottom: 76px !important;
                top: auto !important;
                width: 100% !important;
                border-radius: 1rem 1rem 0 0;
                border-left: none;
                border-right: none;
                border-bottom: none;
                transform-origin: bottom center;
            }
            #emoji-picker-popup.mobile-picker emoji-picker,
            #emoji-picker-popup.mobile-picker .ep-grid-wrap {
                width: 100%;
            }
            #emoji-picker-popup.mobile-picker .ep-grid {
                grid-template-columns: repeat(9, 1fr);
            }
        }

        .mobile-fab { display: none; }

        /* ========== LOGIN BANNER ========== */
        .login-banner {
            position: fixed;
            bottom: 0;
            left: var(--sidebar-collapsed);
            right: 0;
            z-index: 30;
            background: var(--accent-primary);
            color: white;
            transition: left 0.35s cubic-bezier(0.4, 0, 0.2, 1);

        }


        .login-banner-inner {
            max-width: 800px;
            margin: 0 auto;
            padding: 1.1rem 2rem;
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 1.5rem;
        }

        .login-banner-title {
            font-weight: 700;
            font-size: 1rem;
            margin-bottom: 0.15rem;
        }

        .login-banner-sub {
            font-size: 0.85rem;
            opacity: 0.85;
        }

        .login-banner-actions {
            display: flex;
            gap: 0.75rem;
            flex-shrink: 0;
        }

        .login-banner-btn-signup {
            background: var(--bg-surface);
            color: var(--accent-primary);
            border: none;
            padding: 0.55rem 1.4rem;
            border-radius: var(--border-radius-full);
            font-weight: 700;
            font-size: 0.9rem;
            cursor: pointer;
            transition: opacity 0.2s ease;
        }

        .login-banner-btn-signup:hover { opacity: 0.9; }

        .login-banner-btn-login {
            background: transparent;
            color: white;
            border: 2px solid rgba(255,255,255,0.7);
            padding: 0.55rem 1.4rem;
            border-radius: var(--border-radius-full);
            font-weight: 600;
            font-size: 0.9rem;
            cursor: pointer;
            transition: border-color 0.2s ease, background 0.2s ease;
        }

        .login-banner-btn-login:hover {
            border-color: white;
            background: rgba(255,255,255,0.1);
        }

        .main-content { padding-bottom: 72px; }
        /* モバイルボトムナビ分の余白 — ::after で確実にスクロール末尾に余白を確保 */
        body.has-bottom-nav .main-content::after {
            content: '';
            display: block;
            height: calc(76px + env(safe-area-inset-bottom, 0px));
        }
        body.has-bottom-nav.floating-nav .main-content::after {
            height: calc(108px + env(safe-area-inset-bottom, 0px));
        }

        /* ========== POST / USER ANCHOR LINKS ========== */
        .post-user-link,
        .post-thread-link {
            text-decoration: none;
            color: inherit;
        }
        .post-author-handle.post-user-link     { color: var(--text-secondary); }
        .post-time.post-thread-link            { color: var(--text-muted); }

        /* ========== 自作絵文字ピッカー ========== */
        #emoji-picker-popup {
            position: fixed;
            z-index: 9999;
            background: var(--bg-surface);
            border: 1px solid var(--border-color);
            border-radius: 1rem;
            box-shadow: 0 8px 32px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);
            display: none;
            flex-direction: column;
            overflow: hidden;
            width: 320px;
            transform-origin: bottom left;
        }
        #emoji-picker-popup.open {
            display: flex;
            animation: emojiPickerIn 0.2s var(--ease-out-smooth) both;
        }
        #emoji-picker-popup.closing {
            animation: emojiPickerOut 0.15s ease forwards;
        }
        @keyframes emojiPickerIn {
            from { opacity: 0; transform: translateY(8px) scale(0.96); }
            to   { opacity: 1; transform: translateY(0)   scale(1);    }
        }
        @keyframes emojiPickerOut {
            from { opacity: 1; transform: translateY(0)   scale(1);    }
            to   { opacity: 0; transform: translateY(8px) scale(0.96); }
        }

        /* 検索バー */
        .ep-search-wrap {
            padding: 10px 10px 6px;
            position: relative;
        }
        .ep-search {
            width: 100%;
            border: 1px solid var(--border-color);
            border-radius: var(--border-radius-full);
            padding: 7px 38px 7px 36px;
            font-size: 0.875rem;
            font-family: inherit;
            background: var(--bg-main);
            color: var(--text-primary);
            outline: none;
            transition: border-color 0.2s var(--ease-out-smooth),
                        box-shadow   0.2s var(--ease-out-smooth);
            box-sizing: border-box;
        }
        .ep-search:focus {
            border-color: var(--accent-primary);
            box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
        }
        .ep-search-icon {
            position: absolute;
            left: 22px;
            top: 50%;
            transform: translateY(-50%);
            width: 14px;
            height: 14px;
            color: var(--text-muted);
            pointer-events: none;
        }

        /* カテゴリタブ */
        .ep-tabs {
            display: flex;
            border-bottom: 1px solid var(--border-color);
            background: var(--bg-main);
            padding: 2px 4px 0;
            gap: 2px;
            overflow-x: auto;
            scrollbar-width: none;
        }
        .ep-tabs::-webkit-scrollbar { display: none; }
        .ep-tab {
            flex-shrink: 0;
            border: none;
            background: none;
            cursor: pointer;
            padding: 6px 8px 5px;
            border-radius: 8px 8px 0 0;
            font-size: 1rem;
            line-height: 1;
            position: relative;
            transition: background 0.15s;
            color: var(--text-secondary);
        }
        .ep-tab:hover { background: var(--accent-bg); }
        .ep-tab.active {
            color: var(--accent-primary);
        }
        .ep-tab.active::after {
            content: '';
            position: absolute;
            bottom: 0; left: 4px; right: 4px;
            height: 2px;
            background: var(--accent-primary);
            border-radius: 2px 2px 0 0;
        }

        /* 絵文字グリッド */
        .ep-grid-wrap {
            flex: 1;
            overflow-y: auto;
            padding: 6px 6px 4px;
            scrollbar-width: thin;
            scrollbar-color: var(--border-color) transparent;
        }
        .ep-section-label {
            font-size: 0.7rem;
            font-weight: 600;
            color: var(--text-muted);
            text-transform: uppercase;
            letter-spacing: 0.06em;
            padding: 8px 4px 4px;
        }
        .ep-grid {
            display: grid;
            grid-template-columns: repeat(8, 1fr);
            gap: 2px;
        }
        .ep-emoji {
            border: none;
            background: none;
            cursor: pointer;
            font-size: 1.45rem;
            line-height: 1;
            padding: 5px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            overflow: hidden;
            transition: background 0.12s;
        }
        .ep-emoji:hover { background: var(--accent-bg); }
        .ep-emoji:active { background: var(--border-color); }
        /* リップルエフェクト */
        .ep-emoji .ripple { background: rgba(59,130,246,0.2); }
        .ep-empty {
            padding: 2rem;
            text-align: center;
            color: var(--text-muted);
            font-size: 0.875rem;
        }
        /* グリッド高さ上限 + スクロール */
        .ep-grid-wrap {
            max-height: 240px;
        }

        /* 絵文字スタイル設定モーダル */
        #emoji-style-modal {
            position: fixed; inset: 0; z-index: 10000;
            background: rgba(0,0,0,0.5);
            display: none; align-items: center; justify-content: center;
        }
        #emoji-style-modal.open { display: flex; }
        #emoji-style-modal .modal-inner {
            background: var(--bg-surface);
            border-radius: 1rem;
            padding: 1.5rem;
            width: min(400px, 90vw);
            box-shadow: 0 8px 32px rgba(0,0,0,0.15);
        }
        .emoji-style-btn {
            display: flex; align-items: center; gap: 0.75rem;
            width: 100%; padding: 0.75rem 1rem;
            border: 2px solid var(--border-color);
            border-radius: 0.75rem;
            background: var(--bg-surface);
            cursor: pointer; font-size: 0.9rem; font-weight: 500;
            color: var(--text-primary);
            transition: border-color 0.15s, background 0.15s;
            margin-bottom: 0.5rem;
        }
        .emoji-style-btn:last-child { margin-bottom: 0; }
        .emoji-style-btn.active {
            border-color: var(--accent-primary);
            background: var(--accent-bg);
            color: var(--accent-primary);
        }
        .emoji-style-btn .sample { font-size: 1.4rem; line-height: 1; }
        .emoji-style-btn img.sample { width: 1.4em; height: 1.4em; object-fit: contain; vertical-align: middle; }

        /* 絵文字画像（スタイル適用時） */
        .emoji-img {
            width: 1.2em; height: 1.2em;
            vertical-align: -0.15em;
            display: inline-block;
            object-fit: contain;
        }

/* ========== THREAD PAGE & SKELETON ========== */
#thread .post-item { border-bottom: none; }
              #thread .post-interactions { border-top: none; }
      
        /* スケルトンUI */
        .skeleton-text, .skeleton-avatar, .skeleton-line {
          background: linear-gradient(90deg, var(--border-color) 25%, var(--bg-main) 50%, var(--border-color) 75%);
          background-size: 200% 100%;
          animation: skeleton-shimmer 1.2s infinite;
          color: transparent !important;
          border-radius: 4px;
          min-height: 1em;
          display: inline-block;
          width: 100%;
        }
        .skeleton-avatar {
          border-radius: 50% !important;
        }
        @keyframes skeleton-shimmer {
          0%   { background-position: 200% 0; }
          100% { background-position: -200% 0; }
        }

        /* ========== 設定ページ ========== */
        .settings-row {
          display: flex;
          align-items: center;
          gap: 0.75rem;
          padding: 0.875rem 1.25rem;
          width: 100%;
          background: none;
          border: none;
          text-align: left;
          color: var(--text-primary);
          font-family: inherit;
          position: relative;
          overflow: hidden;
        }
        .settings-row-icon {
          width: 36px; height: 36px;
          border-radius: 10px;
          background: var(--accent-bg);
          color: var(--accent-primary);
          display: flex; align-items: center; justify-content: center;
          flex-shrink: 0;
        }
        .settings-row-icon i, .settings-row-icon svg { width: 18px; height: 18px; }
        .settings-row-body { flex: 1; min-width: 0; }
        .settings-row-label { font-size: 0.9rem; font-weight: 500; }
        .settings-row-sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 1px; }
        .settings-row-chevron { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }
        .ripple-btn { cursor: pointer; }
        .ripple-btn:hover { background: var(--bg-main); }
        #settings .ripple-btn:hover { background: var(--bg-main); transition: background 0.15s; }

        /* トグルスイッチ */
        .settings-toggle { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
        .settings-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
        .settings-toggle-track {
          width: 44px; height: 26px;
          background: var(--border-color);
          border-radius: 999px;
          transition: background 0.2s;
          display: flex; align-items: center;
          padding: 0 3px;
        }
        .settings-toggle input:checked + .settings-toggle-track { background: var(--accent-primary); }
        .settings-toggle-thumb {
          width: 20px; height: 20px;
          background: var(--bg-surface);
          border-radius: 50%;
          box-shadow: 0 1px 4px rgba(0,0,0,0.2);
          transition: transform 0.2s var(--transition-bounce);
        }
        .settings-toggle input:checked + .settings-toggle-track .settings-toggle-thumb {
          transform: translateX(18px);
        }

        /* スケルトンUI (sk / sk-circle) */
        @keyframes sk-shimmer {
          0%   { background-position: -800px 0 }
          100% { background-position:  800px 0 }
        }
        .sk {
          background: linear-gradient(90deg, var(--border-color) 25%, var(--bg-main) 50%, var(--border-color) 75%);
          background-size: 800px 100%;
          animation: sk-shimmer 1.4s infinite;
          border-radius: 4px;
          display: block;
        }
        .sk-circle { border-radius: 50% !important; }


/* ========== THEME SELECT ========== */
.theme-select-wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.theme-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 1rem;
}
.theme-card {
    grid-column: span 2;
    position: relative;
    display: flex;
    flex-direction: column;
    border: 2px solid var(--border-color);
    border-radius: 1rem;
    background: var(--bg-surface);
    overflow: hidden;
    transition: border-color 0.2s;
}
.theme-card--mode { grid-column: span 3; }
.theme-card.is-active { border-color: var(--accent-primary); }
.theme-card-hit {
    position: absolute;
    inset: 0;
    padding: 0;
    border: none;
    border-radius: inherit;
    background: none;
    cursor: pointer;
}
.theme-card-hit:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: -2px;
}
.theme-card-preview {
    aspect-ratio: 716 / 433;
    background: var(--bg-surface);
    overflow: hidden;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    pointer-events: none;
}
.theme-card--mode .theme-card-preview { aspect-ratio: 2.52 / 1; }
.theme-card-layer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    container-type: size;
    background: var(--bg-surface);
    color: var(--text-primary);
}
.theme-card-layer--start { clip-path: polygon(0 0, 58% 0, 42% 100%, 0 100%); }
.theme-card-layer--end   { clip-path: polygon(58% 0, 100% 0, 100% 100%, 42% 100%); }
.theme-card-layer--end .theme-card-palette {
    left: auto;
    right: 8.3cqh;
}
.theme-card-post {
    transform-origin: top left;
    user-select: none;
}
.theme-card-post .post-item { border-bottom: none; }
.theme-card-palette {
    position: absolute;
    left: 8.3cqh;
    bottom: 8.3cqh;
    width: 62.8cqh;
    height: 13.2cqh;
    border: 2px solid var(--text-secondary);
    border-radius: 9999px;
    background: linear-gradient(106deg,
        var(--bg-main) 0 30%,
        var(--accent-primary) 30% 70%,
        var(--text-primary) 70% 100%);
}
.theme-card-body {
    position: relative;
    padding: 0.75rem 1rem 0.9rem;
    pointer-events: none;
}
.theme-card-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.5rem;
    margin-bottom: 3px;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
}
.theme-card-title > span:first-child { white-space: nowrap; }
.theme-card-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 9999px;
    color: var(--accent-primary);
    background: var(--accent-bg);
}
.theme-card-desc {
    font-size: 0.78rem;
    color: var(--text-secondary);
}
.theme-card-config {
    margin-left: auto;
    pointer-events: auto;
    padding: 0.15rem 0.7rem;
    border: 1px solid var(--accent-primary);
    border-radius: 9999px;
    background: transparent;
    color: var(--accent-primary);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.3;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.2s;
}
.theme-card-config:hover { background: var(--accent-bg); }
.theme-card-extra {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 100%;
    height: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    background: var(--bg-surface);
    border-top: 0 solid var(--border-color);
    transition: height 0.2s ease, border-top-width 0.2s ease;
}
.theme-card:hover .theme-card-extra,
.theme-card:has(:focus-visible) .theme-card-extra {
    height: 3.25rem;
    border-top-width: 1px;
}
.theme-card-fullbtn {
    pointer-events: auto;
    padding: 0.4rem 1rem;
    border: 1px solid var(--accent-primary);
    border-radius: 9999px;
    background: transparent;
    color: var(--accent-primary);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.2s;
}
.theme-card-fullbtn:hover { background: var(--accent-bg); }

.theme-schedule-modal { padding: 1rem; box-sizing: border-box; }
.theme-schedule-dialog {
    width: min(560px, 100%);
    max-height: 100%;
}
.theme-schedule-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
    padding: 1rem;
    overflow-y: auto;
}
.theme-schedule-sub {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.theme-schedule-bar {
    display: flex;
    height: 2.25rem;
    border: 1px solid var(--border-color);
    border-radius: 0.6rem;
    overflow: hidden;
}
.theme-schedule-seg {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    border-right: 1px solid var(--border-color);
    overflow: hidden;
    font-size: 0.7rem;
    font-weight: 700;
    white-space: nowrap;
}
.theme-schedule-seg:last-child { border-right: none; }
.theme-schedule-ticks {
    display: flex;
    justify-content: space-between;
    margin-top: -0.4rem;
    font-size: 0.68rem;
    color: var(--text-secondary);
}
.theme-schedule-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.theme-schedule-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.theme-schedule-range {
    flex-shrink: 0;
    min-width: 3.4rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.theme-schedule-time,
.theme-schedule-theme {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 0.6rem;
    background: var(--bg-main);
    color: var(--text-primary);
    font: inherit;
    font-size: 0.85rem;
}
.theme-schedule-theme { flex: 1; min-width: 0; }
.theme-schedule-remove,
.theme-schedule-add {
    padding: 0.4rem 0.9rem;
    border-radius: 9999px;
    background: transparent;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
}
.theme-schedule-remove {
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.theme-schedule-remove:disabled {
    opacity: 0.4;
    cursor: default;
}
.theme-schedule-add {
    align-self: flex-start;
    border: 1px solid var(--accent-primary);
    color: var(--accent-primary);
}
.theme-schedule-add:hover { background: var(--accent-bg); }
.theme-schedule-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.25rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}
.theme-schedule-state {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.theme-fullpreview {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.55);
}
.theme-fullpreview-dialog {
    display: flex;
    flex-direction: column;
    max-width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    background: var(--bg-surface);
    color: var(--text-primary);
    overflow: hidden;
}
.theme-fullpreview-bar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: 3rem;
    padding: 0 0.75rem 0 1rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
}
.theme-fullpreview-name {
    flex: 1;
    font-size: 0.9rem;
    font-weight: 700;
}
.theme-fullpreview-apply,
.theme-fullpreview-close {
    padding: 0.4rem 1rem;
    border-radius: 9999px;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
}
.theme-fullpreview-apply {
    border: 1px solid var(--accent-primary);
    background: var(--accent-primary);
    color: #fff;
}
.theme-fullpreview-apply:disabled {
    opacity: 0.5;
    cursor: default;
}
.theme-fullpreview-close {
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
}
.theme-fullpreview-stage {
    position: relative;
    flex-shrink: 0;
    overflow: hidden;
}
.theme-fullpreview-frame {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: top left;
    overflow: hidden;
    background: var(--bg-main);
    color: var(--text-primary);
}

@media (max-width: 640px) {
    .theme-select-wrap { padding: 1rem 0.875rem; }
    .theme-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
    }
    .theme-card,
    .theme-card--mode { grid-column: span 1; }
    .theme-card--mode .theme-card-preview { aspect-ratio: 716 / 433; }
    .theme-card-body {
        display: flex;
        flex-direction: column;
    }
    .theme-card-extra {
        position: static;
        order: 3;
        height: auto;
        padding-top: 0.6rem;
        justify-content: flex-start;
        overflow: visible;
        background: none;
        border-top-width: 0;
    }
    .theme-card:hover .theme-card-extra,
    .theme-card:has(:focus-visible) .theme-card-extra {
        height: auto;
        border-top-width: 0;
    }
    .theme-schedule-row { flex-wrap: wrap; }
    .theme-schedule-theme { flex-basis: 100%; order: 3; }
}

body.has-bottom-nav .theme-card-body {
    display: flex;
    flex-direction: column;
}
body.has-bottom-nav .theme-card-extra {
    position: static;
    order: 3;
    height: auto;
    padding-top: 0.6rem;
    justify-content: flex-start;
    overflow: visible;
    background: none;
    border-top-width: 0;
}
body.has-bottom-nav .theme-card:hover .theme-card-extra,
body.has-bottom-nav .theme-card:has(:focus-visible) .theme-card-extra {
    height: auto;
    border-top-width: 0;
}

        /* ========== NAV STYLE: LIQUID (liquidGL) ========== */
        /* force-mobile-ui側の !important 指定より後ろで勝たせるため、セレクタを3段に分けている */
        body.nav-lens-on .sidebar,
        body.nav-lens-on.force-mobile-ui .sidebar,
        body.nav-lens-on.force-mobile-ui.floating-nav .sidebar {
            background: transparent !important;
            backdrop-filter: none !important;
            -webkit-backdrop-filter: none !important;
            filter: none !important;
        }
        body.nav-lens-on .sidebar.floating,
        body.nav-lens-on.force-mobile-ui.floating-nav .sidebar {
            box-shadow: 0 8px 28px rgba(15, 23, 42, 0.18) !important;
        }

        /* ガラスの上・アイコンの下に敷く薄いベール(背景の文字との重なりを抑える) */
        body.nav-lens-on .sidebar::after {
            content: "";
            position: absolute;
            inset: 0;
            border-radius: inherit;
            pointer-events: none;
            z-index: -1;
            background: color-mix(in srgb, var(--bg-surface) 55%, transparent);
            backdrop-filter: blur(2px);
            -webkit-backdrop-filter: blur(2px);
            opacity: var(--nav-veil, 0);
            transition: opacity 0.25s ease;
        }

        /* 長方形(全幅)ナビ: 上の左右だけ丸める。
           リキッドの角丸は四隅共通なので、下の角は画面外に逃がしている */
        body.nav-lens-on .sidebar:not(.floating),
        body.nav-lens-on.force-mobile-ui .sidebar:not(.floating) {
            bottom: -24px !important;
            height: calc(76px + 24px) !important;
            padding: 0 0 24px !important;
            border-radius: 24px 24px 0 0 !important;
            border: 1px solid rgba(148, 163, 184, 0.55) !important;
            border-bottom: none !important;
            box-shadow: 0 -6px 24px rgba(15, 23, 42, 0.12) !important;
        }
