:root {
  --bg: #0f1413;
  --glass: rgba(18, 24, 23, 0.86);
  --glass-2: rgba(28, 36, 34, 0.9);
  --line: rgba(255, 255, 255, 0.09);
  --ink: #ece7db;
  --ink-2: #b9b6ac;
  --muted: #8d918b;
  --accent: #f2b35b;
  --accent-2: #ffd98a;
  --good: #7ccf8a;
  --warn: #f0b44c;
  --bad: #ef6f5e;
  --lie: #ff9ad0;
  --think: #cfd9ff;
  --radius: 12px;
  --panel-w: 400px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans); }
button { font: inherit; color: inherit; }
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; touch-action: none; }
#labels { position: fixed; inset: 0; pointer-events: none; }

/* ------------------------------------------------ top bar */
#topbar { position: fixed; top: 10px; left: 12px; right: calc(var(--panel-w) + 24px); display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; pointer-events: none; z-index: 5; }
.brand { display: flex; gap: 10px; align-items: center; background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; pointer-events: auto; backdrop-filter: blur(8px); }
.brand h1 { margin: 0; font: 600 16px/1.1 var(--serif); letter-spacing: 0.02em; }
.brand .sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.logo { color: var(--accent); font-size: 20px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; pointer-events: auto; }
.pill { background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; font-size: 12.5px; white-space: nowrap; backdrop-filter: blur(8px); }
.pill.mind { color: var(--accent-2); }
.pill.live i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); margin-right: 6px; vertical-align: 1px; }
.pill.live.ok i { background: var(--good); box-shadow: 0 0 8px var(--good); }
.pill.live.bad i { background: var(--bad); }

#hint { position: fixed; left: 12px; bottom: 12px; max-width: 460px; color: var(--ink-2); font-size: 12px; background: var(--glass); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; z-index: 4; transition: opacity 1s; }
#hint.gone { opacity: 0; pointer-events: none; }
#viewtools { position: fixed; right: calc(var(--panel-w) + 24px); bottom: 12px; display: flex; gap: 6px; z-index: 4; }
.tool { background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 12.5px; }
.tool.on { border-color: var(--accent); color: var(--accent-2); }
.tool:focus-visible, #tabs button:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------ panel */
#panel { position: fixed; top: 10px; right: 12px; bottom: 12px; width: var(--panel-w); background: var(--glass); border: 1px solid var(--line); border-radius: 16px; display: flex; flex-direction: column; z-index: 6; backdrop-filter: blur(10px); overflow: hidden; }
#grab { display: none; }
#tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--line); flex-shrink: 0; }
#tabs button { flex: 1 1 auto; min-width: 0; background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 6px 9px; color: var(--ink-2); cursor: pointer; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.view { display: none; flex: 1; overflow-y: auto; overflow-x: hidden; padding: 12px 14px 18px; overscroll-behavior: contain; }
.view.on { display: block; }
.muted { color: var(--muted); }
.legend { color: var(--muted); font-size: 12px; margin-bottom: 8px; }

/* feed */
#feed { list-style: none; margin: 0; padding: 0; }
#feed li { display: grid; grid-template-columns: 22px 1fr; gap: 8px; padding: 7px 4px; border-bottom: 1px solid var(--line); cursor: default; }
#feed li.click { cursor: pointer; }
#feed li.click:hover { background: rgba(255, 255, 255, 0.03); }
#feed .ic { font-size: 15px; text-align: center; }
#feed .when { color: var(--muted); font-size: 11.5px; margin-right: 6px; font-variant-numeric: tabular-nums; }
#feed .txt { overflow-wrap: anywhere; }
#feed li.imp3 .txt, #feed li.imp4 .txt { color: #fff; font-weight: 500; }
#feed li.imp0 { opacity: 0.62; }
#feed .secret { display: inline-block; font-size: 10.5px; color: var(--lie); border: 1px solid rgba(255, 154, 208, 0.4); border-radius: 6px; padding: 0 5px; margin-left: 4px; }

