/* 配色はブログ（11_blog の src/styles/global.css）に合わせている。ダークテーマのみ */
:root {
  color-scheme: dark;              /* ファイル選択ボタンなどのネイティブ部品も暗色にする */
  --bg: #36373e;
  --surface: #2b2d31;
  --text: #f2f3f5;
  --muted: #b9bbbe;
  --faint: #a8acb3;
  --border: #4a4d54;
  --input: #1f2025;                /* ブログの検索欄と同じ、一段暗い地 */
  --accent: #5865f2;
  --accent-text: #fff;
  --danger: #ff6b6d;               /* ブログの danger バッジの文字色 */
  --highlight: rgba(88, 101, 242, 0.22);
  --anchor: #7bb0f4;               /* ブログのリンク色 */
  --scrollbar-thumb: #202225;
  --scrollbar-track: #2f3136;
}

* { box-sizing: border-box; }

/* スクロールバーの有無でレイアウトがずれないよう、常にその幅を確保する（ブログと同じ）。
   both-edges で左右に同じ幅を取り、中央寄せを保つ */
html { scrollbar-gutter: stable both-edges; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
  line-height: 1.6;
}

a { color: var(--anchor); text-decoration: none; }
a:hover { text-decoration: underline; }

/* スクロールバー（ブログと同じ。Firefox だけ標準プロパティで指定） */
@supports (-moz-appearance: none) {
  html { scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track); }
}
::-webkit-scrollbar { width: 16px; height: 16px; }
::-webkit-scrollbar-button { display: none; }
::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb { background-color: var(--scrollbar-thumb); border: 4px solid transparent; border-radius: 8px; min-height: 40px; background-clip: padding-box; }
::-webkit-scrollbar-track { background-color: var(--scrollbar-track); border: 4px solid transparent; border-radius: 8px; background-clip: padding-box; }

main {
  max-width: 820px;
  margin: 0 auto;
  padding: 16px 16px 0;
}

/* 管理モード中だけ右上に出す目印 */
/* 管理モード中だけ左上に出す歯車 */
.admin-badge {
  position: fixed;
  top: 4px;
  left: 4px;
  z-index: 10;
  display: flex;
  padding: 4px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--danger);
  cursor: pointer;
}
.admin-badge:hover { background: rgba(255, 255, 255, 0.08); }
.admin-badge[hidden] { display: none; }
/* 狭い画面では本文の左上（戻るボタン）と重なるので、管理モード中だけ上に余白を空ける */
@media (max-width: 880px) {
  body.admin-mode main { padding-top: 44px; }
}

h2 { font-size: 1.1rem; margin: 24px 0 12px; }

/* スレッド一覧と書き込み一覧は枠・背景・区切り線を付けず、余白だけで並べる */
.thread-list-section { margin-bottom: 16px; }
.thread-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
}
/* 行全体がリンク。書き込みと同じく左右に少しはみ出させて、ホバー時の背景に余白を持たせる */
.thread-row {
  display: flex;
  align-items: baseline;
  gap: 0 12px;
  margin: 0 -8px;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--text);
  transition: background-color 0.15s;
}
.thread-row:hover { background: rgba(255, 255, 255, 0.03); text-decoration: none; }
/* タイトルが長いときは1行に収め、はみ出す分を … で切る（件数と日時は常に全部見せる） */
.thread-name { display: flex; align-items: baseline; flex: 1; min-width: 0; }
.thread-name-text, .thread-title-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thread-name-text { color: var(--anchor); font-weight: 600; }
.thread-name .count, .thread-heading .count { flex: none; white-space: nowrap; }
.thread-row .meta { flex: none; margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.count { color: var(--muted); margin-left: 4px; font-weight: 400; }
.meta { color: var(--muted); font-size: 0.8rem; margin-left: 8px; }

.thread-title { display: flex; align-items: baseline; gap: 8px; margin-top: 0; font-size: 1.3rem; }
.thread-heading { display: flex; align-items: baseline; flex: 1; min-width: 0; }
.back-button {
  flex: none;
  padding: 0 6px;
  border-radius: 6px;
  color: var(--muted);
}
.back-button:hover { color: var(--text); background: var(--surface); text-decoration: none; }

/* 左右に少しはみ出させて、ハイライト時も文字が背景の端に貼り付かないようにする */
.post { margin: 0 -8px; padding: 12px 8px; border-radius: 6px; scroll-margin-top: 80px; transition: background-color 0.15s; }
.post:hover { background: rgba(255, 255, 255, 0.03); }
.post.highlight { background: var(--highlight); }
.post-header { display: flex; align-items: flex-start; gap: 8px; font-size: 0.9rem; }
.post-info { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; flex: 1; min-width: 0; }
.post-header .meta { margin-left: 0; }
.no { font-weight: 700; }
.name { color: var(--text); font-weight: 700; word-break: break-all; }
.post-body { margin-top: 4px; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.post-body.deleted, .deleted-label { color: var(--muted); font-style: italic; }
.post-actions { display: flex; gap: 2px; flex: none; }
.post-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 26px;
  height: 26px;
  margin: -2px 0;                  /* 行の高さを押し広げないように */
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--faint);
}
.post-action:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.delete-button:hover { color: var(--danger); }

