:root {
  --glass: rgba(22, 19, 30, 0.72);
  --glass-2: rgba(30, 26, 40, 0.78);
  --glass-line: rgba(255, 255, 255, 0.09);
  --text: #f4ecdf;
  --muted: #b9ad9c;
  --coral: #ff8c69;
  --gold: #ffd36b;
  --sky: #7fb2e6;
  --mint: #8fd3a0;
  --rose: #ff7aa2;
  --lav: #b7a6ff;
  --radius: 16px;
  --ui: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: #1a2a1c; color: var(--text); font-family: var(--ui); overflow: hidden; }

#world { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; cursor: grab; touch-action: none; }
#world.dragging { cursor: grabbing; }
#world.hover-agent { cursor: pointer; }

/* ---------- glass HUD ---------- */
.hud {
  position: fixed; z-index: 10;
  background: var(--glass); backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--glass-line); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.06);
  color: var(--text);
}
/* the three top panels live in one flex row so they can never overlap; they wrap if space is tight */
#topbar { position: fixed; top: 16px; left: 16px; right: 16px; z-index: 10; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; pointer-events: none; }
#topbar > .hud { position: static; pointer-events: auto; }
.hud-tl { padding: 12px 14px; display: flex; gap: 16px; align-items: center; }
.hud-tc { padding: 8px; display: flex; gap: 6px; align-items: center; }
.hud-tr { padding: 10px; display: flex; gap: 8px; align-items: stretch; }
.hud-bl { bottom: 16px; left: 16px; width: 300px; max-height: 24vh; display: flex; flex-direction: column; overflow: hidden; }
.hud-bc { bottom: 16px; left: 50%; transform: translateX(-50%); padding: 8px 12px; display: flex; gap: 10px; align-items: center; width: min(560px, 46vw); }