/* chronicle */
.chron { background: #efe6d0; color: #2c261c; border-radius: 10px; padding: 16px 18px; margin-bottom: 14px; font-family: var(--serif); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); }
.chron .mast { display: flex; justify-content: space-between; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: #6b5d45; border-bottom: 2px solid #2c261c; padding-bottom: 5px; margin-bottom: 8px; }
.chron h3 { font-size: 21px; line-height: 1.2; margin: 4px 0 10px; }
.chron p { margin: 0 0 9px; font-size: 14.5px; line-height: 1.5; }
.chron .src { font: 11px var(--sans); color: #7b6e57; }

/* people */
#people { list-style: none; margin: 0; padding: 0; }
#people li { display: grid; grid-template-columns: 14px 1fr auto; gap: 10px; align-items: center; padding: 8px 6px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 8px; }
#people li:hover { background: rgba(255, 255, 255, 0.04); }
#people .sw { width: 12px; height: 12px; border-radius: 4px; }
#people .who { min-width: 0; }
#people .who b { font-weight: 600; }
#people .act { color: var(--ink-2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#people .hp { width: 56px; height: 5px; background: rgba(255, 255, 255, 0.1); border-radius: 3px; overflow: hidden; }
#people .hp i { display: block; height: 100%; background: var(--good); }
#people li.dead { opacity: 0.45; }

/* badges */
.badge { display: inline-block; font-size: 10.5px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); margin-left: 6px; vertical-align: 1px; }
.badge.cheap { color: #9fd3ff; border-color: rgba(159, 211, 255, 0.35); }
.badge.smart { color: #ffd98a; border-color: rgba(255, 217, 138, 0.5); background: rgba(255, 200, 90, 0.08); }
.badge.mid { color: #c7b3ff; border-color: rgba(199, 179, 255, 0.4); }
.badge.mock { color: var(--muted); }
.badge.stranger { color: var(--bad); border-color: rgba(239, 111, 94, 0.4); }

/* agent view */
.ahead { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.ahead .sw { width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0; border: 2px solid rgba(255, 255, 255, 0.2); }
.ahead h2 { margin: 0; font: 600 20px/1.1 var(--serif); }
.ahead .meta { color: var(--ink-2); font-size: 12.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn { background: var(--glass-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 12.5px; }
.btn.on { border-color: var(--accent); color: var(--accent-2); }
.card { background: rgba(255, 255, 255, 0.035); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.card h4 { margin: 0 0 7px; font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.duo { display: grid; grid-template-columns: 1fr; gap: 6px; }
.q { border-radius: 10px; padding: 8px 10px; overflow-wrap: anywhere; }
.q.t { background: rgba(207, 217, 255, 0.08); color: var(--think); font-style: italic; }
.q.s { background: rgba(255, 255, 255, 0.07); }
.q.s.lie { box-shadow: inset 3px 0 0 var(--lie); }
.q .lbl { display: block; font-style: normal; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.bars { display: grid; grid-template-columns: 62px 1fr 30px; gap: 5px 8px; align-items: center; font-size: 12.5px; }
.bar { height: 7px; background: rgba(255, 255, 255, 0.09); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; }
.num { color: var(--ink-2); font-variant-numeric: tabular-nums; text-align: right; font-size: 12px; }
.traits { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 14px; font-size: 12px; }
.traits .tr { display: grid; grid-template-columns: 84px 1fr; gap: 6px; align-items: center; }
.traits .bar { height: 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); }
.chip.hot { border-color: var(--accent); color: var(--accent-2); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 13px; overflow-wrap: anywhere; }
.list li:last-child { border-bottom: 0; }
.list .d { color: var(--muted); font-size: 11px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.rel { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.rel:last-child { border-bottom: 0; }
.rel .nm { font-weight: 600; cursor: pointer; }
.rel .em { font-size: 12px; color: var(--ink-2); text-align: right; }
.rel .note { grid-column: 1 / -1; color: var(--muted); font-size: 12px; font-style: italic; }
.truth { font-size: 11px; margin-left: 5px; }
.truth.t { color: var(--good); }
.truth.f { color: var(--bad); }

/* discoveries */
.tree-graph { width: 100%; }
.tree-graph svg { width: 100%; height: auto; display: block; }
.tnode rect { rx: 8px; }
.study-row { padding: 7px 0; border-bottom: 1px dashed var(--line); }
.study-row:last-child { border-bottom: 0; }
.study-row .v { font-style: italic; color: var(--think); overflow-wrap: anywhere; }

/* 3D labels */
.tag { transform: translateY(-4px); font-size: 11.5px; font-weight: 600; color: #fff; background: rgba(12, 16, 15, 0.62); padding: 1px 7px; border-radius: 999px; white-space: nowrap; transition: opacity 0.3s; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
.tag.sel { background: rgba(242, 179, 91, 0.9); color: #1b1408; text-shadow: none; }
.tag .zz { font-weight: 400; opacity: 0.8; }
.bubanchor { width: 0; height: 0; position: relative; }
.bubbles { position: absolute; left: 0; bottom: 6px; width: max-content; max-width: 230px; display: flex; flex-direction: column; gap: 4px; align-items: center; opacity: 0; transform: translate(-50%, 8px); transition: opacity 0.45s ease, transform 0.45s ease; }
.bubbles.on { opacity: 1; transform: translate(-50%, 0); }
.bub { max-width: 230px; font-size: 12px; line-height: 1.35; padding: 5px 9px; border-radius: 12px; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3); overflow-wrap: anywhere; }
.bub.thought { background: rgba(232, 236, 255, 0.92); color: #273052; font-style: italic; border-radius: 16px; }
.bub.say { background: #fffaf0; color: #20190f; }
.bub.say.lie { box-shadow: 0 0 0 2px var(--lie), 0 3px 10px rgba(0, 0, 0, 0.3); }
.bub .ic { font-style: normal; }
.liemark { font-style: normal; }

#loading { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; background: var(--bg); z-index: 20; transition: opacity 0.6s; }
#loading.gone { opacity: 0; pointer-events: none; }
.spinner { width: 34px; height: 34px; border: 3px solid rgba(255, 255, 255, 0.15); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 12px; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.noscript { position: fixed; inset: 0; display: grid; place-content: center; }

/* ------------------------------------------------ phone: bottom sheet */
@media (max-width: 760px) {
  :root { --panel-w: 0px; }
  #topbar { left: 8px; right: 8px; top: 8px; flex-direction: column; gap: 6px; }
  .brand { padding: 6px 10px; }
  .brand .sub { display: none; }
  .pills { justify-content: flex-start; }
  .pill { padding: 3px 8px; font-size: 11.5px; }
  #hint { display: none; }
  #viewtools { right: 8px; bottom: auto; top: 96px; flex-direction: column; }
  #panel { left: 0; right: 0; bottom: 0; top: auto; width: auto; height: 46vh; border-radius: 16px 16px 0 0; border-bottom: 0; transition: height 0.25s ease; padding-bottom: env(safe-area-inset-bottom); }
  #panel.min { height: 92px; }
  #panel.max { height: 82vh; }
  #grab { display: block; padding: 7px 0 2px; cursor: grab; touch-action: none; }
  #grab span { display: block; width: 42px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.3); margin: 0 auto; }
  #tabs { padding-top: 2px; }
  #tabs button { font-size: 12.5px; padding: 7px 3px 8px; }
  .traits { grid-template-columns: 1fr; }
  .bubbles, .bub { max-width: 170px; }
  .bub { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  .bubbles, #panel, .tag { transition: none; }
}
