/* ------------------------------------------------------------------ tokens -- */

:root {
  --bg: #f5f6fb;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #e8e9ff 0%, transparent 60%),
    radial-gradient(900px 500px at 90% 0%, #e6f6ff 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f2f4f9;
  --surface-3: #e9ecf4;
  --border: #e4e7f0;
  --border-strong: #d3d8e6;
  --text: #14161c;
  --text-2: #565c6d;
  --text-3: #8b91a3;
  --accent: #5b5bd6;
  --accent-hover: #4a4ac4;
  --accent-soft: #eeeefd;
  --up: #e0503c;
  --down: #2c9c6b;
  --danger: #d33f3f;
  --radius-lg: 18px;
  --radius: 13px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(17, 20, 34, 0.05);
  --shadow: 0 1px 2px rgba(17, 20, 34, 0.05), 0 10px 30px rgba(17, 20, 34, 0.06);
  --shadow-lg: 0 24px 60px rgba(17, 20, 34, 0.18);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f15;
    --bg-grad: radial-gradient(1100px 560px at 12% -12%, #1c1d3d 0%, transparent 60%),
      radial-gradient(800px 460px at 92% -4%, #102b38 0%, transparent 55%);
    --surface: #151821;
    --surface-2: #1c2030;
    --surface-3: #242939;
    --border: #262b3a;
    --border-strong: #333a4d;
    --text: #eef0f6;
    --text-2: #a8afc2;
    --text-3: #79808f;
    --accent: #8b8bf0;
    --accent-hover: #9d9df5;
    --accent-soft: #23244a;
    --up: #ff6b56;
    --down: #34b981;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
  }
}

/* ------------------------------------------------------------------- base -- */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background-color: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

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

.muted {
  color: var(--text-3);
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ----------------------------------------------------------------- topbar -- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 62px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-text strong {
  font-size: 15px;
  letter-spacing: 0.2px;
}

.brand-text small {
  color: var(--text-3);
  font-size: 11px;
}

.topnav {
  display: flex;
  gap: 4px;
}

.topnav a {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 14px;
  transition: background 0.15s ease, color 0.15s ease;
}

.topnav a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.topnav a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.search {
  flex: 1;
  max-width: 320px;
  margin-left: auto;
}

.search input {
  width: 100%;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.search input:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ---------------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 38%, transparent);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

@media (prefers-color-scheme: dark) {
  .btn-primary {
    color: #10121a;
  }
}

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

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

.btn-sm {
  height: 30px;
  padding: 0 11px;
  font-size: 13px;
}

.btn-block {
  width: 100%;
}

/* ------------------------------------------------------------------ view -- */

.view {
  flex: 1;
  padding-top: 26px;
  padding-bottom: 48px;
}

.loading {
  padding: 60px 0;
  color: var(--text-3);
  text-align: center;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-head h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.2px;
}

.page-head p {
  margin: 4px 0 0;
  color: var(--text-2);
  font-size: 14px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 292px;
  gap: 20px;
  align-items: start;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.1px;
}

.panel-body {
  padding: 18px;
}

/* ---------------------------------------------------------------- boards -- */

.board-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(212px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.board-card {
  position: relative;
  display: block;
  padding: 16px 17px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.board-card::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.board-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}

.board-card:hover::after {
  opacity: 1;
}

.board-card h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.board-card p {
  margin: 0 0 10px;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.5;
  min-height: 2.9em;
}

.board-meta {
  display: flex;
  gap: 14px;
  color: var(--text-3);
  font-size: 12px;
}

/* ----------------------------------------------------------- thread list -- */

.tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface-2);
}

.tabs button {
  height: 28px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tabs button.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.thread-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
}

.thread-row:last-child {
  border-bottom: 0;
}

.thread-row:hover {
  background: var(--surface-2);
}

.thread-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.45;
}

.thread-title a:hover {
  color: var(--accent);
}

.thread-excerpt {
  margin: 0 0 7px;
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.thread-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  color: var(--text-3);
  font-size: 12.5px;
}

.dot::before {
  content: "·";
  margin: 0 4px;
  color: var(--border-strong);
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 19px;
  padding: 0 7px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 600;
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-pinned {
  background: color-mix(in srgb, var(--up) 14%, transparent);
  color: var(--up);
}

.thread-stats {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--text-3);
  font-size: 12.5px;
  white-space: nowrap;
}

.thread-stats b {
  color: var(--text-2);
  font-weight: 600;
}

.vote-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 30px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.vote-arrow {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-3);
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.vote-arrow:hover {
  background: var(--surface-2);
  color: var(--text);
}

.vote-arrow.up.on {
  background: color-mix(in srgb, var(--up) 14%, transparent);
  color: var(--up);
}

.vote-arrow.down.on {
  background: color-mix(in srgb, var(--down) 14%, transparent);
  color: var(--down);
}

.vote-count {
  min-width: 26px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 14px 18px;
  font-size: 13px;
}

.panel-foot {
  border-top: 1px solid var(--border);
}

/* The action row of the thread editor page. */
.compose-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 15px 20px;
}

