/* smol brains — UI chrome. The world canvas is bright and cute; this is the dark glassy stuff on top. */
@font-face {
  font-family: "JBM";
  src: url("fonts/jetbrains-mono-latin-800-normal.woff2") format("woff2");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --carbon: #101114;
  --carbon2: #17181d;
  --carbon3: #22242b;
  --lime: #c5ff49;
  --lilac: #b59aff;
  --paper: #f5f3ed;
  --pink: #ff5fa2;
  --dim: rgba(245, 243, 237, 0.6);
  --faint: rgba(245, 243, 237, 0.12);
  --glass: rgba(23, 24, 29, 0.8);
  --glass2: rgba(34, 36, 43, 0.86);
  --line: rgba(255, 255, 255, 0.09);
  --r: 16px;
  --mono: "JBM", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --hudH: 112px; /* updated from JS: bottom of hud + roster */
  --panelW: 340px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--carbon);
  color: var(--paper);
  font: 14px/1.4 var(--sans);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
body { position: fixed; inset: 0; }
#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  background: #8fd3ff;
  cursor: none;
}
#view.cursor-ok { cursor: default; }
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#ui > *, #ui .dock > * { pointer-events: auto; }
#ui .ghost, #ui > .dock, #ui > .hud, #ui .dock > .toasts { pointer-events: none; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  margin: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible, input:focus-visible, textarea:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--lime);
  outline-offset: 2px;
}
input, textarea {
  font: inherit;
  color: var(--paper);
  background: var(--carbon);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  user-select: text;
  -webkit-user-select: text;
}
input:focus, textarea:focus { border-color: var(--lime); outline: none; }
textarea { width: 100%; resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 12px; min-height: 92px; word-break: break-all; }
h1, h2, h3, .mono { font-family: var(--mono); font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 13px; margin: 14px 0 6px; color: var(--lilac); text-transform: lowercase; }
p { margin: 0 0 10px; }
a { color: var(--lime); }

.glass {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--r);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
}

