/* ── Scrollbars ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #b0a9a2; border-radius: 4px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--red); }
* { scrollbar-width: thin; scrollbar-color: #b0a9a2 var(--bg); }

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red:        #9b2020;
  --red-dark:   #7a1818;
  --red-light:  #c0392b;
  --green:      #1e5c2e;
  --green-light:#27ae60;
  --bg:         #f0ede8;
  --surface:    #ffffff;
  --surface2:   #f7f4f0;
  --border:     #d6cfc7;
  --text:       #1a1a1a;
  --text-muted: #6b6260;
  --text-faint: #a09896;
  --header-bg:  #1e1e1e;
  --header-fg:  #f0ede8;
  --font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono:       'Courier New', monospace;
  --radius:     4px;
}

html { font-size: 20px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

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

/* ── Header ─────────────────────────────────────────────────────────────────── */
.site-header {
  background: var(--header-bg);
  color: var(--header-fg);
  padding: 0 1.25rem;
  display: flex;
  align-items: stretch;
  height: 44px;
  gap: 1rem;
  border-bottom: 3px solid var(--red);
}

.logo {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--header-fg);
  text-decoration: none;
  letter-spacing: .01em;
  white-space: nowrap;
}
.logo:hover { color: #fff; text-decoration: none; }

.site-nav {
  display: flex;
  align-items: center;
  gap: .15rem;
  margin-left: auto;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: .4rem;
  color: var(--header-fg);
  text-decoration: none;
  padding: .3rem .6rem;
  border-radius: var(--radius);
  font-size: .85rem;
}
.nav-user:hover { background: rgba(255,255,255,.1); text-decoration: none; color: #fff; }

.nav-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  object-fit: cover;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--red);
  color: #fff;
  border: 1px solid var(--red-dark);
  padding: .35rem .9rem;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .1s;
  font-family: var(--font);
}
.btn-primary:hover { background: var(--red-dark); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--header-fg);
  border: 1px solid rgba(255,255,255,.25);
  padding: .3rem .7rem;
  border-radius: var(--radius);
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .1s, border-color .1s;
  font-family: var(--font);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.btn-ghost:hover { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.5); text-decoration: none; color: #fff; }

/* Ghost on light bg */
.page-main .btn-ghost,
.card .btn-ghost,
.post-actions .btn-ghost {
  color: var(--text-muted);
  border-color: var(--border);
}
.page-main .btn-ghost:hover,
.card .btn-ghost:hover,
.post-actions .btn-ghost:hover {
  background: var(--surface2);
  border-color: #bbb;
  color: var(--text);
}