/* brand + clock */
.brand { display: flex; align-items: center; gap: 10px; padding-right: 14px; border-right: 1px solid var(--glass-line); }
.brand-mark { width: 34px; height: 34px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffd36b, #ff8c69 60%, #c8473a); box-shadow: 0 0 0 3px rgba(255,211,107,.18); position: relative; }
.brand-mark span { position: absolute; inset: 9px; border-radius: 50%; border: 2.5px solid rgba(30,20,10,.55); }
.brand-title { font-family: var(--display); font-weight: 900; letter-spacing: 4px; font-size: 18px; line-height: 1; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 3px; }
.clock { display: flex; align-items: center; gap: 10px; }
#sky { width: 56px; height: 56px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(255,255,255,.08), 0 4px 14px rgba(0,0,0,.35); }
.clock-time { font-family: var(--display); font-weight: 700; font-size: 26px; line-height: 1; font-variant-numeric: tabular-nums; }
.clock-day { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* controls */
.ctl {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px;
  border-radius: 11px; border: 1px solid var(--glass-line); background: rgba(255,255,255,.05);
  color: var(--text); font-family: var(--ui); font-weight: 700; font-size: 13px; cursor: pointer;
  transition: background .15s, transform .08s, border-color .15s;
}
.ctl:hover { background: rgba(255,255,255,.11); }
.ctl:active { transform: translateY(1px); }
.ctl .ic { width: 16px; height: 16px; fill: currentColor; }
.ctl.primary { background: linear-gradient(135deg, #8fd3a0, #5cb87a); color: #0f2416; border-color: transparent; }
.ctl.primary:hover { filter: brightness(1.06); }
.ctl.accent { background: linear-gradient(135deg, #ff9f7f, #ff6f8f); color: #2a0c10; border-color: transparent; }
.ctl.accent:hover { filter: brightness(1.06); }
.ctl.on { background: rgba(255,211,107,.18); border-color: rgba(255,211,107,.45); color: var(--gold); }
.ctl.speed { gap: 8px; padding-right: 10px; }
.ctl.speed input { width: 92px; accent-color: var(--gold); }
.ctl.speed span { min-width: 30px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
#btn-play .ic-pause { display: none; }
#btn-play.playing .ic-play { display: none; }
#btn-play.playing .ic-pause { display: inline; }
.ctl.eval { align-self: center; background: rgba(183,166,255,.14); border-color: rgba(183,166,255,.35); color: #d9d0ff; }

/* metrics */
.metric { padding: 8px 12px; border-radius: 12px; background: rgba(255,255,255,.04); border: 1px solid var(--glass-line); min-width: 92px; display: flex; flex-direction: column; justify-content: center; }
.metric.big { min-width: 170px; }
.metric-k { font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 700; }
.metric-v { font-family: var(--display); font-size: 22px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.metric-of { font-size: 13px; color: var(--muted); margin-left: 4px; font-family: var(--ui); font-weight: 600; }
.bar { height: 6px; border-radius: 4px; background: rgba(255,255,255,.08); margin-top: 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; border-radius: 4px; background: linear-gradient(90deg, var(--rose), var(--gold)); transition: width .4s ease; }

/* gazette */
.gz-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 8px; border-bottom: 1px solid var(--glass-line); }
.gz-title { font-family: var(--display); font-weight: 700; font-size: 15px; letter-spacing: .3px; }
.gz-toggle { background: none; border: 1px solid var(--glass-line); color: var(--muted); width: 24px; height: 24px; border-radius: 7px; cursor: pointer; }
.gz-list { overflow-y: auto; padding: 6px 10px 10px; font-size: 12.5px; line-height: 1.45; scrollbar-width: thin; }
#gazette.collapsed .gz-list { display: none; }
.gz-item { display: grid; grid-template-columns: 52px 8px 1fr; gap: 8px; align-items: start; padding: 5px 4px; border-bottom: 1px dashed rgba(255,255,255,.06); }
.gz-item .t { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11px; padding-top: 2px; }
.gz-item .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; background: var(--mint); }
.gz-item.kind-reflection .dot { background: var(--lav); }
.gz-item.kind-party_seed .dot { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.gz-item.kind-party_seed .tx { color: var(--gold); font-weight: 700; }
.gz-item.hl .dot { background: var(--rose); box-shadow: 0 0 8px var(--rose); }
.gz-item.hl .tx { color: #ffd0dc; }
.gz-item.hl .tx::before { content: "✦ "; color: var(--gold); }

/* timeline */
.live { height: 28px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--glass-line); background: rgba(255,255,255,.05); color: var(--muted); font-weight: 800; font-size: 11px; cursor: pointer; letter-spacing: .5px; font-family: var(--ui); }
.live.on { background: rgba(255,110,110,.18); border-color: rgba(255,110,110,.5); color: #ff9c9c; }
#timeline { flex: 1; accent-color: var(--gold); }
#timeline-label { font-size: 12px; color: var(--muted); min-width: 78px; text-align: right; font-variant-numeric: tabular-nums; }

/* hint */
.hint { position: fixed; z-index: 9; bottom: 64px; left: 50%; transform: translateX(-50%); padding: 7px 14px; border-radius: 20px; background: rgba(0,0,0,.45); color: #fff; font-size: 12px; opacity: .9; transition: opacity .6s; pointer-events: none; }
.hint.gone { opacity: 0; }

/* ---------- inspector drawer ---------- */
#inspector {
  position: fixed; z-index: 12; top: 16px; right: 16px; bottom: 16px; width: 400px;
  background: var(--glass-2); backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid var(--glass-line); border-radius: 18px; box-shadow: 0 16px 50px rgba(0,0,0,.45);
  padding: 18px 18px 22px; overflow-y: auto; scrollbar-width: thin;
  transform: translateX(calc(100% + 24px)); transition: transform .28s cubic-bezier(.2,.8,.2,1);
}
#inspector.open { transform: translateX(0); }
.insp-close { position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; border-radius: 9px; border: 1px solid var(--glass-line); background: rgba(255,255,255,.05); color: var(--muted); cursor: pointer; }
.insp-head { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; }
.insp-portrait { width: 84px; height: 84px; border-radius: 22px; flex: none; box-shadow: 0 8px 20px rgba(0,0,0,.35); }
.insp-name { font-family: var(--display); font-weight: 900; font-size: 22px; line-height: 1.05; }
.insp-role { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.insp-traits { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: rgba(255,255,255,.07); border: 1px solid var(--glass-line); color: var(--text); }
.chip.loc { color: var(--gold); border-color: rgba(255,211,107,.35); }
.insp-section { margin-top: 16px; }
.insp-section h4 { margin: 0 0 8px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.1px; color: var(--muted); font-weight: 800; display: flex; align-items: center; gap: 8px; }
.insp-section h4::after { content: ""; flex: 1; height: 1px; background: var(--glass-line); }
.thought { position: relative; padding: 12px 14px 12px 16px; border-radius: 14px; background: linear-gradient(135deg, rgba(255,140,105,.16), rgba(255,211,107,.08)); border: 1px solid rgba(255,140,105,.3); font-size: 14px; font-weight: 600; line-height: 1.4; }
.thought::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--coral); }
.going { margin-top: 8px; font-size: 12px; color: var(--muted); }
.going b { color: var(--gold); }

.plan { position: relative; padding-left: 18px; }
.plan::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: rgba(255,255,255,.1); border-radius: 2px; }
.plan-step { position: relative; display: grid; grid-template-columns: 46px 1fr; gap: 8px; padding: 4px 0; font-size: 12.5px; color: var(--muted); }
.plan-step::before { content: ""; position: absolute; left: -16px; top: 9px; width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,.22); }
.plan-step .pt { font-variant-numeric: tabular-nums; color: var(--sky); font-weight: 700; }
.plan-step.done { opacity: .55; }
.plan-step.now { color: var(--text); font-weight: 700; }
.plan-step.now::before { background: var(--mint); box-shadow: 0 0 0 4px rgba(143,211,160,.2); }
.plan-step.event .pt { color: var(--rose); }

.legend { display: flex; gap: 12px; font-size: 10.5px; color: var(--muted); margin-bottom: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.mem { padding: 9px 10px; border-radius: 12px; background: rgba(255,255,255,.04); border: 1px solid var(--glass-line); margin-bottom: 7px; }
.mem-text { font-size: 12.5px; line-height: 1.45; }
.mem-meta { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.badge { font-size: 10px; padding: 1px 7px; border-radius: 20px; border: 1px solid var(--glass-line); color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.badge.kind-observation { color: #a8d8ff; border-color: rgba(168,216,255,.35); }
.badge.kind-dialogue { color: var(--mint); border-color: rgba(143,211,160,.4); }
.badge.kind-plan { color: var(--gold); border-color: rgba(255,211,107,.4); }
.badge.kind-reflection { color: var(--lav); border-color: rgba(183,166,255,.4); }
.bars { display: flex; gap: 3px; flex: 1; align-items: center; }
.bars .b { height: 6px; border-radius: 3px; min-width: 2px; }
.bars .rec { background: var(--sky); } .bars .imp { background: var(--coral); } .bars .rel { background: var(--mint); }
.score { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.refl { padding: 8px 10px; border-left: 3px solid var(--lav); background: rgba(183,166,255,.08); border-radius: 0 10px 10px 0; font-size: 12.5px; margin-bottom: 6px; font-style: italic; }
.rel-list { display: flex; flex-direction: column; gap: 6px; }
.rel { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.rel .sw { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.rel b { color: var(--text); }
.rel span { color: var(--muted); }
.story { font-size: 12.5px; color: var(--muted); line-height: 1.55; }

/* ---------- eval modal ---------- */
#eval-modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; }
.modal-card { background: var(--glass-2); border: 1px solid var(--glass-line); border-radius: 18px; width: min(820px, 92vw); max-height: 86vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--glass-line); font-family: var(--display); font-weight: 700; font-size: 17px; }
.modal-head button { background: none; border: 1px solid var(--glass-line); color: var(--muted); width: 30px; height: 30px; border-radius: 9px; cursor: pointer; }
#eval-content { padding: 18px; overflow-y: auto; font-size: 13px; }
.eval-headline { display: flex; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.eval-stat { flex: 1; min-width: 150px; background: rgba(255,255,255,.05); border: 1px solid var(--glass-line); border-radius: 14px; padding: 12px 16px; }
.eval-stat .n { font-family: var(--display); font-size: 32px; font-weight: 900; }
.eval-stat .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; }
.eval-stat.good .n { color: var(--mint); } .eval-stat.warn .n { color: var(--gold); }
#eval-content details { border: 1px solid var(--glass-line); border-radius: 12px; padding: 8px 12px; margin-bottom: 8px; background: rgba(255,255,255,.03); }
#eval-content summary { cursor: pointer; font-weight: 700; display: flex; align-items: center; gap: 10px; }
#eval-content summary .sw { width: 10px; height: 10px; border-radius: 50%; }
#eval-content summary .pct { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.eval-row { border-top: 1px dashed rgba(255,255,255,.08); padding: 8px 0; }
.eval-row .q { color: var(--muted); font-size: 12px; }
.eval-row .a { margin: 3px 0; line-height: 1.45; }
.eval-row .s { font-size: 11px; color: var(--muted); }
.eval-row .s .bad { color: var(--rose); font-weight: 700; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.2); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- responsive: shed labels/cards before anything can collide ---------- */
@media (max-width: 1600px) {
  .ctl:not(.primary):not(.speed) .lbl { display: none; }   /* icon-only Step/Seed/Follow/Reset/Eval */
  .ctl.speed input { width: 72px; }
}
@media (max-width: 1400px) {
  .hud-tr .metric:has(#m-cache) { display: none; }
  .metric.big { min-width: 150px; }
  .brand-sub { display: none; }
}
@media (max-width: 1320px) {
  .hud-tr .metric:has(#m-calls) { display: none; }
  .clock-time { font-size: 22px; }
}
@media (max-width: 1000px) {
  .hud-tr .metric:not(.big) { display: none; }
  .hud-bl { width: 300px; }
}
@media (max-width: 820px) {
  .hud-bc { bottom: 16px; width: 94vw; }
  .hud-bl { display: none; }
  #inspector { width: 92vw; top: auto; height: 62vh; }
}
