:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #15171a;
  --muted: #68707c;
  --line: #dde1e6;
  --brand: #f4c21b;
  --brand-dark: #28220b;
  --accent: #2563eb;
  --danger: #c2410c;
  --success: #0f766e;
  --shadow: 0 6px 20px rgba(20, 26, 35, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", Arial, sans-serif;
  letter-spacing: 0;
}

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

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

button,
.primary-action,
.ghost-action,
.small-action,
.wide-action {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 58px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

.menu-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 900;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--brand);
  color: var(--brand-dark);
  font-weight: 900;
  white-space: nowrap;
}

.brand-logo {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  object-fit: cover;
}

.top-search input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 0 12px;
  outline: none;
}

.avatar,
.login-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #1f2937;
  color: #fff;
  font-weight: 800;
}

.login-link {
  min-width: 52px;
  padding: 0 10px;
  background: var(--accent);
}

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 14px 12px 84px;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 14px;
}

.primary-action,
.wide-action,
.form-panel button,
.search-panel button,
.reply-box button,
.report-panel button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  background: #20242b;
  color: #fff;
}

.ghost-action,
.small-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.disabled-action {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.72;
}

.wide-action {
  width: 100%;
  margin: 12px 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0 10px;
}

.ad-slot {
  display: flex;
  justify-content: center;
  margin: 12px 0;
}

.ad-slot a,
.ad-slot img {
  display: block;
}

.ad-slot img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  object-fit: contain;
}

.ad-slot-home_leaderboard img,
.ad-slot-category_leaderboard img,
.ad-slot-thread_top_leaderboard img {
  width: min(100%, 728px);
  max-height: 90px;
}

.ad-slot-home_feed_footer img {
  width: 100%;
  max-height: 220px;
}

.ad-slot-thread_rectangle img {
  width: min(100%, 300px);
  max-height: 250px;
}

.compact-head {
  margin-top: 8px;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 42, 0.4);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.category-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  width: min(86vw, 340px);
  padding: max(14px, env(safe-area-inset-top)) 12px max(18px, env(safe-area-inset-bottom));
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 18px 0 38px rgba(15, 23, 42, 0.18);
  transform: translateX(-105%);
  transition: transform 0.22s ease;
}

.drawer-open {
  overflow: hidden;
}

.drawer-open .drawer-backdrop {
  opacity: 1;
}

.drawer-open .category-drawer {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 4px 2px 10px;
  border-bottom: 1px solid var(--line);
}

.drawer-head strong {
  display: block;
  font-size: 1.15rem;
}

.drawer-head span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.85rem;
}

.drawer-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.4rem;
}

.drawer-list {
  display: grid;
  gap: 8px;
}

.drawer-list a {
  position: relative;
  display: grid;
  gap: 3px;
  min-height: 70px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.drawer-list a.is-active {
  border-color: transparent;
  background: var(--brand);
  color: var(--brand-dark);
}

.drawer-list a.is-active span,
.drawer-list a.is-active small {
  color: var(--brand-dark);
}

.drawer-list strong {
  font-size: 1rem;
  line-height: 1.2;
}

.drawer-list span {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-list small {
  display: block;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1.25;
}

.admin-drawer-list a {
  min-height: 62px;
}

.admin-anchor {
  scroll-margin-top: 76px;
}

.section-head h1,
.form-panel h1,
.admin-list h2,
.form-panel h2 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.25;
}

.section-head p,
.section-head span {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.thread-list {
  display: grid;
  gap: 10px;
}

.thread-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  min-height: 86px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.thread-thumb {
  width: 58px;
  height: 58px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-2);
}

.thread-title {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text);
  font-weight: 800;
  line-height: 1.35;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 10px;
}

.status-row.compact {
  margin: 6px 0 0;
}

.status-row span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--brand);
  color: var(--brand-dark);
  font-size: 0.78rem;
  font-weight: 900;
}

.thread-meta,
.thread-detail-meta,
.reply-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.thread-stats {
  display: grid;
  gap: 4px;
  min-width: 54px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}

.sort-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 8px 0 12px;
}

.sort-tabs a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 800;
}

