/* =====================
   CSS Variables
   ===================== */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-header: #1e40af;
    --bg-header-hover: #1e3a8a;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --link-color: #2563eb;
    --link-hover: #1d4ed8;
    --new-post-bg: #fffbeb;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --btn-default: #64748b;
    --btn-default-hover: #475569;
    --btn-action: #3b82f6;
    --btn-action-hover: #2563eb;
    --btn-danger: #ef4444;
    --btn-danger-hover: #dc2626;
    --btn-success: #10b981;
    --btn-success-hover: #059669;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --radius: 6px;
}

[data-theme="dark"] {
    --bg-primary: #1e293b;
    --bg-secondary: #0f172a;
    --bg-header: #1e293b;
    --bg-header-hover: #334155;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --link-color: #60a5fa;
    --link-hover: #93c5fd;
    --new-post-bg: #422006;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --btn-default: #475569;
    --btn-default-hover: #64748b;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3);
}

/* =====================
   Base
   ===================== */
html {
    scroll-behavior: smooth;
    max-width: 100%;
    overflow-x: hidden;
}

body {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    transition: background-color 0.2s, color 0.2s;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
    font-weight: 400;
    max-width: 100%;
    overflow-x: hidden;
}

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

/* =====================
   Local utility fallback
   Tailwind CDNが読めない環境でも最低限のレイアウトを維持する
   ===================== */