.form-section { margin: 16px 0 24px; }
.post-form { display: grid; gap: 8px; }
input, textarea {
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
::placeholder { color: var(--faint); opacity: 0.8; }

/* 投稿フォーム：Reddit のコメント欄のように、入力欄とツールバーを1つの角丸の枠にまとめる */
.composer {
  background: transparent;
  border: 1px solid #6d717a;       /* 通常時でも枠が分かる明るさ。ホバー時は --faint まで上げる */
  border-radius: 20px;
  padding: 8px 10px 6px;
  transition: border-color 0.15s, background-color 0.15s;
}
.composer:hover, .composer:focus-within { border-color: var(--faint); background: rgba(255, 255, 255, 0.03); }
.composer .composer-title,
.composer .composer-body {
  display: block;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 6px 8px;
}
.composer .composer-title:focus,
.composer .composer-body:focus { outline: none; }
.composer-title { font-weight: 600; border-bottom: 1px solid var(--border) !important; margin-bottom: 2px; }
.composer-body { resize: none; min-height: 3.4em; max-height: 50vh; overflow-y: auto; }
.composer-bar { display: flex; align-items: center; gap: 2px; margin-top: 2px; }
.composer-bar .form-message { flex: 1; min-width: 0; padding: 0 6px; font-size: 0.8rem; }
/* 送信ボタンは紙飛行機アイコンの丸ボタン */
.composer-bar button.primary {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
}
.composer-bar button.primary svg { margin-left: 2px; } /* 紙飛行機の見た目の重心を中央に寄せる */
.composer-bar button.primary:hover:not(:disabled) { filter: brightness(1.1); }
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.icon-button:hover, .icon-button.active, .image-button:focus-within {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}
.composer-key {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  padding: 4px 8px;
  font-size: 0.8rem;
  color: var(--muted);
}
.composer-key[hidden] { display: none; }
.composer-key input { width: 12em; padding: 3px 8px; font-size: 0.9rem; background: var(--surface); }
.hint { font-size: 0.75rem; color: var(--faint); }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.turnstile:empty { display: none; }

button { font: inherit; cursor: pointer; }
button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 6px;
  padding: 8px 20px;
  font-weight: 600;
}
button.primary:disabled { opacity: 0.6; cursor: wait; }
.link-button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  text-decoration: underline;
}
.form-message { font-size: 0.9rem; color: var(--muted); }
.form-message.error, .error { color: var(--danger); }
.loading, .empty, .notice { color: var(--muted); }


.post-image { display: inline-block; margin-top: 6px; }
.post-image img, .image-preview img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(100%, 320px);
  max-height: 320px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.image-preview { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; padding: 4px 8px; }
.image-preview:empty { display: none; }
.image-preview img { max-width: 120px; max-height: 120px; }
.preview-thumb { position: relative; }
.preview-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  line-height: 1;
}

/* アンカーにマウスを乗せたときの、元の書き込みのポップアップ */
.anchor-popup {
  position: absolute;
  z-index: 20;
  max-width: min(560px, calc(100vw - 16px));
  max-height: 60vh;
  overflow-y: auto;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}
.anchor-popup .post { margin: 0; padding: 10px 0; }
.anchor-popup .post:hover { background: none; }
.anchor-popup .post-image img { max-height: 200px; }

