:root {
  color-scheme: dark;
  --bg: #090b0d;
  --panel: #11161a;
  --panel-2: #171d22;
  --line: #2b363d;
  --line-bright: #4b6874;
  --text: #e8edf0;
  --muted: #9daab1;
  --dim: #6d7a82;
  --green: #82f5b1;
  --cyan: #8fd8ff;
  --amber: #f1c76b;
  --red: #ff7d72;
  --shadow: 0 18px 80px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    linear-gradient(rgba(143, 216, 255, 0.026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(143, 216, 255, 0.026) 1px, transparent 1px),
    radial-gradient(circle at 22% 0%, rgba(130, 245, 177, 0.08), transparent 28rem),
    var(--bg);
  background-size: 28px 28px, 28px 28px, auto, auto;
  color: var(--text);
  font-family:
    "Inter",
    "Segoe UI",
    "Hiragino Kaku Gothic ProN",
    "Yu Gothic",
    sans-serif;
  letter-spacing: 0;
}

button,
select,
input {
  font: inherit;
}

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

.lab-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

h1 {
  margin: 0;
  font-size: clamp(2.25rem, 5.6vw, 5.6rem);
  line-height: 0.92;
  letter-spacing: 0;
}

.lead {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.18rem);
}

.hero-summary {
  max-width: 780px;
  margin: 10px 0 0;
  color: #c7d4d8;
  font-size: 0.94rem;
  line-height: 1.75;
}

.hero-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.hero-tags span,
.status-strip span,
.lab-links a,
.lab-footer a {
  border: 1px solid var(--line);
  text-decoration: none;
}

.hero-tags span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  color: var(--muted);
  background: rgba(17, 22, 26, 0.72);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.status-strip,
.control-band,
.lab-links {
  border: 1px solid var(--line);
  background: rgba(17, 22, 26, 0.82);
  box-shadow: var(--shadow);
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
}

.status-strip span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 10px;
  color: var(--muted);
  background: #0d1113;
  font-size: 0.72rem;
  font-weight: 700;
}

.lamp {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 16px rgba(130, 245, 177, 0.75);
}

.lamp-live {
  animation: pulse 1.8s ease-in-out infinite;
}

.control-band {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  margin-bottom: 14px;
}

.primary-button,
.secondary-button,
.switch,
.select-label,
.mode-control {
  min-height: 42px;
  border: 1px solid var(--line-bright);
  background: #10161a;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.primary-button,
.secondary-button {
  padding: 0 18px;
  cursor: pointer;
}

.primary-button {
  color: #06110c;
  background: var(--green);
}

.secondary-button:disabled {
  color: var(--dim);
  border-color: var(--line);
  cursor: not-allowed;
}

.switch,
.select-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  color: var(--muted);
}

.mode-control {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
}

.mode-button {
  min-width: 74px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.mode-button.is-selected {
  color: #06120c;
  background: var(--green);
}

.switch input {
  accent-color: var(--green);
}

.select-label {
  margin-left: auto;
}

select {
  max-width: 260px;
  color: var(--text);
  border: 0;
  background: transparent;
  outline: 0;
}

.observation-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  gap: 14px;
}

.monitor {
  position: relative;
  min-height: 420px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--line-bright);
  background:
    linear-gradient(rgba(143, 216, 255, 0.065) 1px, transparent 1px),
    linear-gradient(90deg, rgba(143, 216, 255, 0.065) 1px, transparent 1px),
    #070a0c;
  background-size: 40px 40px;
  box-shadow: var(--shadow);
}

.monitor::after {
  content: "FACE SIGNAL";
  position: absolute;
  top: 12px;
  right: 12px;
  writing-mode: vertical-rl;
  color: rgba(232, 237, 240, 0.55);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  pointer-events: none;
}

video,
#overlayCanvas,
#sampleCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

video {
  object-fit: cover;
  opacity: 0;
  transition: opacity 180ms ease;
}

.is-live video {
  opacity: 0.88;
}

.is-mirrored video {
  transform: scaleX(-1);
}

#sampleCanvas {
  display: none;
}

#traceCanvas {
  display: block;
  width: 100%;
  height: 96px;
  border: 1px solid var(--line-bright);
  background:
    linear-gradient(rgba(143, 216, 255, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(143, 216, 255, 0.07) 1px, transparent 1px),
    #070a0c;
  background-size: 24px 24px;
}

