:root {
  color-scheme: dark;
  background: #050505;
  color: #f4f4f0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --bg: #050505;
  --panel: #10110f;
  --panel-2: #171915;
  --line: rgb(255 255 255 / 12%);
  --text: #f4f4f0;
  --muted: rgb(244 244 240 / 64%);
  --green: #86efac;
  --cyan: #67e8f9;
  --yellow: #facc15;
  --blue: #93c5fd;
  --red: #fb7185;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body { overflow: hidden; background: var(--bg); }
button, input, select { font: inherit; }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  width: 100vw;
  height: 100vh;
  background: var(--bg);
}

@supports (height: 100dvh) {
  .app { height: 100dvh; }
}

.viewer {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #020202;
}

#video {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #020202;
}

.child-overlay {
  position: absolute;
  left: clamp(12px, 3vw, 36px);
  right: clamp(12px, 3vw, 36px);
  bottom: clamp(12px, 3vw, 36px);
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.child-overlay[hidden] { display: none; }

.child-summary {
  width: min(520px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  padding: 10px;
  border: 1px solid rgb(244 244 240 / 18%);
  border-radius: 16px;
  background: rgb(5 5 5 / 42%);
  color: #f8fafc;
  backdrop-filter: blur(16px);
  box-shadow: 0 12px 44px rgb(0 0 0 / 24%);
}

.child-summary-group {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.child-summary h2 {
  color: rgb(248 250 252 / 72%);
  font-size: 10px;
  line-height: 1;
}

.child-summary-list {
  display: grid;
  gap: 6px;
}

.child-summary-row {
  --share: 0%;
  position: relative;
  min-width: 0;
  min-height: 34px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  border: 1px solid rgb(244 244 240 / 12%);
  border-radius: 10px;
  background: rgb(255 255 255 / 8%);
  padding: 7px 8px;
}

.child-summary-row[data-active="true"] {
  border-color: rgb(134 239 172 / 58%);
  background: rgb(134 239 172 / 12%);
}

.child-emotion-cards .child-summary-row[data-active="true"] {
  border-color: rgb(250 204 21 / 58%);
  background: rgb(250 204 21 / 11%);
}

.child-summary-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--share);
  background: rgb(255 255 255 / 9%);
}

.child-summary-label,
.child-summary-percent {
  position: relative;
  z-index: 1;
}

.child-summary-label {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  color: rgb(248 250 252 / 88%);
  font-size: 12px;
  font-weight: 760;
  line-height: 1;
  white-space: nowrap;
}

.child-summary-label span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.child-summary-emoji {
  flex: none;
  font-size: 18px;
  line-height: 1;
}

.child-summary-percent {
  color: rgb(248 250 252 / 72%);
  font-size: 11px;
  font-weight: 760;
  line-height: 1;
}

.runtime-status {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.status {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: rgb(255 255 255 / 88%);
  font-size: 13px;
  line-height: 1.35;
}

.loader {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 7px 9px;
  border: 1px solid rgb(103 232 249 / 38%);
  border-radius: 8px;
  background: rgb(103 232 249 / 8%);
  color: var(--cyan);
  font-size: 12px;
  line-height: 1.25;
}

.loader[hidden] { display: none; }
.loader[data-state="ready"] {
  border-color: rgb(134 239 172 / 34%);
  background: rgb(134 239 172 / 8%);
  color: var(--green);
}
.loader[data-state="error"] {
  border-color: rgb(251 113 133 / 40%);
  background: rgb(251 113 133 / 8%);
  color: var(--red);
}

.spinner {
  width: 12px;
  height: 12px;
  flex: none;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 999px;
  animation: spin 0.75s linear infinite;
}

.loader[data-state="ready"] .spinner,
.loader[data-state="error"] .spinner {
  display: none;
}

@keyframes spin { to { transform: rotate(360deg); } }

.panel {
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 19px; line-height: 1.1; font-weight: 720; }
h2 { font-size: 12px; line-height: 1.2; font-weight: 700; color: var(--muted); text-transform: uppercase; }

.panel-link {
  flex: none;
  border: 1px solid rgb(103 232 249 / 30%);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--cyan);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
}
.panel-link:hover { border-color: rgb(103 232 249 / 58%); }

.badge {
  flex: none;
  border: 1px solid rgb(134 239 172 / 34%);
  border-radius: 999px;
  padding: 5px 8px;
  color: var(--green);
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
}

.controls,
.dynamic-controls,
.readout {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}

.controls,
.control-body { border-top: 0; padding-top: 0; margin-top: 0; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; line-height: 1.25; }

input,
select,
button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  min-height: 34px;
  padding: 7px 9px;
  outline: none;
}