.hidden { display: none; }
.block { display: block; }
.inline-block { display: inline-block; }
.inline-flex { display: inline-flex; }
.flex { display: flex; }
.grid { display: grid; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.flex-1 { flex: 1 1 0%; }
.flex-shrink-0 { flex-shrink: 0; }
.min-w-0 { min-width: 0; }
.min-h-screen { min-height: 100vh; }
.w-full { width: 100%; }
.max-w-md { max-width: 28rem; }
.max-w-sm { max-width: 24rem; }
.max-w-3xl { max-width: 48rem; }
.max-w-4xl { max-width: 56rem; }
.max-w-5xl { max-width: 64rem; }
.mx-auto { margin-left: auto; margin-right: auto; }
.mt-0\.5 { margin-top: 0.125rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-1\.5 { margin-top: 0.375rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mb-8 { margin-bottom: 2rem; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.p-8 { padding: 2rem; }
.px-1 { padding-left: 0.25rem; padding-right: 0.25rem; }
.px-1\.5 { padding-left: 0.375rem; padding-right: 0.375rem; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.px-8 { padding-left: 2rem; padding-right: 2rem; }
.py-0\.5 { padding-top: 0.125rem; padding-bottom: 0.125rem; }
.py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.py-8 { padding-top: 2rem; padding-bottom: 2rem; }
.py-12 { padding-top: 3rem; padding-bottom: 3rem; }
.pt-6 { padding-top: 1.5rem; }
.pb-2 { padding-bottom: 0.5rem; }
.pb-8 { padding-bottom: 2rem; }
.gap-1 { gap: 0.25rem; }
.gap-1\.5 { gap: 0.375rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.space-y-2 > :not([hidden]) ~ :not([hidden]) { margin-top: 0.5rem; }
.space-y-8 > :not([hidden]) ~ :not([hidden]) { margin-top: 2rem; }
.rounded { border-radius: 0.25rem; }
.rounded-lg { border-radius: 0.5rem; }
.shadow { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1); }
.border { border: 1px solid var(--border-color); }
.border-b { border-bottom: 1px solid var(--border-color); }
.bg-gray-100 { background-color: #f3f4f6; }
.bg-white { background-color: #fff; }
.bg-red-100 { background-color: #fee2e2; }
.bg-green-100 { background-color: #dcfce7; }
.bg-blue-100 { background-color: #dbeafe; }
.bg-blue-500 { background-color: #3b82f6; }
.bg-green-600 { background-color: #16a34a; }
.bg-gray-300 { background-color: #d1d5db; }
.bg-gray-500 { background-color: #6b7280; }
.text-white { color: #fff; }
.text-gray-400 { color: #9ca3af; }
.text-gray-500 { color: #6b7280; }
.text-gray-700 { color: #374151; }
.text-gray-800 { color: #1f2937; }
.text-gray-900 { color: #111827; }
.text-red-600 { color: #dc2626; }
.text-red-700 { color: #b91c1c; }
.text-green-700 { color: #15803d; }
.text-blue-500 { color: #3b82f6; }
.text-blue-600 { color: #2563eb; }
.text-xs { font-size: 0.75rem; line-height: 1rem; }
.text-sm { font-size: 0.875rem; line-height: 1.25rem; }
.text-base { font-size: 1rem; line-height: 1.5rem; }
.text-lg { font-size: 1.125rem; line-height: 1.75rem; }
.text-xl { font-size: 1.25rem; line-height: 1.75rem; }
.text-2xl { font-size: 1.5rem; line-height: 2rem; }
.text-3xl { font-size: 1.875rem; line-height: 2.25rem; }
.font-medium { font-weight: 500; }
.font-bold { font-weight: 700; }
.font-extrabold { font-weight: 800; }
.leading-tight { line-height: 1.25; }
.appearance-none { appearance: none; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.break-words { overflow-wrap: break-word; word-break: break-word; }
.whitespace-nowrap { white-space: nowrap; }
.whitespace-pre-wrap { white-space: pre-wrap; }
.overflow-hidden { overflow: hidden; }
.overflow-y-auto { overflow-y: auto; }
.sticky { position: sticky; }
.fixed { position: fixed; }
.inset-0 { inset: 0; }
.top-0 { top: 0; }
.bottom-0 { bottom: 0; }
.left-0 { left: 0; }
.right-0 { right: 0; }
.z-10 { z-index: 10; }
.z-50 { z-index: 50; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.divide-y > :not([hidden]) ~ :not([hidden]) { border-top: 1px solid var(--border-color); }
.container { width: 100%; }
.top-4 { top: 1rem; }
.right-4 { right: 1rem; }
.bottom-20 { bottom: 5rem; }
.max-h-\[90vh\] { max-height: 90vh; }
.max-w-\[95vw\] { max-width: 95vw; }
.max-h-\[95vh\] { max-height: 95vh; }
.min-w-\[2rem\] { min-width: 2rem; }
.object-contain { object-fit: contain; }
.transition { transition-property: color, background-color, border-color, opacity, box-shadow, transform; transition-duration: 150ms; }
.hover\:underline:hover { text-decoration: underline; }
.hover\:bg-gray-100:hover { background-color: #f3f4f6; }
.hover\:bg-gray-400:hover { background-color: #9ca3af; }
.hover\:bg-gray-600:hover { background-color: #4b5563; }
.hover\:bg-green-700:hover { background-color: #15803d; }
.hover\:bg-blue-700:hover { background-color: #1d4ed8; }
.focus\:outline-none:focus { outline: 2px solid transparent; outline-offset: 2px; }
.focus\:ring-2:focus { box-shadow: 0 0 0 2px rgba(59,130,246,0.45); }

input,
button,
textarea,
select {
    font: inherit;
}

input,
textarea,
select {
    max-width: 100%;
}

.post-message img,
.post-message video,
.post-message iframe,
.post-message table,
.post-message pre,
.post-message code {
    max-width: 100%;
}

.post-message pre,
.post-message code {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

@media (min-width: 640px) {
    .sm\:inline { display: inline; }
    .sm\:flex-row { flex-direction: row; }
    .sm\:max-w-xs { max-width: 20rem; }
    .sm\:px-4 { padding-left: 1rem; padding-right: 1rem; }
    .sm\:px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
    .sm\:py-4 { padding-top: 1rem; padding-bottom: 1rem; }
    .sm\:py-8 { padding-top: 2rem; padding-bottom: 2rem; }
    .sm\:p-3 { padding: 0.75rem; }
    .sm\:p-4 { padding: 1rem; }
    .sm\:p-6 { padding: 1.5rem; }
    .sm\:gap-3 { gap: 0.75rem; }
    .sm\:gap-6 { gap: 1.5rem; }
    .sm\:text-base { font-size: 1rem; line-height: 1.5rem; }
    .sm\:text-xl { font-size: 1.25rem; line-height: 1.75rem; }
    .sm\:text-2xl { font-size: 1.5rem; line-height: 2rem; }
    .sm\:w-56 { width: 14rem; }
}

@media (min-width: 768px) {
    .md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1024px) {
    .lg\:px-8 { padding-left: 2rem; padding-right: 2rem; }
    .lg\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .lg\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .lg\:col-span-1 { grid-column: span 1 / span 1; }
    .lg\:col-span-3 { grid-column: span 3 / span 3; }
}

/* =====================
   Scrollbar
   ===================== */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* =====================
   Header
   ===================== */
.site-header {
    background: var(--bg-header);
    color: #fff;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 50;
}

.site-header a { color: #fff; }
.site-header a:hover { opacity: 0.85; }

.header-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-nav-item {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    opacity: 0.85;
    transition: opacity 0.15s, background 0.15s;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    border: none;
    background: transparent;
    color: #fff;
}

.header-nav-item:hover {
    opacity: 1;
    background: rgba(255,255,255,0.15);
}

.header-nav-item .icon {
    font-size: 1rem;
}

/* =====================
   Unified Buttons
   ===================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
    line-height: 1.4;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

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

/* Button variants */
.btn-default {
    background: var(--btn-default);
    color: #fff;
}
.btn-default:hover { background: var(--btn-default-hover); }

.btn-action {
    background: var(--btn-action);
    color: #fff;
}
.btn-action:hover { background: var(--btn-action-hover); }

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

.btn-danger {
    background: var(--btn-danger);
    color: #fff;
}
.btn-danger:hover { background: var(--btn-danger-hover); }

.btn-success {
    background: var(--btn-success);
    color: #fff;
}
.btn-success:hover { background: var(--btn-success-hover); }

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.btn-outline:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* =====================
   Bookmark Star (compact)
   ===================== */
.bookmark-star {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.15s;
    border: none;
    background: transparent;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}

.bookmark-star:hover {
    transform: scale(1.15);
}

.bookmark-star.active {
    color: #f59e0b;
}

.bookmark-star.inactive {
    color: var(--text-muted);
    opacity: 0.5;
}

.bookmark-star.inactive:hover {
    opacity: 0.8;
}

/* Thread/Board bookmark button (⭐ emoji) */
.btn-bookmark {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.125rem;
    font-size: 1rem;
    line-height: 1;
    transition: transform 0.15s, filter 0.15s, opacity 0.15s;
    filter: grayscale(1);
    opacity: 0.3;
}

.btn-bookmark:hover {
    transform: scale(1.2);
    opacity: 0.5;
}

.btn-bookmark.active {
    filter: none;
    opacity: 1;
}

.btn-bookmark.active:hover {
    transform: scale(1.2);
}

/* =====================
   Sort / Mode Buttons
   ===================== */
.btn-mode, .sort-btn {
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    display: inline-block;
}

.btn-mode:hover, .sort-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--accent);
}

.btn-mode.active, .sort-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* =====================
   Thread Item Row
   ===================== */
.thread-item {
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.thread-item:hover {
    border-left-color: var(--accent);
    background-color: var(--bg-secondary);
}

.thread-item-row {
    border-bottom: 1px solid var(--border-color);
}

/* =====================
   Post / Res Display
   ===================== */
.post-message {
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.7;
}

.post-message a {
    color: var(--link-color);
    text-decoration: underline;
}

.post-message a:hover {
    color: var(--link-hover);
}

.new-post {
    background-color: var(--new-post-bg);
    border-left: 3px solid #f59e0b;
}

.post-item {
    transition: background-color 0.15s;
}

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

/* =====================
   Unread Badge
   ===================== */
.unread-badge {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* =====================
   Bottom Action Bar
   ===================== */
.action-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 0;
}

.action-group {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    flex-wrap: wrap;
}

/* =====================
   Loading & Toast
   ===================== */
.loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.2);
    border-left-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--btn-success);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease-out;
    z-index: 10000;
    font-size: 1rem;
}

.toast.error { background: var(--btn-danger); }

@keyframes slideIn {
    from { transform: translateX(300px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* =====================
   Fade In
   ===================== */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =====================
   Card
   ===================== */
.card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

/* =====================
   Back-to-prev button
   ===================== */
#back-to-prev {
    animation: slideInFromRight 0.3s ease-out;
}

@keyframes slideInFromRight {
    from { transform: translateX(300px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* =====================
   Images
   ===================== */
.image-thumbnail {
    display: inline-block;
    transition: all 0.2s ease;
}

.image-thumbnail:hover { transform: scale(1.02); }

.lazy-image {
    transition: all 0.2s ease;
    display: block;
}

.lazy-image[data-expanded="false"] { cursor: zoom-in; }
.lazy-image[data-expanded="true"] { cursor: zoom-out; }

[data-theme="dark"] .lazy-image { opacity: 0.95; }
[data-theme="dark"] .lazy-image:hover { opacity: 1; }

/* =====================
   Typography - Font Size Scale
   ===================== */
body {
    font-size: 14px;
    line-height: 1.6;
}

/* ヘッダー内テキスト */
.site-header {
    font-size: 0.8125rem;
}

/* スレッドタイトル */
.thread-title {
    font-size: 1.375rem;
    line-height: 1.4;
    font-weight: 700;
}

/* レス本文 */
.post-message {
    font-size: 0.9375rem;
    line-height: 1.75;
}

/* レスヘッダー（名前・日時・ID） */
.post-header {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* レス番号 */
.post-number {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* スレッド一覧のタイトル */
.thread-list-title {
    font-size: 0.9375rem;
}

/* スレッド一覧のメタ情報（レス数・日時） */
.thread-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* セクション見出し */
h2 {
    font-size: 1.25rem;
}

/* 検索ボックス */
input[type="text"],
input[placeholder] {
    font-size: 1rem;
}

/* =====================
   Mobile Responsive (Unified)
   ===================== */
@media (max-width: 768px) {
    body {
        font-size: 14px;
    }

    .thread-title {
        font-size: 1.125rem;
        line-height: 1.3;
    }

    .post-message {
        font-size: 1rem;
        line-height: 1.7;
    }

    .post-header {
        font-size: 0.75rem;
    }

    .post-number {
        min-width: 2rem;
        font-size: 0.8125rem;
    }

    h2 {
        font-size: 1.125rem;
    }

    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .action-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .action-group {
        justify-content: center;
    }
}

@media (max-width: 640px) {
    /* ヘッダー：横並びを維持してタイトルを縮める */
    .site-header .container {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }
    .site-header .container > div.flex {
        flex-direction: row;
        align-items: center;
        gap: 0.25rem;
    }
    .site-header .container > div.flex > div.flex-1 {
        flex: 1 1 0;
        min-width: 0;
        overflow: hidden;
    }
    .site-header .container > div.flex > div.flex-1 a,
    .site-header .container > div.flex > div.flex-1 h1,
    .site-header .container > div.flex > div.flex-1 > div {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    /* タイトル+ブックマーク行はflexを維持して★ボタンを常に表示 */
    .site-header .thread-title-bar {
        display: flex !important;
        overflow: visible !important;
        white-space: normal !important;
    }
    .site-header .thread-title-bar .truncate {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .bookmark-star {
        flex-shrink: 0;
        min-width: 2rem;
        min-height: 2rem;
    }
    .site-header .container > div.flex > nav.header-nav {
        flex-shrink: 0;
        gap: 0;
    }
    /* ナビアイコンのラベル非表示＋タッチ領域確保 */
    .header-nav-item .label {
        display: none;
    }

    .header-nav-item {
        min-width: 36px;
        min-height: 36px;
        padding: 0.25rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .header-nav-item .icon {
        font-size: 1.125rem;
    }

    button.header-nav-item {
        -webkit-tap-highlight-color: rgba(255,255,255,0.2);
        touch-action: manipulation;
    }

    /* スマホではA-/A+をヘッダーから非表示（設定モーダルで変更可） */
    button.header-nav-item[title="文字小"],
    button.header-nav-item[title="文字大"] {
        display: none;
    }

    .site-header a[href="logout.php"].btn {
        width: 36px;
        min-width: 36px;
        height: 36px;
        padding: 0;
        overflow: hidden;
        font-size: 0;
        line-height: 1;
        flex-shrink: 0;
    }

    .site-header a[href="logout.php"].btn::before {
        content: "退出";
        font-size: 0.6875rem;
        font-weight: 700;
    }

    .site-header input[type="text"] {
        width: 100% !important;
        max-width: 14rem;
        min-width: 0;
    }
}

/* =====================
   Content Width Constraint
   ===================== */
.post-message {
    max-width: 52rem;
}

/* スレッド表示エリア全体の幅制限 */
.thread-content-area {
    max-width: 60rem;
}

/* =====================
   Font Scale System
   ===================== */
:root {
}

.post-message {
    font-size: 0.9375em;
}

.thread-title {
    font-size: 1.375em;
}

.post-header {
    font-size: 0.8125em;
}

/* A-/A+ ボタンスタイル */
button.header-nav-item[title="文字小"],
button.header-nav-item[title="文字大"] {
    font-size: 0.6875rem;
    font-weight: 700;
    font-family: sans-serif;
    min-width: auto;
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    background: rgba(255,255,255,0.15);
}
button.header-nav-item[title="文字小"]:hover,
button.header-nav-item[title="文字大"]:hover {
    background: rgba(255,255,255,0.3);
}

/* =====================
   フローティングスクロールボタン
   ===================== */
.float-scroll-btn {
    position: fixed;
    right: 1.25rem;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 1.25rem;
    font-weight: bold;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, background 0.15s, transform 0.15s;
    z-index: 200;
    line-height: 1;
}
.float-scroll-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.08);
}
@media (max-width: 640px) {
    .float-scroll-btn {
        width: 2.25rem;
        height: 2.25rem;
        font-size: 1rem;
        right: 0.75rem;
    }
}

/* =====================
   設定モーダル
   ===================== */
.settings-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
    padding: 1rem;
}
.settings-modal-overlay.hidden {
    display: none;
}
.settings-modal-box {
    background: var(--bg-primary);
    border-radius: 10px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.35);
}
.settings-modal-header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}
.settings-modal-header h2 {
    font-size: 1.125rem;
    font-weight: 700;
    margin: 0;
}
.settings-close-btn {
    background: transparent;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    padding: 0.25rem;
}
.settings-close-btn:hover { color: var(--text-primary); }
.settings-modal-body {
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}
.settings-section {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
}
.settings-section h3 {
    font-size: 0.9375rem;
    font-weight: 600;
    margin: 0 0 0.625rem 0;
    color: var(--text-primary);
}
.settings-radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.settings-radio-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    cursor: pointer;
    color: var(--text-primary);
}
.settings-color-swatches {
    display: flex;
    gap: 0.625rem;
    flex-wrap: wrap;
    margin-bottom: 0.625rem;
}
.color-swatch {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: var(--text-primary); transform: scale(1.1); }
.settings-reset-btn {
    margin-top: 0.5rem;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius);
    cursor: pointer;
}
.settings-reset-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.settings-link-btn {
    display: inline-block;
    font-size: 1rem;
    color: var(--link-color);
    text-decoration: underline;
}
.settings-link-btn:hover { color: var(--link-hover); }

/* =====================
   IDホバーポップアップ
   ===================== */
.id-count-link {
    cursor: pointer;
    font-weight: bold;
    color: var(--link-color);
    text-decoration: underline dotted;
    font-size: 0.8125em;
}
.id-count-link:hover { color: var(--link-hover); }

.id-popup {
    position: fixed;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    z-index: 3000;
    font-size: 0.8125rem;
    min-width: 240px;
    max-height: 360px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.id-popup-header {
    padding: 0.5rem 0.75rem;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    font-size: 0.8125rem;
    flex-shrink: 0;
}
.id-popup-list {
    overflow-y: auto;
    flex: 1;
    padding: 0.375rem 0;
}
.id-popup-item {
    padding: 0.375rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}
.id-popup-item:last-child { border-bottom: none; }
.id-popup-num {
    color: var(--text-muted);
    font-size: 0.75rem;
    flex-shrink: 0;
    margin-top: 0.1rem;
}
.id-popup-msg {
    flex: 1;
    min-width: 0;
    font-size: 0.8125rem;
    line-height: 1.6;
    word-break: break-all;
    max-width: unset !important;
}

/* 検索対象板ボタン */
.btn-search-board {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    opacity: 0.25;
    transition: opacity 0.15s;
}
.btn-search-board:hover { opacity: 0.6; }
.btn-search-board.active { opacity: 1; }

/* ドラッグ&ドロップ並び替え */
.bookmark-sort-item.drag-over {
    border-top: 2px solid var(--accent-color, #3b82f6);
}
.drag-handle {
    font-size: 1rem;
    line-height: 1;
    user-select: none;
}

/* ドラッグ中に子要素がイベントを横取りしないようにする */
.bookmark-sort-item.dragging * {
    pointer-events: none;
}

/* ===== URL要約ポップアップ ===== */
#url-summary-popup {
    position: absolute;
    z-index: 9999;
    width: 360px;
    max-width: calc(100vw - 16px);
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #ccc);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    font-size: 0.85rem;
    line-height: 1.6;
    padding: 0;
    pointer-events: none;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}
#url-summary-popup.visible {
    opacity: 1;
    transform: translateY(0);
}
.url-summary-header {
    padding: 8px 12px 4px;
    font-weight: bold;
    font-size: 0.8rem;
    color: var(--text-secondary, #666);
    border-bottom: 1px solid var(--border-color, #eee);
}
.url-summary-body {
    padding: 8px 12px;
    color: var(--text-primary, #333);
}
.url-summary-url {
    padding: 4px 12px 8px;
    font-size: 0.75rem;
    color: var(--text-secondary, #999);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.url-summary-loading {
    display: block;
    padding: 12px;
    color: var(--text-secondary, #666);
    text-align: center;
}
.url-summary-error {
    display: block;
    padding: 12px;
    color: #e74c3c;
}
[data-theme="dark"] #url-summary-popup {
    background: var(--bg-primary);
    border-color: var(--border-color);
}

/* =====================
   返信ツリー
   ===================== */
.reply-tree-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    font-size: 0.7rem;
    font-weight: bold;
    line-height: 1;
    border-radius: 3px;
    border: 1px solid var(--accent);
    color: var(--accent);
    background: transparent;
    cursor: pointer;
    margin-left: 0.25rem;
    vertical-align: middle;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.reply-tree-btn:hover,
.reply-tree-btn.open {
    background: var(--accent);
    color: #fff;
}
.reply-tree {
    margin-top: 0.5rem;
    margin-left: 0.25rem;
    border-left: 2px solid var(--border-color);
    padding-left: 0.75rem;
}
.reply-tree-item {
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85em;
}
.reply-tree-item:last-child {
    border-bottom: none;
}
.reply-tree-header {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    margin-bottom: 0.2rem;
}
.reply-tree-num {
    font-weight: bold;
    color: var(--link-color);
    text-decoration: none;
}
.reply-tree-meta {
    color: var(--text-secondary);
    font-size: 0.85em;
}