/* YouTube・X の埋め込み */
.embeds { display: grid; gap: 8px; margin-top: 8px; max-width: 480px; }
.yt-embed {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  cursor: pointer;
}
.yt-embed img { width: 100%; height: 100%; object-fit: cover; display: block; }
.yt-play { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); opacity: 0.9; transition: opacity 0.15s; }
.yt-embed:hover .yt-play { opacity: 1; }
/* X は読み込み前から高さを確保しておき、読み込み後のずれを小さくする */
.x-embed { max-width: 480px; min-height: 160px; }
.x-embed.loaded, .x-embed.failed { min-height: 0; }
.x-embed .twitter-tweet { margin: 0 !important; border-radius: 12px; overflow: hidden; }
/* このページは color-scheme: dark だが X の埋め込み側はライト扱いのため、そのままだと
   ブラウザが iframe の背景を白で塗り、角丸の外側に白がはみ出す。iframe だけライト扱いにそろえて透明に戻す */
.x-embed iframe { color-scheme: light; border-radius: 12px; }
.x-embed-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}
.x-embed.failed .x-embed-placeholder { min-height: 0; padding: 12px; }

/* 押せる範囲を 40〜48px に広げる（指でもマウスでも押しやすいように）。
   アイコン自体の大きさは変えず周りの余白を広げるので、見た目はほとんど変わらない */

/* スレッド一覧：行の高さを約48pxにして、隣の行を誤って押さないようにする */
.thread-row { padding-top: 11px; padding-bottom: 11px; }

/* 返信・× ボタン：40px 角にして間隔を 8px 空ける。上下は負のマージンで行の高さを押し広げない */
.post-actions { gap: 8px; }
.post-action { width: 40px; height: 40px; margin: -9px 0; }

/* 戻るボタン・書き込み欄のアイコン・送信ボタン */
.back-button { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; min-height: 40px; padding: 0; }
.icon-button { width: 40px; height: 40px; }
.preview-remove { width: 32px; height: 32px; }

/* 管理モードの歯車 */
.admin-badge { top: 0; left: 0; padding: 10px; }

/* 新着表示 */
.new-badge {
  flex: none;
  margin-left: 8px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}
.new-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 700;
  scroll-margin-top: 16px;
}
.new-divider::before, .new-divider::after { content: ""; flex: 1; height: 1px; background: var(--danger); opacity: 0.6; }

/* 被アンカー（この書き込みへの返信件数） */
.reply-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--anchor);
  font-size: 0.8rem;
  cursor: pointer;
}
.reply-link:hover { text-decoration: underline; }
.anchor-popup .post + .post { border-top: 1px solid var(--border); }

/* 過去ログ */
.archive-link-row { margin: -8px 0 0; text-align: right; }
.archive-link { display: inline-flex; align-items: center; min-height: 40px; padding: 0 4px; font-size: 0.85rem; color: var(--muted); }
.archive-link:hover { color: var(--text); }
.archive-note { margin: -8px 0 12px; color: var(--muted); font-size: 0.85rem; }
.archive-chip {
  flex: none;
  margin-right: 8px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.8;
  align-self: center;
}
.pager { display: flex; justify-content: space-between; margin: 12px 0 24px; }
.pager a { display: inline-flex; align-items: center; min-height: 40px; }

/* 国内限定スレッドの印 */
.jp-chip {
  flex: none;
  margin-left: 8px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.8;
  white-space: nowrap;
  align-self: center;
}

/* 画像の拡大表示 */
body.lightbox-open { overflow: hidden; }
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
}
.lightbox-image {
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 112px);
  object-fit: contain;
  border-radius: 4px;
  background: var(--bg);
}
.lightbox-close, .lightbox-nav {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
}
.lightbox-close:hover, .lightbox-nav:hover { background: rgba(255, 255, 255, 0.24); }
.lightbox-close { top: 12px; right: 12px; }
.lightbox-nav { top: 50%; transform: translateY(-50%); }
.lightbox-nav.prev { left: 12px; }
.lightbox-nav.next { right: 12px; }
.lightbox-footer {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 16px;
  color: #ddd;
  font-size: 0.85rem;
}
.lightbox-original { color: #ddd; text-decoration: underline; }