button {
  cursor: pointer;
  font-weight: 680;
}
button:hover { border-color: rgb(255 255 255 / 28%); }
button:disabled { cursor: not-allowed; opacity: 0.45; }

.grid { display: grid; gap: 8px; }
.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.controls { display: grid; gap: 10px; }

.primary-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.primary-actions button:only-child {
  grid-column: 1 / -1;
}

.toggles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.quick-toggles {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 0;
}
.toggles label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 11px;
}
.toggles input { width: 14px; min-height: 14px; padding: 0; }

.dynamic-controls {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 12px;
}
.dynamic-controls:empty { display: none; }

.session-controls {
  display: grid;
  gap: 10px;
  margin: 10px 0 12px;
}

.label-groups {
  display: grid;
  gap: 12px;
  margin: 12px 0;
}

.label-group {
  display: grid;
  gap: 8px;
}

.label-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 7px;
}

.label-buttons button {
  min-height: 32px;
  padding: 6px;
  font-size: 11px;
}

.review-cards {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.review-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 9px;
}

.review-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
  color: var(--text);
  font-size: 12px;
  font-weight: 730;
}

.review-card-evidence {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 54px;
  gap: 8px;
  align-items: end;
}
.range-row input[type="range"] { padding: 0; min-height: 28px; }

.section-toggle {
  border-top: 1px solid var(--line);
  margin-top: 10px;
}

.section-toggle summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 14px;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  cursor: pointer;
  color: var(--text);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0;
  list-style: none;
  text-transform: uppercase;
}
.section-toggle summary::-webkit-details-marker { display: none; }
.section-toggle summary::after {
  content: "+";
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  text-align: right;
}
.section-toggle[open] summary::after { content: "-"; }
.summary-value {
  min-width: 0;
  max-width: 170px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 620;
  text-align: right;
  text-overflow: ellipsis;
  text-transform: none;
  white-space: nowrap;
}
.section-body {
  margin: 0 0 12px;
}
.section-body.readout,
.readout.section-body {
  border-top: 0;
  padding-top: 0;
}

.readout dl {
  display: grid;
  grid-template-columns: minmax(96px, 0.85fr) minmax(0, 1fr);
  gap: 7px 10px;
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.3;
}
.readout dt { color: var(--muted); }
.readout dd { margin: 0; overflow-wrap: anywhere; color: var(--text); }

pre {
  max-height: 210px;
  overflow: auto;
  margin: 10px 0 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #070806;
  color: rgb(244 244 240 / 84%);
  font-size: 11px;
  line-height: 1.45;
}

@media (max-width: 1120px) {
  .three { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  body:not(.lab-page) { overflow: hidden; }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(260px, 44vh) minmax(0, 1fr);
    height: 100vh;
    min-height: 0;
  }

  @supports (height: 100dvh) {
    .app {
      grid-template-rows: minmax(260px, 44dvh) minmax(0, 1fr);
      height: 100dvh;
    }
  }

  .viewer {
    height: auto;
    min-height: 0;
  }

  .panel {
    min-height: 0;
    overflow: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 12px 16px calc(18px + env(safe-area-inset-bottom));
  }

  .panel-head {
    position: sticky;
    top: 0;
    z-index: 2;
    margin: -12px -16px 8px;
    padding: 12px 16px 10px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, var(--panel) 74%, rgb(16 17 15 / 92%));
  }

  h1 { font-size: 18px; }

  .panel-link {
    min-height: 30px;
    display: inline-flex;
    align-items: center;
  }

  .section-toggle { margin-top: 0; }

  .section-toggle summary {
    grid-template-columns: minmax(0, 1fr) minmax(76px, auto) 14px;
    min-height: 40px;
  }

  .summary-value { max-width: 142px; }

  .status { font-size: 12px; }

  .primary-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .primary-actions button {
    min-height: 42px;
    padding: 8px 6px;
    font-size: 12px;
  }

  .toggles,
  .quick-toggles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toggles label {
    min-height: 36px;
    padding: 0 9px;
    font-size: 12px;
  }

  .label-buttons { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  .readout dl {
    grid-template-columns: minmax(82px, 0.8fr) minmax(0, 1fr);
  }

  pre { max-height: 160px; }

  .child-card { flex-basis: 58px; }
  .child-emotion-cards .child-card { flex-basis: 54px; }
}

