:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #1a2233;
  --muted: #66707f;
  --line: #e3e7ee;
  --accent: #4f46e5;
  --up: #e8590c;
  --down: #4263eb;
  --good: #2b8a3e;
  --good-bg: #f0fbf2;
  --good-line: #b2f2bb;
  --bad: #c92a2a;
  --error-bg: #fff5f5;
  --error-line: #ffc9c9;
  --warn-bg: #fff9db;
  --warn-line: #ffe066;
  --warn-ink: #7a5b00;
  --chip-bg: #eef1f5;
  --hover-bg: rgba(0, 0, 0, 0.06);
  --toast-bg: #1a2233;
  --toast-ink: #ffffff;
  --map-edge: #c9d2e0;
  --map-ghost-edge: #eebfbf;
  --shadow: rgba(15, 23, 42, 0.18);
  --wld: #8247e5;
  --on-accent: #ffffff;
  --on-good: #ffffff;
  --radius: 10px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0f131a;
  --surface: #171d28;
  --ink: #e7ebf3;
  --muted: #98a3b5;
  --line: #2a3342;
  --accent: #8f88ff;
  --up: #ff9147;
  --down: #7ea4ff;
  --good: #57c878;
  --good-bg: #16281c;
  --good-line: #2d5c3a;
  --bad: #ff7676;
  --error-bg: #2b1a1c;
  --error-line: #5c2c31;
  --warn-bg: #2a2412;
  --warn-line: #5c5222;
  --warn-ink: #e6d38a;
  --chip-bg: #222b39;
  --hover-bg: rgba(255, 255, 255, 0.08);
  --toast-bg: #e7ebf3;
  --toast-ink: #0f131a;
  --map-edge: #3a4456;
  --map-ghost-edge: #5c3a3a;
  --shadow: rgba(0, 0, 0, 0.5);
  --wld: #a883ff;
  --on-accent: #10131c;
  --on-good: #0f131a;
  color-scheme: dark;
}

/* No-JS fallback: honor the OS preference unless a theme was explicitly set. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0f131a;
    --surface: #171d28;
    --ink: #e7ebf3;
    --muted: #98a3b5;
    --line: #2a3342;
    --accent: #8f88ff;
    --up: #ff9147;
    --down: #7ea4ff;
    --good: #57c878;
    --good-bg: #16281c;
    --good-line: #2d5c3a;
    --bad: #ff7676;
    --error-bg: #2b1a1c;
    --error-line: #5c2c31;
    --warn-bg: #2a2412;
    --warn-line: #5c5222;
    --warn-ink: #e6d38a;
    --chip-bg: #222b39;
    --hover-bg: rgba(255, 255, 255, 0.08);
    --toast-bg: #e7ebf3;
    --toast-ink: #0f131a;
    --map-edge: #3a4456;
    --map-ghost-edge: #5c3a3a;
    --shadow: rgba(0, 0, 0, 0.5);
    --wld: #a883ff;
    --on-accent: #10131c;
    --on-good: #0f131a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}

.wrap { max-width: 880px; margin: 0 auto; padding: 0 16px; }

a { color: var(--accent); }

h1 { letter-spacing: -0.02em; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0 0 8px; }
section { margin: 28px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; font-weight: 400; }

/* header */
header.site { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
header.site .wrap { display: flex; align-items: center; gap: 14px; height: 56px; }
.logo { font-weight: 800; font-size: 20px; color: var(--accent); text-decoration: none; letter-spacing: -0.02em; }
.search { flex: 1; }
.search input { width: 100%; max-width: 340px; padding: 7px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); font-size: 14px; }
.usernav { display: flex; align-items: center; gap: 12px; font-size: 14px; white-space: nowrap; }
.usernav .me { font-weight: 600; text-decoration: none; }
form.inline { display: inline; }

/* buttons + forms */
.btn { display: inline-block; background: var(--accent); color: var(--on-accent); border: none; border-radius: 8px; padding: 9px 16px; font-weight: 600; cursor: pointer; text-decoration: none; font-size: 14px; font-family: inherit; }
.btn:hover { filter: brightness(1.08); }
.btn.small { padding: 6px 11px; font-size: 13px; }
.linklike { background: none; border: none; color: var(--muted); cursor: pointer; font-family: inherit; font-size: 13px; padding: 0; }
.linklike:hover { color: var(--ink); text-decoration: underline; }
textarea, input[type="text"], input[type="search"], input[type="password"], input[type="number"] { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; width: 100%; background: var(--surface); color: var(--ink); }
textarea:focus, input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
form .row { margin: 12px 0; }
label { font-size: 13px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }

