/* =========================================================
   Mini SNS — シンプルで落ち着いたデザイン
   色はすべてここの変数で管理（ダークモード対応）
   ========================================================= */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f1f3f6;
  --border: #e3e6eb;
  --text: #1f2328;
  --text-muted: #636c76;
  --accent: #3b5bdb;
  --accent-hover: #3249b8;
  --accent-soft: #e8edff;
  --danger: #c92a2a;
  --danger-soft: #fff0f0;
  --success: #2b8a3e;
  --success-soft: #ebfbee;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 2px 8px rgba(15, 23, 42, .04);
  --font: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN",
          "Noto Sans JP", Meiryo, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-muted: #22262d;
    --border: #2e333b;
    --text: #e6e8eb;
    --text-muted: #9aa3ad;
    --accent: #7b93f5;
    --accent-hover: #93a7f7;
    --accent-soft: #232a45;
    --danger: #ff8787;
    --danger-soft: #3a1f22;
    --success: #69db7c;
    --success-soft: #1d3322;
    --shadow: none;
  }
}

/* ---------- ベース ---------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { line-height: 1.35; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

img { max-width: 100%; height: auto; }

.container {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---------- ヘッダー / フッター ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 56px;
}
.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  letter-spacing: .02em;
}
.brand:hover { text-decoration: none; }

.nav { display: flex; align-items: center; gap: 12px; font-size: .9rem; }
.nav .user { color: var(--text-muted); }
.nav form { margin: 0; }

.site-main { padding: 28px 0 48px; }

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .8rem;
  padding: 20px 0 32px;
}

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .15s, border-color .15s;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #0e1116; } }

.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-muted); }

.btn-link {
  background: none; border: none; padding: 0;
  color: var(--accent); font: inherit; cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

.btn-block { width: 100%; }

/* ---------- カード ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; }

.meta { color: var(--text-muted); font-size: .85rem; }

/* ---------- スレッド一覧 ---------- */
.thread-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.thread-list li + li { border-top: 1px solid var(--border); }
.thread-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  color: var(--text);
}
.thread-item:hover { background: var(--surface-muted); text-decoration: none; }
.thread-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}
.thread-item .meta { margin-top: 2px; }
.badge {
  flex-shrink: 0;
  min-width: 2.5em;
  text-align: center;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .8rem;
  font-weight: 700;
}

.empty {
  padding: 36px 18px;
  text-align: center;
  color: var(--text-muted);
}

/* ---------- スレッド詳細（レス） ---------- */
.thread-head { margin-bottom: 20px; }
.thread-head h1 { overflow-wrap: anywhere; }

.post-list { list-style: none; margin: 0 0 28px; padding: 0; display: grid; gap: 12px; }
.post { padding: 16px 18px; }
.post-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-bottom: 6px;
  font-size: .85rem;
}
.post-no { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.post-author { font-weight: 700; color: var(--text); }
.post-body { overflow-wrap: anywhere; }
.post-image { margin-top: 10px; }
.post-image img {
  display: block;
  max-height: 360px;
  width: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* ---------- ページ送り ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 16px 0;
}
.page-status { color: var(--text-muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.btn.is-disabled { opacity: .4; cursor: default; pointer-events: none; }

.login-prompt { text-align: center; }
.login-prompt p { margin: 0 0 12px; color: var(--text-muted); }

/* ---------- フォーム ---------- */
.form-card { max-width: 440px; margin: 0 auto; }
.form-card h1 { text-align: center; margin-bottom: 4px; }
.form-card .lead { text-align: center; color: var(--text-muted); font-size: .9rem; margin: 0 0 20px; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-weight: 600;
  font-size: .9rem;
  margin-bottom: 6px;
}
.field input[type="text"],
.field input[type="password"],
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.field textarea { min-height: 120px; resize: vertical; }
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input[type="file"] { font-size: .85rem; color: var(--text-muted); max-width: 100%; }
.field input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.help-text { display: block; margin-top: 4px; font-size: .78rem; color: var(--text-muted); }
.help-text ul { margin: 4px 0 0; padding-left: 1.2em; }
.error-text { margin-top: 4px; font-size: .8rem; color: var(--danger); }

.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.form-foot { text-align: center; margin: 16px 0 0; font-size: .9rem; color: var(--text-muted); }

/* ---------- お知らせ・エラー ---------- */
.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.alert,
.messages li {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: .9rem;
  margin-bottom: 12px;
  background: var(--accent-soft);
  color: var(--text);
}
.alert-error,
.messages li.error { background: var(--danger-soft); color: var(--danger); }
.messages li.success { background: var(--success-soft); color: var(--success); }
.errorlist { list-style: none; padding: 0; margin: 0; }

/* ---------- ログイン画面の背景演出 ---------- */
.float-bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
}
.float-item {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 50%;
  background: var(--bubble, var(--accent));
  opacity: .35;
  cursor: pointer;
  will-change: transform;
  animation: float var(--dur, 16s) linear infinite;
}
@keyframes float {
  from { transform: translate3d(var(--x, 0), 110vh, 0); }
  to   { transform: translate3d(calc(var(--x, 0) + var(--drift, 0px)), -20vh, 0); }
}
.float-item.pop { animation: pop .25s ease-out forwards; }
@keyframes pop { to { transform: scale(1.8); opacity: 0; } }

/* 本文レイヤは背景の泡より前面。カード以外はクリックを透過して泡に触れられるようにする */
.auth-layer { position: relative; z-index: 1; pointer-events: none; }
.auth-layer .card, .auth-layer .messages { pointer-events: auto; }

.caught-counter {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 2;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .8rem;
}

.bgm-control { text-align: center; margin: 16px 0 0; }

@media (prefers-reduced-motion: reduce) {
  .float-item { animation: none; display: none; }
}

/* ---------- スマホ ---------- */
@media (max-width: 520px) {
  .site-main { padding-top: 20px; }
  .card, .post { padding: 16px; }
  .thread-item { padding: 12px 14px; }
  .nav .user { display: none; }
}