@media (max-width: 480px) {
  .two,
  .three {
    grid-template-columns: 1fr;
  }

  .summary-value { max-width: 116px; }
}

@media (max-width: 360px) {
  .primary-actions,
  .label-buttons,
  .toggles,
  .quick-toggles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

body.child-runtime {
  overflow: hidden;
}

body.child-runtime .app {
  display: block;
  width: 100vw;
  height: 100vh;
}

@supports (height: 100dvh) {
  body.child-runtime .app { height: 100dvh; }
}

body.child-runtime .viewer {
  width: 100vw;
  height: 100vh;
  min-height: 0;
}

@supports (height: 100dvh) {
  body.child-runtime .viewer { height: 100dvh; }
}

body.child-runtime .panel {
  display: none;
}

body.child-runtime .child-overlay {
  left: clamp(10px, 4vw, 28px);
  right: clamp(10px, 4vw, 28px);
  bottom: calc(clamp(12px, 4vw, 30px) + env(safe-area-inset-bottom));
}

body.child-runtime .child-summary {
  width: min(520px, 100%);
}

@media (orientation: landscape) and (max-height: 700px) {
  body.child-runtime .child-overlay {
    left: auto;
    width: min(390px, 38vw);
    justify-content: flex-end;
  }

  body.child-runtime .child-summary {
    width: 100%;
  }
}

@media (max-width: 380px) {
  .child-summary {
    grid-template-columns: 1fr;
    width: min(280px, 100%);
  }
}

.lab-page {
  min-height: 100%;
  overflow: auto;
  background:
    linear-gradient(180deg, rgb(103 232 249 / 5%), transparent 220px),
    var(--bg);
}

.lab-shell {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

.lab-head {
  display: grid;
  gap: 18px;
  margin-bottom: 30px;
}

.lab-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding-top: 4px;
}

.lab-action {
  min-width: 148px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  font-size: 12px;
}

.lab-action-primary {
  border-color: rgb(134 239 172 / 42%);
  background: rgb(134 239 172 / 10%);
  color: var(--green);
}

.lab-feedback,
.lab-support {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.lab-feedback {
  margin-top: -8px;
}

.lab-support {
  margin-top: -10px;
}

.lab-feedback-link {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  font-size: 11px;
}

.lab-feedback-primary {
  border-color: rgb(103 232 249 / 42%);
  background: rgb(103 232 249 / 9%);
}

.lab-support-link {
  border-color: rgb(250 204 21 / 42%);
  background: rgb(250 204 21 / 9%);
  color: var(--yellow);
}

.lab-head p,
.lab-section p {
  max-width: 780px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.lab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.lab-section + .lab-section { margin-top: 24px; }

.lab-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 12px;
}

.lab-card h2 {
  margin-bottom: 7px;
  color: var(--text);
  text-transform: none;
  font-size: 13px;
}

.lab-card p {
  margin: 0 0 10px;
  font-size: 12px;
}

.lab-card a {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 700;
}

.lab-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.lab-tags span {
  border: 1px solid rgb(244 244 240 / 14%);
  border-radius: 999px;
  padding: 4px 7px;
  color: rgb(244 244 240 / 72%);
  font-size: 11px;
}

@media (max-width: 600px) {
  .lab-shell {
    width: min(1120px, calc(100vw - 24px));
    padding: 24px 0 36px;
  }

  .lab-head {
    gap: 12px;
    margin-bottom: 24px;
  }

  .lab-head h1 { font-size: 20px; }

  .lab-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .lab-card { padding: 12px; }
}
