* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #111; color: #ddd;
  font: 12px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif; }
#app { display: grid; grid-template-columns: 1fr 300px; grid-template-rows: 1fr auto; height: 100vh; }
#view { position: relative; grid-column: 1; grid-row: 1; overflow: hidden; }
#view canvas.gl { display: block; width: 100%; height: 100%; touch-action: none; }
#panel { grid-column: 2; grid-row: 1 / span 2; overflow-y: auto; background: #1b1d21; border-left: 1px solid #333; }
#panel section { padding: 8px 10px; border-bottom: 1px solid #2c2f35; }
#panel h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: #9aa; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 3px 0; }
.toggles label { white-space: nowrap; }
.muted { color: #889; }
.hidden { display: none !important; }
select, button, input { font: inherit; }
select, button { background: #2a2d33; color: #ddd; border: 1px solid #444; border-radius: 3px; padding: 2px 6px; }
button:hover { background: #353941; }
button.on { background: #36506b; border-color: #5a86b0; }
#session-select { flex: 1; min-width: 0; }

#subjects .subj { display: grid; grid-template-columns: 14px 12px 1fr auto auto; gap: 0 6px; align-items: center;
  padding: 2px 4px; border-radius: 3px; }
#subjects .subj .av { grid-column: 3 / span 3; font-size: 11px; color: #aab; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
#subjects .subj .av.fallback { font-style: italic; color: #889; }
#subjects .subj.absent { opacity: .45; }
#subjects .subj.followed { background: #2b3a4a; }
#subjects .sw { width: 12px; height: 12px; border-radius: 6px; }
#subjects .sid { font-family: ui-monospace, Consolas, monospace; }
#subjects button { padding: 0 5px; font-size: 11px; }

#episodes { max-height: 45vh; overflow-y: auto; font-family: ui-monospace, Consolas, monospace; font-size: 11px; }
#episodes .ep { display: grid; grid-template-columns: 54px 82px 34px 1fr; gap: 4px; padding: 1px 4px; cursor: pointer;
  border-radius: 2px; white-space: nowrap; overflow: hidden; }
#episodes .ep:hover { background: #2a2f37; }
#episodes .ep.active { background: #36506b; }
#episodes .ep .ty { overflow: hidden; text-overflow: ellipsis; }
#episodes .ep .subs { overflow: hidden; text-overflow: ellipsis; color: #99a; }
#episodes .more { color: #889; padding: 4px; }

#timeline { grid-column: 1; grid-row: 2; display: flex; gap: 8px; align-items: center; padding: 6px 10px;
  background: #1b1d21; border-top: 1px solid #333; flex-wrap: wrap; }
#btn-play { width: 34px; }
#time-label { font-family: ui-monospace, Consolas, monospace; min-width: 140px; }
#scrub-wrap { position: relative; flex: 1; min-width: 200px; height: 30px; }
#ticks { position: absolute; left: 0; top: 0; width: 100%; height: 12px; pointer-events: none; }
#scrub { position: absolute; left: 0; bottom: 0; width: 100%; margin: 0; }
#legend { display: flex; flex-wrap: wrap; gap: 4px; width: 100%; }
#legend .chip { display: inline-flex; gap: 3px; align-items: center; padding: 0 5px; border-radius: 8px;
  background: #24272d; cursor: pointer; user-select: none; font-size: 11px; }
#legend .chip.off { opacity: .35; }
#legend .chip i { width: 8px; height: 8px; border-radius: 4px; display: inline-block; }

#hud { position: absolute; left: 8px; top: 8px; pointer-events: none; text-shadow: 0 1px 2px #000; color: #fff;
  font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
#help { margin-top: 4px; background: rgba(0, 0, 0, .55); padding: 6px 8px; border-radius: 4px; max-width: 560px;
  font-family: system-ui, sans-serif; }
#loading { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px; align-items: center;
  justify-content: center; background: rgba(10, 12, 16, .6); font-size: 16px; color: #fff; padding: 0 20px;
  text-align: center; z-index: 8; }
#loading-bar { width: min(320px, 80%); height: 6px; background: #333; border-radius: 3px; overflow: hidden; }
#loading-bar i { display: block; height: 100%; width: 0; background: #5a9cff; transition: width .1s; }

