:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --line: #e3e6ea;
  --text: #1a1d21;
  --muted: #6b7280;
  --brand: #9b1b30;
  --brand-dark: #7a1526;
  --accent: #1a4b8c;
  --green: #1a7f4b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ---------- topbar ---------- */
.topbar {
  background: var(--brand);
  border-bottom: 3px solid var(--brand-dark);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner { display: flex; align-items: center; gap: 20px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px; background: #fff;
  color: var(--brand); font-weight: 800; display: grid; place-items: center;
  letter-spacing: -.5px;
}
.brand-text { font-size: 18px; font-weight: 400; }
.brand-text strong { font-weight: 800; }

.searchbar { flex: 1; display: flex; max-width: 460px; }
.searchbar input {
  flex: 1; height: 36px; padding: 0 12px; border: none;
  border-radius: 6px 0 0 6px; font-size: 14px; outline: none;
}
.searchbar button {
  height: 36px; padding: 0 16px; border: none; cursor: pointer;
  background: var(--brand-dark); color: #fff; border-radius: 0 6px 6px 0;
  font-size: 14px;
}

.topnav { margin-left: auto; display: flex; align-items: center; gap: 18px; }
.topnav > a { color: #fff; font-size: 14px; }
.notif { position: relative; }
.badge-dot {
  background: #ffd166; color: #333; font-size: 11px; font-weight: 700;
  border-radius: 10px; padding: 1px 6px; margin-left: 5px;
}

.user-menu { position: relative; }
.user-menu > a { color: #fff; font-size: 14px; }
.dropdown {
  display: none; position: absolute; right: 0; top: 26px; min-width: 160px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.12); overflow: hidden;
}
.user-menu:hover .dropdown { display: block; }
.dropdown a { display: block; padding: 9px 14px; font-size: 14px; color: var(--text); }
.dropdown a:hover { background: #f3f4f6; text-decoration: none; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 230px 1fr; gap: 24px; padding-top: 22px; padding-bottom: 40px; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } .sidebar { display: none; } }

.sidebar { position: sticky; top: 82px; }
.side-block { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.side-block h3 { margin: 4px 6px 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.side-link { display: flex; justify-content: space-between; padding: 6px 8px; border-radius: 6px; color: var(--text); font-size: 14px; }
.side-link:hover { background: #f3f4f6; text-decoration: none; }
.side-link.active { background: #fdeaee; color: var(--brand); font-weight: 600; }
.side-link .count { color: var(--muted); font-size: 12px; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.tabs { display: flex; gap: 6px; }
.tab { padding: 6px 14px; border-radius: 20px; font-size: 14px; color: var(--muted); background: #fff; border: 1px solid var(--line); }
.tab:hover { text-decoration: none; }
.tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- thread list ---------- */
.thread-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.thread-row { display: flex; gap: 14px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.thread-row:last-child { border-bottom: none; }
.thread-row:hover { background: #fafbfc; }
.vote-box { display: flex; flex-direction: column; align-items: center; min-width: 44px; color: var(--muted); }
.vote-box .score { font-size: 17px; font-weight: 700; color: var(--text); }
.vote-box .label { font-size: 11px; }
.thread-main { flex: 1; min-width: 0; }
.thread-title { font-size: 17px; font-weight: 600; color: var(--text); }
.thread-title:hover { color: var(--brand); text-decoration: none; }
.thread-excerpt { color: var(--muted); font-size: 14px; margin: 5px 0 8px; }
.thread-meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); }
.chip { background: #eef2f7; color: var(--accent); border-radius: 20px; padding: 2px 10px; font-size: 12px; }
.chip:hover { text-decoration: none; background: #e2e9f3; }
.chip-uni { background: #f3ecff; color: #5b2ea6; }
.pin { background: var(--green); color: #fff; border-radius: 4px; padding: 1px 7px; font-size: 11px; font-weight: 700; }
.lock { background: #6b7280; color: #fff; border-radius: 4px; padding: 1px 7px; font-size: 11px; }
.verified { color: var(--green); font-weight: 700; }

/* ---------- thread detail ---------- */
.post-head h1 { margin: 0 0 10px; font-size: 26px; line-height: 1.3; }
.post-body { font-size: 15px; line-height: 1.75; word-wrap: break-word; }
.post-body p { margin: 0 0 14px; }
.post-body h3, .post-body h4, .post-body h5, .post-body h6 { margin: 20px 0 8px; }
.post-body code { background: #f1f3f5; border-radius: 4px; padding: 2px 6px; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.post-body .code-block { background: #1e2228; color: #e6e6e6; border-radius: 8px; padding: 14px 16px; overflow-x: auto; }
.post-body .code-block code { background: none; color: inherit; padding: 0; }
.post-body blockquote { border-left: 3px solid var(--line); margin: 0 0 14px; padding: 4px 14px; color: var(--muted); }
.post-body ul, .post-body ol { margin: 0 0 14px; padding-left: 24px; }
.post-body li { margin-bottom: 6px; }
.post-body .mention { color: var(--accent); font-weight: 600; }

.reply { display: flex; gap: 14px; padding: 16px 0; border-top: 1px solid var(--line); }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: linear-gradient(135deg, var(--brand), #c94f63); color: #fff; display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.reply-body { flex: 1; min-width: 0; }
.reply-meta { font-size: 13px; color: var(--muted); margin-bottom: 6px; }

/* ---------- forms ---------- */
.form-group { margin-bottom: 16px; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=number], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 140px; line-height: 1.6; }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }

.btn { display: inline-block; padding: 9px 18px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; font-size: 14px; font-family: inherit; }
.btn:hover { text-decoration: none; background: #f3f4f6; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-link { border: none; background: none; color: var(--muted); padding: 2px 6px; }

.alert { padding: 11px 15px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; border: 1px solid transparent; }
.alert-success { background: #e8f6ee; color: #14603a; border-color: #bfe5cf; }
.alert-danger  { background: #fdecee; color: #8a1c2b; border-color: #f5c2c9; }
.alert-warning { background: #fff6e5; color: #7a5200; border-color: #ffe0a3; }
.alert-info    { background: #e9f1fb; color: #17457f; border-color: #c3d8f2; }

/* ---------- misc ---------- */
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 20px; }
.pagination a, .pagination span { padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: 14px; }
.pagination .current { background: var(--brand); color: #fff; border-color: var(--brand); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.footer { border-top: 1px solid var(--line); background: #fff; padding: 20px 0; color: var(--muted); font-size: 13px; }
.footer .wrap { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.inline { display: inline; }

/* ---------- login gate ---------- */
.gate {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(17, 20, 24, .55); backdrop-filter: blur(2px);
  align-items: center; justify-content: center; padding: 20px;
}
.gate.show { display: flex; }
.gate-box {
  position: relative; background: #fff; border-radius: 14px; padding: 32px 30px;
  max-width: 400px; width: 100%; text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .28);
  animation: gate-in .16s ease-out;
}
@keyframes gate-in { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; } }
.gate-box h2 { margin: 0 0 10px; font-size: 21px; }
.gate-box p { margin: 0 0 22px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.gate-btn { display: block; width: 100%; padding: 12px; font-size: 15px; }
.gate-later {
  display: block; width: 100%; margin-top: 10px; padding: 8px;
  border: none; background: none; color: var(--muted); font-size: 13px;
  cursor: pointer; font-family: inherit;
}
.gate-later:hover { color: var(--text); text-decoration: underline; }
.gate-close {
  position: absolute; top: 10px; right: 14px; border: none; background: none;
  font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0;
}
.gate-close:hover { color: var(--text); }