/* flash + chips */
.flash { padding: 10px 14px; border-radius: 8px; margin: 14px 0; font-size: 14px; }
.flash.error { background: var(--error-bg); border: 1px solid var(--error-line); color: var(--bad); }
.flash.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); }
.flash.success { background: var(--good-bg); border: 1px solid var(--good-line); color: var(--good); }
.chip { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; vertical-align: 1px; }
.chip.good { color: var(--good); background: var(--good-bg); border: 1px solid var(--good-line); }
.chip.bad { color: var(--bad); background: var(--error-bg); border: 1px solid var(--error-line); }
.chip.gray { color: var(--muted); background: var(--chip-bg); border: 1px solid var(--line); }
.tag { display: inline-block; background: var(--good); color: var(--on-good); font-size: 12px; font-weight: 700; padding: 3px 11px; border-radius: 999px; margin-bottom: 4px; }

/* hero + home */
.hero { text-align: center; padding: 36px 0 8px; }
.hero h1 { font-size: 34px; margin: 0 0 10px; }
.hero p { max-width: 640px; margin: 0 auto; color: var(--muted); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topic-card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin: 10px 0; text-decoration: none; color: inherit; transition: border-color 0.15s; }
.topic-card:hover { border-color: var(--accent); }
.topic-card h3 { margin: 0 0 6px; }
.snippet { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.meta { color: var(--muted); font-size: 13px; }
.meta a { color: inherit; }

/* topic page */
.topic-head { padding: 26px 0 0; }
.topic-head .desc { color: var(--muted); margin: 0 0 6px; max-width: 700px; }
.rule { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }

/* definitions */
.definition { display: flex; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 10px 0; }
.definition.is-accepted { border-color: var(--good-line); background: var(--good-bg); }
.definition.is-contested { opacity: 0.72; }
.def-main { flex: 1; min-width: 0; }
.def-body { overflow-wrap: break-word; }
.byline { color: var(--muted); font-size: 12.5px; margin-top: 10px; }
.byline a { color: inherit; font-weight: 600; }

.wikilink { color: var(--accent); text-decoration: none; border-bottom: 1px dashed currentColor; font-weight: 600; }
.wikilink.missing { color: var(--bad); }

.refs { margin-top: 10px; font-size: 13px; }
.refs-label { font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.refs ul { margin: 4px 0 0; padding-left: 18px; }
.refs .domain { color: var(--muted); margin-left: 7px; font-size: 12px; }

/* votes */
.vote { display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 34px; }
.vote-btn { background: none; border: none; cursor: pointer; font-size: 13px; color: #a3abbd; padding: 2px 7px; border-radius: 6px; line-height: 1; }
.vote-btn:hover { background: var(--hover-bg); color: var(--ink); }
.vote-btn.up.active { color: var(--up); }
.vote-btn.down.active { color: var(--down); }
.vote .score { font-weight: 700; font-size: 14px; }

/* comments */
.comment { display: flex; gap: 10px; padding-top: 12px; }
.comment .vote { min-width: 28px; }
.comment .vote-btn { font-size: 11px; padding: 1px 6px; }
.comment .score { font-size: 12.5px; }
.comment-main { flex: 1; min-width: 0; }
.comment-body { font-size: 14.5px; overflow-wrap: break-word; }
.children { border-left: 2px solid var(--line); margin-top: 4px; padding-left: 14px; }
.comment-form textarea { margin-bottom: 8px; }
.reply-form { margin-top: 8px; }
.reply-form textarea { margin-bottom: 6px; }
.hidden { display: none; }

/* backlinks + misc */
.backlinks ul { margin: 6px 0; padding-left: 20px; }
.mini-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin: 8px 0; }
.mini-card p { margin: 4px 0 0; font-size: 14px; }

.auth-card { max-width: 420px; margin: 44px auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.auth-card.wide { max-width: 560px; }
.auth-card h1 { font-size: 24px; }

footer.site-foot { border-top: 1px solid var(--line); margin-top: 48px; padding: 18px 0; color: var(--muted); font-size: 13px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--toast-bg); color: var(--toast-ink); padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25); z-index: 100; }

/* theme toggle */
.theme-toggle { font-size: 16px; line-height: 1; }
.theme-toggle::before { content: '\263E'; }
[data-theme="dark"] .theme-toggle::before { content: '\2600'; }

/* rating card */
.rating-card, .wallet-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin: 18px 0; }
.rep-row { display: flex; align-items: center; gap: 12px; margin: 4px 0 10px; }
.rep-num { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; }
.rating-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.rating-item { font-size: 13px; }
.rating-item b { display: block; margin-bottom: 3px; }
.rating-big { font-size: 18px; font-weight: 700; margin-right: 4px; }
.bar { background: var(--chip-bg); border-radius: 999px; height: 8px; overflow: hidden; margin: 5px 0; }
.bar .fill { background: var(--good); height: 100%; border-radius: 999px; }

