/* bara ─ the control room. every widget lives on screen at once, all of it
   live, arranged around the tank. desktop never scrolls the page; columns
   manage their own overflow. palette: abyss #05070a, moonlight #9fb4c7,
   bioluma #57e6c8, yuzu #e8c15a, warn #d96a5a. */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --abyss: #05070a;
  --line: rgba(159, 180, 199, .14);
  --ink: #9fb4c7;
  --ink-dim: #74879a;
  --ink-bright: #d9e6f2;
  --luma: #57e6c8;
  --luma-dim: rgba(87, 230, 200, .35);
  --yuzu: #e8c15a;
  --warn: #d96a5a;
  --glass: rgba(4, 6, 9, .78);
  --serif: "Fraunces", georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
}

html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  background: var(--abyss);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  overflow: hidden;
  height: 100svh;
}
::selection { background: var(--luma-dim); color: var(--ink-bright); }

.serif { font-family: var(--serif); }
.mono  { font-family: var(--mono); font-size: .74rem; letter-spacing: .04em; }
a { color: var(--luma); text-decoration: none; }
a:focus-visible, button:focus-visible { outline: 1px solid var(--luma); outline-offset: 3px; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.veil {
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  background:
    radial-gradient(90% 80% at 50% 115%, rgba(2,3,4,.7) 0%, transparent 55%),
    linear-gradient(rgba(5,7,10,.4) 0%, rgba(5,7,10,0) 18%);
}

/* ── the room grid ───────────────────────────────────────────── */
.room {
  position: fixed; inset: 0; z-index: 3;
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr) minmax(280px, 340px);
  gap: .9rem;
  padding: 1rem 1.1rem;
  pointer-events: none;              /* empty space belongs to the tank */
}
.col { display: flex; flex-direction: column; gap: .9rem; min-height: 0; min-width: 0; }
.brand, .hud, .widget, .surface-thought { pointer-events: auto; }

/* ── widgets ─────────────────────────────────────────────────── */
.widget {
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  transition: border-color .3s ease;
}
.widget:hover { border-color: rgba(87, 230, 200, .22); }
.w-head {
  color: var(--ink); font-size: .66rem; letter-spacing: .1em;
  padding: .65rem .9rem; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: .55em; flex-shrink: 0;
}
.live {
  width: 5px; height: 5px; border-radius: 50%; background: var(--luma);
  box-shadow: 0 0 6px var(--luma); flex-shrink: 0;
  animation: livepulse 2.6s ease-in-out infinite;
}
@keyframes livepulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.w-scroll { overflow-y: auto; min-height: 0;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

/* ── brand + hud ─────────────────────────────────────────────── */
.brand { padding: .2rem .95rem 0; }
.eyebrow { color: var(--luma); text-transform: lowercase; font-size: .66rem; }
.wordmark {
  font-weight: 340; font-style: italic;
  font-size: clamp(2.4rem, 3.6vw, 3.4rem); line-height: .95;
  color: var(--ink-bright); letter-spacing: -.02em;
  margin: .15rem 0 .4rem;
}
.thesis { font-size: .82rem; color: var(--ink); }

.hud {
  display: flex; flex-direction: column; gap: .16rem; text-align: right;
  color: var(--ink-dim); font-size: .66rem; padding: .1rem .95rem 0;
}
.hud span { display: block; }
#hud-odometer { color: var(--ink); }
#hud-steering { color: var(--warn); }
.sound-toggle {
  align-self: flex-end; margin-top: .3rem;
  background: none; border: 1px solid var(--line); color: var(--ink-dim);
  font-size: .66rem; letter-spacing: .08em; padding: .34rem .8rem;
  border-radius: 999px; cursor: pointer; transition: color .2s, border-color .2s;
}
.sound-toggle:hover { color: var(--ink-bright); }
.sound-toggle.on { color: var(--luma); border-color: var(--luma-dim);
  box-shadow: 0 0 10px rgba(87, 230, 200, .15); }

.t-play {
  background: none; border: 0; color: var(--luma); cursor: pointer;
  font-family: var(--mono); font-size: .64rem; letter-spacing: .06em;
  padding: 0; text-decoration: underline dotted;
}
.docs-link { display: inline-block; margin-top: .5rem; color: var(--ink-dim);
  font-size: .64rem; letter-spacing: .1em; border-bottom: 1px dotted var(--line); }
.docs-link:hover { color: var(--luma); }

body.shotmode .room, body.shotmode .veil, body.shotmode .hint,
body.shotmode .yuzu { display: none; }

.yuzu {
  position: fixed; z-index: 2; left: 61%; top: 24vh;
  width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #f4dd90, var(--yuzu) 60%, #a8842e);
  box-shadow: 0 0 18px rgba(232, 193, 90, .45);
  animation: bob 5s ease-in-out infinite;
}
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-4deg);} 50% { transform: translateY(-7px) rotate(5deg);} }