.btn-sm { padding: .2rem .55rem; font-size: .8rem; }
.btn-danger { color: var(--red) !important; border-color: #d9a0a0 !important; }
.btn-danger:hover { background: #fdf0f0 !important; }

.btn-upvote {
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: .2rem .55rem;
  cursor: pointer;
  font-size: .82rem;
  color: var(--text-muted);
  transition: all .1s;
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-family: var(--font);
}
.btn-upvote:hover { border-color: var(--red); color: var(--red); background: #fdf5f5; }
.btn-upvote.upvoted { background: #fdf5f5; border-color: var(--red); color: var(--red); }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.page-main {
  flex: 1;
  max-width: 1450px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1rem 2.5rem;
}

.page-breadcrumb {
  font-size: .8rem;
  color: var(--text-faint);
  margin-bottom: .75rem;
  padding: .4rem 0;
  border-bottom: 1px solid var(--border);
}
.page-breadcrumb a { color: var(--text-muted); }
.page-breadcrumb a:hover { color: var(--red); }

/* ── Forum board index ──────────────────────────────────────────────────────── */
.board-title {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
  padding: .6rem .75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom: none;
}

.categories-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.categories-table th {
  background: var(--surface2);
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  padding: .45rem .75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.categories-table th.col-stats { text-align: center; width: 70px; }

.cat-row { border-bottom: 1px solid var(--border); }
.cat-row:last-child { border-bottom: none; }
.cat-row:hover { background: #fdfbf8; }

.cat-row td { padding: .75rem; vertical-align: middle; }
.cat-row td.col-stats { text-align: center; font-size: .82rem; color: var(--text-muted); }

.cat-icon-cell { width: 36px; text-align: center; font-size: 1.3rem; }

.cat-name {
  font-size: .97rem;
  font-weight: 700;
  color: var(--red);
  display: block;
  margin-bottom: .15rem;
}
.cat-name:hover { color: var(--red-dark); text-decoration: underline; }
.cat-desc { font-size: .82rem; color: var(--text-muted); }

/* ── Threads header ─────────────────────────────────────────────────────────── */
.threads-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem 0 .6rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: .75rem;
  gap: 1rem;
}
.threads-header h1 { font-size: 1.1rem; font-weight: 700; }

/* ── Thread rows ────────────────────────────────────────────────────────────── */
.thread-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
}

.thread-table th {
  background: var(--surface2);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  padding: .4rem .75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.thread-table th.col-num { text-align: center; width: 55px; }

.thread-row { border-bottom: 1px solid var(--border); }
.thread-row:last-child { border-bottom: none; }
.thread-row:hover { background: #fdfbf8; }
.thread-row td { padding: .6rem .75rem; vertical-align: middle; }
.thread-row td.col-num { text-align: center; font-size: .82rem; color: var(--text-muted); }

.thread-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; display: block; }
.thread-avatar-cell { width: 42px; }

.thread-title-link {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  display: block;
  margin-bottom: .15rem;
}
.thread-title-link:hover { color: var(--red); text-decoration: none; }

.thread-meta {
  font-size: .78rem;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}
.thread-meta .meta-author { color: var(--red); font-weight: 500; }

/* ── New thread form ────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: .75rem;
}

.new-thread-form label,
.reply-box label,
.auth-form label,
.profile-edit-section label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .6rem;
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="email"],
textarea,
select {
  width: 100%;
  padding: .4rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  transition: border-color .1s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--red);
}
textarea { resize: vertical; }

.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .6rem; }
.form-error   { color: var(--red); font-size: .82rem; margin-top: .4rem; min-height: 1.1em; }
.auth-success { color: var(--green-light); font-size: .82rem; margin-top: .4rem; }

/* ── Auth page ──────────────────────────────────────────────────────────────── */
.auth-page {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--bg);
}

.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 380px;
  overflow: hidden;
}

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.tab-btn {
  flex: 1;
  padding: .7rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .1s;
  margin-bottom: -1px;
  font-family: var(--font);
}
.tab-btn.active { color: var(--red); border-bottom-color: var(--red); background: var(--surface); }

.auth-form { padding: 1.25rem; }
.auth-form h2 { font-size: 1rem; margin-bottom: 1rem; color: var(--text); }
.auth-form .btn-primary { width: 100%; padding: .5rem; margin-top: .2rem; }

.hint { font-size: .75rem; color: var(--text-faint); font-weight: 400; }

/* ── Post layout ────────────────────────────────────────────────────────────── */
.posts-wrapper {
  border: 1px solid var(--border);
  background: var(--surface);
}

.post-card {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
}
.post-card:last-child { border-bottom: none; }
.post-thread { border-left: 3px solid var(--red); }
.post-reply  { border-left: 3px solid #aaa; }

.post-sidebar {
  width: 130px;
  flex-shrink: 0;
  padding: .85rem .75rem;
  background: var(--surface2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .3rem;
  text-align: center;
}

.post-avatar-wrap {
  position: relative;
  display: inline-block;
  margin-bottom: .25rem;
}
.post-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.online-dot {
  position: absolute;
  bottom: 1px; right: 1px;
  width: 11px; height: 11px;
  background: #27ae60;
  border: 2px solid var(--surface);
  border-radius: 50%;
}
.online-dot-lg {
  position: static;
  display: inline-block;
  width: 13px; height: 13px;
  border: 2px solid var(--bg);
  vertical-align: middle;
  margin-left: .1rem;
}

.post-author-name {
  font-size: .82rem;
  font-weight: 700;
  color: var(--red);
  word-break: break-word;
}
.post-author-name:hover { text-decoration: underline; }

.post-body {
  flex: 1;
  padding: .85rem 1rem;
  min-width: 0;
}

.post-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .5rem;
  flex-wrap: wrap;
  justify-content: space-between;
}

.mod-thread-actions {
  display: flex;
  gap: .4rem;
  margin-left: auto;
}

.post-title { font-size: 1.15rem; font-weight: 700; margin-bottom: .5rem; line-height: 1.3; }
.post-date  { font-size: .78rem; color: var(--text-faint); }
.edited-note { font-size: .75rem; color: var(--text-faint); font-style: italic; }

.post-content {
  font-size: .92rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}
.post-content blockquote {
  border-left: 3px solid var(--red);
  background: var(--surface2);
  margin: .4rem 0;
  padding: .3rem .65rem;
  color: var(--text-muted);
  font-style: italic;
}

.post-actions {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-top: .75rem;
  padding-top: .5rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.edit-form { margin-top: .75rem; }
.edit-textarea { width: 100%; }

/* ── Reply box ──────────────────────────────────────────────────────────────── */
.reply-box { margin-top: .75rem; }
.reply-box h3 { font-size: .9rem; font-weight: 700; margin-bottom: .6rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.reply-meta { display: flex; justify-content: flex-end; margin-top: .2rem; }
.char-count { font-size: .72rem; color: var(--text-faint); }
.char-count-warn { color: #b85c00; font-weight: 700; }

.login-prompt {
  text-align: center;
  padding: .85rem;
  color: var(--text-muted);
  font-size: .88rem;
  border: 1px solid var(--border);
  background: var(--surface);
  margin-top: .75rem;
}

/* ── Profile ────────────────────────────────────────────────────────────────── */
.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
}

.profile-header {
  display: flex;
  align-items: flex-start;
  gap: 1.25rem;
  padding: 1.25rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

.profile-avatar {
  width: 72px; height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.profile-username { font-size: 1.2rem; font-weight: 700; margin-bottom: .25rem; }
.profile-bio      { margin-top: .4rem; font-size: .88rem; color: var(--text-muted); white-space: pre-wrap; }

.profile-edit-section {
  padding: 1rem;
  border-top: 1px solid var(--border);
}
.profile-edit-section h3 { font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: .75rem; }

/* ── Post images ────────────────────────────────────────────────────────────── */
.post-image {
  display: block;
  max-width: 100%;
  max-height: 400px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: .4rem 0;
  cursor: zoom-in;
}

/* ── User hover card ────────────────────────────────────────────────────────── */
.user-card {
  position: fixed;
  z-index: 999;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  width: 230px;
  pointer-events: auto;
}
.user-card-inner {
  display: flex;
  gap: .65rem;
  padding: .75rem;
  align-items: flex-start;
}
.user-card-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.user-card-info { flex: 1; min-width: 0; }
.user-card-name {
  font-weight: 700;
  font-size: .85rem;
  display: block;
  color: var(--red);
  margin-bottom: .2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-card-name:hover { text-decoration: underline; }
.user-card-stats { font-size: .72rem; color: var(--text-muted); margin-top: .2rem; }
.user-card-bio   { font-size: .72rem; color: var(--text-muted); margin-top: .2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Mentions ───────────────────────────────────────────────────────────────── */
.mention {
  color: var(--red);
  font-weight: 600;
  text-decoration: none;
}
.mention:hover { text-decoration: underline; }

/* ── Thread badges (pinned / locked) ────────────────────────────────────────── */
.thread-badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 700;
  padding: .1rem .4rem;
  border-radius: 2px;
  vertical-align: middle;
}
.badge-pinned { background: #fff8e1; color: #b8860b; border: 1px solid #f0d070; }
.badge-locked { background: #f5f0f0; color: #7a3030; border: 1px solid #ddb0b0; }

.locked-banner {
  background: #fdf0f0;
  border: 1px solid #ddb0b0;
  color: #7a3030;
  padding: .65rem 1rem;
  font-size: .9rem;
  font-weight: 600;
  margin-bottom: .75rem;
  border-radius: var(--radius);
}

/* ── Follow ─────────────────────────────────────────────────────────────────── */
.follow-stats {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: .4rem;
}
.follow-stat {
  cursor: pointer;
  transition: color .1s;
}
.follow-stat:hover { color: var(--red); text-decoration: underline; }
.follow-stat-sep { color: var(--border); }

.btn-follow {
  background: var(--red);
  color: #fff;
  border: 1px solid var(--red-dark);
  padding: .25rem .8rem;
  border-radius: var(--radius);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background .1s;
}
.btn-follow:hover { background: var(--red-dark); }
.btn-follow.btn-following {
  background: var(--surface2);
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-follow.btn-following:hover { background: #fdecea; color: var(--red); border-color: var(--red); }

.follow-list-container {
  border-top: 1px solid var(--border);
}
.follow-list-header {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  padding: .5rem .75rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
.follow-list-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: background .1s;
}
.follow-list-item:last-child { border-bottom: none; }
.follow-list-item:hover { background: var(--surface2); text-decoration: none; }
.follow-list-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  object-fit: cover;
}
.follow-list-name { font-weight: 600; font-size: .9rem; flex: 1; }

/* ── Role badge ─────────────────────────────────────────────────────────────── */
.role-badge {
  display: inline-block;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: .1rem .4rem;
  border-radius: 2px;
  letter-spacing: .05em;
}
.role-admin { background: #fdecea; color: var(--red); border: 1px solid #f5c0bc; }
.role-mod   { background: #e6f4ea; color: #1a5c2e; border: 1px solid #b4d9bc; }
.role-user  { background: var(--surface2); color: var(--text-faint); border: 1px solid var(--border); }

/* ── Misc ───────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

.empty {
  color: var(--text-faint);
  text-align: center;
  padding: 2rem 1rem;
  font-size: .9rem;
  background: var(--surface);
  border: 1px solid var(--border);
}

.loading-spinner {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-faint);
  font-size: .88rem;
  background: var(--surface);
  border: 1px solid var(--border);
}

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  overflow: hidden;
}
.modal-header {
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  padding: .65rem 1rem;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}
.modal-body {
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
  text-align: center;
}
.modal-owner-avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
}
.modal-title   { font-size: 1rem; font-weight: 700; }
.modal-sub     { font-size: .85rem; color: var(--text-muted); }
.modal-actions { display: flex; gap: .6rem; margin-top: .25rem; }

/* ── Footer ─────────────────────────────────────────────────────────────────── */
.site-footer {
  background: var(--header-bg);
  color: var(--text-faint);
  text-align: center;
  padding: .75rem 1rem;
  font-size: .78rem;
  margin-top: auto;
  border-top: 2px solid var(--red);
}
.site-footer a { color: #aaa; }
.site-footer a:hover { color: #fff; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  html { font-size: 13px; }
  .post-sidebar { width: 90px; }
  .post-avatar { width: 38px; height: 38px; }
  .profile-header { flex-direction: column; }
  .categories-table th.col-stats,
  .categories-table td.col-stats,
  .thread-table th.col-num,
  .thread-table td.col-num { display: none; }
}