/* wallet */
.wallet-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.wallet-balance { font-size: 24px; font-weight: 800; color: var(--wld); }
.wld { color: var(--wld); font-weight: 600; }
.tip-btn { color: var(--wld); font-weight: 600; }
.tip-btn:hover { color: var(--wld); }
.tx-head { font-size: 13px; margin: 14px 0 4px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.tx-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.tx-list li { padding: 5px 0; border-bottom: 1px solid var(--line); }
.tx-list li:last-child { border-bottom: none; }
.tx-amt { font-weight: 700; }
.tx-amt.in { color: var(--good); }
.tx-amt.out { color: var(--bad); }
.send-row { display: flex; gap: 8px; }
.send-row input[type="number"] { max-width: 110px; }
.wallet-card code { background: var(--chip-bg); padding: 2px 7px; border-radius: 6px; font-size: 12.5px; }

/* surveys */
.q-block { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; }
.q-head { display: flex; justify-content: space-between; align-items: center; }
.q-num { font-weight: 700; font-size: 13px; color: var(--muted); }
.survey-q { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; margin: 12px 0; }
.survey-q h3 { margin: 0 0 10px; font-size: 16px; }
.opt-row { margin: 8px 0; }
.opt-row.mine .opt-label { font-weight: 700; }
.opt-label { font-size: 14px; }
.opt-meta { font-size: 12.5px; }
.opt-choice { display: block; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; margin: 6px 0; font-size: 14px; cursor: pointer; }
.opt-choice:hover { border-color: var(--accent); }

/* edit / delete controls */
.linklike.danger { color: var(--bad); }
.linklike.danger:hover { color: var(--bad); text-decoration: underline; }
.edit-def-form, .edit-comment-form, .edit-topic-form { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
mark { background: #ffe066; color: inherit; padding: 0 1px; border-radius: 2px; }
[data-theme="dark"] mark { background: #6b5d1f; color: #fff; }
.comment.deleted > .comment-main > .comment-body { font-style: italic; }

/* social sign-in */
.oauth-block { margin: 4px 0 14px; }
.oauth-btns { display: flex; flex-direction: column; gap: 8px; }
.oauth-btn { background: var(--surface); color: var(--ink); border: 1px solid var(--line); text-align: center; }
.oauth-btn:hover { border-color: var(--accent); filter: none; }
.oauth-google { border-color: #4285f4; }
.oauth-facebook { border-color: #1877f2; }
.oauth-yahoo { border-color: #6001d2; }
.oauth-sep { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 14px 0 2px; }
.oauth-sep::before, .oauth-sep::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* moderation */
.mod-panel { margin-top: 8px; font-size: 13px; }
.mod-panel > summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.mod-panel > summary:hover { color: var(--ink); }
.mod-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.mod-form { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 5px 7px; background: var(--bg); }
.mod-form select, .mod-form input[type="text"] { font: inherit; font-size: 12px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); max-width: 130px; }
.definition.is-mod-hidden, .comment.is-mod-hidden > .comment-main { opacity: 0.6; outline: 1px dashed var(--bad); outline-offset: 2px; }
.mod-user { border-color: var(--bad); }
.modlog-wrap { overflow-x: auto; }
.modlog { width: 100%; border-collapse: collapse; font-size: 13px; }
.modlog th, .modlog td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.modlog th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }

/* connected accounts */
.conn-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin: 18px 0; }
.conn-list { list-style: none; margin: 6px 0 10px; padding: 0; font-size: 14px; }
.conn-list li { padding: 3px 0; }

/* idea map */
.map-section { margin-top: 20px; }
.map-legend { margin: 6px 0 12px; }
.map-legend .lg { display: inline-block; width: 11px; height: 11px; border-radius: 50%; vertical-align: -1px; margin: 0 2px 0 6px; }
.lg-consensus { background: var(--good-bg); border: 2px solid var(--good); }
.lg-contested { background: var(--error-bg); border: 2px solid var(--bad); }
.lg-empty { background: var(--chip-bg); border: 2px solid var(--muted); }
.lg-ghost { background: var(--surface); border: 2px dashed var(--bad); }
#map-wrap { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
#map { display: block; width: 100%; height: 72vh; min-height: 420px; cursor: grab; touch-action: none; }
#map.panning { cursor: grabbing; }
#map .edge { stroke: var(--map-edge); stroke-linecap: round; transition: opacity 0.2s; }
#map .edge.ghost-edge { stroke: var(--map-ghost-edge); stroke-dasharray: 5 5; }
#map .edge.dim { opacity: 0.1; }
#map .node { cursor: pointer; transition: opacity 0.2s; }
#map .node.dim { opacity: 0.22; }
#map .node .bubble { transition: transform 0.25s ease; transform-box: fill-box; transform-origin: center; }
#map .node.hover .bubble { transform: scale(1.85); }
#map .node circle { stroke-width: 2.5; }
#map .node text { fill: var(--ink); font-weight: 600; pointer-events: none; user-select: none; }
.state-consensus circle { fill: var(--good-bg); stroke: var(--good); }
.state-contested circle { fill: var(--error-bg); stroke: var(--bad); }
.state-empty circle { fill: var(--chip-bg); stroke: var(--muted); }
.state-ghost circle { fill: var(--surface); stroke: var(--bad); stroke-dasharray: 6 5; }
.state-ghost text { fill: var(--bad); }
#map-card { position: absolute; width: 300px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 30px var(--shadow); padding: 14px 16px; pointer-events: none; z-index: 5; }

/* member-made topic links */
#map .topic-link-edge { stroke: var(--accent); stroke-dasharray: none; opacity: 0.85; }
.lg-tl { display: inline-block; width: 16px; border-top: 3px solid var(--accent); vertical-align: 3px; margin: 0 2px 0 6px; }
#map .node.link-src circle { stroke: var(--accent); stroke-width: 5; }
#map.linking { cursor: crosshair; }
#link-bar { background: var(--chip-bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0 0 8px; font-size: 14px; }
#link-form { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); width: 320px; max-width: 92%; background: var(--surface); border: 1px solid var(--accent); border-radius: 12px; box-shadow: 0 12px 30px var(--shadow); padding: 14px 16px; z-index: 6; }
#link-form textarea { width: 100%; margin: 8px 0; }
.card-links-head { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; margin-top: 10px; }
.card-link { font-size: 13px; margin: 4px 0; }
.card-link-note { color: var(--ink); }
.card-link-del { margin-left: 6px; font-size: 12px; }
#map-card h3 { margin: 0 0 6px; font-size: 16px; }
#map-card p { margin: 8px 0 0; font-size: 13px; }
#map-card .meta { font-size: 12px; }
.map-empty { position: absolute; top: 50%; left: 0; right: 0; text-align: center; transform: translateY(-50%); }

@media (max-width: 700px) {
  /* On small screens the floating card would cover the hovered bubble —
     dock it to the bottom of the map instead. */
  #map-card { left: 10px !important; right: 10px; bottom: 10px; top: auto !important; width: auto; }
}

@media (max-width: 560px) {
  header.site .wrap { gap: 8px; }
  .search input { max-width: none; }
  .usernav .btn { display: none; }
  .hero h1 { font-size: 26px; }
}
