/* 避難所ビューワー：意見箱・過去ログ検索と同じ「落ち着いた赤」 */
:root {
    --bg: #faf5f4; --card: #fffdfc; --text: #2e2424; --muted: #7d6b6a; --line: #ecdedc;
    --head: #3b2224; --head-accent: #f0a59d; --head-title: #ff7b72; --head-odai: #b9aeac;
    --primary: #a24a47; --on-primary: #ffffff; --accent: #b04c47; --accent-bg: #f9e9e7;
    --ok-bg: #edf5ee; --ok: #3d7a4e; --danger: #b3261e; --mark-bg: #ffe08a; --mark-fg: #3a2a00;
    --new: #c2410c;
    --radius: 8px;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #191314; --card: #231b1c; --text: #ece3e2; --muted: #a89795; --line: #3a2e2f;
        --primary: #d98580; --on-primary: #2a1515; --accent: #e08b84; --accent-bg: #3a2425;
        --ok-bg: #1d2d22; --ok: #86c99a; --danger: #ff8a80; --mark-bg: #7a5a12; --mark-fg: #fff3cf; --new: #fb923c;
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #191314; --card: #231b1c; --text: #ece3e2; --muted: #a89795; --line: #3a2e2f;
    --primary: #d98580; --on-primary: #2a1515; --accent: #e08b84; --accent-bg: #3a2425;
    --ok-bg: #1d2d22; --ok: #86c99a; --danger: #ff8a80; --mark-bg: #7a5a12; --mark-fg: #fff3cf; --new: #fb923c;
    color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
    line-height: 1.7; font-size: 15px;
}
a { color: var(--primary); }
.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--card); padding: 6px 10px; z-index: 100; }
.skip:focus { left: 8px; }
main { padding: 16px 0 40px; outline: none; }
.loading, .empty { color: var(--muted); text-align: center; padding: 32px 8px; }
.error-box { background: var(--accent-bg); color: var(--danger); border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; }

/* ヘッダー（意見箱と同じ） */
.site-header { background: var(--head); color: #fff; }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; padding-bottom: 12px; }
.brand { color: #fff; text-decoration: none; line-height: 1.3; }
.brand small { display: block; font-size: .75rem; opacity: .75; letter-spacing: .05em; }
.brand strong { font-size: 1.2rem; color: var(--head-title); white-space: nowrap; }
.brand-row { display: flex; align-items: center; gap: 10px; }
.unofficial {
    display: inline-grid; place-items: center; line-height: 1; white-space: nowrap;
    padding: 4px 6px 3px; border: 2px solid var(--head-accent); border-radius: 4px;
    color: var(--head-accent); transform: rotate(-8deg);
    box-shadow: inset 0 0 0 1px var(--head), inset 0 0 0 2px rgba(255,255,255,.18); user-select: none;
}
.unofficial b { font-size: .8rem; font-weight: 900; letter-spacing: .2em; margin-right: -.2em; }
.unofficial small { font-size: .45rem; font-weight: 700; letter-spacing: .18em; margin-top: 2px; opacity: 1; display: block; }
.header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.board-link {
    display: inline-flex; align-items: center; gap: 4px; color: #fff; text-decoration: none; font-size: .85rem; font-weight: 700;
    border: 1px solid rgba(255,255,255,.55); border-radius: 99px; padding: 4px 12px; white-space: nowrap; transition: background .15s;
}
.board-link:hover { background: rgba(255,255,255,.14); }
.board-link:focus-visible { outline: 2px solid var(--head-accent); outline-offset: 2px; }
.theme-switch {
    position: relative; flex: none; width: 52px; height: 28px; padding: 0; cursor: pointer;
    border: 1px solid rgba(255,255,255,.55); border-radius: 99px; background: rgba(255,255,255,.12); transition: background .2s, border-color .2s;
}
.theme-knob {
    position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35);
    display: grid; place-items: center; font-size: 12px; line-height: 1; transition: transform .2s ease, background .2s;
}
.theme-knob::after { content: "☀️"; }
.theme-switch[aria-checked="true"] .theme-knob::after { content: "🌙"; }
.theme-switch[aria-checked="true"] { background: rgba(255,123,114,.35); border-color: var(--head-title); }
.theme-switch[aria-checked="true"] .theme-knob { transform: translateX(24px); background: #2a1f20; box-shadow: 0 0 0 1px var(--head-title); }
.theme-switch:focus-visible { outline: 2px solid var(--head-title); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .theme-knob, .theme-switch, .board-link { transition: none; } }
@media (max-width: 520px) { .board-link .long { display: none; } .board-link { padding: 4px 10px; } }
@media (max-width: 440px) {
    .site-header .wrap { gap: 8px; flex-wrap: wrap; }
    .header-right { margin-left: auto; flex-wrap: nowrap; gap: 6px; }
    .board-link { padding: 3px 8px; font-size: .78rem; }
    .board-link [aria-hidden="true"] { display: none; }
    .theme-switch { width: 44px; height: 24px; }
    .theme-knob { width: 18px; height: 18px; font-size: 10px; }
    .theme-switch[aria-checked="true"] .theme-knob { transform: translateX(20px); }
}
@media (max-width: 360px) { .unofficial small { display: none; } }

.site-footer { color: var(--muted); font-size: .8rem; text-align: center; padding: 8px 16px 48px; }
.site-footer a { color: var(--muted); }

/* 共通パーツ */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
    border: 1px solid var(--primary); color: var(--primary); background: var(--card);
    border-radius: 6px; padding: 5px 12px; font: inherit; font-size: .85rem; font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--accent-bg); }