#tooltip { position: absolute; pointer-events: none; background: rgba(16, 18, 22, .9); color: #eee; padding: 6px 8px;
  border-radius: 4px; border: 1px solid #444; font-size: 12px; max-width: 280px; z-index: 5; word-break: break-all; }
#selection { font-size: 12px; word-break: break-all; }
#selection-section h3 button { float: right; padding: 0 5px; font-size: 11px; }

/* ---- touch and narrow layouts (desktop unchanged: these elements are hidden there) */
.touch-only, .mobile-only, #btn-drawer, #drawer-backdrop { display: none; }
body.touch .touch-only { display: block; }
#selcard { position: absolute; left: 8px; right: 8px; bottom: 8px; max-width: 420px; background: rgba(16, 18, 22, .92);
  border: 1px solid #444; border-radius: 6px; padding: 8px 10px; font-size: 13px; z-index: 6; word-break: break-all; }
#selcard button { min-height: 34px; padding: 4px 12px; }
body.touch #selcard { right: 86px; } /* keep the mode/boost buttons free */

#joy { position: absolute; left: 24px; bottom: 24px; width: 112px; height: 112px; border-radius: 56px;
  border: 2px solid rgba(255, 255, 255, .35); background: rgba(0, 0, 0, .15); pointer-events: none; z-index: 4; }
body.touch.follow #joy { display: none; }
#joy.engaged { border-color: rgba(255, 255, 255, .7); background: rgba(0, 0, 0, .25); bottom: auto; }
#joy-knob { position: absolute; left: 32px; top: 32px; width: 48px; height: 48px; border-radius: 24px;
  background: rgba(255, 255, 255, .55); }
#touch-buttons { position: absolute; right: 10px; bottom: 12px; z-index: 5; }
body.touch #touch-buttons { display: flex; flex-direction: column; gap: 8px; }
#touch-buttons button { min-width: 64px; min-height: 44px; font-size: 14px; background: rgba(30, 33, 38, .85); }
body.follow #btn-boost { display: none; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  #view { grid-column: 1; }
  #timeline { grid-column: 1; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); gap: 6px; }
  #panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(88vw, 380px); z-index: 30;
    transform: translateX(105%); transition: transform .2s ease; box-shadow: -4px 0 16px rgba(0, 0, 0, .5);
    padding-bottom: env(safe-area-inset-bottom); }
  body.drawer-open #panel { transform: none; }
  body.drawer-open #drawer-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 25; }
  #btn-drawer { display: block; position: absolute; top: 8px; right: 8px; z-index: 7; width: 48px; height: 44px;
    font-size: 22px; background: rgba(30, 33, 38, .85); }
  .mobile-only { display: inline-block; }
  #timeline button, #timeline select { min-width: 44px; min-height: 44px; font-size: 15px; }
  #btn-play { width: 52px; }
  #time-label { min-width: 0; font-size: 12px; order: 10; }
  #scrub-wrap { order: 9; flex-basis: 100%; height: 40px; }
  #ticks { height: 10px; }
  #legend { display: none; }
  #scrub { -webkit-appearance: none; appearance: none; height: 28px; background: transparent; }
  #scrub::-webkit-slider-runnable-track { height: 6px; background: #444; border-radius: 3px; }
  #scrub::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px; margin-top: -11px;
    border-radius: 14px; background: #5a9cff; border: 2px solid #fff; }
  #scrub::-moz-range-track { height: 6px; background: #444; border-radius: 3px; }
  #scrub::-moz-range-thumb { width: 26px; height: 26px; border-radius: 13px; background: #5a9cff; border: 2px solid #fff; }
  #hud { font-size: 11px; right: 64px; }
  #panel select, #panel button { min-height: 36px; }
  #panel .toggles label { padding: 4px 2px; }
  #subjects .subj { padding: 6px 4px; }
  #subjects button { min-height: 32px; padding: 0 10px; }
  #episodes .ep { padding: 6px 4px; font-size: 12px; }
  #help { max-width: none; }
  #panel input[type=checkbox] { width: 20px; height: 20px; vertical-align: middle; }
}
