html, body {
  margin: 0; background: #000; color: #ddd; font: 16px -apple-system, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
/* Fixed positioning stops iOS rubber-band scrolling of the page.
   The controls keep their width when collapsed so their contents do not reflow. */
:root { --panel-w: min(340px, 38vw); }
body { position: fixed; inset: 0; display: flex; flex-direction: row-reverse; overflow: hidden; }

#viewer { position: relative; flex: 1 1 0; min-height: 0; min-width: 0; }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; }
#info {
  position: absolute; top: 8px; left: 8px; color: #ddd; font: 14px monospace;
  white-space: pre; pointer-events: none; text-shadow: 0 0 3px #000;
}
/* Drawer handle: a tab on the panel's right border, halfway down. */
#panel-toggle {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%); z-index: 3;
  width: 26px; height: 76px; padding: 0; border: 1px solid #555; border-left: 0;
  border-radius: 0 10px 10px 0; background: rgba(28,28,28,0.85); color: #ddd; font-size: 14px;
}
/* U+25C2 / U+25B8 have no emoji form, so iPad browsers draw them as plain text. */
#panel-toggle::before { content: "\25C2"; font-size: 22px; }
body.panel-collapsed #panel-toggle::before { content: "\25B8"; }
/* Shown over the last prepared frame while the selected frame's predictions load. */
#preparing {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 2;
  padding: 6px 12px; border-radius: 6px; background: rgba(0,0,0,0.7); color: #ffd27a;
  font: 14px sans-serif; white-space: pre; text-align: center; pointer-events: none;
}
#preparing[hidden] { display: none; }
#home-link {
  position: absolute; top: 8px; right: 8px; padding: 6px 8px; color: #7ab8ff;
  font: 14px sans-serif; text-decoration: none;
}

#controls {
  flex: 0 0 var(--panel-w); box-sizing: border-box; display: flex; flex-direction: column; gap: 10px;
  height: 100%; overflow-y: auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  background: #1c1c1c; border-right: 1px solid #444;
  touch-action: manipulation;
  margin-left: 0; visibility: visible;
  transition: margin-left 0.28s ease, visibility 0s;
}

#browser > summary {
  cursor: pointer; padding: 8px 4px; min-height: 24px; color: #7ab8ff;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#load-btn {
  display: block; width: 100%; min-height: 44px; margin-top: 8px; border: 1px solid #7ab8ff;
  border-radius: 8px; background: #2f6fbd; color: #fff; font-size: 16px;
}
#load-btn:disabled { background: #2a2a2a; border-color: #555; color: #888; }
#meta-tip {
  position: fixed; z-index: 10; max-width: min(320px, 60vw); padding: 8px 10px;
  background: rgba(20,20,20,0.95); color: #ddd; border: 1px solid #666; border-radius: 6px;
  font: 13px/1.4 sans-serif; pointer-events: none; box-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
#meta-tip[hidden] { display: none; }
#meta-tip b { color: #7ab8ff; font-weight: 600; }

#file-tree {
  flex: 0 0 auto; max-height: 28vh; min-height: 90px; overflow-y: auto; box-sizing: border-box;
  padding: 2px 4px; background: #111; border: 1px solid #444; border-radius: 6px; font-size: 14px;
}
#file-tree summary { cursor: pointer; padding: 5px 4px; }
#file-tree details details { margin-left: 14px; }
#file-tree .leaf {
  display: block; max-width: calc(100% - 18px); margin-left: 18px; padding: 5px 8px;
  border: 0; border-radius: 4px; cursor: pointer;
  background: transparent; color: inherit; font: inherit; text-align: left;
}
#file-tree .leaf.selected { background: #2f6fbd; color: #fff; }
:focus-visible { outline: 2px solid #7ab8ff; outline-offset: 2px; }

#load-status { display: flex; align-items: center; gap: 10px; font-size: 14px; }
#load-status[hidden] { display: none; }
#load-bar { flex: 1; min-width: 0; height: 14px; accent-color: #7ab8ff; }
#model-status { font-size: 14px; }
#model-status[hidden], #errors[hidden] { display: none; }
#errors {
  position: fixed; bottom: 12px; right: 12px; z-index: 20;
  max-width: min(460px, calc(100vw - 24px)); max-height: 40vh; overflow-y: auto;
  background: #381c1c; border: 1px solid #e99; border-radius: 8px; padding: 8px;
}
#errors > div { display: flex; align-items: center; gap: 12px; padding: 4px; }
#errors span { overflow-wrap: anywhere; }
#errors button {
  flex: 0 0 auto; min-height: 44px; padding: 4px 10px;
  background: #2a2a2a; color: #fff; border: 1px solid #e99; border-radius: 6px;
}
body.loading #errors { pointer-events: none; opacity: 0.5; }
/* While loading, everything except the status line ignores input. */
body.loading #controls > :not(#load-status), body.loading #viewer { pointer-events: none; }
body.loading #controls > :not(#load-status) { opacity: 0.5; }