.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  background: var(--carbon3);
  border: 1px solid var(--line);
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--lime); color: var(--carbon); border-color: transparent; }
.btn.danger { background: #ff4d6a; color: #fff; border-color: transparent; }
.btn.ghosty { background: transparent; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
@media (hover: hover) {
  .btn:hover { background: #2c2f38; }
  .btn.primary:hover { background: #d4ff73; }
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex: none;
}

/* ---------------- HUD ---------------- */
.hud {
  position: absolute;
  top: calc(8px + var(--sat));
  left: calc(8px + var(--sal));
  right: calc(8px + var(--sar));
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
.hud-row {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto auto auto;
  grid-template-areas: "clock map speed stats menu";
  gap: 6px;
  align-items: center;
}
.hud-row > * { pointer-events: auto; }
.clock { grid-area: clock; height: 44px; padding: 0 12px; display: flex; align-items: center; gap: 8px; white-space: nowrap; font-family: var(--mono); font-weight: 800; font-size: 13px; }
.clock .wx { font-size: 18px; }
.mapwrap { grid-area: map; height: 44px; padding: 5px; justify-self: center; width: 100%; max-width: 460px; position: relative; overflow: hidden; }
.mapwrap canvas { width: 100%; height: 100%; display: block; border-radius: 10px; cursor: pointer; touch-action: none; }
.speed { grid-area: speed; display: flex; padding: 3px; gap: 2px; height: 44px; }
.speed button { min-width: 40px; height: 36px; border-radius: 10px; font-family: var(--mono); font-weight: 800; font-size: 13px; color: var(--dim); padding: 0 6px; }
.speed button.on { background: var(--lime); color: var(--carbon); }
.speed button.glyph { display: inline-flex; align-items: center; justify-content: center; }
.speed .sp-mini.glyph { display: none; }
.speed .sp-mini { display: none; }
.stats { grid-area: stats; height: 44px; padding: 0 12px; display: flex; align-items: center; gap: 10px; white-space: nowrap; font-family: var(--mono); font-weight: 800; font-size: 13px; }
.stats .iq { color: var(--lime); }
.menu-btn { grid-area: menu; }
.menu-btn.glass { border-radius: 14px; }

.roster {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  pointer-events: auto;
  align-self: flex-start;
  max-width: 100%;
  padding: 2px;
}
.roster::-webkit-scrollbar { display: none; }
.roster:empty { display: none; }
.rost {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  position: relative;
  padding: 0;
}
.rost canvas { width: 100%; height: 100%; display: block; }
.rost.sel { border-color: var(--lime); box-shadow: 0 0 0 2px var(--lime) inset; }
.rost .dot { position: absolute; right: 3px; bottom: 3px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--carbon2); }
.rost .nm { position: absolute; left: 0; right: 0; bottom: -1px; font-size: 9px; text-align: center; font-weight: 700; color: var(--paper); text-shadow: 0 1px 2px #000; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 0 2px; }

/* ---------------- ticker ---------------- */
.ticker {
  position: absolute;
  top: calc(var(--hudH) + 6px);
  left: calc(10px + var(--sal));
  width: min(320px, 70vw);
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}
.tick {
  align-self: flex-start;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 10px;
  background: rgba(16, 17, 20, 0.66);
  color: var(--paper);
  max-width: 100%;
  animation: tickIn 0.3s ease-out;
  transition: opacity 0.6s;
}
.tick.out { opacity: 0; }
@keyframes tickIn { from { opacity: 0; transform: translateX(-10px); } }

/* ---------------- bottom dock: toasts, talk bar, smol sheet (phone), toolbar ---------------- */
.dock {
  position: absolute;
  left: calc(8px + var(--sal));
  right: calc(8px + var(--sar));
  bottom: calc(8px + var(--sab));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.toolbar {
  display: flex;
  gap: 4px;
  padding: 5px;
  border-radius: 20px;
}
.tool {
  width: 72px;
  height: 58px;
  border-radius: 15px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  color: var(--dim);
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.tool .em { font-size: 24px; line-height: 1; filter: grayscale(0.25); }
.tool .lb { font-size: 11px; font-weight: 700; text-transform: lowercase; }
.tool .key { display: none; }
.tool.on { background: var(--lime); color: var(--carbon); }
.tool.on .em { filter: none; }
.tool:active { transform: scale(0.95); }
@media (hover: hover) and (min-width: 900px) {
  .tool .key { display: inline; opacity: 0.5; font-family: var(--mono); font-size: 9px; }
}

.talkbar {
  width: min(600px, 100%);
  padding: 8px;
  display: none;
  flex-direction: column;
  gap: 8px;
}
.talkbar.open { display: flex; }
.talk-row { display: flex; gap: 6px; }
.talk-row input { flex: 1; min-width: 0; min-height: 44px; font-size: 16px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 18px;
  background: var(--carbon3);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.chip.name { background: rgba(181, 154, 255, 0.18); border-color: rgba(181, 154, 255, 0.45); color: var(--lilac); }
.chip.praise { color: var(--lime); }
.chip.scold { color: var(--pink); }
.talk-to { font-size: 11px; color: var(--dim); padding: 0 4px; }
.talk-to b { color: var(--lilac); }

.toasts {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--dockH, 90px) + 8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(420px, calc(100% - 16px));
  pointer-events: none;
  z-index: 60;
}
#ui > .toasts { pointer-events: none; }
.modal-on .toasts { bottom: auto; top: calc(8px + var(--sat)); left: 50% !important; }
@media (max-width: 699px) { .brain-on .toasts { bottom: auto; top: calc(8px + var(--sat)); } }
@media (min-width: 700px) { .has-panel .toasts { left: calc((100% - var(--panelW) - 16px) / 2); } }
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--glass2);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.35);
  animation: toastIn 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
  transition: opacity 0.4s, transform 0.4s;
  max-width: 100%;
}
.toast.out { opacity: 0; transform: translateY(8px); }
.toast .ti { font-size: 26px; flex: none; }
.toast .tt { font-family: var(--mono); font-weight: 800; font-size: 13px; color: var(--lime); }
.toast .td { font-size: 12px; color: var(--dim); }
.toast.t-ach { border-color: rgba(197, 255, 73, 0.45); }
.toast.click { cursor: pointer; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(0.95); } }

/* ---------------- smol panel ---------------- */
.panel {
  position: fixed;
  right: calc(8px + var(--sar));
  top: calc(var(--hudH) + 6px);
  width: var(--panelW);
  max-height: calc(100% - var(--hudH) - 16px - var(--sab));
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.panel.open { display: flex; }
.p-head { display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 10px; flex: none; }
.p-por { width: 52px; height: 52px; border-radius: 14px; background: var(--carbon3); flex: none; }
.p-id { flex: 1; min-width: 0; }
.p-name { display: flex; align-items: center; gap: 4px; }
.p-name input {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 17px;
  background: transparent;
  border: 1px solid transparent;
  padding: 2px 6px;
  margin-left: -6px;
  border-radius: 8px;
  width: 100%;
  min-width: 0;
  min-height: 32px;
}
.p-name input:hover, .p-name input:focus { border-color: var(--line); background: var(--carbon); }
.p-sub { font-size: 12px; color: var(--dim); line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.p-sub b { color: var(--lime); font-weight: 700; }
.p-head .icon-btn { color: var(--dim); }
.p-head .brain-btn { background: rgba(197, 255, 73, 0.12); color: var(--lime); }
.p-think { padding: 0 6px 6px 12px; font-size: 13px; flex: none; display: flex; gap: 6px; align-items: center; min-height: 44px; }
.p-mood { font-size: 20px; flex: none; }
.p-toggle { margin-left: auto; flex: none; min-height: 40px; min-width: 64px; padding: 0 10px; border-radius: 10px; font-size: 12px; font-weight: 700; color: var(--lilac); background: rgba(181, 154, 255, 0.1); white-space: nowrap; }
.p-think .lbl { color: var(--dim); font-size: 11px; text-transform: lowercase; flex: none; }
.p-think .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; min-width: 0; flex: 1; }
.p-body { overflow-y: auto; padding: 0 12px 12px; overscroll-behavior: contain; touch-action: pan-y; }
.panel.collapsed .p-body { display: none; }
.p-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 4px; }
.p-actions .btn { padding: 0 4px; font-size: 12px; flex-direction: column; gap: 0; min-height: 50px; }
.p-actions .btn .em { font-size: 18px; }
.p-actions .btn.on { border-color: var(--lime); color: var(--lime); }

.bars { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 12px; }
.bar { display: grid; grid-template-columns: 18px 1fr; align-items: center; gap: 4px; font-size: 11px; }
.bar .e { font-size: 13px; text-align: center; }
.bar .t { position: relative; height: 14px; background: var(--carbon); border-radius: 7px; overflow: hidden; }
.bar .f { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 7px; transition: width 0.3s; }
.bar .n { position: absolute; left: 6px; top: 0; font-size: 9px; line-height: 14px; color: var(--paper); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); font-weight: 700; }
.bar.wide { grid-column: 1 / -1; }
.chemlist { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; font-size: 11px; }
.chemlist div { background: var(--carbon); border-radius: 8px; padding: 4px 6px; display: flex; justify-content: space-between; gap: 4px; }
.chemlist b { font-family: var(--mono); color: var(--lime); }
.vocab { display: flex; flex-wrap: wrap; gap: 5px; }
.vw { font-size: 12px; padding: 3px 8px 5px; border-radius: 10px; background: var(--carbon); color: var(--dim); position: relative; overflow: hidden; }
.vw i { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--lilac); }
.vw.known { color: var(--carbon); background: var(--lime); font-weight: 700; }
.vw.known i { background: rgba(16, 17, 20, 0.4); }
.empty { color: var(--dim); font-size: 12px; font-style: italic; }
.traits { display: flex; flex-wrap: wrap; gap: 5px; }
.trait { font-size: 12px; padding: 3px 9px; border-radius: 10px; border: 1px solid rgba(181, 154, 255, 0.4); color: var(--lilac); }
.links { display: flex; flex-wrap: wrap; gap: 5px; font-size: 12px; align-items: center; }
.links .lk { min-height: 32px; padding: 0 10px; border-radius: 10px; background: var(--carbon3); font-size: 12px; }
.links .lk.dead { opacity: 0.6; }
.chat { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.chat div { color: var(--dim); }
.chat b { color: var(--paper); }
.grump-blurb { font-size: 13px; color: var(--dim); }
.kv { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--dim); }
.kv b { color: var(--paper); font-family: var(--mono); }

/* ---------------- brain viewer ---------------- */
.brainwin {
  position: fixed;
  left: calc(8px + var(--sal));
  top: calc(var(--hudH) + 6px);
  width: min(560px, calc(100% - var(--panelW) - 32px));
  height: min(520px, calc(100% - var(--hudH) - 100px - var(--sab)));
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 5;
}
.brainwin.open { display: flex; }
.bw-head { display: flex; align-items: center; gap: 8px; padding: 6px 6px 4px 12px; flex: none; }
.bw-head h2 { flex: 1; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bw-head h2 span { color: var(--lime); }
.bw-canvas { flex: 1; min-height: 0; position: relative; margin: 0 6px; }
.bw-canvas canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.bw-foot { flex: none; padding: 8px 12px 10px; display: grid; grid-template-columns: 1fr 170px; gap: 12px; align-items: start; }
.bw-explain { font-size: 13px; }
.bw-explain b { color: var(--lime); }
.bw-explain .lesson { color: var(--dim); font-size: 12px; margin-top: 3px; }
.bw-explain .lesson .pos { color: var(--lime); }
.bw-explain .lesson .neg { color: var(--pink); }
.bw-att { display: flex; flex-direction: column; gap: 3px; font-size: 11px; }
.bw-att .lbl { color: var(--dim); font-size: 10px; text-transform: lowercase; }
.att-row { display: grid; grid-template-columns: 18px 1fr; align-items: center; gap: 4px; }
.att-row .t { height: 10px; background: var(--carbon); border-radius: 5px; overflow: hidden; }
.att-row .f { height: 100%; background: var(--lilac); border-radius: 5px; }
.att-row.cur .f { background: var(--lime); }
.bw-legend { font-size: 10px; color: var(--dim); padding: 0 12px; display: flex; gap: 10px; flex-wrap: wrap; flex: none; }
.bw-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 3px; }

/* ---------------- coach / tutorial ---------------- */
.coach {
  position: absolute;
  top: calc(var(--hudH) + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, calc(100% - 24px));
  padding: 12px 12px 10px 14px;
  display: none;
  border-color: rgba(197, 255, 73, 0.4);
  z-index: 4;
}
.coach.open { display: block; animation: toastIn 0.4s cubic-bezier(0.2, 1.4, 0.4, 1); }
.coach .ct { font-size: 15px; font-weight: 650; margin-bottom: 8px; }
.coach .ct em { font-style: normal; color: var(--lime); }
.coach .cr { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.coach .cs { font-family: var(--mono); font-weight: 800; font-size: 11px; color: var(--dim); }
.coach .cbtns { display: flex; gap: 6px; }
.arrow {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  display: none;
  pointer-events: none !important;
  z-index: 30;
}
.arrow.open { display: block; }
.arrow .a-in {
  position: absolute;
  left: -22px;
  bottom: 4px;
  width: 44px;
  height: 52px;
  animation: bob 0.9s ease-in-out infinite;
}
.arrow.up .a-in { bottom: auto; top: 4px; animation-name: bobUp; }
.arrow svg { width: 44px; height: 52px; filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.5)); }
.arrow.up svg { transform: rotate(180deg); }
.arrow.side .a-in { left: 4px; bottom: auto; top: -26px; width: 52px; height: 44px; animation-name: bobSide; }
.arrow.side svg { transform: rotate(90deg); }
.arrow.side .ring { display: none; }
@keyframes bobSide { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(12px); } }
.arrow .ring { position: absolute; left: -26px; top: -26px; width: 52px; height: 52px; border-radius: 50%; border: 3px solid var(--lime); animation: ring 1.3s ease-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes bobUp { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(12px); } }
@keyframes ring { from { transform: scale(0.5); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }

@media (min-width: 700px) and (min-height: 521px) {
  .brain-on .coach { left: auto; right: 12px; transform: none; width: min(340px, calc(100% - 600px)); }
  .brain-on.has-panel .coach { right: calc(var(--panelW) + 20px); width: min(340px, calc(100% - var(--panelW) - 600px)); min-width: 240px; }
}

/* ---------------- tooltip (fixed things) ---------------- */
.tip {
  position: absolute;
  max-width: 240px;
  padding: 8px 12px;
  font-size: 12px;
  transform: translate(-50%, calc(-100% - 14px));
  display: none;
  pointer-events: none !important;
  z-index: 6;
}
.tip.open { display: block; animation: toastIn 0.25s ease-out; }
.tip b { font-family: var(--mono); color: var(--lime); display: block; font-size: 12px; }

/* ---------------- pause badge ---------------- */
.pausebadge {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  padding: 14px 16px 14px 20px;
  display: none;
  align-items: center;
  gap: 14px;
  z-index: 3;
}
.pausebadge.open { display: flex; }
.pausebadge > div { min-width: 170px; }
.pausebadge .pt { font-family: var(--mono); font-weight: 800; font-size: 16px; }
.pausebadge .ps { font-size: 12px; color: var(--dim); }

/* ---------------- celebration ---------------- */
.celebrate {
  position: absolute;
  left: 50%;
  top: 52%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none !important;
  z-index: 70;
  display: none;
}
.celebrate.open { display: block; animation: pop 2.8s cubic-bezier(0.2, 1.5, 0.4, 1) forwards; }
.celebrate .big {
  font-family: var(--mono);
  font-weight: 800;
  font-size: clamp(34px, 9vw, 64px);
  color: var(--lime);
  text-shadow: 0 4px 0 #101114, 0 0 30px rgba(197, 255, 73, 0.5);
  white-space: nowrap;
}
.celebrate .word {
  display: inline-block;
  margin-top: 6px;
  font-family: var(--mono);
  font-weight: 800;
  font-size: clamp(20px, 5vw, 30px);
  background: var(--paper);
  color: var(--carbon);
  padding: 4px 16px;
  border-radius: 18px;
}
.celebrate .who { display: inline-block; color: var(--paper); font-weight: 700; margin-top: 8px; padding: 4px 12px; border-radius: 12px; background: rgba(16, 17, 20, 0.75); }
.confetti { position: absolute; left: 50%; top: 50%; font-size: 26px; animation: fly 1.6s ease-out forwards; }
@keyframes fly { from { transform: translate(-50%, -50%) scale(0.4); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(1); opacity: 0; } }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  20% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.95); }
}

