:root {
  /* dark theme on the Mochi / Solana palette */
  --bg: #0d0a1a; --bg2: #120e24; --card: #171230; --card2: #1d1740; --line: #2e2556; --line2: #4a3d82;
  --ink: #ece8ff; --soft: #a99fd6; --accent: #14F195; --violet: #9945FF; --pink: #e2557b;
  --good: #3fd08a; --bad: #ff7d72; --gold: #ffd27a; --neon: #6ee7d8;
  --night: #0b1020; --glass: rgba(13, 19, 38, 0.92);
  --r: 16px; --r-sm: 10px; --gap: 14px; --side: 420px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(1200px 600px at 15% -10%, #22164a 0%, transparent 60%), var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button, .btn { border: 1px solid var(--line2); background: var(--card2); color: var(--ink); border-radius: var(--r-sm); padding: 6px 10px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 4px; line-height: 1.2; transition: background .15s, border-color .15s, transform .05s; white-space: nowrap; }
button:hover, .btn:hover { background: #2a2158; border-color: #6a5bb0; }
button:active { transform: translateY(1px); }
button.on { background: rgba(20, 241, 149, .14); border-color: rgba(20, 241, 149, .55); }
button.good { background: rgba(63, 208, 138, .14); border-color: rgba(63, 208, 138, .5); }
button.bad { background: rgba(255, 125, 114, .12); border-color: rgba(255, 125, 114, .5); }
button.held { background: rgba(169, 153, 255, .22); border-color: #a999ff; box-shadow: 0 0 0 3px rgba(169, 153, 255, .25); }
.btn.accent { border-color: rgba(20, 241, 149, .5); color: var(--accent); }
.spacer { flex: 1; }
.fine { color: var(--soft); font-size: 12px; }
.warn { color: #ffb4b4; }
code { font-size: 12px; word-break: break-all; background: var(--bg2); padding: 2px 5px; border-radius: 6px; }

/* ---------------------------------------------------------------- top bar */
#app { min-height: 100vh; display: flex; flex-direction: column; }
#top { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 8px 16px; position: sticky; top: 0; z-index: 20;
  background: rgba(13, 10, 26, .82); border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.brand { display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 16px; height: 16px; border-radius: 50%; background: linear-gradient(45deg, #9945ff, #5a8fe0 50%, #14f195); box-shadow: 0 0 12px rgba(153, 69, 255, .6); flex: none; }
#name { border: none; background: transparent; font-weight: 700; font-size: 18px; width: 9ch; padding: 2px 4px; border-radius: 6px; }
#name:focus { outline: 2px solid var(--violet); background: var(--card); }
.status { display: flex; align-items: center; gap: 8px; }
#clock { color: var(--soft); font-variant-numeric: tabular-nums; font-size: 13px; }
#mood { padding: 2px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line2); font-size: 12px; }
.bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.group { display: inline-flex; }
.group button { border-radius: 0; margin-left: -1px; padding: 6px 8px; }
.group button:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); margin-left: 0; }
.group button:last-child { border-radius: 0 var(--r-sm) var(--r-sm) 0; }
#saved { min-width: 0; }
#plazaToggle { border-color: rgba(153, 69, 255, .7); }

/* ---------------------------------------------------------------- layout */
#layout { flex: 1; width: 100%; max-width: 1600px; margin: 0 auto; padding: var(--gap) 16px; display: grid; gap: var(--gap);
  grid-template-columns: minmax(0, 1fr) var(--side); align-items: start; }
#play { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
#stage { position: relative; border-radius: 20px; overflow: hidden; background: #ecd6b4; border: 1px solid var(--line2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45), 0 0 0 1px rgba(153, 69, 255, .15); }
#room { display: block; width: 100%; height: auto; touch-action: none; cursor: none; }
#boot { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(13, 10, 26, .72); backdrop-filter: blur(3px); z-index: 3; }
#boot.done { display: none; }
#boot .card { text-align: center; padding: 22px 26px; border-radius: var(--r); background: var(--card); border: 1px solid var(--line2); width: min(320px, 86%); }
#boot .egg { font-size: 44px; animation: wobble 1.4s ease-in-out infinite; }
#boot .bar { display: block; height: 6px; border-radius: 6px; background: var(--line); overflow: hidden; margin: 12px 0 10px; }
#boot .bar i { display: block; height: 100%; width: 5%; background: linear-gradient(90deg, #9945ff, #14f195); transition: width .4s; }
@keyframes wobble { 0%, 100% { transform: rotate(-7deg); } 50% { transform: rotate(7deg); } }
#toast { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); padding: 7px 14px; border-radius: 999px; background: rgba(13, 10, 26, .88); color: #fff;
  opacity: 0; transition: opacity .3s; pointer-events: none; max-width: 92%; text-align: center; z-index: 2; border: 1px solid var(--line2); }
#toast.show { opacity: 1; }
#needAlert { position: absolute; left: 12px; top: 12px; padding: 6px 12px; border-radius: 999px; background: rgba(13, 10, 26, .9); color: #ffd27a;
  border: 1px solid #ffd27a; font-size: 13px; opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 2; }
#needAlert.show { opacity: 1; }

/* controls under the room */
#controls { display: grid; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.row .label { width: 50px; color: var(--soft); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.row .sep { width: 1px; height: 22px; background: var(--line2); margin: 0 4px; }
.row .hint { color: var(--soft); font-size: 12px; margin-left: 6px; }
#words { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.word { display: inline-flex; align-items: center; border: 1px solid var(--line2); background: var(--card2); border-radius: var(--r-sm); overflow: hidden; }
.word button { border: none; border-radius: 0; background: transparent; padding: 6px 8px; }
.word input { border: none; background: transparent; width: 7ch; padding: 6px 6px 6px 0; }
.word input:focus { outline: none; background: var(--bg2); }
.word.ringing { box-shadow: 0 0 0 3px rgba(226, 85, 123, .3); border-color: var(--pink); }

/* ---------------------------------------------------------------- side panel */
#side { position: sticky; top: 64px; display: flex; flex-direction: column; gap: 10px; min-width: 0; max-height: calc(100vh - 78px); }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; overflow-x: auto; scrollbar-width: none; flex: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 1 0 auto; border: none; background: transparent; border-radius: 999px; padding: 6px 10px; font-size: 13px; color: var(--soft); }
.tabs button.on { background: var(--card2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line2); }
.tabpane { display: none; flex-direction: column; gap: 10px; overflow: auto; min-height: 0; }
.tabpane.active { display: flex; }
#brain.tabpane:not(.active):not(.wide), #brain.tabpane:not(.open) { display: none; }
#plazaBar[hidden] { display: none !important; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.panel h3 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--soft); }
.panel p { margin: 6px 0; }
.need { display: grid; grid-template-columns: 84px 1fr 34px; align-items: center; gap: 8px; margin: 6px 0; font-size: 13px; }
.need .track, .meter .track { height: 8px; border-radius: 8px; background: var(--line); position: relative; overflow: hidden; }
.need .track i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 8px; background: linear-gradient(90deg, #14f195, #9945ff 60%, #e2557b); transition: width .3s; }
.need b { font-weight: 500; color: var(--soft); text-align: right; font-variant-numeric: tabular-nums; }
.wordCard { border-top: 1px dashed var(--line2); padding: 8px 0; font-size: 13px; }
.wordCard:first-child { border-top: none; }
.wordCard .top { display: flex; justify-content: space-between; gap: 8px; }
.wordCard .answer { color: var(--soft); }
.wordCard .bars { display: grid; grid-template-columns: 50px 1fr; gap: 3px 8px; align-items: center; margin-top: 4px; font-size: 11px; color: var(--soft); }
.wordCard .bar { height: 6px; background: var(--line); border-radius: 6px; overflow: hidden; }
.wordCard .bar i { display: block; height: 100%; background: #a999ff; }
.wordCard .bar.fresh i { background: var(--gold); }
#todo { margin: 0; padding: 0; list-style: none; font-size: 13px; }
#todo li { padding: 3px 0 3px 22px; position: relative; color: var(--soft); }
#todo li::before { content: "○"; position: absolute; left: 2px; }
#todo li.done { color: var(--ink); }
#todo li.done::before { content: "●"; color: var(--good); }
#diary { font-size: 13px; }
#diary div { padding: 4px 0; border-bottom: 1px dotted var(--line2); }
#diary time { color: var(--soft); font-variant-numeric: tabular-nums; margin-right: 6px; }

#foot { padding: 14px 16px 22px; text-align: center; font-size: 12px; color: var(--soft); border-top: 1px solid var(--line); }

/* ------------------------------------------------------------------ the brain overlay */
#brain { position: relative; display: none; flex-direction: column; gap: 8px; padding: 10px; border-radius: var(--r); color: #dfe7ff; min-height: 560px;
  background: radial-gradient(120% 80% at 70% 0%, rgba(40, 54, 110, .55), transparent 60%), var(--glass);
  border: 1px solid rgba(120, 150, 255, .28); box-shadow: 0 18px 50px rgba(8, 12, 30, .55), inset 0 0 40px rgba(80, 110, 255, .08); backdrop-filter: blur(8px); overflow: hidden; }
#brain.open { display: flex; }
#brain.wide { position: fixed; inset: 12px; z-index: 30; min-height: 0; }
#brain button { background: rgba(255, 255, 255, .06); border-color: rgba(160, 180, 255, .25); color: #dfe7ff; padding: 4px 9px; }
#brain button:hover { background: rgba(255, 255, 255, .14); box-shadow: none; }
#brain .head { display: flex; align-items: center; gap: 8px; }
#brain .title { font-weight: 700; letter-spacing: .12em; text-transform: uppercase; font-size: 12px; color: #9fb2ff; }
.chip { padding: 3px 10px; border-radius: 999px; font-size: 12px; border: 1px solid rgba(110, 231, 216, .45); color: var(--neon); background: rgba(110, 231, 216, .08); transition: all .2s; }
.chip.aroused { border-color: rgba(255, 210, 122, .6); color: var(--gold); background: rgba(255, 210, 122, .1); box-shadow: 0 0 14px rgba(255, 210, 122, .25); }
.chip.guided { border-color: rgba(169, 153, 255, .7); color: var(--violet); background: rgba(169, 153, 255, .12); box-shadow: 0 0 14px rgba(169, 153, 255, .3); }
.chip.asleep { border-color: rgba(120, 140, 255, .5); color: #8fa2ff; background: rgba(90, 110, 255, .1); }
.chip.refused { border-color: rgba(255, 120, 110, .7); color: #ff8f85; }
#scanWrap { position: relative; flex: 1 1 auto; min-height: 220px; border-radius: 14px; overflow: hidden; background: #05080f; border: 1px solid rgba(120, 150, 255, .18); }
#scan { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#scanLabels { position: absolute; inset: 0; pointer-events: none; font-size: 10.5px; letter-spacing: .02em; color: #cfd8ff; text-shadow: 0 0 6px #000, 0 0 2px #000; }
#scanLabels > * { position: absolute; white-space: nowrap; }
#inspector { position: absolute; left: 10px; bottom: 8px; font-size: 11px; color: #9fb2ff; text-shadow: 0 0 6px #000; pointer-events: none; }
#pulse { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .6s; }
#pulse.reward { background: radial-gradient(circle at 50% 55%, rgba(255, 210, 122, .32), transparent 62%); opacity: 1; transition: opacity .05s; }
#pulse.pain { background: radial-gradient(circle at 50% 55%, rgba(110, 160, 255, .34), transparent 62%); opacity: 1; transition: opacity .05s; }
#pulse.memory { background: radial-gradient(circle at 50% 55%, rgba(169, 153, 255, .34), transparent 66%); opacity: 1; transition: opacity .05s; }
#montage { width: 100%; height: 92px; border-radius: 10px; background: #05080f; border: 1px solid rgba(120, 150, 255, .14); flex: 0 0 auto; }
#transmitters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; flex: 0 0 auto; }
.meter { display: grid; grid-template-columns: 92px 1fr 40px; align-items: center; gap: 8px; font-size: 12px; }
.meter span { color: #9fb2ff; }
.meter b { text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; color: #dfe7ff; }
.meter .track { background: rgba(255, 255, 255, .08); height: 7px; }
.meter .track i { position: absolute; top: 0; bottom: 0; left: 0; width: 0; border-radius: 8px; background: var(--neon); transition: width .18s, left .18s, background .18s; }
.meter .track.signed i { left: 50%; }
.meter .track.signed::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: rgba(255, 255, 255, .35); }
.meter .track u { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--gold); }
#work { flex: 0 0 auto; }
#workChart { width: 100%; height: 54px; display: block; border-radius: 10px; background: #05080f; border: 1px solid rgba(120, 150, 255, .14); }
#work .caption { font-size: 11px; color: #8ea0d8; margin-top: 3px; }
#intent { flex: 0 0 auto; }
#intent h4 { margin: 0 0 4px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #9fb2ff; }
.intent { display: grid; grid-template-columns: 78px 1fr 34px; gap: 8px; align-items: center; font-size: 12px; margin: 2px 0; }
.intent .track { height: 6px; border-radius: 6px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.intent .track i { display: block; height: 100%; background: linear-gradient(90deg, #6ee7d8, #a999ff); transition: width .15s; }
.intent b { text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; }
.intent.chosen span { color: var(--gold); }
#brainFacts, #brainStats { color: #8ea0d8; flex: 0 0 auto; }
#brainStats { color: #b9c6f5; font-variant-numeric: tabular-nums; }

dialog { border: 1px solid var(--line2); border-radius: var(--r); padding: 18px 20px; background: var(--card); color: var(--ink); width: min(560px, 94vw); }
dialog::backdrop { background: rgba(5, 3, 12, .6); }
dialog h3 { margin: 0 0 8px; }
dialog .row { margin-top: 10px; gap: 12px; }
.filebutton { border: 1px solid var(--line2); background: var(--card2); border-radius: 10px; padding: 6px 10px; cursor: pointer; }
.filebutton input { display: none; }

select { background: var(--bg2); border: 1px solid var(--line2); border-radius: 8px; padding: 4px; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1180px) { :root { --side: 360px; } }
@media (max-width: 899px) {
  #layout { grid-template-columns: 1fr; padding: 10px; gap: 10px; }
  #side { position: static; max-height: none; }
  .tabpane { overflow: visible; }
  #brain { min-height: 70vh; }
}
@media (max-width: 599px) {
  #top { padding: 6px 10px; gap: 6px 8px; }
  #name { font-size: 16px; width: 8ch; }
  .status { margin-left: auto; }
  .spacer { display: none; }
  .bar { width: 100%; }
  .bar button, .bar .btn { padding: 6px 8px; }
  .lbl, #saved { display: none; }
  #stage { border-radius: 14px; }
  #controls { padding: 8px; }
  .row .label { width: 100%; }
  .row .hint { margin-left: 0; }
  #transmitters { grid-template-columns: 1fr; }
}