/* --------------------------------------------------------------- sidebar -- */

.side-card {
  padding: 16px 17px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.side-card h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-3);
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13.5px;
  color: var(--text-2);
  border-bottom: 1px dashed var(--border);
}

.stat-row:last-child {
  border-bottom: 0;
}

.stat-row b {
  color: var(--text);
}

.side-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.side-list a {
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.45;
}

.side-list a:hover {
  color: var(--accent);
}

.side-list .side-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.side-rank {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--text-3);
  font-size: 11px;
  font-weight: 700;
}

.side-rank.top {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------------------------------------------------------------- thread -- */

.breadcrumb {
  margin-bottom: 14px;
  color: var(--text-3);
  font-size: 13px;
}

.breadcrumb a:hover {
  color: var(--accent);
}

.thread-head {
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}

.thread-head h1 {
  margin: 0 0 10px;
  font-size: 21px;
  line-height: 1.45;
  letter-spacing: -0.2px;
}

.post {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  gap: 20px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}

.post:last-child {
  border-bottom: 0;
}

.post-author {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  text-align: center;
  font-size: 13px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: hsl(var(--hue, 210) 70% 58%);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 4px 12px hsl(var(--hue, 210) 60% 45% / 0.28);
  user-select: none;
}

.avatar-sm {
  width: 26px;
  height: 26px;
  font-size: 12px;
  box-shadow: none;
}

.post-author .author-name {
  font-weight: 600;
  color: var(--text);
}

.post-body {
  min-width: 0;
}

.post-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  line-height: 1.78;
}

.post-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  color: var(--text-3);
  font-size: 12.5px;
}

.reply-box {
  padding: 20px 22px;
}

.reply-box textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  resize: vertical;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.reply-box textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.reply-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

/* ----------------------------------------------------------------- forms -- */

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
}

.input,
.textarea,
.select {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.textarea {
  min-height: 140px;
  resize: vertical;
  line-height: 1.7;
}

.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) calc(50% + 1px), calc(100% - 12px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.field-hint {
  margin-top: 6px;
  color: var(--text-3);
  font-size: 12px;
}

/* ----------------------------------------------------------------- modal -- */

.modal-host:empty {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 14, 22, 0.5);
  backdrop-filter: blur(3px);
  animation: fade 0.16s ease;
}

.modal {
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: pop 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  margin: 0;
  font-size: 16px;
}

.modal-body {
  padding: 20px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 15px 20px;
  border-top: 1px solid var(--border);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-3);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.tabs-auth {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.auth-note {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12.5px;
  line-height: 1.6;
}

.code-row {
  display: flex;
  gap: 8px;
}

.code-row .input {
  flex: 1;
  min-width: 0;
}

.code-row .btn {
  flex-shrink: 0;
  height: 40px;
}

.tabs-auth button {
  flex: 1;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  cursor: pointer;
}

.tabs-auth button.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* The login button sits below the last field, so it needs some air. */
#auth-form .btn-block {
  margin-top: 20px;
}

.form-error {
  margin: 0 0 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  font-size: 13px;
}

/* ----------------------------------------------------------------- toast -- */

.toast-host {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 14px;
  animation: slide 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

.toast.error {
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
}

.toast.success {
  border-color: color-mix(in srgb, var(--down) 40%, transparent);
  color: var(--down);
}

/* ---------------------------------------------------------------- footer -- */

.footer {
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  color: var(--text-3);
  font-size: 12.5px;
}

.footer .container {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 16px;
  padding-bottom: 16px;
  flex-wrap: wrap;
}

/* --------------------------------------------------------------- empty -- */

.empty {
  padding: 54px 20px;
  color: var(--text-3);
  text-align: center;
}

.empty strong {
  display: block;
  margin-bottom: 6px;
  color: var(--text-2);
  font-size: 15px;
}

/* ------------------------------------------------------------ animation -- */

@keyframes fade {
  from {
    opacity: 0;
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

@keyframes slide {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
}

/* ------------------------------------------------------------ responsive -- */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 720px) {
  .topbar-inner {
    flex-wrap: wrap;
    gap: 10px;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .search {
    order: 3;
    max-width: none;
    flex-basis: 100%;
  }

  .topnav {
    order: 2;
    margin-left: auto;
  }

  .post {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    padding: 18px 16px;
  }

  .post-author {
    flex-direction: row;
    align-items: center;
    text-align: left;
  }

  .thread-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    padding: 14px 16px;
  }

  .thread-stats {
    justify-content: flex-start;
  }
}