.btn:focus-visible, .field:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn[aria-pressed="true"] { background: var(--accent-bg); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-primary); }
.btn-primary:hover { background: var(--accent); filter: brightness(.95); }
.btn:disabled { opacity: .55; cursor: wait; }
.field { display: block; width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; font: inherit; background: var(--card); color: var(--text); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 0 0 10px; font-size: .85rem; }
.toolbar .grow { flex: 1; }
.toolbar select.field, .toolbar input.field { width: auto; padding: 4px 8px; font-size: .85rem; }
.toolbar input[type="search"] { flex: 1 1 160px; min-width: 0; }
.muted { color: var(--muted); }

/* スレ一覧 */
.thread-list { list-style: none; margin: 0; padding: 0; }
.thread-row { border-bottom: 1px solid var(--line); }
.thread-row:last-child { border-bottom: 0; }
.thread-row a { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 14px; color: var(--text); text-decoration: none; }
.thread-row a:hover { background: var(--accent-bg); }
.thread-row a:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.thread-title { font-weight: 700; overflow-wrap: anywhere; line-height: 1.45; }
.thread-row.read .thread-title { font-weight: 500; color: var(--muted); }
.thread-meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: .78rem; color: var(--muted); }
.thread-count { align-self: start; font-size: .8rem; font-weight: 700; color: var(--accent); background: var(--accent-bg); border-radius: 99px; padding: 1px 9px; white-space: nowrap; }
.badge-new { color: var(--new); font-weight: 700; }

/* 専ブラ用URL */
.senbura { padding: 8px 14px; margin: 0 0 12px; font-size: .85rem; }
.senbura summary { cursor: pointer; font-weight: 700; color: var(--primary); }
.senbura summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
.senbura p { margin: 6px 0; color: var(--muted); }
.senbura .row { display: flex; gap: 8px; margin-bottom: 4px; }
.senbura .field { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .85rem; padding: 5px 8px; }
.list-summary { font-size: .8rem; color: var(--muted); margin: 8px 2px 0; }