/* ── center column ───────────────────────────────────────────── */
.col-center { pointer-events: none; }
.tankwindow { flex: 1 1 auto; min-height: 24vh; }   /* he lives in this gap */
.surface-thought { padding: 0 .4rem .8rem; text-align: center; }
#hero-thought {
  font-style: italic; font-weight: 350;
  font-size: clamp(1rem, 1.6vw, 1.3rem); color: var(--luma);
  max-width: 60ch; margin: 0 auto;
  text-shadow: 0 0 24px rgba(87, 230, 200, .3), 0 1px 14px rgba(5, 7, 10, .85);
  transition: opacity .4s ease;
}
#thought-meta { color: var(--ink-dim); font-size: .64rem; margin-top: .25rem;
  text-shadow: 0 0 8px rgba(5, 7, 10, .9); }

.w-web { height: clamp(200px, 30vh, 340px); flex-shrink: 0; }
.webwrap { position: relative; flex: 1; min-height: 0; }
#mindmap { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#mindmap.grabbing { cursor: grabbing; }
.node-panel {
  position: absolute; top: .8rem; right: .8rem; width: min(280px, 80%);
  background: rgba(2, 3, 4, .95); border: 1px solid var(--line);
  padding: .9rem 1rem; z-index: 2;
}
.node-panel h3 { color: var(--luma); font-size: .85rem; font-weight: 500; margin-bottom: .25rem; }
.node-panel p { color: var(--ink-dim); font-size: .66rem; margin-bottom: .45rem; }
.node-panel ul { list-style: none; display: grid; gap: .45rem; max-height: 60px; overflow-y: auto; }
.node-panel li { font-size: .68rem; color: var(--ink); border-left: 1px solid var(--line); padding-left: .55rem; }
.node-close { position: absolute; top: .25rem; right: .45rem; background: none; border: 0;
  color: var(--ink-dim); font-size: 1rem; cursor: pointer; }

