:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-strong: #f0f5f7;
  --text: #17202a;
  --muted: #5d6978;
  --line: #dbe3ea;
  --line-strong: #c8d3dc;
  --teal: #007f78;
  --teal-dark: #00655f;
  --coral: #c84732;
  --gold: #9b6b00;
  --blue: #245fbd;
  --green: #1f7a4d;
  --shadow: 0 14px 38px rgba(25, 39, 52, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.74), rgba(246, 248, 251, 0.96)),
    radial-gradient(circle at 12% 16%, rgba(0, 127, 120, 0.13), transparent 32%),
    radial-gradient(circle at 88% 4%, rgba(200, 71, 50, 0.12), transparent 28%),
    var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 70px;
  padding: 12px clamp(16px, 4vw, 34px);
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--teal), var(--blue));
  color: #ffffff;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1.02rem;
}

.brand small {
  color: var(--muted);
  font-size: 0.78rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.ghost-button,
.chip-button,
.icon-button,
.sort-button,
.vote-button,
.report-button {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 700;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}

.primary-button {
  background: var(--teal);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--teal-dark);
}

.ghost-button,
.chip-button,
.icon-button,
.sort-button,
.vote-button,
.report-button {
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--line-strong);
}

.ghost-button:hover,
.chip-button:hover,
.icon-button:hover,
.sort-button:hover,
.vote-button:hover,
.report-button:hover {
  background: var(--panel-strong);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(360px, 0.95fr) minmax(360px, 1.05fr);
  gap: 18px;
  width: min(1520px, calc(100% - 32px));
  max-width: 100%;
  margin: 20px auto 28px;
  align-items: start;
}

.side-panel,
.feed-panel,
.thread-panel {
  min-width: 0;
}

.side-panel {
  position: sticky;
  top: 90px;
}

#pulseMap {
  display: block;
  width: 100%;
  height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f2027;
  box-shadow: var(--shadow);
}

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

.stat-grid div {
  min-width: 0;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stat-grid strong {
  display: block;
  font-size: 1.25rem;
  color: var(--teal-dark);
}

.stat-grid span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.feed-panel,
.thread {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.feed-toolbar {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.sort-button {
  width: 100%;
}

.sort-button.active {
  background: #e4f3f1;
  border-color: var(--teal);
  color: var(--teal-dark);
}

.search-box {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.search-box input,
.composer input,
.composer textarea,
.comment-form textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

.search-box input {
  height: 42px;
  padding: 0 12px;
}

.composer input,
.composer textarea,
.comment-form textarea {
  padding: 10px 12px;
}

.search-box input:focus,
.composer input:focus,
.composer textarea:focus,
.comment-form textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 127, 120, 0.14);
}

.filter-row {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  color: var(--muted);
  font-size: 0.85rem;
  border-bottom: 1px solid var(--line);
}

.hidden {
  display: none !important;
}

.topic-list {
  display: grid;
}

.topic-item {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  min-height: 112px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
}

.topic-item > div {
  min-width: 0;
}

.topic-item:last-child {
  border-bottom: 0;
}

.topic-item:hover,
.topic-item.active {
  background: #f0f7f6;
}

.rank-cell {
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 6px;
}

.rank-cell strong {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #17202a;
  color: #ffffff;
}

.rank-cell span {
  color: var(--muted);
  font-size: 0.74rem;
}

.topic-title {
  display: block;
  overflow-wrap: anywhere;
  font-size: 0.98rem;
  line-height: 1.32;
}

.topic-body-preview {
  display: -webkit-box;
  margin: 6px 0 8px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.meta-line,
.tag-row,
.thread-meta,
.comment-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.meta-line {
  color: var(--muted);
  font-size: 0.78rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 8px;
  padding: 0 9px;
  background: #eef2f7;
  color: #354254;
  font-size: 0.76rem;
  font-weight: 700;
}

button.tag {
  border: 1px solid transparent;
}

button.tag:hover {
  border-color: var(--line-strong);
}

.thread-panel {
  position: sticky;
  top: 90px;
}

.thread {
  min-height: calc(100vh - 122px);
  overflow: hidden;
}

.thread-header {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.thread h1 {
  margin: 0 0 10px;
  overflow-wrap: anywhere;
  font-size: 1.42rem;
  line-height: 1.22;
}

.thread-body {
  margin: 12px 0 0;
  color: #253242;
  line-height: 1.6;
  white-space: pre-wrap;
}

.thread-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.vote-button {
  min-width: 78px;
}

.report-button {
  color: var(--coral);
}

.comments {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.comment-form {
  display: grid;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.comment-form footer {
  display: flex;
  justify-content: flex-end;
}

.comment {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.comment p {
  margin: 0;
  color: #253242;
  line-height: 1.5;
  white-space: pre-wrap;
}

.empty-thread,
.empty-list {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 260px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.empty-thread strong,
.empty-list strong {
  color: var(--text);
  font-size: 1.1rem;
}

.composer {
  width: min(680px, calc(100% - 24px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 28px 70px rgba(15, 28, 40, 0.32);
}

.composer::backdrop {
  background: rgba(10, 18, 26, 0.46);
}

.dialog-shell {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: #ffffff;
}

.dialog-shell header,
.dialog-shell footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-shell label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.policy-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: min(420px, calc(100% - 36px));
  min-height: 42px;
  transform: translateY(16px);
  border-radius: 8px;
  padding: 12px 14px;
  background: #17202a;
  color: #ffffff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(300px, 0.92fr) minmax(360px, 1.08fr);
  }

  .side-panel {
    grid-column: 1 / -1;
    position: static;
    display: grid;
    grid-template-columns: minmax(260px, 0.8fr) minmax(240px, 0.6fr) minmax(260px, 1fr);
    gap: 12px;
    align-items: stretch;
  }

  #pulseMap,
  .stat-grid,
  .tag-cloud {
    margin-top: 0;
  }
}

@media (max-width: 820px) {
  .topbar {
    position: static;
    align-items: flex-start;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .workspace {
    width: min(calc(100% - 20px), 720px);
    grid-template-columns: 1fr;
    margin-top: 12px;
  }

  .side-panel,
  .thread-panel {
    position: static;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .thread {
    min-height: auto;
  }
}

@media (max-width: 520px) {
  .topbar {
    display: grid;
  }

  .top-actions,
  .dialog-shell footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .topic-item {
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
  }

  .rank-cell strong {
    width: 38px;
    height: 38px;
  }

  .thread h1 {
    font-size: 1.18rem;
  }
}
