:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --ink: #14202f;
  --muted: #5d6b7e;
  --line: #d9dfe8;
  --primary: #27407a;
  --primary-ink: #ffffff;
  --tint: #e3e9f5;
  --bar: rgba(39, 64, 122, .16);
  --top: #27407a;
  --hi: #f2c14e;
  --hi-ink: #3a2b00;
  --danger: #b42318;
  --ok: #1a7f4b;
  --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --display: "Unbounded", "Onest", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1521;
    --surface: #161f31;
    --ink: #e6ebf4;
    --muted: #93a1b8;
    --line: #26324a;
    --primary: #8fa9f0;
    --primary-ink: #0e1521;
    --tint: #1e2a44;
    --bar: rgba(143, 169, 240, .22);
    --top: #1b2a4d;
    --danger: #ff8f84;
    --ok: #62d195;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.55 var(--font);
  min-height: 100vh;
}
a { color: var(--primary); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--hi); outline-offset: 2px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--top); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
}
.brand {
  font: 700 15px/1.2 var(--display); color: inherit; text-decoration: none;
  letter-spacing: -.01em;
}
.langs { display: inline-flex; gap: 4px; }
.langs button {
  cursor: pointer; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 6px; line-height: 1.3;
  background: transparent; color: rgba(255,255,255,.85); border: 1px solid rgba(255,255,255,.35);
}
.langs button.on { background: #fff; color: var(--top); border-color: #fff; }
.langs.on-light { margin-bottom: 14px; }
.langs.on-light button { color: var(--primary); border-color: var(--line); }
.langs.on-light button.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.apt { font-size: .82em; font-weight: 500; color: var(--muted); white-space: nowrap; }
.chip .apt { font-size: .9em; }
.tools { margin-top: 8px; font-size: 13px; }
.tlink { color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; align-items: end; }
.person details.edit { flex-basis: 100%; font-size: 14px; }
.person details.edit summary { cursor: pointer; color: var(--primary); }
.person .meta { gap: 0 10px; }
main {
  max-width: 680px; margin: 0 auto;
  padding: 16px 14px calc(96px + env(safe-area-inset-bottom));
}
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs-inner { display: flex; width: 100%; max-width: 680px; }
.tab {
  flex: 1; text-align: center; text-decoration: none; color: var(--muted);
  padding: 9px 4px 8px; font-size: 12px; font-weight: 500; position: relative;
}
.tab svg { display: block; margin: 0 auto 2px; width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--primary); }
.tab.active::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; background: var(--primary); border-radius: 0 0 3px 3px; }
.tab .dot {
  position: absolute; top: 5px; left: calc(50% + 6px);
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--hi); color: var(--hi-ink); font-size: 11px; font-weight: 700; line-height: 17px;
}

.page-title { font: 500 19px/1.3 var(--display); margin: 4px 0 14px; letter-spacing: -.01em; }
.loading, .empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }

/* ---------- Topic list ---------- */
.search {
  width: 100%; padding: 11px 14px; margin-bottom: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
.topic {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 8px; position: relative;
}
.topic.important { border-left: 5px solid var(--hi); }
.topic h3 { margin: 0 0 4px; font-size: 16.5px; line-height: 1.35; font-weight: 700; overflow-wrap: anywhere; }
.topic:hover { border-color: var(--primary); }
.meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0 12px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.badges:empty { display: none; }
.badge {
  font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 6px;
  background: var(--tint); color: var(--primary);
}
.badge.imp { background: var(--hi); color: var(--hi-ink); }

/* ---------- Topic page ---------- */
.back { display: inline-block; margin-bottom: 10px; font-size: 14px; text-decoration: none; }
.post {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px; margin-bottom: 14px;
}
.post.important { border-left: 5px solid var(--hi); }
.post h1 { margin: 0 0 6px; font-size: 21px; line-height: 1.3; overflow-wrap: anywhere; }
.body { margin-top: 12px; overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }

.section-title { font-size: 14px; font-weight: 700; margin: 20px 2px 8px; color: var(--muted); }

.reply {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 8px;
}
.reply .head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; margin-bottom: 4px; }
.reply .name { font-weight: 700; font-size: 14.5px; }
.reply .head .meta { flex: none; white-space: nowrap; }
.reply .body { margin-top: 0; }
.reply .del { background: none; border: 0; padding: 2px 4px; color: var(--muted); font-size: 13px; cursor: pointer; }
.reply .del:hover { color: var(--danger); }

/* ---------- Voting ---------- */
.poll { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.poll-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 10px; }
.poll-head strong { font-size: 15px; }
.opt { margin-bottom: 12px; }
.optbtn {
  position: relative; display: flex; justify-content: space-between; gap: 12px; align-items: center;
  width: 100%; text-align: left; cursor: pointer; overflow: hidden;
  background: var(--tint); border: 2px solid transparent; border-radius: 9px; padding: 11px 13px;
}
.optbtn:disabled { cursor: default; }
.optbtn .bar { position: absolute; inset: 0 auto 0 0; background: var(--bar); pointer-events: none; }
.optbtn .lbl, .optbtn .cnt { position: relative; }
.optbtn .lbl { font-weight: 500; overflow-wrap: anywhere; }
.optbtn .cnt { font-size: 13px; font-weight: 700; white-space: nowrap; }
.opt.mine .optbtn { border-color: var(--primary); }
.opt.mine .lbl::after { content: " \2713"; color: var(--primary); font-weight: 700; }
.voters { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.chip { font-size: 12.5px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 0 9px; }
.chip.me { border-color: var(--primary); color: var(--primary); font-weight: 700; }
.novote { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 13px; color: var(--muted); }
.novote .chip { background: transparent; }

/* ---------- Forms & buttons ---------- */
form.card, .card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 14px;
}
label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 12px; }
label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
label.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--primary); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], textarea, select {
  display: block; width: 100%; margin-top: 5px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
textarea { min-height: 110px; resize: vertical; }
.btn {
  display: inline-block; cursor: pointer; text-decoration: none; text-align: center;
  padding: 10px 16px; border-radius: 8px; font-weight: 700; font-size: 15px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
}
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 13.5px; }
.btn.block { display: block; width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; color: var(--primary); cursor: pointer; padding: 6px; text-decoration: underline; }
.hint { font-size: 13.5px; color: var(--muted); margin: 6px 0 0; }
.notice { background: var(--tint); border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { margin-top: 0; }
.stack > * + * { margin-top: 10px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 24px 22px; }
.logo { font: 700 22px/1.2 var(--display); color: var(--primary); margin-bottom: 6px; letter-spacing: -.02em; }
.auth-card .btn.primary { width: 100%; margin-top: 4px; }
.auth-card .link { display: block; margin: 12px auto 0; }

/* ---------- People (admin) ---------- */
.person { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person .who2 strong { display: block; }
.person select { width: auto; margin: 0; padding: 7px 10px; }
.person.pending { background: linear-gradient(90deg, var(--hi) 0 5px, transparent 5px); padding-left: 14px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  width: max-content; max-width: min(92vw, 460px); padding: 11px 16px; border-radius: 9px; z-index: 50;
  background: var(--ink); color: var(--bg); font-size: 14.5px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--danger); color: #fff; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (min-width: 720px) { main { padding-top: 24px; } .page-title { font-size: 21px; } }
