:root {
  --bg: #0f1a14;
  --panel: #16241b;
  --panel2: #1d3025;
  --line: #2a4232;
  --ink: #eef4e8;
  --ink2: #c3cfc4;
  --muted: #93a896;
  --accent: #f2b441;
  --mem: #7de8ff;
  --brain: #3987e5;
  /* outcome colors: validated categorical slots (dark) */
  --o-blocked: #d95926;
  --o-move: #199e70;
  --o-collision: #c98500;
  --o-ride: #3987e5;
  --o-harvest: #d55181;
  --drawer-h: 78px;
  --board: min(calc(100vw - 16px), calc(100svh - 250px), 720px);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 700px at 30% 0%, #1f3b29 0%, var(--bg) 60%) fixed;
  color: var(--ink);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  overflow-x: hidden;
  padding-bottom: calc(var(--drawer-h) + env(safe-area-inset-bottom) + 12px);
  -webkit-tap-highlight-color: transparent;
}
button, select { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
kbd { background: #2c4434; border-radius: 4px; padding: 0 5px; font-size: 11px; border-bottom: 2px solid #1a2a20; margin-right: 2px; }

/* ------------------------------------------------ header + ticker */
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
.brand { display: flex; align-items: center; gap: 9px; margin-right: auto; min-width: 0; flex: 1 1 auto; }
.brand > div { min-width: 0; }
.brand h1 { font-size: 16px; margin: 0; letter-spacing: .3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand p { margin: 0; color: var(--muted); font-size: 11.5px; display: none; }
.logo {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 10%, #86b6ef 24%, #2a78d6 62%, #0d366b 100%);
  box-shadow: 0 0 12px #3987e580, 0 3px 6px #0008;
}
.me { display: flex; align-items: center; gap: 7px; background: var(--panel2); padding: 4px 10px 4px 5px; border-radius: 999px; min-width: 0; flex: 0 1 auto; max-width: 42vw; }
.me > div { min-width: 0; overflow: hidden; }
.me b { font-size: 12.5px; white-space: nowrap; }
.me small { display: block; color: var(--muted); font-size: 10.5px; white-space: nowrap; }
.me-ball { flex: none; width: 22px; height: 22px; border-radius: 50%; background: #888; box-shadow: 0 2px 4px #0008; }
.guide-btn {
  display: flex; align-items: center; gap: 6px; border: 1px solid #3a5a45; background: var(--panel2);
  color: var(--ink); border-radius: 999px; padding: 4px 6px; flex: none;
}
.guide-btn span { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #2a1a00; font-weight: 800; }
.guide-btn em { font-style: normal; display: none; padding-right: 6px; }
.guide-btn:hover { background: #2b4735; }

.ticker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 0 8px 8px; }
@media (min-width: 700px) { .ticker { display: flex; justify-content: center; } }
.ticker::-webkit-scrollbar { display: none; }
.ticker div { min-width: 0; text-align: center; background: #0e1812; border: 1px solid var(--line); border-radius: 10px; padding: 3px 6px; }
.ticker b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.ticker small { color: var(--muted); font-size: 9.5px; text-transform: uppercase; letter-spacing: .5px; white-space: nowrap; }

/* ------------------------------------------------ layout */
.stage { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 0 8px; }
.board-col { width: 100%; display: flex; justify-content: center; }
.board-wrap { position: relative; padding: 0; }
.board-frame {
  position: relative; width: var(--board); height: var(--board);
  border-radius: 14px; overflow: hidden; touch-action: none;
  box-shadow: 0 0 0 4px #3b2a18, 0 0 0 6px #22170c, 0 18px 36px #000a;
}
#board { display: block; width: 100%; height: 100%; cursor: grab; }
#board.panning { cursor: grabbing; }
#board.placing { cursor: crosshair; }
.pan { display: none; }
.panel { width: 100%; max-width: 720px; }

@media (min-width: 700px) {
  .brand p { display: block; }
  .guide-btn em { display: inline; }
  .board-wrap { padding: 28px; }
  .pan {
    display: block; position: absolute; z-index: 5; border: 0; border-radius: 10px;
    background: #24392b; color: #cfe5d2; width: 44px; height: 22px; opacity: .8;
  }
  .pan:hover { background: #33563f; opacity: 1; }
  .pan-up { top: 2px; left: 50%; margin-left: -22px; }
  .pan-down { bottom: 2px; left: 50%; margin-left: -22px; }
  .pan-left, .pan-right { top: 50%; margin-top: -22px; width: 22px; height: 44px; }
  .pan-left { left: 2px; }
  .pan-right { right: 2px; }
  :root { --board: min(calc(100vw - 72px), calc(100svh - 260px), 720px); }
}
@media (min-width: 1100px) {
  :root { --board: min(calc(100vw - 520px), calc(100svh - 200px), 760px); }
  .stage { flex-direction: row; align-items: flex-start; justify-content: center; gap: 18px; }
  .board-col { width: auto; position: sticky; top: 8px; }
  .panel { width: 420px; max-height: calc(100svh - 150px); overflow-y: auto; border-radius: 14px; }
  .ticker { justify-content: center; }
  .ticker div { flex: 0 0 auto; min-width: 92px; }
}

/* ------------------------------------------------ board overlays */
.coord {
  position: absolute; left: 8px; top: 8px; padding: 2px 8px; border-radius: 8px;
  background: #0009; color: #e6f2e6; font-size: 11px; pointer-events: none;
}
.tooltip {
  position: absolute; pointer-events: none; padding: 6px 9px; border-radius: 8px; max-width: 80%;
  background: #0b140fe6; border: 1px solid #365a42; font-size: 12px; z-index: 6;
}
.tooltip b { color: var(--accent); }
.offscreen {
  position: absolute; z-index: 4; padding: 3px 10px; border-radius: 999px; font-size: 12px;
  background: #000a; border: 1px solid #fff3; cursor: pointer; white-space: nowrap;
}
.brain-off { background: #1c5caccc; border-color: #9ec5f4; }
.follow-chip {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 8px; z-index: 6;
  background: #1c5cabee; border: 1px solid #9ec5f4; border-radius: 999px; padding: 4px 6px 4px 12px;
  font-size: 12px; display: flex; gap: 8px; align-items: center; white-space: nowrap;
}
.follow-chip button { border: 0; border-radius: 999px; background: #fff2; color: #fff; padding: 2px 8px; }
.board-btns { position: absolute; top: 8px; right: 8px; z-index: 8; display: flex; gap: 6px; }
.board-btns button {
  display: flex; align-items: center; gap: 6px; border: 1px solid #ffffff40; border-radius: 999px;
  padding: 6px 11px; font-size: 12.5px; font-weight: 600; color: #fff; background: #0b1410cc;
  box-shadow: 0 4px 12px #0007; backdrop-filter: blur(4px); touch-action: manipulation;
}
.board-btns button:active { transform: scale(.95); }
#fabBrain { background: linear-gradient(#2f6fd6, #1d4fa8); border-color: #9cc4ff80; }
.fab-dot { width: 12px; height: 12px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff 0 12%, #9fc8ff 35%, #2a5bc0 100%); box-shadow: 0 0 8px #9fc8ff; animation: think 1.6s ease-in-out infinite; }
@keyframes think { 50% { box-shadow: 0 0 2px #4d8bff; } }

.radial { position: absolute; width: 0; height: 0; z-index: 7; }
.radial button {
  position: absolute; width: 40px; height: 40px; margin: -20px 0 0 -20px; border-radius: 50%;
  border: 2px solid #fff; background: #1c2d22ee; color: #fff; font-size: 20px; font-weight: 700;
  box-shadow: 0 4px 10px #0009; animation: pop .22s cubic-bezier(.3,1.6,.5,1) both;
}
.radial button:hover { background: var(--accent); color: #231400; }
.radial .r-up { left: 0; top: -54px; }
.radial .r-down { left: 0; top: 54px; }
.radial .r-left { left: -54px; top: 0; }
.radial .r-right { left: 54px; top: 0; }
@keyframes pop { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ------------------------------------------------ panel + tabs */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.tabs {
  display: flex; position: sticky; top: 0; z-index: 3; background: var(--panel);
  border-bottom: 1px solid var(--line); border-radius: 14px 14px 0 0; padding: 4px;
}
.tab {
  flex: 1; border: 0; background: transparent; color: var(--muted); padding: 9px 6px; border-radius: 10px;
  font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.tab.active { background: var(--panel2); color: var(--ink); }
.badge { font-size: 11px; background: #1c5cab; color: #fff; border-radius: 999px; padding: 0 7px; font-weight: 700; }
.badge:empty { display: none; }
.badge.dot { width: 8px; height: 8px; padding: 0; background: var(--accent); }
.tab-body { padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.tab-body[hidden] { display: none; }
.card-lite { background: #0f1a13; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.card-lite h3 { margin: 0; font-size: 13.5px; }
.card-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.card-head small { color: var(--muted); font-size: 11.5px; }
.card-head select { margin-left: auto; background: var(--panel2); color: var(--ink); border: 1px solid #3a5a45; border-radius: 8px; padding: 3px 6px; font-size: 12px; }
.rules { margin: 8px 0 0; padding-left: 18px; color: var(--ink2); font-size: 13px; }
.rules li { margin-bottom: 6px; }
.row-btns { display: flex; gap: 8px; margin-top: 10px; }
.row-btns button {
  flex: 1; border: 1px solid #3a5a45; background: var(--panel2); color: var(--ink);
  padding: 8px 10px; border-radius: 9px;
}
.row-btns button:hover { background: #2b4735; }
.row-btns button.primary { background: var(--accent); color: #2a1a00; border-color: #ffd27a; font-weight: 600; }
.row-btns button.blue { background: #1c5cab; border-color: #5598e7; color: #fff; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.kpi { background: #0f1a13; border: 1px solid var(--line); border-radius: 10px; padding: 7px 6px; text-align: center; min-width: 0; }
.kpi b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; color: var(--ink); line-height: 1.2; }
.kpi small { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi i { font-style: normal; color: var(--ink2); font-size: 11px; }

/* population chart */
.chart-card { margin: 0; background: #0f1a13; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 6px; }
.chart-card figcaption { font-size: 13.5px; font-weight: 600; margin-bottom: 4px; }
.chart-card figcaption small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.chart { position: relative; height: 120px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid line { stroke: #ffffff14; stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 10px; }
.chart .line { fill: none; stroke: var(--brain); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: #3987e51f; }
.chart .cross { stroke: #ffffff55; stroke-width: 1; }
.chart .dot { fill: var(--brain); stroke: #0f1a13; stroke-width: 2; }
.chart-tip {
  position: absolute; pointer-events: none; transform: translate(-50%, -110%); white-space: nowrap;
  background: #0b140ff0; border: 1px solid #365a42; border-radius: 8px; padding: 4px 8px; font-size: 11.5px; color: var(--ink);
}
.chart-empty { color: var(--muted); font-size: 12px; display: grid; place-items: center; height: 100%; }

/* lineages */
.lineages { display: flex; flex-direction: column; gap: 6px; }
.lin { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; font-size: 12.5px; }
.lin .sw { width: 12px; height: 12px; border-radius: 50%; }
.lin .bar { height: 8px; border-radius: 4px; background: #ffffff10; overflow: hidden; margin-top: 3px; }
.lin .bar span { display: block; height: 100%; background: #5598e7; border-radius: 4px; }
.lin .meta { color: var(--muted); font-size: 11.5px; text-align: right; white-space: nowrap; }

/* brain list */
.brain-list { display: flex; flex-direction: column; gap: 4px; }
.brain-row {
  display: grid; grid-template-columns: 18px minmax(0, 1fr) 76px 40px; gap: 8px; align-items: center;
  padding: 7px 6px; border-radius: 9px; cursor: pointer; border: 1px solid transparent;
}
.brain-row:hover { background: #ffffff08; }
.brain-row.sel { background: #1c5cab26; border-color: #2a78d6; }
.brain-row .orb { width: 16px; height: 16px; border-radius: 50%; box-shadow: 0 0 6px #3987e5aa; }
.brain-row .nm { min-width: 0; }
.brain-row .nm b { display: block; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brain-row .nm small { color: var(--muted); font-size: 11px; white-space: nowrap; }
.ebar { height: 8px; border-radius: 4px; background: #ffffff12; overflow: hidden; }
.ebar span { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, #1c5cab, #5598e7); transition: width .6s; }
.ebar.low span { background: #9a4a2a; }
.etext { font-size: 10.5px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.acc { text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink2); }
.brain-detail { padding: 8px 6px 12px 32px; border-bottom: 1px dashed var(--line); margin-bottom: 4px; }
.brain-detail h4 { margin: 10px 0 6px; font-size: 12px; color: var(--ink2); text-transform: uppercase; letter-spacing: .5px; }
.brain-detail h4:first-child { margin-top: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.stat-grid div { background: #ffffff07; border-radius: 8px; padding: 4px; text-align: center; }
.stat-grid b { display: block; font-size: 14px; font-variant-numeric: tabular-nums; }
.stat-grid small { font-size: 9.5px; color: var(--muted); text-transform: uppercase; }
.pred-grid { display: grid; grid-template-columns: 22px 1fr 42px; gap: 4px 8px; align-items: center; font-size: 12px; }
.pred-grid .dir { text-align: center; font-weight: 700; color: var(--ink2); }
.pred-grid .dir.chosen { color: #fff; background: #2a78d6; border-radius: 6px; }
.pred-grid .bar { display: flex; gap: 2px; height: 12px; }
.pred-grid .bar span { display: block; height: 100%; border-radius: 3px; min-width: 0; }
.pred-grid .val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.o-blocked { background: var(--o-blocked); } .o-move { background: var(--o-move); } .o-collision { background: var(--o-collision); } .o-ride { background: var(--o-ride); } .o-harvest { background: var(--o-harvest); }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--ink2); margin: 6px 0 0; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.verdict { margin-top: 6px; font-size: 12.5px; color: var(--ink2); }
.verdict .ok { color: #7fd48a; } .verdict .miss { color: #f0a08a; }
.genes { display: grid; grid-template-columns: 76px 1fr 38px; gap: 3px 8px; align-items: center; font-size: 11.5px; }
.genes .g { color: var(--ink2); }
.genes .gbar { height: 6px; background: #ffffff10; border-radius: 3px; position: relative; }
.genes .gbar span { position: absolute; top: 0; bottom: 0; background: #86b6ef; border-radius: 3px; }
.genes .gv { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* feed */
.feed { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.feed li { padding: 8px 2px; border-bottom: 1px dashed var(--line); animation: feedIn .35s ease both; display: flex; gap: 8px; align-items: baseline; }
.feed li time { color: var(--muted); font-size: 11px; margin-left: auto; white-space: nowrap; }
.feed .dot { flex: none; display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.feed .mem { color: var(--mem); }
.feed li.go { cursor: pointer; }
.feed li.go:hover { background: #ffffff06; }
@keyframes feedIn { from { opacity: 0; transform: translateX(-8px); } }

/* ------------------------------------------------ drawer: ball + arrows */
.drawer {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 15;
  width: min(560px, 100vw);
  animation: drawerOpen .7s cubic-bezier(.2,1.2,.4,1) .2s both;
}
@keyframes drawerOpen { from { transform: translate(-50%, 110%); } }
.drawer-inner {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  background: repeating-linear-gradient(92deg, #0000 0 18px, #0000000d 18px 20px), linear-gradient(#8a5a33, #5c3a1f);
  box-shadow: inset 0 3px 0 #b07c4a, inset 0 -6px 12px #0005, 0 -8px 24px #0008;
}
.slot { display: flex; align-items: center; gap: 8px; background: #0000002e; padding: 6px 8px; border-radius: 12px; box-shadow: inset 0 3px 8px #0007; }
.slot-label { font-size: 11.5px; color: #f7e6cf; line-height: 1.25; display: none; }
.slot-label small { color: #d8bf9f; }
.token {
  width: 50px; height: 50px; border-radius: 12px; display: grid; place-items: center; position: relative;
  background: linear-gradient(#fbf3e4, #e2d3b7); box-shadow: 0 4px 0 #b39c77, 0 6px 10px #0006;
  cursor: grab; transition: transform .15s, box-shadow .15s, opacity .2s; touch-action: none;
}
.token:hover { transform: translateY(-3px) rotate(-2deg); }
.token.disabled { opacity: .35; pointer-events: none; filter: grayscale(.6); }
.arrow-token svg { width: 32px; height: 32px; }
.arrow-token path { fill: #e8543f; stroke: #7a1d10; stroke-width: 2; stroke-linejoin: round; }
.sphere { width: 34px; height: 34px; border-radius: 50%; display: block; box-shadow: 0 4px 6px #0007; }
.ball-token.placed { opacity: .7; cursor: pointer; }
.ball-token.placed .sphere { filter: saturate(.5); }
.ball-token.placed::after {
  content: "↺"; position: absolute; right: -6px; top: -6px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font-size: 14px; font-weight: 800; color: #2a1a00;
  background: var(--accent); box-shadow: 0 2px 4px #0007;
}
@media (min-width: 520px) { .slot-label { display: block; } }
.drag-ghost {
  position: fixed; z-index: 50; pointer-events: none; width: 60px; height: 60px; margin: -30px 0 0 -30px;
  display: grid; place-items: center; filter: drop-shadow(0 10px 8px #0008); transform: scale(1.15);
}
.drag-ghost svg { width: 44px; height: 44px; }
.drag-ghost path { fill: #e8543f; stroke: #fff; stroke-width: 2.5; }

/* ------------------------------------------------ toast, confirm */
.toast {
  position: fixed; left: 50%; top: 12px; transform: translateX(-50%); z-index: 70;
  background: #0d1811f2; border: 1px solid #3e6a4c; padding: 10px 16px; border-radius: 12px;
  box-shadow: 0 10px 24px #000a; animation: toastIn .25s ease both; max-width: 92vw;
}
.toast.bad { border-color: #a4473b; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -10px); } }
.confirm { position: fixed; inset: 0; background: #0008; z-index: 60; display: grid; place-items: center; }
.confirm-box { background: var(--panel); border: 1px solid #3a5a45; border-radius: 16px; padding: 18px 20px; width: min(360px, 90vw); box-shadow: 0 20px 50px #000c; }
.confirm-box p { margin: 0 0 6px; }
[hidden] { display: none !important; }

/* ------------------------------------------------ guide sheet */
.sheet { position: fixed; inset: 0; z-index: 80; background: #000a; display: flex; align-items: flex-end; justify-content: center; }
.sheet-box {
  width: 100%; max-width: 820px; height: 94svh; background: #111c15; border: 1px solid var(--line);
  border-radius: 18px 18px 0 0; display: flex; flex-direction: column; animation: sheetUp .35s cubic-bezier(.2,1,.3,1);
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 900px) { .sheet { align-items: center; } .sheet-box { height: 88vh; border-radius: 18px; } }
.sheet-head { flex: none; display: flex; align-items: center; padding: 14px 16px 8px; gap: 10px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.close { margin-left: auto; border: 0; background: var(--panel2); color: var(--ink); width: 34px; height: 34px; border-radius: 50%; font-size: 16px; }
.toc { flex: none; display: flex; gap: 6px; overflow-x: auto; padding: 0 16px 10px; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.toc a { flex: none; font-size: 12px; line-height: 1.4; white-space: nowrap; color: var(--ink2); text-decoration: none; background: var(--panel2); border-radius: 999px; padding: 4px 10px; }
.toc a:hover { background: #2b4735; }
.guide { overflow-y: auto; padding: 8px 18px 40px; color: var(--ink2); font-size: 14.5px; line-height: 1.6; }
.guide h3 { color: var(--ink); font-size: 16px; margin: 22px 0 6px; scroll-margin-top: 10px; }
.guide h4 { color: var(--ink); font-size: 14px; margin: 14px 0 4px; }
.guide p { margin: 6px 0; }
.guide ul, .guide ol { padding-left: 20px; margin: 6px 0; }
.guide li { margin: 3px 0; }
.guide b { color: var(--ink); }
.guide code { color: #9fd0ff; font-size: 13px; }
.guide table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.guide th, .guide td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.guide th { color: var(--ink); font-weight: 600; }
.guide td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.guide .callout { background: #1c5cab1f; border: 1px solid #2a78d6; border-radius: 12px; padding: 10px 12px; margin: 10px 0; }
.guide .watch { background: #c985001a; border: 1px solid #c98500; border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.guide .watch b { color: #f2c46b; }
.guide .flow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; font-size: 12.5px; }
.guide .flow span { background: var(--panel2); border-radius: 8px; padding: 4px 8px; color: var(--ink); }
.guide .flow em { color: var(--muted); font-style: normal; }

.clock-chip {
  position: absolute; left: 8px; top: 34px; z-index: 6; padding: 3px 9px; border-radius: 999px; font-size: 11.5px;
  pointer-events: none; white-space: nowrap; border: 1px solid #ffffff30;
}
.clock-chip:empty { display: none; }
.clock-chip.day { background: #c98500d9; color: #231400; }
.clock-chip.night { background: #1b2350e6; color: #dfe6ff; border-color: #6f7fd0; }
.chart .nightband { fill: #6f7fd01c; }

/* Chronicles */
.chron-btn span { background: #8a5a33; color: #fff; font-size: 13px; }
.chron-btn { position: relative; }
.chron-new { position: absolute; top: 2px; right: 2px; width: 9px; height: 9px; border-radius: 50%; background: #e0674a; box-shadow: 0 0 0 2px var(--bg); }
.chron-entry { border-bottom: 1px solid var(--line); padding: 14px 0 16px; }
.chron-entry h3 { margin: 0 0 2px; }
.chron-entry time { color: var(--muted); font-size: 12px; }
.chron-stats { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chron-stats span { background: var(--panel2); border-radius: 8px; padding: 2px 8px; font-size: 12px; color: var(--ink); }

/* Minimap */
.mm-overlay {
  position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; gap: 6px; padding: 8px;
  background: #0a120df2; backdrop-filter: blur(3px);
}
.mm-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mm-head b { margin-right: auto; font-size: 13.5px; }
.mm-head button {
  border: 1px solid #3a5a45; background: var(--panel2); color: var(--ink); border-radius: 8px;
  padding: 4px 9px; font-size: 12px; min-width: 32px; touch-action: manipulation;
}
.mm-head button:hover { background: #2b4735; }
.mm-overlay canvas { flex: 1; min-height: 0; width: 100%; border-radius: 10px; border: 1px solid var(--line); cursor: crosshair; }
.mm-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11px; color: var(--ink2); }
.mm-legend i { display: inline-block; width: 9px; height: 9px; margin-right: 3px; vertical-align: -1px; border-radius: 50%; }
.lg-brain { background: #5598e7; } .lg-hut { background: #f0a040; border-radius: 2px !important; }
.lg-road { background: #d6ba82; height: 3px !important; border-radius: 2px !important; vertical-align: 2px !important; }
.lg-human { background: #fff; } .lg-you { border: 2px solid #f2b441; box-sizing: border-box; }
.lg-view { border: 1.5px solid #fff; border-radius: 1px !important; box-sizing: border-box; }
.mm-clusters { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: none; }
.mm-clusters button {
  flex: none; border: 1px solid #2a78d6; background: #1c5cab33; color: var(--ink); border-radius: 999px;
  padding: 4px 10px; font-size: 12px; white-space: nowrap;
}
.mm-clusters button:hover { background: #1c5cab66; }
.mm-card { display: none; padding: 10px 12px; border-bottom: 1px solid var(--line); gap: 6px; flex-direction: column; }
.mm-card canvas { width: 100%; height: 200px; border-radius: 10px; border: 1px solid var(--line); cursor: crosshair; }
@media (min-width: 1100px) { .mm-card { display: flex; } }

/* Chronicles: new behaviour highlight */
.new-behaviour {
  margin: 10px 0; padding: 12px 14px; border-radius: 14px;
  background: linear-gradient(135deg, #3a2a05, #2a1d05); border: 2px solid #f2b441;
  box-shadow: 0 0 0 4px #f2b44122, 0 8px 24px #f2b44133; animation: nbGlow 2.4s ease-in-out infinite;
}
@keyframes nbGlow { 50% { box-shadow: 0 0 0 6px #f2b44133, 0 8px 28px #f2b44155; } }
.new-behaviour .nb-tag {
  display: inline-block; font-weight: 800; font-size: 12.5px; letter-spacing: .4px; text-transform: uppercase;
  background: #f2b441; color: #2a1a00; border-radius: 999px; padding: 3px 10px; margin-bottom: 6px;
}
.new-behaviour p { margin: 6px 0; color: #fff3d6; }
.new-behaviour .nb-who { font-size: 12px; color: #f2c46b; background: #f2b4411f; border-radius: 6px; padding: 1px 6px; }
.new-behaviour small { color: #d8bf8f; font-size: 11.5px; }
.chron-entry.has-new h3::after { content: " 🆕"; }
.chron-new.behaviour {
  width: auto; height: auto; padding: 0 5px; border-radius: 999px; top: -4px; right: -6px;
  background: #f2b441; box-shadow: 0 0 0 2px var(--bg);
}
.chron-new.behaviour::after { content: "NEW"; font-style: normal; font-size: 9px; font-weight: 800; color: #2a1a00; }

/* Discord community widget */
.discord-fab {
  position: fixed; right: 14px; z-index: 30; width: 52px; height: 52px; border-radius: 50%; border: 0;
  bottom: calc(var(--drawer-h) + env(safe-area-inset-bottom) + 18px);
  background: #5865f2; display: grid; place-items: center;
  box-shadow: 0 8px 22px #0009, 0 0 0 3px #5865f233; transition: transform .18s, box-shadow .18s, background .18s;
}
.discord-fab svg { width: 28px; height: 28px; fill: #fff; }
.discord-fab:hover { transform: translateY(-2px) scale(1.05); box-shadow: 0 10px 26px #000a, 0 0 0 5px #5865f244; }
.discord-fab.open { background: #4752c4; }
.discord-pop {
  position: fixed; z-index: 31; left: 8px; right: 8px;
  bottom: calc(var(--drawer-h) + env(safe-area-inset-bottom) + 80px);
  height: min(500px, 62svh); display: flex; flex-direction: column;
  background: #1e1f22; border: 1px solid #3a3d44; border-radius: 18px; overflow: hidden;
  box-shadow: 0 20px 50px #000c; animation: dpIn .22s cubic-bezier(.2,1,.3,1);
  transform-origin: bottom right;
}
.discord-pop[hidden] { display: none; }
@keyframes dpIn { from { opacity: 0; transform: translateY(10px) scale(.96); } }
.dp-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #2b2d31; border-bottom: 1px solid #3a3d44; flex: none; }
.dp-head b { display: block; font-size: 14px; color: #fff; }
.dp-head small { display: block; font-size: 11.5px; color: #b5bac1; }
.dp-head .close { margin-left: auto; width: 30px; height: 30px; font-size: 14px; background: #383a40; }
.dp-logo { width: 32px; height: 32px; border-radius: 10px; background: #5865f2; display: grid; place-items: center; flex: none; }
.dp-logo svg { width: 19px; height: 19px; fill: #fff; }
.dp-frame { flex: 1; min-height: 0; }
.dp-frame iframe { display: block; width: 100%; height: 100%; border: 0; }
@media (min-width: 700px) {
  .discord-pop { left: auto; right: 16px; width: 350px; height: min(556px, calc(100svh - 190px)); }
}
@media (min-width: 1100px) {
  .discord-fab { right: 22px; bottom: 22px; }
  .discord-pop { right: 22px; bottom: 86px; }
}

/* Below desktop width the floating button would cover the map, so Discord lives in the tab bar */
.tab-discord { flex: 0 0 auto; padding: 6px 12px; }
.tab-discord svg { width: 22px; height: 22px; fill: #fff; }
.tab-discord { background: #5865f2; margin-left: 4px; }
.tab-discord:hover { background: #4752c4; }
.discord-fab { display: none; }
@media (min-width: 1100px) {
  .discord-fab { display: grid; }
  .tab-discord { display: none; }
}
@media (max-width: 1099px) {
  .discord-pop { bottom: calc(var(--drawer-h) + env(safe-area-inset-bottom) + 14px); }
}

/* Trailer button + player */
.trailer-btn span { background: #e0674a; color: #fff; font-size: 11px; padding-left: 2px; }
.trailer-box {
  width: min(1100px, 96vw); background: #0d1611; border: 1px solid var(--line); border-radius: 18px; overflow: hidden;
  box-shadow: 0 30px 80px #000c; animation: sheetUp .3s cubic-bezier(.2,1,.3,1); align-self: center;
}
#trailer { align-items: center; }
.trailer-box video { display: block; width: 100%; aspect-ratio: 16 / 9; background: #000; }
.trailer-dl {
  margin-left: auto; color: #2a1a00; background: var(--accent); text-decoration: none; font-weight: 700; font-size: 13px;
  padding: 6px 12px; border-radius: 999px; white-space: nowrap;
}
.trailer-box .close { margin-left: 8px; }
.trailer-box .sheet-head h2 { font-size: 16px; }

/* First-visit hint, pointing down at the ball in the drawer */
.join-hint {
  position: fixed; z-index: 40; width: min(320px, calc(100vw - 24px)); padding: 14px 34px 14px 16px;
  background: linear-gradient(135deg, #f2b441, #e8a020); color: #2a1a00; border-radius: 16px;
  box-shadow: 0 16px 40px #000a, 0 0 0 3px #f2b44155; font-size: 13.5px; line-height: 1.4;
  animation: hintIn .45s cubic-bezier(.3,1.5,.5,1) both;   /* still once it lands, so its buttons are easy to hit */
}
.join-hint b { color: #1a0f00; }
.join-hint .tour-title { display: block; font-size: 15px; margin-bottom: 4px; }
.join-hint .tour-step { display: block; font-size: 10.5px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: #5a3a00; margin-bottom: 2px; }
.tour-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.tour-btns button { border: 0; border-radius: 999px; padding: 5px 12px; font-size: 12.5px; font-weight: 700; background: #0002; color: #2a1a00; }
.tour-btns button.next { background: #2a1a00; color: #ffd98a; }
.join-hint.below::after { top: -9px; bottom: auto; }
.join-hint::after {
  content: ""; position: absolute; left: var(--arrow-x, 40px); bottom: -9px; width: 18px; height: 18px;
  background: #e8a020; transform: rotate(45deg); border-radius: 3px;
}
.jh-close { position: absolute; right: 8px; top: 8px; border: 0; background: #0002; color: #2a1a00; width: 24px; height: 24px; border-radius: 50%; font-size: 12px; }
@keyframes hintIn { from { opacity: 0; transform: translateY(14px) scale(.9); } }
@keyframes hintBob { 50% { transform: translateY(-5px); } }
.ball-token.nudge { animation: ballNudge 1.2s ease-in-out infinite; }
@keyframes ballNudge { 0%, 100% { box-shadow: 0 4px 0 #b39c77, 0 6px 10px #0006, 0 0 0 0 #f2b441aa; } 50% { box-shadow: 0 4px 0 #b39c77, 0 6px 10px #0006, 0 0 0 10px #f2b44100; transform: translateY(-3px); } }

/* ------------------------------------------------ top menu: a ☰ menu on phones, inline on wider screens */
.topbar { position: relative; z-index: 30; }
.top-menu { display: contents; }
.menu-btn { display: none; }
.sound-btn span { background: #3a5a45; color: #fff; font-size: 12px; }
@media (max-width: 699px) {
  .menu-btn {
    display: grid; align-content: center; gap: 4px; flex: none; width: 34px; height: 32px; padding: 0 8px;
    border: 1px solid #3a5a45; background: var(--panel2); border-radius: 10px;
  }
  .menu-btn i { display: block; height: 2px; border-radius: 2px; background: var(--ink); transition: transform .2s, opacity .2s; }
  .menu-btn[aria-expanded="true"] i:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .menu-btn[aria-expanded="true"] i:nth-child(2) { opacity: 0; }
  .menu-btn[aria-expanded="true"] i:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
  .top-menu {
    display: none; position: absolute; top: calc(100% + 2px); right: 10px; min-width: 190px;
    flex-direction: column; gap: 6px; padding: 8px; border-radius: 14px;
    background: var(--panel); border: 1px solid var(--line); box-shadow: 0 14px 34px #000c;
  }
  .top-menu.open { display: flex; animation: menuIn .16s ease-out; }
  .top-menu .guide-btn { padding: 6px 8px; justify-content: flex-start; }
  .top-menu .guide-btn em { display: inline; }
}
@keyframes menuIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* first visit: after a few seconds the Chronicles button glows until it is opened */
.chron-btn.glow { animation: chronGlow 1.8s ease-in-out infinite; border-color: #e0a15a; }
@keyframes chronGlow {
  0%, 100% { box-shadow: 0 0 0 0 #f0b45a00, 0 0 6px #f0b45a44; }
  50% { box-shadow: 0 0 0 4px #f0b45a33, 0 0 18px #f0b45acc; }
}
@media (prefers-reduced-motion: reduce) { .chron-btn.glow { animation: none; box-shadow: 0 0 0 3px #f0b45a88; } }
.share-btn span { background: #3b7bd8; color: #fff; font-size: 13px; }
.share-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.share-head .close { background: none; border: 0; color: var(--muted); font-size: 16px; }
.share-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.share-grid button {
  display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 8px 2px; font-size: 11px;
  background: var(--panel2); color: var(--ink); border: 1px solid var(--line); border-radius: 12px;
}
.share-grid button:hover { background: #2b4735; }
.share-grid button[hidden] { display: none; }
.share-grid i { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-weight: 800; color: #fff; font-size: 15px; }

/* ------------------------------------------------ chat: brains talking in symbols */
.chat-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin: 4px 2px 8px; }
.chat-head b { display: block; font-size: 15px; }
.chat-head small { color: var(--muted); font-size: 11.5px; }
.gloss-toggle { font-size: 11.5px; color: var(--muted); white-space: nowrap; display: flex; gap: 4px; align-items: center; }
.chat-window {
  height: min(52vh, 460px); overflow-y: auto; padding: 10px 8px; border-radius: 14px;
  background: linear-gradient(180deg, #0c1610, #0f1d14); border: 1px solid var(--line);
  scroll-behavior: smooth;
}
.chat-empty { text-align: center; margin-top: 40px; }
.msg { margin: 8px 0 2px; max-width: 92%; }
.msg.cont { margin-top: 2px; }
.msg .who { font-size: 11.5px; margin: 0 0 3px 4px; display: flex; align-items: center; gap: 5px; color: hsl(var(--hue), 70%, 78%); }
.msg .who .dot, .convo .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.msg .bubble {
  display: inline-block; padding: 6px 9px 4px; border-radius: 4px 14px 14px 14px;
  background: hsl(var(--hue), 35%, 20%); border: 1px solid hsl(var(--hue), 40%, 30%);
}
.msg.cont .bubble { border-radius: 14px; }
.words { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.word { display: inline-flex; gap: 1px; padding: 2px 4px; border-radius: 7px; background: rgba(255, 250, 230, 0.92); }
.word img { width: 26px; height: 26px; display: block; }
.gloss { font-size: 11px; color: #c9d8c8; font-style: italic; margin-top: 3px; }
.no-gloss .gloss { display: none; }
.bubble time { display: block; text-align: right; font-size: 10px; color: var(--muted); margin-top: 2px; }
.bubble time .why { opacity: 0.85; }
.chat-older h4 { margin: 14px 2px 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.convo { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 6px; background: var(--panel2); }
.convo summary { list-style: none; cursor: pointer; padding: 8px 10px; display: grid; grid-template-columns: auto auto 1fr auto; gap: 6px; align-items: center; }
.convo summary::-webkit-details-marker { display: none; }
.convo summary small { color: var(--muted); font-size: 11px; }
.convo summary .preview { grid-column: 2 / 4; font-size: 11.5px; color: #b9c8b8; font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo summary .show { grid-row: 1 / 3; grid-column: 4; border: 1px solid #3a5a45; background: #16261c; color: var(--ink); border-radius: 8px; width: 28px; height: 28px; }
.convo .live { color: #7fe3a0; font-style: normal; }
.convo .thread { padding: 0 8px 8px; max-height: 320px; overflow-y: auto; }

/* ------------------------------------------------ the dynasty drawer */
.dynasty-slot { display: flex; align-items: center; gap: 10px; width: 100%; }
.dyn-btn {
  display: flex; align-items: center; gap: 8px; flex: none; padding: 8px 12px; border-radius: 14px;
  border: 1px solid #b38a2e; background: linear-gradient(180deg, #4a3a14, #2e2410); color: #fff3d6; text-align: left;
}
.dyn-btn small { color: #e3cf9e; }
.dyn-btn.alive { border-color: #6d8f78; background: linear-gradient(180deg, #24392b, #1a2a20); color: var(--ink); }
.dyn-crest { font-size: 22px; }
.dyn-info { flex: 1; min-width: 0; font-size: 12px; color: #d9e6d6; }
.dyn-info small { color: var(--muted); }
.dyn-find { flex: none; border: 1px solid #3a5a45; background: var(--panel2); color: var(--ink); border-radius: 10px; padding: 6px 10px; }
@media (max-width: 520px) { .dyn-info { display: none; } }

/* ------------------------------------------------ a brain's mind */
.mind { display: grid; gap: 6px; margin-bottom: 6px; }
.mode-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.m-habit { background: #6f8f7a; }
.m-imagine { background: #8f7be0; }
.m-learn { background: #e0b15a; }
.m-sleep { background: #6d7fb8; }
.mode-bar { display: flex; gap: 2px; height: 8px; border-radius: 6px; overflow: hidden; }
.mode-bar span { display: block; }
.dyn-tag { color: #f0d48a; }
.dream { font-size: 12px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.dream .word img { width: 20px; height: 20px; }

/* zoom buttons on the map (3 x 3 to 20 x 20 tiles) */
.zoom-ctl { position: absolute; left: 8px; bottom: 62px; z-index: 8; display: flex; flex-direction: column; gap: 4px; }
.zoom-ctl button {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid #3a5a45; background: rgba(16, 28, 20, 0.85);
  color: #e8f0e6; font-size: 20px; font-weight: 700; line-height: 1; box-shadow: 0 4px 10px #0007;
}
.zoom-ctl button:disabled { opacity: 0.35; }
.zoom-ctl button:active:not(:disabled) { transform: scale(.94); }

/* "Start your Dynasty" glows now and then for visitors who have not started one (inside the button: the drawer clips outer glows) */
.dyn-btn.invite { animation: dynInvite 18s ease-in-out 6s infinite; }
@keyframes dynInvite {
  0%, 16%, 100% { transform: scale(1); border-color: #b38a2e; background: linear-gradient(180deg, #4a3a14, #2e2410);
    box-shadow: inset 0 0 0 0 rgba(255, 210, 90, 0); }
  4%, 11% { transform: scale(1.05); border-color: #ffe08a; background: linear-gradient(180deg, #8a6a1e, #5a4414);
    box-shadow: inset 0 0 14px 3px rgba(255, 225, 120, 0.85), 0 0 0 2px rgba(255, 220, 110, 0.9); }
  7.5% { transform: scale(1.02); border-color: #e0b04a; background: linear-gradient(180deg, #6a5218, #3e3010);
    box-shadow: inset 0 0 8px 1px rgba(255, 225, 120, 0.5), 0 0 0 1px rgba(255, 220, 110, 0.6); }
}
@media (prefers-reduced-motion: reduce) { .dyn-btn.invite { animation: none; border-color: #ffd36a; } }

/* Hall of Dynasties (Dynasty tab) and the "tap a tile yourself" link in the naming dialog */
.hall-card { margin-top: 12px; }
.hall { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.hall li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.04); }
.hall li > div { flex: 1; min-width: 0; line-height: 1.3; }
.hall li small { color: var(--muted); }
.hall li.mine { background: rgba(255, 210, 90, .12); box-shadow: inset 0 0 0 1px rgba(255, 210, 90, .45); }
.hall li.gone { opacity: .6; }
.hall .rank { width: 1.6em; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.hall .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.hall button { padding: 4px 10px; font-size: 12px; }
.link-btn { margin-top: 8px; background: none; border: 0; padding: 0; color: #9fd4ff; text-decoration: underline; cursor: pointer; font: inherit; font-size: 13px; }
.hall button { background: #1d3326; color: #e8f0e6; border: 1px solid #3a5a45; border-radius: 8px; cursor: pointer; }
.hall button.primary { background: #f0b443; color: #2a1d05; border-color: #f0b443; font-weight: 600; }