.seg-group { display: flex; flex-direction: column; gap: 4px; }
.seg-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: #999; }
.segmented { display: flex; }
.segmented button {
  flex: 1; min-width: 0; min-height: 44px; border: 1px solid #555; margin-left: -1px;
  background: #2a2a2a; color: #ddd; font-size: 16px; border-radius: 0;
}
.segmented button:first-child { margin-left: 0; border-radius: 8px 0 0 8px; }
.segmented button:last-child { border-radius: 0 8px 8px 0; }
.segmented button.active { background: #2f6fbd; border-color: #7ab8ff; color: #fff; position: relative; }
.segmented button:disabled { color: #888; cursor: not-allowed; }

.row { display: flex; align-items: center; gap: 12px; min-height: 40px; }
.row[hidden] { display: none; }
.row label { flex: 0 0 auto; min-width: 48px; }
.row input[type=range] { flex: 1; min-width: 0; height: 32px; accent-color: #7ab8ff; }
.row .val { flex: 0 0 auto; min-width: 52px; text-align: right; font: 14px monospace; }
.check { display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; }
.check input { width: 24px; height: 24px; accent-color: #7ab8ff; }

#pad-overlay {
  position: absolute; left: 23px; top: 108px; z-index: 2;   /* just below the 5-line #info text */
  width: min(200px, 38vmin); aspect-ratio: 1;
  opacity: 0.3; transition: opacity 0.2s;
}
#pad-overlay.dragging, #pad-overlay:focus-within { opacity: 1; }
#pad-overlay[hidden] { display: none; }
#blend-pad { display: block; width: 100%; height: 100%; touch-action: none; }
#blend-keyboard-controls {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%);
}
#blend-keyboard-controls:focus-within {
  width: 100%; height: auto; overflow: visible; clip-path: none;
  box-sizing: border-box; padding: 8px; background: #1c1c1c; border: 1px solid #555;
}
#blend-keyboard-controls label { display: block; font-size: 13px; }
#blend-keyboard-controls input { box-sizing: border-box; width: 100%; accent-color: #7ab8ff; }

#advanced > summary { cursor: pointer; padding: 8px 4px; min-height: 24px; color: #7ab8ff; }
#advanced-body { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; }

#interaction-help {
  flex: 0 0 auto; margin-top: auto; padding-top: 12px; border-top: 1px solid #444;
  color: #aaa; font-size: 12px; line-height: 1.45;
}
#interaction-help h2 { margin: 0 0 6px; color: #ccc; font-size: 13px; font-weight: 600; }
#interaction-help h3 { margin: 8px 0 4px; color: #ccc; font-size: 12px; font-weight: 600; }
#interaction-help p { margin: 0; }
#interaction-help ul { margin: 0; padding: 0; list-style: none; }
#interaction-help li + li { margin-top: 4px; }

#group-select, #interp-select {
  flex: 1; min-width: 0; min-height: 40px; background: #2a2a2a; color: #ddd;
  border: 1px solid #555; border-radius: 8px; padding: 0 8px; font-size: 16px;
}

#log {
  display: block; box-sizing: border-box; width: 100%; margin: 0;
  height: calc(10 * 1.4em + 8px); min-height: calc(3 * 1.4em + 8px); resize: none;
  padding: 4px 8px; background: #111; color: #9fdf9f;
  border: 1px solid #444; font: 12px/1.4 monospace;
  -webkit-user-select: text; user-select: text;
}

body.panel-collapsed #controls {
  margin-left: calc(-1 * var(--panel-w)); visibility: hidden;
  transition: margin-left 0.28s ease, visibility 0s 0.28s;   /* hide only after it has slid out */
}
@media (prefers-reduced-motion: reduce) {
  #controls, body.panel-collapsed #controls { transition: none; }
}
