:root {
  --bg: #0d0f14;
  --panel: rgba(20, 23, 30, 0.72);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e8eaee;
  --muted: #9aa1ad;
  --accent: #5eead4;
  --ctx: #a78bfa;
  --warn: #fbbf24;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, sans-serif; }
#stage, #stage canvas { position: fixed; inset: 0; display: block; touch-action: none; }
.glass { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
kbd { font: 600 11px 'JetBrains Mono', monospace; padding: 1px 5px; border-radius: 5px; border: 1px solid var(--line); background: rgba(255,255,255,0.06); color: var(--muted); }
button { font: inherit; color: inherit; cursor: pointer; }

#title { position: fixed; top: 18px; left: 22px; pointer-events: none; text-shadow: 0 2px 12px rgba(0,0,0,0.6); }
#title .brand { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; display: flex; align-items: center; gap: 10px; }
#title .brand small { font-weight: 500; color: var(--muted); font-size: 22px; }
#title .logo { width: 20px; height: 20px; border-radius: 5px; background: conic-gradient(from 45deg, var(--accent), var(--ctx), var(--accent)); box-shadow: 0 0 18px rgba(94,234,212,0.45); }
#title .sub { color: var(--muted); margin-top: 2px; font-size: 13px; }

#stats { position: fixed; top: 18px; right: 18px; display: flex; gap: 18px; padding: 10px 16px; }
#stats div { display: flex; flex-direction: column; min-width: 64px; }
#stats label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
#stats span { font: 600 14px 'JetBrains Mono', monospace; white-space: nowrap; }
#stats #state { font-family: Inter, sans-serif; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,0.15); margin-left: 4px; transition: background 0.1s; }
.dot.on { background: var(--accent); box-shadow: 0 0 10px var(--accent); }

#panel { position: fixed; left: 18px; top: 92px; width: 268px; max-height: calc(100% - 210px); overflow: auto; padding: 12px 14px 14px; transition: transform 0.25s, opacity 0.25s; }
#panel h3 { margin: 12px 0 7px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 600; }
#panel h3:first-of-type { margin-top: 2px; }
#panel-toggle { position: absolute; top: 8px; right: 8px; border: 0; background: none; color: var(--muted); font-size: 16px; }
body.panel-collapsed #panel { transform: translateX(-232px); opacity: 0.85; }
body.panel-collapsed #panel .panel-body { visibility: hidden; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 1px solid var(--line); background: rgba(255,255,255,0.04); padding: 5px 9px; border-radius: 999px; font-size: 12.5px; display: inline-flex; gap: 6px; align-items: center; transition: all 0.12s; }
.chips button kbd { padding: 0 4px; font-size: 10px; }
.chips button:hover { border-color: rgba(255,255,255,0.25); }
.chips button.on { background: var(--accent); color: #062b25; border-color: var(--accent); font-weight: 600; }
.chips button.on kbd { color: #062b25; border-color: rgba(6,43,37,0.3); }
#toggles label { display: flex; align-items: center; gap: 8px; padding: 3px 0; color: #cfd3da; font-size: 13px; cursor: pointer; }
#toggles input { accent-color: var(--accent); }
ul.keys { list-style: none; padding: 0; margin: 0; color: #c3c8d0; font-size: 12.5px; }
ul.keys li { margin: 4px 0; }
.note { color: var(--muted); font-size: 12.5px; margin: 12px 0 0; }
.note b { color: var(--text); }

#log { position: fixed; right: 18px; top: 84px; width: 330px; font: 12px 'JetBrains Mono', monospace; color: #cbd5e1; text-align: right; pointer-events: none; }
#log div { padding: 3px 0; text-shadow: 0 1px 8px rgba(0,0,0,0.8); }
#log b { color: var(--accent); font-weight: 600; }

#timeline-wrap { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); width: min(560px, calc(100% - 36px)); padding: 10px 14px 9px; }
#timeline { position: relative; height: 10px; border-radius: 6px; background: linear-gradient(90deg, rgba(94,234,212,0.25), rgba(94,234,212,0.45)); overflow: visible; }
#timeline .ctx { position: absolute; left: -8px; top: 0; width: 8px; height: 10px; border-radius: 4px 0 0 4px; background: var(--ctx); }
#timeline .play { position: absolute; top: -4px; left: var(--play, 0%); width: 3px; height: 18px; background: #fff; border-radius: 2px; transform: translateX(-1px); box-shadow: 0 0 8px rgba(255,255,255,0.8); }
#timeline .trans { position: absolute; top: -2px; left: var(--trans, 100%); width: 10px; height: 14px; border-radius: 3px; border: 2px solid var(--accent); transform: translateX(-5px); }
#timeline.idle { background: rgba(255,255,255,0.08); }
#timeline.idle i { display: none; }
#tl-label { margin-top: 6px; font: 12px 'JetBrains Mono', monospace; color: #cbd5e1; text-align: center; }
.legend { display: flex; gap: 14px; justify-content: center; margin-top: 4px; font-size: 11px; color: var(--muted); }
.legend span::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: -0.5px; }
.legend .l-ctx::before { background: var(--ctx); }
.legend .l-tgt::before { background: var(--accent); }
.legend .l-plan::before { background: var(--accent); height: 2px; vertical-align: 2px; }
.legend .l-tr::before { border: 2px solid var(--accent); background: none; width: 5px; height: 5px; }

#loading { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(520px, calc(100% - 32px)); padding: 26px 26px 20px; z-index: 10; transition: opacity 0.4s, transform 0.4s; }
#loading h1 { margin: 0 0 8px; font-size: 26px; letter-spacing: -0.02em; }
#loading h1 span { color: var(--accent); }
#loading p { color: #c3c8d0; margin: 0 0 16px; }
#loading .small, .small { font-size: 12px; color: var(--muted); }
.loadrow { display: grid; grid-template-columns: 120px 1fr 150px; align-items: center; gap: 10px; margin: 10px 0; font-size: 13px; }
.loadrow b { height: 6px; background: rgba(255,255,255,0.08); border-radius: 4px; overflow: hidden; }
.loadrow i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.loadrow em { font: 11.5px 'JetBrains Mono', monospace; color: var(--muted); font-style: normal; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.loadrow.err em, .err { color: #f87171; }
#start { margin-top: 6px; border: 1px solid var(--line); background: rgba(255,255,255,0.06); padding: 8px 14px; border-radius: 10px; }
body:not(.world-ready) #start { visibility: hidden; }
body.model-ready #loading, body.dismissed #loading { opacity: 0; transform: translate(-50%, -46%); pointer-events: none; }

#credits { position: fixed; right: 18px; bottom: 18px; color: var(--muted); font-size: 12px; text-decoration: none; }
#about { position: fixed; right: 18px; bottom: 44px; width: min(420px, calc(100% - 36px)); padding: 16px 18px; display: none; z-index: 12; }
#about.open { display: block; }
#about h3 { margin: 0 0 8px; }
#about p { color: #c3c8d0; font-size: 13px; margin: 0 0 10px; }
#about a { color: var(--accent); }
#about button { border: 1px solid var(--line); background: rgba(255,255,255,0.06); padding: 6px 12px; border-radius: 8px; }

#touch { display: none; }
@media (pointer: coarse) {
  #touch { display: block; }
  #joystick { position: fixed; left: 24px; bottom: 120px; width: 120px; height: 120px; border-radius: 50%; background: rgba(255,255,255,0.06); border: 1px solid var(--line); touch-action: none; }
  #knob { position: absolute; left: 36px; top: 36px; width: 48px; height: 48px; border-radius: 50%; background: rgba(255,255,255,0.25); }
  .touch-buttons { position: fixed; right: 18px; bottom: 120px; display: flex; flex-direction: column; gap: 10px; }
  .touch-buttons button { width: 84px; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); }
}
@media (max-width: 760px) {
  #panel { top: auto; bottom: 110px; max-height: 40%; width: calc(100% - 36px); }
  body:not(.panel-collapsed) #panel { }
  #stats { top: auto; bottom: 96px; left: 18px; right: 18px; gap: 10px; flex-wrap: wrap; justify-content: space-between; display: none; }
  #log { display: none; }
  #title .brand, #title .brand small { font-size: 18px; }
  .loadrow { grid-template-columns: 96px 1fr 110px; }
}

/* Capture mode: clean frame for video recording. */
body.capture #panel, body.capture #credits, body.capture #touch, body.capture #loading { display: none !important; }

#caption, #card { display: none; }
body.capture #caption { display: block; position: fixed; z-index: 20; left: 50%; bottom: 128px; transform: translateX(-50%); text-align: center; opacity: 0; transition: opacity 0.4s; pointer-events: none; }
body.capture #caption.on { opacity: 1; }
#caption b { display: inline-block; font-size: 30px; font-weight: 700; letter-spacing: -0.02em; padding: 6px 18px; border-radius: 12px; background: rgba(13,15,20,0.62); }
#caption span { display: block; margin-top: 8px; font-size: 18px; color: #d4d8de; text-shadow: 0 2px 10px rgba(0,0,0,0.9); }
body.capture #card { display: flex; position: fixed; inset: 0; z-index: 30; align-items: center; justify-content: center; flex-direction: column; text-align: center; background: radial-gradient(ellipse at center, rgba(13,15,20,0.55), rgba(13,15,20,0.92)); opacity: 0; transition: opacity 0.5s; pointer-events: none; }
body.capture #card.on { opacity: 1; }
#card h1 { font-size: 76px; margin: 0; letter-spacing: -0.03em; background: linear-gradient(90deg, #5eead4, #a78bfa); -webkit-background-clip: text; background-clip: text; color: transparent; }
#card p { font-size: 28px; color: #e8eaee; margin: 14px 0 18px; }
#card small { font-size: 16px; color: #9aa1ad; line-height: 1.6; }
body.capture #title { opacity: 0.95; }
