:root {
  color-scheme: dark;
  --bg: #0e1114;
  --panel: rgba(22, 27, 31, 0.78);
  --panel-border: rgba(226, 232, 240, 0.18);
  --text: #f4f2ec;
  --muted: #aeb8bd;
  --accent: #78d08f;
  --accent-strong: #9febaa;
  --button: rgba(244, 242, 236, 0.1);
  --button-hover: rgba(244, 242, 236, 0.17);
}

* {
  box-sizing: border-box;
}

html,
body,
.app-shell {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background:
    radial-gradient(circle at 78% 12%, rgba(120, 208, 143, 0.16), transparent 28%),
    linear-gradient(135deg, #11161a 0%, #0c0f12 52%, #161310 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.app-shell {
  position: relative;
  min-width: 320px;
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#scene:active {
  cursor: grabbing;
}

.toolbar {
  position: fixed;
  left: 18px;
  bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  max-width: calc(100vw - 36px);
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
}

.control-group {
  display: flex;
  gap: 8px;
}

button {
  min-width: 74px;
  min-height: 38px;
  border: 1px solid rgba(244, 242, 236, 0.14);
  border-radius: 6px;
  background: var(--button);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  background: var(--button-hover);
  outline: none;
}

button[aria-pressed="true"] {
  border-color: rgba(159, 235, 170, 0.72);
  background: rgba(120, 208, 143, 0.19);
  color: var(--accent-strong);
}

.select-control,
.slider-control {
  display: flex;
  align-items: center;
  gap: 8px;                /* label sits close to its control */
  min-width: 0;            /* allow shrinking so items wrap instead of overflowing */
  color: var(--muted);
  font-size: 0.86rem;
}

/* The control (dropdown / slider) takes the remaining width; the label stays
   tight against it. */
.select-control > select,
.slider-control > input[type="range"] {
  flex: 1 1 auto;
  min-width: 70px;
}

.select-control {
  flex: 1 1 200px;
}

.slider-control {
  flex: 1 1 150px;
}

select {
  min-height: 38px;
  max-width: 100%;
  border: 1px solid rgba(244, 242, 236, 0.14);
  border-radius: 6px;
  background: rgba(14, 17, 20, 0.88);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  padding: 0 34px 0 10px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.status {
  position: fixed;
  top: 18px;
  left: 50%;
  max-width: min(560px, calc(100vw - 36px));
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.35;
  text-align: center;
  transform: translateX(-50%);
  backdrop-filter: blur(18px);
}

/* Normal model description is suppressed (updateStatus leaves it empty), but a
   real error/fallback message populates it and becomes visible. */
.status:empty {
  display: none;
}

.status.error {
  border-color: rgba(255, 122, 107, 0.6);
  color: #ffb4aa;
}

.gesture-guide {
  position: fixed;
  top: 18px;
  left: 18px;
  width: min(360px, calc(100vw - 36px));
  padding: 8px 10px 10px;
  border-radius: 8px;
  background: rgba(14, 17, 20, 0.42);
  backdrop-filter: blur(6px);
  z-index: 5;
}

.gesture-guide.hidden {
  display: none;
}

.guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.guide-title {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text);
}

.gesture-guide.minimized {
  width: auto;
}

.gesture-guide.minimized .guide-body {
  display: none;
}

/* Small square toggle used by panels (overrides the global button sizing). */
.panel-toggle {
  width: 26px;
  height: 22px;
  min-width: 0;
  min-height: 0;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}

.gesture-guide .guide-body {
  margin: 7px 0 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.gesture-guide div {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 0.74rem;
  line-height: 1.25;
}

.gesture-guide dt {
  flex: 0 0 168px;
  color: var(--text);
  font-weight: 500;
}

.gesture-guide dd {
  margin: 0;
  color: var(--muted);
}

.hand-hud {
  position: fixed;
  left: 18px;
  /* Sit above the toolbar, whose height grows as it wraps (set by JS). */
  bottom: calc(var(--toolbar-height, 64px) + 16px);
  width: min(240px, 42vw);
  padding: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
  z-index: 6;
}

.hand-hud.hidden {
  display: none;
}

.hand-hud video {
  display: none;
}

.hand-hud canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 5px;
  background: #000;
}

.hand-readout {
  display: none;
}

.hand-readout.alert {
  display: block;
  margin: 6px 2px 0;
  font-size: 0.72rem;
  line-height: 1.3;
  color: #ff7a6b;
  font-variant-numeric: tabular-nums;
}

.graphs {
  position: fixed;
  top: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(340px, calc(100vw - 36px));
  z-index: 5;
}

.graphs:empty,
.graphs.hidden {
  display: none;
}

.graphs-toggle {
  align-self: flex-end;
  width: 28px;
  height: 24px;
  min-width: 0;
  min-height: 0;
  margin-bottom: -4px;
  padding: 0;
  font-size: 1.05rem;
  line-height: 1;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
}

.graphs-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.graphs.minimized {
  width: auto;
}

.graphs.minimized .graphs-body {
  display: none;
}

.graph-card {
  margin: 0;
  padding: 10px 10px 6px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
}

.graph-card figcaption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.graph-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
}

.graph-readout {
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  text-align: right;
}

.graph-readout.alert {
  color: #ff7a6b;
}

.graph-card canvas {
  display: block;
  width: 100%;
  height: auto;
}

@media (max-width: 560px) {
  .toolbar {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  button {
    min-width: 62px;
    padding-inline: 10px;
  }

  /* Keep the panels in their corners but let them use the narrow width. */
  .graphs,
  .gesture-guide {
    width: calc(100vw - 24px);
  }
}