.w-gallery { flex-shrink: 0; }
.gallery-strip {
  display: flex; gap: .6rem; overflow-x: auto; padding: .7rem .9rem;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.g-item { position: relative; flex: 0 0 auto; overflow: hidden; }
.g-item img { height: 96px; width: auto; display: block;
  filter: brightness(.82) saturate(.9);
  transition: filter .5s ease, transform .5s ease; }
.g-item:hover img { filter: brightness(1) saturate(1); transform: scale(1.03); }
.g-item figcaption {
  position: absolute; inset: auto 0 0 0; padding: 1.2rem .5rem .35rem;
  background: linear-gradient(transparent, rgba(2,3,4,.94));
  font-family: var(--mono); font-size: .62rem; color: var(--ink);
  opacity: 0; transition: opacity .4s; max-width: 240px;
}
.g-item:hover figcaption { opacity: 1; }

/* ── thoughts ────────────────────────────────────────────────── */
.w-thoughts { flex: 1 1 220px; }
.thought-stream { list-style: none; display: grid; gap: .8rem; padding: .9rem; }
.thought {
  border-left: 1px solid var(--line);
  padding: .15rem 0 .15rem .8rem;
  opacity: 0; transform: translateY(8px);
  animation: bloom .6s ease forwards;
}
@keyframes bloom { to { opacity: 1; transform: none; } }
.thought .t-text { font-family: var(--serif); font-style: italic; font-weight: 350;
  font-size: .95rem; color: var(--ink-bright); line-height: 1.45; }
.thought .t-meta { font-family: var(--mono); font-size: .64rem; color: var(--ink-dim);
  margin-top: .25rem; letter-spacing: .06em; }
.thought.fresh { border-left-color: var(--luma); }
.thought.fresh .t-text { color: var(--luma); text-shadow: 0 0 20px rgba(87,230,200,.2); }

/* ── machine ─────────────────────────────────────────────────── */
.w-machine { flex-shrink: 0; }
.monitor-ecg { height: 46px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
#ecg { width: 100%; height: 100%; display: block; }
.vitals {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.vitals > div { padding: .5rem .7rem; border-right: 1px solid var(--line); }
.vitals > div:nth-child(3n) { border-right: 0; }
.vitals > div:nth-child(n+4) { border-top: 1px solid var(--line); }
.vitals dt { color: var(--ink-dim); font-size: .6rem; text-transform: lowercase; letter-spacing: .08em; }
.vitals dd { color: var(--ink-bright); font-size: .7rem; margin-top: .1rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lifebar-wrap { padding: .7rem .9rem; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.lifebar-head { display: flex; justify-content: space-between; color: var(--ink-dim); font-size: .66rem; }
.lifebar-head strong { color: var(--luma); font-size: .8rem; }
.lifebar { height: 5px; background: rgba(159,180,199,.16); margin-top: .45rem; }
#lifebar-fill { height: 100%; width: 0%; min-width: 3px; background: var(--luma);
  box-shadow: 0 0 12px var(--luma-dim); transition: width 1.2s ease; }
#lifebar-fill.low { background: var(--warn); box-shadow: 0 0 12px rgba(217,106,90,.4); }
.lifebar-note { margin-top: .5rem; color: var(--ink-dim); font-size: .64rem; }
.receipts-label { color: var(--ink-dim); font-size: .62rem; letter-spacing: .1em;
  padding: .55rem .9rem .35rem; flex-shrink: 0; }
#tool-feed { list-style: none; display: grid; gap: .35rem; max-height: 5.5rem;
  padding: 0 .9rem .7rem; }
#tool-feed li { font-size: .66rem; color: var(--ink); display: flex; flex-wrap: wrap; gap: .6em; }
#tool-feed li span { min-width: 0; overflow-wrap: anywhere; }
#tool-feed .ok  { color: var(--luma); }
#tool-feed .bad { color: var(--warn); }
#tool-feed time { color: var(--ink-dim); flex-shrink: 0; }

/* ── training ────────────────────────────────────────────────── */
.w-training { flex-shrink: 0; }
.odometer-wrap { text-align: center; padding: .5rem .9rem .1rem; }
.odo-label { color: var(--ink-dim); letter-spacing: .28em; font-size: .62rem; }
.odometer { font-size: clamp(1.4rem, 2vw, 1.8rem); font-weight: 320; color: var(--ink-bright);
  font-variant-numeric: tabular-nums; line-height: 1.15;
  text-shadow: 0 0 40px rgba(87,230,200,.12); }
.odo-sub { color: var(--ink-dim); font-size: .62rem; margin-top: .2rem; }
.ring-fig { position: relative; width: 132px; margin: .25rem auto .35rem; }
#ring { width: 100%; aspect-ratio: 1; display: block; }
.ring-tip { position: absolute; pointer-events: none; background: rgba(2,3,4,.95);
  border: 1px solid var(--line); padding: .3rem .55rem; font-size: .62rem; color: var(--ink-bright);
  white-space: nowrap; z-index: 3; }
#topic-bars { display: grid; gap: .32rem; padding: 0 .9rem .6rem; }
.tbar { display: grid; grid-template-columns: 7em 1fr 3em; gap: .7em; align-items: center;
  font-family: var(--mono); font-size: .66rem; color: var(--ink); }
.tbar .bar { height: 3px; background: rgba(159,180,199,.1); position: relative; }
.tbar .bar i { position: absolute; inset: 0 auto 0 0; background: var(--luma-dim); }
.tbar .n { color: var(--ink-dim); text-align: right; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem .4rem; padding: 0 .9rem .8rem; }
.chips span { border: 1px solid var(--line); padding: .06rem .45rem; font-size: .62rem;
  color: var(--ink); border-radius: 2px; }

/* ── coin ────────────────────────────────────────────────────── */
.w-coin { flex-shrink: 0; }
.coin-card { }
.coin-row { display: flex; justify-content: space-between; gap: 1rem;
  padding: .38rem .9rem; border-bottom: 1px solid var(--line); font-size: .66rem; }
.coin-row:last-child { border-bottom: 0; }
.coin-row span { color: var(--ink-dim); flex-shrink: 0; }
.coin-row strong { color: var(--ink-bright); font-weight: 500; text-align: right;
  overflow-wrap: anywhere; }
.coin-row strong.up { color: var(--luma); }
.coin-row strong.down { color: var(--warn); }

/* ── lore ────────────────────────────────────────────────────── */
.w-lore { flex: 1 1 0; min-height: 88px; }
.lore-scroll { padding: .9rem; }
.floor-portrait { width: 100%; max-width: 190px; filter: brightness(.75);
  border: 1px solid var(--line); margin-bottom: .8rem; }
.floor-lore p { font-weight: 350; font-size: .85rem; color: var(--ink);
  margin-bottom: .7rem; line-height: 1.5; }
.floor-sign { color: var(--luma); font-style: italic; }
.laws { list-style: none; display: grid; gap: .45rem; margin: .9rem 0; }
.laws li { font-style: italic; font-weight: 350; color: var(--ink-bright); font-size: .82rem;
  border-left: 1px solid var(--luma-dim); padding-left: .7rem; }
.floor-foot { display: flex; flex-wrap: wrap; gap: .5rem 1.1rem; color: var(--ink-dim);
  font-size: .62rem; border-top: 1px solid var(--line); padding-top: .8rem; }

.hint {
  position: fixed; z-index: 4; left: 50%; transform: translateX(-50%); top: 1.1rem;
  color: var(--ink-dim); font-size: .64rem; letter-spacing: .14em; opacity: .85;
  pointer-events: none;
}

/* ── scroll fades: clipped content gets an affordance ─────────── */
.w-thoughts, .w-machine { position: relative; }
.w-thoughts::after, .w-machine::after {
  content: ""; position: absolute; left: 1px; right: 1px; bottom: 1px;
  height: 26px; background: linear-gradient(transparent, rgba(4, 6, 9, .92));
  pointer-events: none;
}

/* ── short desktops: compress chrome before anything clips ────── */
@media (min-width: 1181px) and (max-height: 840px) {
  .room { padding: .7rem .9rem; gap: .7rem; }
  .col { gap: .7rem; }
  .w-head { padding: .5rem .9rem; }
  .odometer-wrap { padding: .35rem .9rem 0; }
  .ring-fig { width: 96px; }
  #topic-bars { gap: .22rem; }
  .chips { max-height: 1.7rem; overflow: hidden; padding-bottom: .55rem; }
  .coin-row { padding: .3rem .9rem; }
  .lifebar-wrap { padding: .55rem .9rem; }
  .w-training { flex-shrink: 1; min-height: 0; overflow: hidden; }
  .w-lore { min-height: 96px; }
}

/* ── touch: hover reveals must not gate content ───────────────── */
@media (hover: none) {
  .g-item figcaption { opacity: 1; }
}

/* ── small screens: he comes first, then his mind, then the rest ── */
@media (max-width: 1180px) {
  body { overflow-y: auto; height: auto; min-height: 100svh; }
  .room {
    position: relative; z-index: 3;
    display: flex; flex-direction: column; gap: .9rem;
    max-width: 740px; margin: 0 auto;
    padding: max(.9rem, env(safe-area-inset-top)) max(.9rem, env(safe-area-inset-right))
             max(.9rem, env(safe-area-inset-bottom)) max(.9rem, env(safe-area-inset-left));
  }
  .col { display: contents; }
  .brand { order: 1; }
  .tankwindow { order: 2; height: 44svh; min-height: 260px; flex: 0 0 auto; }
  .surface-thought { order: 3; text-align: center; padding: 0 .2rem .4rem; }
  .hud { order: 4; text-align: left; padding-bottom: .2rem; flex-direction: row;
    flex-wrap: wrap; gap: .3rem 1.2rem; align-items: center; }
  .hud .sound-toggle { margin-top: 0; margin-left: auto; }
  .w-thoughts { order: 5; }
  .w-web { order: 6; height: 300px; }
  .w-gallery { order: 7; }
  .w-machine { order: 8; }
  .w-training { order: 9; }
  .w-coin { order: 10; }
  .w-lore { order: 11; }
  .w-thoughts .thought-stream { max-height: 320px; }
  .w-lore .lore-scroll { max-height: none; }
  .hint { display: none; }
  .yuzu { position: absolute; z-index: 2; left: auto; right: 10vw; top: 26vh; }

  /* performance: glass without live blur over webgl */
  .widget { backdrop-filter: none; background: rgba(4, 6, 9, .92); }

  /* legibility floor on phones */
  .mono { font-size: .8rem; }
  .w-head { font-size: .7rem; }
  .vitals dt { font-size: .62rem; }
  .vitals dd { font-size: .78rem; }
  .coin-row { font-size: .72rem; }
  #tool-feed li { font-size: .7rem; }
  .receipts-label, .odo-label, .odo-sub { font-size: .64rem; }
  .thought .t-meta { font-size: .68rem; }
  .g-item img { height: 120px; }

  /* touch targets */
  .sound-toggle { font-size: .72rem; padding: .6rem 1.1rem; }
  .t-play { font-size: .7rem; padding: .5rem; margin: -.5rem; }
  .node-close { top: 0; right: 0; width: 44px; height: 44px; font-size: 1.2rem; }
  .docs-link { font-size: .74rem; padding: .5rem 0; }

  /* the graph must not trap vertical scroll */
  #mindmap { touch-action: pan-y; }
}
@media (prefers-reduced-motion: reduce) {
  .yuzu { animation: none; }
  .live { animation: none; }
  .thought { animation-duration: .01s; }
}
