:root {
  --bg: #f5f5f1;
  --bg-deep: #ebebe5;
  --card: #ffffff;
  --card-soft: rgba(255, 255, 255, 0.88);
  --ink: #101112;
  --muted: #6e6e69;
  --line: #191a1d;
  --primary: #111214;
  --primary-2: #2c2d31;
  --danger: #b23636;
  --shadow: 0 16px 42px rgb(16 18 20 / 10%);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  touch-action: manipulation;
}

body {
  color: var(--ink);
  font-family: "Avenir Next", "Noto Sans TC", "PingFang TC", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 0% 0%, rgb(0 0 0 / 0.035) 0%, transparent 24%),
    radial-gradient(circle at 100% 10%, rgb(0 0 0 / 0.028) 0%, transparent 20%),
    linear-gradient(180deg, #fafaf7 0%, var(--bg-deep) 100%);
  min-height: 100dvh;
}

.app {
  width: min(760px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  padding: 18px 16px calc(108px + env(safe-area-inset-bottom));
  display: grid;
  align-content: start;
  gap: 16px;
}

.card {
  background: color-mix(in srgb, var(--card) 98%, white);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 18px;
  backdrop-filter: blur(8px);
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 18px 18px 16px;
}

.hero-copy {
  min-width: 0;
}

.hero-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #f9f9f7;
  background: var(--primary);
  border: 1px solid var(--line);
}

.hero h1 {
  margin: 2px 0 2px;
  font-size: clamp(1.5rem, 4.8vw, 1.92rem);
  line-height: 1.05;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.12em;
  color: var(--primary-2);
  font-weight: 700;
  font-size: 0.74rem;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  max-width: 38ch;
  font-size: 0.92rem;
  line-height: 1.45;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

button {
  border: none;
  border-radius: 12px;
  padding: 10px 13px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  color: #fafaf8;
  background: var(--primary);
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  background: #2a2b2f;
}

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

button.ghost {
  color: var(--primary-2);
  border: 1px solid var(--line);
  background: var(--card-soft);
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--ink);
  background: #fff;
}

input:focus {
  outline: 2px solid rgb(17 18 20 / 0.18);
  outline-offset: 1px;
}

.status-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 2px 2px 4px;
}

.stat .label {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.stat .value {
  margin: 0;
  font-weight: 650;
  font-size: 0.9rem;
  line-height: 1.45;
}

.range-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.range-wrap input {
  padding: 0;
  border: none;
  background: transparent;
}

.radar-controls {
  width: min(100%, 420px);
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fafaf7;
}

.range-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.range-head .label {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.range-head span {
  min-width: 56px;
  text-align: right;
  font-weight: 700;
  color: var(--primary);
}

.views {
  min-height: 0;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
  animation: view-in 180ms ease;
}

html[data-active-tab="radar"] [data-tab-view="radar"],
html[data-active-tab="chat"] [data-tab-view="chat"],
html[data-active-tab="events"] [data-tab-view="events"],
html[data-active-tab="polls"] [data-tab-view="polls"] {
  display: block;
}

html[data-active-tab="radar"] [data-tab-btn="radar"],
html[data-active-tab="chat"] [data-tab-btn="chat"],
html[data-active-tab="events"] [data-tab-btn="events"],
html[data-active-tab="polls"] [data-tab-btn="polls"] {
  background: var(--primary);
  border-color: var(--line);
  color: #fafaf8;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 1.08rem;
}

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

.section-pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: #f3f3ef;
  border: 1px solid var(--line);
}

.radar-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.radar-card > .section-head,
.radar-card > .radar-controls,
.radar-card > .list {
  width: min(100%, 360px);
  margin-inline: auto;
}

.radar-card > .section-head {
  width: fit-content;
  max-width: 100%;
  justify-content: center;
  align-items: center;
}

#radarCanvas {
  display: block;
  width: min(100%, 360px);
  height: auto;
  border-radius: 50%;
  margin: 4px auto 0;
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.04);
  background: radial-gradient(circle, #f7f7f4 0%, #e8e8e2 100%);
}

.list {
  margin: 0;
  max-height: 300px;
  overflow: auto;
  padding: 0;
  list-style: none;
}

.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px dashed rgb(0 0 0 / 0.12);
  padding: 10px 2px;
  font-size: 0.9rem;
}

.feed {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  min-height: 180px;
  max-height: min(50dvh, 430px);
  overflow: auto;
  display: grid;
  gap: 10px;
  background: #fafaf7;
}

.msg,
.item {
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgb(0 0 0 / 0.1);
  background: #fff;
}

.msg p,
.item p {
  margin: 4px 0;
}

.item small,
.msg small {
  color: var(--muted);
}

.inline-form {
  margin-top: 14px;
  display: flex;
  gap: 10px;
}

.inline-form input {
  flex: 1;
}

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

.split {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.split label {
  color: var(--muted);
  font-size: 0.84rem;
}

.poll-option {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.bar {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.08);
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  background: var(--primary);
}

.tab-nav {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  z-index: 40;
  background: rgb(255 255 255 / 0.92);
  backdrop-filter: blur(14px);
  box-shadow: 0 16px 32px rgb(16 18 20 / 10%);
}

.tab-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-weight: 600;
  padding: 11px 8px;
}

.tab-btn:hover {
  background: #f3f3ef;
  color: var(--ink);
}

.tab-btn.is-active {
  background: var(--primary);
  border-color: var(--line);
  color: #fafaf8;
}

.danger {
  color: var(--danger);
}

body[data-active-tab="chat"] .status-row,
body[data-active-tab="events"] .status-row,
body[data-active-tab="polls"] .status-row {
  display: none;
}

body[data-active-tab="chat"] .hero,
body[data-active-tab="events"] .hero,
body[data-active-tab="polls"] .hero {
  padding-bottom: 18px;
}

body[data-active-tab="chat"] .views,
body[data-active-tab="events"] .views,
body[data-active-tab="polls"] .views {
  display: grid;
  justify-items: center;
}

body[data-active-tab="chat"] .view.is-active,
body[data-active-tab="events"] .view.is-active,
body[data-active-tab="polls"] .view.is-active {
  width: min(100%, 620px);
  margin-top: 12px;
}

@media (min-width: 960px) {
  .app {
    padding: 28px 24px 124px;
  }

  .status-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tab-nav {
    left: 50%;
    right: auto;
    width: min(700px, calc(100% - 48px));
    transform: translateX(-50%);
  }
}

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

  .hero {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-actions {
    justify-content: flex-start;
  }

  .hero-title-row {
    flex-wrap: wrap;
  }

  .split,
  .inline-form {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .app {
    padding: 16px 14px calc(108px + env(safe-area-inset-bottom));
  }
}
