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

:root {
  --bg: #f2f2f2;
  --surface: #fff;
  --border: #ccc;
  --primary: #111;
  --primary-hover: #000;
  --danger: #b00;
  --text: #1a1a1a;
  --muted: #666;
  --sticky-bg: #f9f9f9;
  --unread-bg: #ececec;
  --radius: 3px;
}

/* ── Base ─────────────────────────────────────────────── */
html { font-size: 16px; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: underline; }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; height: auto; display: block; }

/* ── Layout ───────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 14px;
}

/* ── Header / Nav ─────────────────────────────────────── */
header {
  background: #fff;
  border-bottom: 2px solid #111;
  position: sticky;
  top: 0;
  z-index: 100;
}
header .container {
  display: flex;
  align-items: center;
  min-height: 56px;
  gap: 12px;
  flex-wrap: wrap;
}
.site-logo { flex-shrink: 0; line-height: 0; }
.site-logo img { height: 40px; width: auto; }

.nav-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  width: 44px;
  height: 44px;
  background: none;
  border: 1px solid #ccc;
  color: #111;
  font-size: 1.3rem;
  cursor: pointer;
  border-radius: var(--radius);
}
.nav-toggle:hover { background: #f0f0f0; }

#main-nav {
  display: none;
  flex-direction: column;
  width: 100%;
  padding: 6px 0 10px;
  border-top: 1px solid #ddd;
}
#main-nav.open { display: flex; }
#main-nav a {
  color: #111;
  font-size: 0.95rem;
  padding: 9px 4px;
  border-bottom: 1px solid #eee;
  text-decoration: none;
}
#main-nav a:last-child { border-bottom: none; }
#main-nav a:hover { background: #f5f5f5; }

@media (min-width: 640px) {
  .nav-toggle { display: none; }
  #main-nav {
    display: flex !important;
    flex-direction: row;
    width: auto;
    margin-left: auto;
    padding: 0;
    border-top: none;
    gap: 2px;
    flex-wrap: wrap;
    align-items: center;
  }
  #main-nav a {
    font-size: 0.88rem;
    padding: 6px 10px;
    border-bottom: none;
    border-radius: var(--radius);
  }
  #main-nav a:hover { background: #f0f0f0; }
}

/* ── Main ─────────────────────────────────────────────── */
main { padding: 16px 0 48px; }

/* ── Footer ───────────────────────────────────────────── */
footer {
  border-top: 2px solid #111;
  padding: 14px 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  background: #fff;
}

/* ── Breadcrumb ───────────────────────────────────────── */
.breadcrumb {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 12px;
}
.breadcrumb a { color: var(--primary); }

/* ── Headings ─────────────────────────────────────────── */
h1 { font-size: 1.3rem; margin-bottom: 14px; line-height: 1.3; }
h2 { font-size: 1.05rem; margin: 16px 0 8px; }

