:root {
  --bg: #f6f5f2; --card: #ffffff; --ink: #12161c; --ink2: #3b424c; --muted: #6b7280; --line: #e6e2da;
  --soft: #efece6; --accent: #e5484d; --accent-ink: #ffffff; --accent-soft: #fdecec; --ok: #18794e; --ok-soft: #e6f4ea;
  --warn: #ad5700; --warn-soft: #fff1e0; --link: #1f5fbf; --shadow: 0 1px 2px rgba(18,22,28,.06), 0 4px 16px rgba(18,22,28,.05);
  --radius: 14px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --card: #171b22; --ink: #eef0f3; --ink2: #c4c9d1; --muted: #8b93a0; --line: #272d36; --soft: #1e232b;
    --accent: #ff6369; --accent-soft: #3a1d20; --ok: #4cc38a; --ok-soft: #13291e; --warn: #ffb35c; --warn-soft: #33240f;
    --link: #7fb0ff; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; min-height: 100dvh; }
a { color: var(--link); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* prototype strip */
#proto-bar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 6px) 12px 6px;
  background: #12161c; color: #e9ebee; font-size: 12.5px; }
.proto-tag { background: var(--accent); color: #fff; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; font-size: 10.5px; padding: 3px 7px; border-radius: 99px; }
.proto-who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }
@media (max-width: 420px) { .proto-who { font-size: 11.5px; } .proto-btn { padding: 4px 8px !important; } }
.proto-btn { background: transparent; border: 1px solid #3a414c; color: #e9ebee; border-radius: 99px; padding: 4px 10px; font-size: 12px; min-height: 30px; cursor: pointer; white-space: nowrap; }
#lab-offline-status:empty { display: none; }
#lab-offline-status { margin: 0; padding: 8px 14px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }

/* shell */
#shell { max-width: 1180px; margin: 0 auto; }
#topbar { position: sticky; top: calc(env(safe-area-inset-top) + 42px); z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 800; letter-spacing: .08em; font-size: 15px; }
.brand b { color: var(--accent); font-weight: 800; margin-left: 2px; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { position: relative; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; color: var(--ink); background: none; border: 0; cursor: pointer; }
.icon-btn svg, .tab svg, .side-link svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.dot { position: absolute; top: 8px; right: 8px; min-width: 9px; height: 9px; border-radius: 9px; background: var(--accent); border: 2px solid var(--bg); }
#view { padding: 12px 12px calc(96px + env(safe-area-inset-bottom)); outline: none; min-width: 0; }
#tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 25; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--card);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; position: relative; min-height: 48px; justify-content: center; }
.tab.on { color: var(--ink); font-weight: 600; }
.tab .badge-n { position: absolute; top: 0; left: calc(50% + 6px); }
.tab-post { display: grid; place-items: center; }
.tab-post span { width: 48px; height: 48px; border-radius: 16px; background: var(--accent); color: #fff; display: grid; place-items: center; box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 40%, transparent); }
.tab-post svg { width: 26px; height: 26px; stroke: #fff; }
.badge-n { background: var(--accent); color: #fff; font-size: 10.5px; font-weight: 700; border-radius: 99px; padding: 1px 6px; line-height: 1.4; }

@media (min-width: 900px) {
  #shell { display: grid; grid-template-columns: 220px minmax(0, 1fr) 300px; gap: 20px; padding: 0 16px; }
  #topbar { grid-column: 1 / -1; top: 42px; }
  #sidenav { display: flex !important; flex-direction: column; gap: 2px; position: sticky; top: 110px; align-self: start; padding-top: 14px; }
  #sidenav[hidden] { display: none !important; }
  #view { padding: 16px 0 40px; }
  #rail { display: block; position: sticky; top: 110px; align-self: start; padding-top: 16px; }
  #rail[hidden] { display: none !important; }
  #tabbar { display: none !important; }
  .no-session #shell { display: block; }
}
@media (max-width: 899px) { #sidenav, #rail { display: none !important; } }
.side-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; color: var(--ink2); font-weight: 500; }
.side-link:hover { background: var(--soft); }
.side-link.on { background: var(--card); color: var(--ink); font-weight: 700; box-shadow: var(--shadow); }
.side-link .badge-n { margin-left: auto; }
.side-post { margin: 10px 0; }

/* building blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 14px; }
.stack > * + * { margin-top: 10px; }
.stack-lg > * + * { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 8px; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.bold { font-weight: 700; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin: 18px 4px 8px; display: flex; align-items: center; gap: 8px; }
.page-title { font-size: 24px; font-weight: 800; letter-spacing: -.01em; margin: 6px 4px 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--ink);
  background: var(--ink); color: var(--bg); font-weight: 600; cursor: pointer; text-align: center; }
.btn.red { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 13.5px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 99px; background: var(--soft); color: var(--ink2); font-size: 12.5px; white-space: nowrap; }
.chip.red { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip.ok { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.chip.warn { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.chip.ink { background: var(--ink); color: var(--bg); }
.seg { display: inline-flex; background: var(--soft); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 9px; min-height: 36px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13.5px; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
input[type=text], input[type=search], input[type=number], select, textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); min-height: 44px; font-size: 16px; }
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
label.field { display: block; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink2); margin: 0 0 5px 2px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--soft); cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--accent); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 99px; background: var(--line); position: relative; flex: none; cursor: pointer; transition: background .2s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }
.empty { text-align: center; color: var(--muted); padding: 30px 12px; }

/* avatars */
.av { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; flex: none; letter-spacing: .02em; }
.av.lg { width: 76px; height: 76px; font-size: 26px; }
.av.sm { width: 28px; height: 28px; font-size: 11px; }
.av.anon { background: repeating-linear-gradient(45deg, #6b7280, #6b7280 4px, #808792 4px, #808792 8px); }
.tick { display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; background: var(--link); color: #fff; font-size: 9px; font-weight: 900; vertical-align: 1px; margin-left: 3px; }
.tick.pending { background: var(--warn); }

/* posts */
.post { padding: 14px; cursor: pointer; }
.post + .post { margin-top: 10px; }
.post-head { display: flex; gap: 10px; align-items: center; }
.post-meta { font-size: 12.5px; color: var(--muted); }
.post-title { font-size: 16.5px; font-weight: 700; margin: 10px 0 4px; letter-spacing: -.005em; }
.post-body { color: var(--ink2); white-space: pre-wrap; word-wrap: break-word; }
.post-foot { display: flex; gap: 4px; margin-top: 10px; border-top: 1px solid var(--line); padding-top: 6px; }
.act { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 6px 10px; border-radius: 10px; border: 0; background: none; color: var(--muted); font-size: 13.5px; cursor: pointer; font-weight: 500; }
.act:hover { background: var(--soft); }
.act.on { color: var(--accent); }
.thumbs { display: grid; gap: 4px; margin-top: 10px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.thumbs img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 10px; background: #000; display: block; }
.thumbs.one img { aspect-ratio: 16/10; }
.pt { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pinned-label { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.golive { border: 2px solid var(--accent); background: linear-gradient(180deg, var(--accent-soft), var(--card) 70%); }
.live-pill { display: inline-flex; align-items: center; gap: 6px; background: var(--accent); color: #fff; font-weight: 800; font-size: 11.5px; letter-spacing: .06em; padding: 4px 9px; border-radius: 99px; }
.live-pill i { width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .live-pill i { animation: none; } }
.answered-pill { display: inline-flex; align-items: center; gap: 5px; background: var(--ok-soft); color: var(--ok); font-weight: 700; font-size: 11.5px; padding: 4px 9px; border-radius: 99px; }
.countdown { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); font-size: 13px; }
.poll { margin-top: 10px; display: grid; gap: 6px; }
.poll-opt { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--card); text-align: left; cursor: pointer; min-height: 44px; display: flex; justify-content: space-between; gap: 8px; }
.poll-opt .bar { position: absolute; inset: 0 auto 0 0; background: var(--soft); z-index: 0; transition: width .3s; }
.poll-opt > span { position: relative; z-index: 1; }
.poll-opt.mine { border-color: var(--ink); font-weight: 600; }

/* comments */
.comment { display: flex; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.comment:first-child { border-top: 0; }
.comment .body { white-space: pre-wrap; word-wrap: break-word; color: var(--ink2); margin-top: 2px; }
.comment.answer { background: var(--ok-soft); margin: 0 -14px; padding: 12px 14px; border-radius: 0; }
.answer-label { color: var(--ok); font-weight: 700; font-size: 12px; }
.hidden-mark { opacity: .55; }
.reply-box { margin-top: 12px; }

/* groups */
.group-card { display: flex; gap: 12px; padding: 14px; align-items: center; color: var(--ink); }
.group-card + .group-card { margin-top: 8px; }
.g-emoji { width: 46px; height: 46px; border-radius: 14px; background: var(--soft); display: grid; place-items: center; font-size: 22px; flex: none; }
.g-emoji.rapid { background: var(--accent); }
.hero { padding: 18px 16px; }
.hero h1 { font-size: 22px; }

/* messages */
.conv { display: flex; gap: 12px; align-items: center; padding: 12px 14px; color: var(--ink); }
.conv + .conv { border-top: 1px solid var(--line); }
.chat { display: flex; flex-direction: column; gap: 6px; padding: 8px 2px 10px; }
.bubble { max-width: 82%; padding: 9px 12px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); white-space: pre-wrap; word-wrap: break-word; }
.bubble.mine { align-self: flex-end; background: var(--ink); color: var(--bg); border-color: var(--ink); border-bottom-right-radius: 4px; }
.bubble.theirs { border-bottom-left-radius: 4px; }
.bubble .who { font-size: 11.5px; font-weight: 700; margin-bottom: 2px; }
.bubble .when { font-size: 10.5px; opacity: .6; margin-top: 3px; text-align: right; }
.composer { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); display: flex; gap: 8px; padding: 8px; }
.composer textarea { min-height: 44px; height: 44px; resize: none; }
@media (min-width: 900px) { .composer { bottom: 12px; } }
.e2e-note { text-align: center; font-size: 12px; color: var(--muted); padding: 6px; }

/* admin */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 600px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { padding: 12px 14px; }
.tile .n { font-size: 26px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile .l { font-size: 12.5px; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 110px; padding-top: 8px; }
.bars div { flex: 1; display: flex; flex-direction: column-reverse; gap: 2px; height: 100%; }
.bars span { display: block; border-radius: 3px 3px 0 0; min-height: 1px; }
.bars .p { background: var(--ink); }
.bars .r { background: var(--accent); opacity: .8; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.queue-item { display: flex; gap: 10px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.queue-item:first-child { border-top: 0; }

/* misc */
.list-link { display: flex; align-items: center; gap: 12px; padding: 14px; color: var(--ink); border-top: 1px solid var(--line); }
.list-link:first-child { border-top: 0; }
.list-link .ico { width: 36px; height: 36px; border-radius: 10px; background: var(--soft); display: grid; place-items: center; font-size: 17px; flex: none; }
.list-link .chev { margin-left: auto; color: var(--muted); }
.persona { display: flex; gap: 12px; align-items: flex-start; padding: 14px; text-align: left; width: 100%; cursor: pointer; color: var(--ink); }
.persona + .persona { margin-top: 8px; }
.persona:hover { border-color: var(--ink); }
.landing { max-width: 640px; margin: 0 auto; }
.landing-hero { background: #12161c; color: #f2f3f5; border-radius: 20px; padding: 26px 20px; position: relative; overflow: hidden; }
.landing-hero h1 { font-size: 30px; font-weight: 900; letter-spacing: -.02em; }
.landing-hero h1 b { color: #ff6369; }
.landing-hero p { color: #c3c8d0; margin: 10px 0 0; }
.landing-hero svg.bolt { position: absolute; right: -20px; top: -10px; width: 160px; opacity: .14; }
.feature-list { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; margin-top: 12px; }
.feature-list div { font-size: 13px; padding: 10px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
#toast { position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 60; background: var(--ink); color: var(--bg);
  padding: 11px 16px; border-radius: 12px; font-size: 14px; max-width: min(92vw, 460px); opacity: 0; pointer-events: none; transition: .25s; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; cursor: pointer; }
dialog { border: 0; border-radius: 18px; padding: 18px; max-width: min(560px, 94vw); width: 100%; background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10,12,16,.55); }
dialog h2 { font-size: 19px; margin-bottom: 10px; }
#modal.wide { max-width: min(900px, 96vw); }
.lightbox img { width: 100%; border-radius: 10px; background: #000; }
.editor-wrap { position: relative; background: #000; border-radius: 10px; overflow: hidden; touch-action: none; }
.editor-wrap canvas { display: block; width: 100%; height: auto; touch-action: none; }
.tools { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.tools button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.img-slot { position: relative; }
.img-slot img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 10px; display: block; background: #000; }
.img-slot .x { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; }
.img-slot .edit { position: absolute; bottom: 4px; right: 4px; }
.disclaimer { border-left: 3px solid var(--accent); padding: 10px 12px; background: var(--accent-soft); border-radius: 0 10px 10px 0; font-size: 13.5px; color: var(--ink2); }
.prose { white-space: pre-wrap; color: var(--ink2); }
.coverage td, .coverage th { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: top; font-size: 13.5px; }
.coverage { border-collapse: collapse; width: 100%; }
.rail-card { padding: 14px; }
.rail-card + .rail-card { margin-top: 12px; }
.print-only { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { position: absolute; inset: 0; padding: 20px; color: #000; background: #fff; }
}