.sort-tabs a.is-active {
  border-color: transparent;
  background: var(--brand);
  color: var(--brand-dark);
}

.pagination {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  margin: 14px 0 0;
}

.pagination a,
.pagination span,
.pagination strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.pagination a {
  color: var(--text);
}

.thread-detail,
.reply,
.form-panel,
.search-panel,
.profile-head,
.admin-list {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.admin-shell {
  max-width: 920px;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.admin-stats div {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.admin-stats strong {
  display: block;
  font-size: 1.4rem;
  line-height: 1.1;
}

.admin-stats span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.admin-pagination {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.admin-page-jump,
.admin-page-meta {
  display: grid;
  gap: 8px;
  align-items: center;
}

.admin-page-jump {
  grid-template-columns: 1fr minmax(120px, auto) 1fr;
}

.admin-page-meta {
  grid-template-columns: 1fr;
}

.admin-page-jump a,
.admin-page-jump span,
.admin-page-jump label,
.admin-page-meta span,
.admin-page-meta label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
}

.admin-page-jump a {
  color: var(--text);
}

.admin-page-jump form,
.admin-page-meta form {
  margin: 0;
}

.admin-page-jump select,
.admin-page-meta select {
  min-height: 30px;
  margin: 0 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
}

.admin-inline-form,
.admin-edit-row form {
  display: grid;
  gap: 8px;
}

.admin-inline-form input,
.admin-edit-row input,
.admin-settings-form input,
.admin-settings-form textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 9px 10px;
}

.admin-settings-form {
  display: grid;
  gap: 9px;
}

.admin-settings-form label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.admin-settings-form textarea {
  resize: vertical;
  line-height: 1.5;
}

.segmented-field {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.segmented-field label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.segmented-field input {
  width: 16px;
  min-height: 16px;
}

.admin-settings-form button {
  min-height: 42px;
  border: 0;
  background: #20242b;
  color: #fff;
}

.settings-grid {
  display: grid;
  gap: 9px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
}

.check-row input[type="checkbox"],
.check-row input[type="radio"] {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  accent-color: var(--brand);
}

.admin-inline-form button,
.admin-edit-row button,
.admin-topic-actions button,
.admin-reply-row button {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.thread-detail {
  padding: 16px;
}

.thread-detail h1 {
  margin: 12px 0;
  font-size: 1.42rem;
  line-height: 1.35;
}

.post-body {
  margin: 0;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.post-body p {
  margin: 0 0 0.8em;
}

.post-body p:last-child {
  margin-bottom: 0;
}

.post-body blockquote {
  margin: 10px 0;
  padding: 8px 10px;
  border-left: 4px solid var(--brand);
  border-radius: 0 8px 8px 0;
  background: var(--surface-2);
  color: var(--muted);
}

.post-body ul,
.post-body ol {
  margin: 8px 0 8px 22px;
  padding: 0;
}

.post-body a {
  color: var(--accent);
  text-decoration: underline;
}

.post-image {
  display: block;
  width: 100%;
  max-height: 520px;
  margin-top: 14px;
  border-radius: 8px;
  object-fit: contain;
  background: var(--surface-2);
}

.vote-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}

.vote-row form {
  margin: 0;
}

.vote-row button {
  min-width: 72px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.vote-row button.is-voted {
  background: var(--brand);
  color: var(--brand-dark);
}

.reply-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.9rem;
}

.report-panel {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.report-panel summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.report-panel form {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.report-panel textarea {
  width: 100%;
  min-height: 82px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 10px 12px;
  outline: none;
}

.compact-report {
  margin-top: 10px;
  padding-top: 8px;
}

.replies {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.reply {
  padding: 14px;
}

.reply-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.reply-actions button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
}

.reply-box {
  position: sticky;
  bottom: 62px;
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

.form-panel,
.search-panel {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.form-panel label {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.form-panel input:not([type="checkbox"]):not([type="radio"]),
.file-input,
.form-panel select,
.form-panel textarea,
.search-panel input,
.reply-box textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 11px 12px;
  outline: none;
}

.rich-editor {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.rich-editor.is-invalid {
  border-color: #f97316;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.15);
}

.editor-toolbar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  border-bottom: 1px solid var(--line);
  background: var(--line);
}

.editor-toolbar button {
  min-width: 0;
  min-height: 40px;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
}

.editor-surface {
  min-height: 138px;
  padding: 12px;
  line-height: 1.7;
  outline: none;
  overflow-wrap: anywhere;
}

.editor-surface:empty::before {
  color: var(--muted);
  content: attr(data-placeholder);
}

.rich-editor.is-invalid .editor-surface::after {
  display: block;
  margin-top: 8px;
  color: #c2410c;
  content: attr(data-error);
  font-size: 0.86rem;
  font-weight: 800;
}

.editor-surface blockquote {
  margin: 8px 0;
  padding: 8px 10px;
  border-left: 4px solid var(--brand);
  background: rgba(244, 194, 27, 0.12);
  color: var(--muted);
}

.editor-value {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-input {
  min-height: 44px;
}

.form-panel textarea,
.reply-box textarea {
  resize: vertical;
}

.form-link {
  display: block;
  padding: 6px 0;
  color: var(--accent);
  text-align: center;
}

.inline-link {
  min-height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 800;
  text-decoration: underline;
}

.form-panel button.inline-link {
  display: inline;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 800;
  text-decoration: underline;
}

.terms-check span {
  color: var(--text);
}

.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.48);
}

.terms-modal {
  position: fixed;
  right: 12px;
  bottom: calc(72px + env(safe-area-inset-bottom));
  left: 12px;
  z-index: 70;
  display: grid;
  gap: 12px;
  max-height: min(74vh, 620px);
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.28);
}

.user-popover {
  position: fixed;
  right: 14px;
  bottom: calc(72px + env(safe-area-inset-bottom));
  left: 14px;
  z-index: 70;
  display: grid;
  gap: 12px;
  max-width: 420px;
  margin: 0 auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.28);
}

.user-popover[aria-hidden="true"] {
  display: none;
}

.user-popover p {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.user-popover-trigger {
  min-height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 800;
  text-decoration: underline;
}

.turnstile-box {
  min-height: 65px;
}

.terms-modal[aria-hidden="true"] {
  display: none;
}

.terms-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.terms-modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.terms-modal-head button {
  width: 36px;
  min-height: 36px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.terms-modal-body {
  max-height: 44vh;
  overflow: auto;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-2);
  line-height: 1.65;
  white-space: pre-wrap;
}

.auth-shell {
  max-width: 460px;
}

.search-panel {
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 12px;
}

.profile-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
}

.profile-avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 8px;
  background: var(--brand);
  color: var(--brand-dark);
  font-size: 1.6rem;
  font-weight: 900;
}

.profile-head h1 {
  margin: 0;
  font-size: 1.25rem;
}

.profile-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.profile-settings {
  margin-top: 12px;
}

.profile-settings p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.profile-settings form {
  display: grid;
  gap: 10px;
}

.admin-list {
  display: grid;
  gap: 1px;
  margin-top: 12px;
  padding: 12px;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.admin-row:first-of-type {
  border-top: 0;
}

.admin-edit-row,
.admin-topic-row,
.admin-reply-row,
.admin-report-row,
.admin-audit-row {
  display: grid;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.admin-edit-row:first-of-type,
.admin-topic-row:first-of-type,
.admin-reply-row:first-of-type,
.admin-report-row:first-of-type,
.admin-audit-row:first-of-type {
  border-top: 0;
}

.admin-topic-row small,
.admin-reply-row small,
.admin-edit-row small,
.admin-report-row small,
.admin-audit-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.admin-topic-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.admin-topic-actions form,
.admin-reply-row form {
  margin: 0;
}

.admin-reply-body {
  max-height: 120px;
  overflow: auto;
  margin-top: 8px;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-2);
  line-height: 1.6;
}

.admin-report-row p,
.admin-audit-row p {
  margin: 8px 0 0;
  color: var(--text);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.admin-target-link {
  display: inline-flex;
  margin-top: 8px;
  color: var(--accent);
  font-weight: 800;
  text-decoration: underline;
}

.admin-ad-list {
  display: grid;
  gap: 10px;
}

.admin-ad-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.admin-ad-row:first-of-type {
  border-top: 0;
}

.admin-ad-preview {
  display: grid;
  place-items: center;
  width: 96px;
  min-height: 56px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
}

.admin-ad-preview img {
  max-width: 100%;
  max-height: 70px;
  object-fit: contain;
}

.admin-ad-main {
  min-width: 0;
}

.admin-ad-title {
  display: inline-flex;
  color: var(--text);
  font-weight: 800;
  line-height: 1.35;
  text-decoration: none;
}

.admin-ad-title:hover {
  color: var(--accent);
  text-decoration: underline;
}

.admin-ad-main small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.admin-ad-actions {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.admin-ad-actions form {
  margin: 0;
}

.admin-ad-form {
  margin-top: 8px;
}

.category-checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.category-checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 6px 8px;
  border-radius: 7px;
  background: var(--surface);
  font-size: 0.9rem;
}

.category-checkbox-grid input {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.admin-user-row {
  display: grid;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.admin-user-row:first-of-type {
  border-top: 0;
}

.admin-user-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.admin-user-main strong {
  font-size: 1rem;
}

.admin-user-main span,
.admin-user-main small {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.admin-user-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.admin-user-profile-form {
  display: grid;
  grid-column: 1 / -1;
  gap: 8px;
}

.admin-user-profile-form input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 9px 10px;
}

.admin-user-actions form {
  margin: 0;
}

.admin-user-actions button {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.danger {
  min-height: 36px;
  padding: 0 12px;
  background: var(--danger);
  color: #fff;
}

.restore {
  min-height: 36px;
  padding: 0 12px;
  background: var(--success);
  color: #fff;
}

.flash,
.empty {
  margin: 0 0 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

.flash-error {
  border: 1px solid #fecaca;
  background: #fff1f2;
  color: #9f1239;
}

.flash-success {
  border: 1px solid #99f6e4;
  background: #ecfeff;
  color: var(--success);
}

.bottomnav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  min-height: calc(58px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(14px);
}

.bottomnav a,
.bottomnav button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 58px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.bottomnav a.is-active,
.bottomnav button.is-active {
  color: var(--text);
  box-shadow: inset 0 3px 0 var(--brand);
}

@media (min-width: 820px) {
  .topbar {
    grid-template-columns: auto auto minmax(320px, 520px) auto;
    justify-content: center;
  }

  .app-shell {
    padding-top: 22px;
  }

  .thread-card {
    min-height: 78px;
  }

  .admin-stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .admin-inline-form {
    grid-template-columns: 1fr 1fr 2fr auto;
    align-items: center;
  }

  .admin-page-meta {
    grid-template-columns: 1fr auto;
  }

  .settings-grid {
    grid-template-columns: 1fr 160px;
  }

  .segmented-field {
    grid-template-columns: 1fr 1fr;
  }

  .admin-edit-row {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .admin-edit-row form:first-child {
    grid-template-columns: 1fr 1fr 2fr minmax(160px, auto) auto;
    align-items: center;
  }

  .admin-topic-row,
  .admin-reply-row,
  .admin-report-row {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }

  .admin-topic-actions {
    grid-template-columns: repeat(4, auto);
  }

  .admin-ad-row {
    grid-template-columns: 260px minmax(0, 1fr);
    align-items: start;
  }

  .bottomnav {
    right: 50%;
    left: 50%;
    width: min(760px, 100%);
    transform: translateX(-50%);
    border-right: 1px solid var(--line);
    border-left: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  .admin-ad-row {
    grid-template-columns: 1fr;
  }

  .admin-ad-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-items: stretch;
  }

  .admin-ad-actions .small-action,
  .admin-ad-actions button,
  .admin-ad-actions form {
    width: 100%;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121417;
    --surface: #1c2026;
    --surface-2: #242932;
    --text: #f2f5f8;
    --muted: #a4acb8;
    --line: #333a45;
    --shadow: none;
  }

  .topbar,
  .bottomnav,
  .reply-box {
    background: rgba(28, 32, 38, 0.96);
  }
}