.monitor-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 20px;
  text-align: center;
  color: var(--muted);
}

.monitor-empty span {
  color: var(--green);
  font-weight: 900;
  letter-spacing: 0.14em;
}

.monitor-empty small {
  color: var(--dim);
}

.is-live .monitor-empty {
  display: none;
}

.panel-stack {
  display: grid;
  gap: 14px;
  align-content: start;
}

.readout-panel,
.info-block,
.comment-panel,
.lab-footer {
  border: 1px solid var(--line);
  background: rgba(17, 22, 26, 0.9);
  box-shadow: var(--shadow);
}

.readout-panel {
  padding: 14px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.panel-title b {
  color: var(--green);
}

.meter-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.compact-list {
  grid-template-columns: 1fr 1fr;
}

.meter-list div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}

.readiness-panel {
  border-color: rgba(130, 245, 177, 0.36);
}

dt {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

dd {
  margin: 0;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 900;
}

.bar-meter {
  height: 20px;
  overflow: hidden;
  border: 1px solid var(--line-bright);
  background: #090d10;
}

.bar-meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--cyan), var(--amber));
  transition: width 120ms linear;
}

.note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.7;
}

.policy-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.policy-list li {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

.policy-list li::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border: 1px solid var(--green);
}

.info-band {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.info-block {
  padding: 16px;
}

.info-block-wide {
  grid-column: 1 / -1;
}

.info-block h2 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.45;
  letter-spacing: 0;
}

.info-block p:not(.eyebrow) {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.85;
}

.guide-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.guide-list div {
  display: grid;
  gap: 4px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.guide-list div:first-child {
  border-top: 0;
  padding-top: 0;
}

.guide-list dd {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 500;
  line-height: 1.7;
}

.trace-panel {
  padding-bottom: 12px;
}

.trace-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.trace-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.trace-legend i {
  display: inline-block;
  width: 18px;
  height: 2px;
}

.trace-expression {
  background: var(--green);
}

.trace-blink {
  background: var(--cyan);
}

.trace-mouth {
  background: var(--amber);
}

.events-panel {
  max-height: 220px;
  overflow: hidden;
}

.event-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.event-list li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: baseline;
  min-height: 28px;
  padding: 6px 8px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 0.76rem;
  line-height: 1.35;
}

.event-list time {
  color: var(--green);
  font-weight: 900;
  letter-spacing: 0.06em;
}

.lab-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding: 10px;
}

.lab-links a {
  min-height: 34px;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.comment-panel,
.lab-footer {
  margin-top: 14px;
}

.comment-panel {
  padding: 16px;
}

.comment-panel h2 {
  margin: 0 0 8px;
  font-size: 1rem;
  letter-spacing: 0;
}

.comment-panel p:not(.eyebrow) {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.8;
}

.lab-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: start;
  padding: 18px;
}

.lab-footer p:not(.eyebrow) {
  max-width: 780px;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.8;
}

.lab-footer nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.lab-footer a {
  color: var(--muted);
  padding: 8px 10px;
  font-size: 0.76rem;
  font-weight: 800;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

@media (max-width: 980px) {
  .lab-header,
  .control-band {
    align-items: stretch;
    flex-direction: column;
  }

  .select-label {
    margin-left: 0;
  }

  .mode-control {
    width: 100%;
  }

  .observation-grid,
  .info-band,
  .lab-footer {
    grid-template-columns: 1fr;
  }

  .info-block-wide {
    grid-column: auto;
  }

  .lab-footer nav {
    justify-content: flex-start;
  }

  .monitor {
    min-height: 300px;
  }
}

@media (max-width: 560px) {
  .lab-shell {
    width: min(100vw - 18px, 1480px);
    padding-top: 14px;
  }

  h1 {
    font-size: 2.05rem;
  }

  .status-strip,
  .lab-links {
    display: grid;
  }

  .monitor {
    min-height: auto;
    aspect-ratio: 4 / 3;
  }

  .monitor::after {
    display: none;
  }

  .compact-list,
  .meter-list div {
    grid-template-columns: 1fr;
  }

  .meter-list div {
    padding: 8px 10px;
  }
}