/* スレ表示（過去ログと同じ見た目） */
.thread { padding: 12px 16px 8px; }
.thread-head { border-bottom: 2px solid var(--text); padding-bottom: 6px; margin-bottom: 4px; }
.thread-head h1 { font-size: 1.15rem; margin: 0; line-height: 1.4; overflow-wrap: anywhere; }
.thread-head small { color: var(--muted); font-size: .78rem; }
.res { padding: 10px 0 12px; border-bottom: 1px solid var(--line); scroll-margin-top: 60px; }
.res:last-child { border-bottom: 0; }
.res.flash { background: var(--accent-bg); margin: 0 -10px; padding-left: 10px; padding-right: 10px; border-radius: 6px; }
.res.mine { box-shadow: inset 3px 0 0 var(--accent); padding-left: 8px; }
.res-info { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; font-size: .8rem; color: var(--muted); }
.res-no { font-weight: 700; color: var(--primary); background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.res-no:hover { text-decoration: underline; }
.res-name { font-weight: 700; color: var(--ok); overflow-wrap: anywhere; }
.res-mail { color: var(--muted); }
.res-id { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
.res-id:hover { color: var(--primary); text-decoration: underline; }
.res-id .cnt { margin-left: 2px; }
.res-id.many .cnt { color: var(--danger); font-weight: 700; }
.reply-badge { display: inline-flex; align-items: center; gap: 3px; font-size: .75rem; font-weight: 700; color: var(--accent); background: var(--accent-bg); border: 0; border-radius: 99px; padding: 1px 8px; font-family: inherit; cursor: pointer; }
.reply-badge:hover { background: var(--accent); color: var(--on-primary); }
.res-body { margin: 4px 0 0; padding-left: 1.4em; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.75; }
.res-body .anchor { color: var(--primary); text-decoration: none; font-weight: 600; }
.res-body .anchor:hover { text-decoration: underline; }
.res-body .hidden-note { color: var(--muted); font-style: italic; }
.res-thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; padding-left: 1.4em; }
.res-thumbs a { display: block; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--bg); line-height: 0; }
.res-thumbs a:hover { border-color: var(--accent); }
.res-thumbs img { display: block; max-width: 180px; max-height: 140px; width: auto; height: auto; min-width: 40px; min-height: 40px; object-fit: cover; }
.thumbs-off .res-thumbs { display: none; }
.new-divider { display: flex; align-items: center; gap: 8px; color: var(--new); font-size: .78rem; font-weight: 700; margin: 6px 0; scroll-margin-top: 60px; }
.new-divider::before, .new-divider::after { content: ""; flex: 1; border-top: 2px solid var(--new); }

/* スレ表示の上部バー（スクロールしても見える） */
.thread-bar { position: sticky; top: 0; z-index: 20; background: var(--bg); padding: 8px 0; margin: -8px 0 8px; border-bottom: 1px solid var(--line); }
.thread-bar .toolbar { margin: 0; }
.thread-bar .t { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1 1 120px; }
@media (max-width: 520px) {
    .thread-bar .t, .thread-bar .hide-sm { display: none; }
    .thread-bar .toolbar { flex-wrap: nowrap; gap: 6px; }
    .thread-bar .btn { padding: 4px 9px; font-size: .8rem; }
}
.fab.away { opacity: 0; pointer-events: none; transform: translateY(8px); }
.fab { transition: opacity .15s, transform .15s; }
@media (prefers-reduced-motion: reduce) { .fab { transition: none; } }

/* 書き込み欄 */
.composer { margin-top: 14px; padding: 12px 14px; display: grid; gap: 8px; scroll-margin-top: 70px; }
.composer h2 { font-size: .95rem; margin: 0; }
.composer .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.composer .row .field { flex: 1 1 140px; width: auto; }
.composer textarea.field { min-height: 7em; resize: vertical; line-height: 1.6; }
.composer .meter { font-size: .78rem; color: var(--muted); }
.composer .meter.over { color: var(--danger); font-weight: 700; }
.composer .grow { flex: 1; }
.composer label.check { display: inline-flex; align-items: center; gap: 4px; font-size: .85rem; white-space: nowrap; }
.form-msg { margin: 0; font-size: .85rem; }
.form-msg.err { color: var(--danger); }
.form-msg.ok { color: var(--ok); }
.composer .hint { margin: 0; font-size: .75rem; color: var(--muted); }

/* 書き込むボタン（右下に浮かぶ） */
.fab {
    position: fixed; right: 16px; bottom: 16px; z-index: 30; border-radius: 99px; padding: 10px 16px;
    box-shadow: 0 6px 18px rgba(0,0,0,.22); font-size: .9rem;
}
.new-pill {
    position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 31; border-radius: 99px;
    box-shadow: 0 6px 18px rgba(0,0,0,.22);
}

/* ポップアップ（アンカー・返信・ID） */
.res-pop {
    position: absolute; z-index: 50; width: max-content; max-width: min(600px, calc(100vw - 24px)); max-height: 60vh; overflow: auto;
    background: var(--card); border: 1px solid var(--line); border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.2); padding: 4px 12px; font-size: .95em;
}
.res-pop .pop-title { font-size: .75rem; color: var(--muted); padding: 6px 0 0; }
.res-pop .res { scroll-margin-top: 0; }
.res-pop .empty { padding: 10px; }

#toasts { position: fixed; left: 50%; bottom: 70px; transform: translateX(-50%); z-index: 60; display: grid; gap: 6px; justify-items: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 99px; font-size: .85rem; max-width: calc(100vw - 32px); }