@media (min-width: 640px) {
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.15rem; }
}

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid #bbb;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  font-size: 0.92rem;
  font-family: inherit;
  line-height: 1.4;
  white-space: nowrap;
  touch-action: manipulation;
}
.btn:hover { background: #f0f0f0; text-decoration: none; }
.btn-primary { background: #111; color: #fff; border-color: #111; }
.btn-primary:hover { background: #000; border-color: #000; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #900; }
.btn-sm { padding: 4px 9px; font-size: 0.8rem; }
.btn-full { width: 100%; text-align: center; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Forms ────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 0.88rem;
}
.form-group input[type=text],
.form-group input[type=email],
.form-group input[type=password],
.form-group textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #bbb;
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  background: #fff;
  color: var(--text);
  -webkit-appearance: none;
}
.form-group input:focus,
.form-group textarea:focus {
  outline: 2px solid #111;
  outline-offset: 1px;
  border-color: #111;
}
.form-group textarea { resize: vertical; min-height: 100px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.form-narrow { max-width: 520px; }

.auth-form { max-width: 400px; margin: 0 auto; }
.auth-form h1 { margin-bottom: 18px; }
.auth-link { margin-top: 10px; font-size: 0.88rem; }

/* ── Alerts ───────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 0.9rem;
  border: 1px solid;
}
.alert-error { background: #fef0f0; border-color: #daa; color: #800; }
.alert-ok    { background: #f0faf0; border-color: #ada; color: #040; }

/* ── Badges ───────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 2px;
  font-size: 0.7rem;
  font-weight: 700;
  background: #111;
  color: #fff;
  margin-right: 3px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge.closed { background: #888; }

/* ── Pagination ───────────────────────────────────────── */
.pagination { display: flex; gap: 4px; margin: 14px 0; flex-wrap: wrap; }
.page-link, .page-current {
  display: inline-block;
  min-width: 34px;
  padding: 5px 9px;
  border: 1px solid #bbb;
  border-radius: var(--radius);
  font-size: 0.88rem;
  text-align: center;
  text-decoration: none;
  color: var(--text);
}
.page-link:hover { background: #f0f0f0; text-decoration: none; }
.page-current { background: #111; color: #fff; border-color: #111; }

/* ── Forum index / channel cards ─────────────────────── */
.channel-group { margin-bottom: 22px; }
.channel-group > h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 6px;
  border-bottom: 1px solid #ddd;
  padding-bottom: 4px;
}
.channel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 4px;
  padding: 10px 13px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  align-items: center;
}
.channel-card-title { font-weight: 600; font-size: 0.97rem; }
.channel-card-title a { text-decoration: none; color: var(--text); }
.channel-card-title a:hover { text-decoration: underline; }
.channel-card-desc { font-size: 0.8rem; color: var(--muted); grid-column: 1; }
.channel-card-stats { font-size: 0.78rem; color: var(--muted); text-align: right; white-space: nowrap; }

/* ── Thread list ──────────────────────────────────────── */
.thread-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
}
.thread-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 10px;
  padding: 9px 13px;
  border-bottom: 1px solid #e8e8e8;
  align-items: start;
}
.thread-row:last-child { border-bottom: none; }
.thread-row.sticky { background: var(--sticky-bg); }
.thread-row.unread { background: var(--unread-bg); }
.thread-row.unread .thread-title { font-weight: 700; }
.thread-title { font-size: 0.94rem; }
.thread-title a { color: var(--text); text-decoration: none; }
.thread-title a:hover { text-decoration: underline; }
.thread-meta { font-size: 0.76rem; color: var(--muted); grid-column: 1; }
.thread-meta a { color: var(--muted); }
.thread-stats { font-size: 0.78rem; color: var(--muted); text-align: right; white-space: nowrap; }

/* ── Posts ────────────────────────────────────────────── */
.post {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.post-author {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #f6f6f6;
  border-bottom: 1px solid #e0e0e0;
  font-size: 0.86rem;
}
.post-author a { text-decoration: none; font-weight: 600; color: var(--text); }
.post-author a:hover { text-decoration: underline; }
.post-num { font-size: 0.72rem; color: var(--muted); margin-left: auto; }
.post-body {
  padding: 13px;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
  font-size: 0.97rem;
  line-height: 1.65;
}
.post-body p { margin-bottom: .75em; }
.post-body p:last-child { margin-bottom: 0; }
.post-body a { word-break: break-all; }
.post-meta {
  padding: 6px 13px;
  border-top: 1px solid #e8e8e8;
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

@media (min-width: 640px) {
  .post {
    display: grid;
    grid-template-columns: 120px 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .post-author {
    grid-column: 1;
    grid-row: 1 / -1;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 4px;
    border-bottom: none;
    border-right: 1px solid #e0e0e0;
    background: #f8f8f8;
  }
  .post-num { margin-left: 0; margin-top: auto; }
  .post-body { grid-column: 2; grid-row: 1; }
  .post-meta { grid-column: 2; grid-row: 2; }
}

/* ── Reply / forms in threads ─────────────────────────── */
.reply-form { margin-top: 20px; }
.reply-form h2 { margin-bottom: 8px; }
.closed-notice { color: var(--muted); font-style: italic; margin-top: 14px; }

/* ── Blog ─────────────────────────────────────────────── */
.blog-list { display: flex; flex-direction: column; gap: 10px; }
.blog-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 13px;
}
.blog-preview h2 { margin: 0 0 4px; font-size: 0.97rem; }
.blog-preview h2 a { text-decoration: none; color: var(--text); }
.blog-preview h2 a:hover { text-decoration: underline; }
.blog-desc { color: var(--muted); font-size: 0.86rem; margin-bottom: 10px; }
.blog-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  overflow-wrap: anywhere;
  line-height: 1.7;
}
.blog-body p { margin-bottom: .75em; }
.blog-body p:last-child { margin-bottom: 0; }

/* ── Private messages ─────────────────────────────────── */
.pm-view {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.pm-meta {
  font-size: 0.84rem;
  color: var(--muted);
  margin-bottom: 12px;
  border-bottom: 1px solid #e8e8e8;
  padding-bottom: 10px;
}
.pm-body {
  margin-bottom: 12px;
  overflow-wrap: anywhere;
  line-height: 1.65;
  white-space: pre-wrap;
}
.pm-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Profile ──────────────────────────────────────────── */
.profile { max-width: 520px; }
.signature {
  margin-top: 12px;
  border-top: 1px solid #ddd;
  padding-top: 10px;
  font-size: 0.86rem;
  color: var(--muted);
}

/* ── Tables ───────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.88rem;
}
th, td { padding: 8px 11px; text-align: left; border-bottom: 1px solid #e8e8e8; }
th { background: #f2f2f2; font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
tr.sticky td { background: var(--sticky-bg); }
tr.unread td { background: var(--unread-bg); font-weight: 600; }

/* ── Admin ────────────────────────────────────────────── */
.admin-stats { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  text-align: center;
  flex: 1 1 90px;
}
.stat strong { display: block; font-size: 1.5rem; }
.stat span { font-size: 0.78rem; color: var(--muted); }
.admin-nav { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Misc ─────────────────────────────────────────────── */
.meta { font-size: 0.84rem; color: var(--muted); }
.sub-desc { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

/* ── Inline post edit ─────────────────────────────────── */
.post-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.inline-edit { display: inline-block; }
.inline-edit summary { cursor: pointer; list-style: none; }
.inline-edit summary::-webkit-details-marker { display: none; }
.inline-edit[open] summary { margin-bottom: 8px; }
.edit-form { padding: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); margin-top: 4px; }
.edit-form textarea { width: 100%; min-height: 120px; }

/* ── Post attachments ─────────────────────────────────── */
.post-attachments { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.post-attachment-img { max-width: 480px; max-height: 400px; width: auto; height: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.attachment-link { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border: 1px solid var(--border); border-radius: var(--radius); font-size: .875rem; text-decoration: none; }