/* ---------------- modals ---------------- */
.modal-layer {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: calc(12px + var(--sat)) calc(12px + var(--sar)) calc(12px + var(--sab)) calc(12px + var(--sal));
  background: rgba(10, 10, 12, 0.55);
  z-index: 50;
}
.modal-layer.open { display: flex; animation: fade 0.2s; }
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(560px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: rgba(23, 24, 29, 0.94);
  overflow: hidden;
  animation: toastIn 0.3s cubic-bezier(0.2, 1.3, 0.4, 1);
}
.modal.wide { width: min(820px, 100%); }
.modal.small { width: min(400px, 100%); }
.m-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 18px; border-bottom: 1px solid var(--line); flex: none; }
.m-head h2 { flex: 1; }
.m-head h2 .sub { font-family: var(--sans); font-weight: 600; font-size: 13px; color: var(--dim); margin-left: 6px; }
.m-body { padding: 14px 18px 18px; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; user-select: text; -webkit-user-select: text; }
.m-body.nopad { padding: 0; }
.m-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 18px 14px; flex-wrap: wrap; border-top: 1px solid var(--line); flex: none; }
.m-foot.left { justify-content: flex-start; }

.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.menu-grid .btn { justify-content: flex-start; min-height: 54px; font-size: 14px; }
.menu-grid .btn .em { font-size: 20px; width: 26px; text-align: center; }
.menu-grid .btn.full { grid-column: 1 / -1; }
.err { color: #ff8aa8; font-size: 13px; margin-top: 8px; min-height: 1em; }
.ok { color: var(--lime); }
.muted { color: var(--dim); font-size: 12px; }

.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding: 8px 12px; border-bottom: 1px solid var(--line); flex: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; min-height: 38px; padding: 0 12px; border-radius: 12px; font-weight: 700; font-size: 13px; color: var(--dim); text-transform: lowercase; }
.tab.on { background: var(--lime); color: var(--carbon); }
.pedia p { color: rgba(245, 243, 237, 0.86); }
.pedia h3:first-child { margin-top: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.card { background: var(--carbon3); border-radius: 12px; padding: 10px 12px; display: flex; gap: 10px; align-items: flex-start; }
.card .ce { font-size: 26px; line-height: 1; flex: none; width: 32px; text-align: center; }
.card .cn { font-weight: 750; font-size: 13px; }
.card .cd { font-size: 12px; color: var(--dim); }
.card .cw { font-family: var(--mono); font-size: 11px; color: var(--lime); }
.wordgroup { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.wordpill { font-size: 12px; padding: 4px 10px; border-radius: 10px; background: var(--carbon3); }
.wordpill b { font-family: var(--mono); }
.wordpill span { color: var(--dim); font-size: 11px; margin-left: 4px; }
.wordpill.k { border: 1px solid rgba(197, 255, 73, 0.5); }
.diagram { width: 100%; height: auto; display: block; margin: 6px 0 12px; background: var(--carbon); border-radius: 12px; }
.pedia ul { padding-left: 18px; margin: 0 0 10px; }
.pedia li { margin-bottom: 4px; color: rgba(245, 243, 237, 0.86); }

.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.ach { background: var(--carbon3); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 3px; border: 1px solid transparent; }
.ach .ai { font-size: 26px; }
.ach .an { font-weight: 750; font-size: 13px; }
.ach .ad { font-size: 11px; color: var(--dim); }
.ach.got { border-color: rgba(197, 255, 73, 0.45); }
.ach.got .an { color: var(--lime); }
.ach.locked { opacity: 0.45; }
.ach.locked .ai { filter: grayscale(1); }
.progress { height: 8px; border-radius: 4px; background: var(--carbon); overflow: hidden; margin: 0 0 14px; }
.progress div { height: 100%; background: var(--lime); }

.tree { position: relative; margin: 0 auto; }
.tree svg { position: absolute; left: 0; top: 0; pointer-events: none; }
.tnode { position: absolute; width: 76px; display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; padding: 0; }
.tnode canvas { width: 56px; height: 56px; border-radius: 14px; background: var(--carbon3); border: 2px solid transparent; }
.tnode.alive canvas { border-color: rgba(197, 255, 73, 0.6); }
.tnode.dead canvas { opacity: 0.55; filter: grayscale(0.6); }
.tnode.sel canvas { border-color: var(--lime); box-shadow: 0 0 0 3px rgba(197, 255, 73, 0.3); }
.tnode .tn { font-size: 11px; font-weight: 700; max-width: 76px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tnode .tg { font-size: 10px; color: var(--dim); }
.genlbl { position: absolute; left: 4px; font-family: var(--mono); font-weight: 800; font-size: 10px; color: var(--lilac); }
.treewrap { overflow: auto; max-height: 60vh; padding: 10px; touch-action: pan-x pan-y; }

.namebox { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.namebox canvas { width: 120px; height: 120px; }
.namebox .row { display: flex; gap: 6px; width: 100%; }
.namebox input { flex: 1; min-width: 0; font-family: var(--mono); font-weight: 800; font-size: 20px; text-align: center; min-height: 50px; }
.cardprev { width: 100%; max-width: 340px; border-radius: 14px; display: block; margin: 0 auto; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); }

/* ---------------- responsive ---------------- */
/* desktop: center the toolbar in the space left of the panel */
@media (min-width: 700px) {
  .has-panel .dock { right: calc(var(--panelW) + 16px + var(--sar)); }
}

/* phones (portrait-ish) */
@media (max-width: 699px) {
  :root { --panelW: 100%; }
  .hud-row {
    grid-template-columns: auto 1fr auto auto;
    grid-template-areas: "clock speed speed menu" "map map stats stats";
  }
  .speed { justify-self: end; }
  .clock { padding: 0 10px; font-size: 12px; }
  .mapwrap { height: 34px; padding: 4px; max-width: none; }
  .stats { height: 34px; padding: 0 10px; font-size: 12px; gap: 8px; }
  .panel {
    position: relative;
    right: auto;
    top: auto;
    width: 100%;
    max-height: 52vh;
  }
  .panel.collapsed { max-height: none; }
  .toolbar { width: 100%; justify-content: space-between; }
  .tool { flex: 1; width: auto; }
  .brainwin {
    left: calc(6px + var(--sal));
    right: calc(6px + var(--sar));
    top: auto;
    bottom: calc(6px + var(--sab));
    width: auto;
    height: min(62%, 560px);
    z-index: 20;
  }
  .bw-foot { grid-template-columns: 1fr 120px; gap: 8px; }
  .modal-layer { padding: calc(8px + var(--sat)) calc(8px + var(--sar)) calc(8px + var(--sab)) calc(8px + var(--sal)); }
  .menu-grid .btn { font-size: 13px; padding: 0 10px; }
  .cards { grid-template-columns: 1fr; }
  .ach-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 439px) {
  .speed .sp-full, .speed button.sp-full.glyph { display: none; }
  .speed .sp-mini, .speed .sp-mini.glyph { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; }
  .m-head h2 .sub { display: block; margin: 2px 0 0; font-size: 12px; }
}

/* landscape phones: short screen. toolbar goes vertical on the left, panel on the right. */
@media (max-height: 520px) and (min-width: 560px) {
  :root { --panelW: 300px; }
  .hud-row { grid-template-columns: auto minmax(80px, 1fr) auto auto auto; grid-template-areas: "clock map speed stats menu"; }
  .clock, .speed, .stats { height: 40px; }
  .speed button { height: 32px; min-width: 36px; }
  .mapwrap { height: 40px; }
  .menu-btn { width: 40px; height: 40px; }
  .rost { width: 40px; height: 40px; border-radius: 12px; }
  .toolbar {
    position: fixed;
    left: calc(6px + var(--sal));
    top: 50%;
    transform: translateY(-50%);
    flex-direction: column;
    margin-top: calc(var(--hudH) / 2);
    width: auto;
  }
  .tool { width: 60px; height: 48px; flex: none; }
  .tool .em { font-size: 20px; }
  .tool .lb { font-size: 10px; }
  .dock { left: calc(84px + var(--sal)); }
  .ticker { left: calc(84px + var(--sal)); }
  .panel {
    position: fixed;
    right: calc(6px + var(--sar));
    top: calc(var(--hudH) + 4px);
    width: var(--panelW);
    max-height: calc(100% - var(--hudH) - 10px - var(--sab));
  }
  .has-panel .dock { right: calc(var(--panelW) + 14px + var(--sar)); }
  .brainwin {
    left: calc(78px + var(--sal));
    right: auto;
    top: calc(var(--sat) + 56px);
    bottom: calc(6px + var(--sab));
    width: min(520px, calc(100% - var(--panelW) - 100px));
    z-index: 8;
    height: auto;
  }
  .bw-foot { grid-template-columns: 1fr 110px; padding: 2px 10px 6px; gap: 8px; }
  .bw-explain { font-size: 12px; }
  .bw-head { padding: 2px 4px 0 12px; }
  .bw-legend { display: none; }
  .coach { left: auto; right: calc(var(--panelW) + 16px); transform: none; width: min(320px, calc(100% - var(--panelW) - 110px)); }
  .has-nopanel .coach { right: 12px; }
  .treewrap { max-height: 55vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; transition-duration: 0.001s !important; }
  .arrow .a-in, .arrow .ring { animation: none !important; }
  .celebrate.open { animation: none !important; opacity: 1; }
}

/* phones: while talking, the talk bar takes the smol sheet's place */
@media (max-width: 700px) {
  .dock.talking .panel { display: none !important; }
}

/* phones: toasts float at the very top (over the HUD) so they never hide the smol on the ground */
@media (max-width: 699px) {
  .toasts { bottom: auto; top: calc(6px + var(--sat)); }
  .toast { padding: 7px 12px; }
}

/* the chip row scrolls sideways: fade the right edge so it reads as "there's more" */
.chips { -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); padding-right: 28px; }
