* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #04080d;
  color: #b8dbe4;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

#stage { position: fixed; inset: 0; display: block; }

/* The video is the tracking source as well as the optional preview, so it must
   stay in the render tree at all times: Chrome will not start playback on a
   display:none video, and a paused video yields no frames to track. Hiding it
   therefore means shrinking it to nothing, never removing it. */
#cam {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 180px;
  border-radius: 10px;
  transform: scaleX(-1); /* mirror, so it matches the particle face */
  opacity: 0.85;
  border: 1px solid rgba(120, 220, 240, 0.25);
  z-index: 5;
  transition: opacity 0.2s;
}
#cam:not(.visible) {
  width: 8px;
  height: 6px;
  opacity: 0;
  border-color: transparent;
  pointer-events: none;
}

/* fixation target for gaze scoring */
#target {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: #ff4d4d;
  box-shadow: 0 0 12px 3px rgba(255, 77, 77, 0.55);
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  z-index: 6;
}
#target.visible { opacity: 1; animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.35); } }

#hud {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
  user-select: none;
}

#status {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.6;
}

#hint {
  font-size: 12px;
  letter-spacing: 0.03em;
  color: #7fd4ea;
  opacity: 0;
  transition: opacity 0.4s;
}
#hint.visible { opacity: 0.85; }

#privacy {
  font-size: 10.5px;
  line-height: 1.5;
  letter-spacing: 0.02em;
  color: #4e7f8d;
  max-width: 300px;
}

#controls { display: flex; gap: 8px; }

button {
  background: rgba(20, 45, 55, 0.55);
  color: #9fdceb;
  border: 1px solid rgba(120, 220, 240, 0.3);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 12px;
  letter-spacing: 0.05em;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
button:hover { background: rgba(30, 70, 85, 0.7); }

/* ---------- settings menu ---------- */

#menu {
  position: fixed;
  left: 16px;
  bottom: 122px;
  z-index: 12;
  display: none;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  min-width: 232px;
  background: rgba(8, 22, 30, 0.92);
  border: 1px solid rgba(120, 220, 240, 0.22);
  border-radius: 8px;
  backdrop-filter: blur(8px);
}
#menu.open { display: flex; }

.menu-row {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 6px 8px;
  background: none;
  border: none;
  border-radius: 5px;
  color: #6f9dab;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-align: left;
  cursor: pointer;
}
.menu-row:hover { background: rgba(45, 100, 120, 0.35); }
.menu-row .tick {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border: 1px solid rgba(120, 220, 240, 0.4);
  border-radius: 3px;
}
.menu-row.on { color: #d6f4ff; }
.menu-row.on .tick { background: #35c8e8; border-color: #35c8e8; box-shadow: 0 0 8px #35c8e8a0; }
.mlabel { flex: 1; }
.mkey {
  font: 10px ui-monospace, Menlo, monospace;
  opacity: 0.5;
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 0 4px;
}

/* ---------- driver-monitoring panel ---------- */

#panel {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 9;
  width: min(430px, calc(100vw - 32px));
  padding: 10px 12px;
  background: rgba(10, 9, 4, 0.82);
  border: 1px solid rgba(255, 154, 46, 0.35);
  border-radius: 6px;
  font: 11px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #ffb055;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  backdrop-filter: blur(6px);
  overflow-x: auto;
}
#panel.visible { opacity: 1; transform: none; }

.panel-head {
  color: #ffd9a0;
  letter-spacing: 0.16em;
  padding-bottom: 6px;
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(255, 154, 46, 0.28);
}
.panel-row { display: flex; gap: 8px; white-space: nowrap; }
.pk { color: #a3702e; flex: 0 0 auto; white-space: pre; }
.pv { color: #ffc98a; }
.pv.ok { color: #7dffb8; }
.pv.warn { color: #ffd166; }
.pv.alert { color: #ff6b6b; }
.pv.dim { color: #9a7440; }
/* face briefly lost: hold the numbers, but show them as stale */
#panel.stale .pv { opacity: 0.5; }
.panel-foot {
  margin-top: 7px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 154, 46, 0.28);
  color: #8e6a3a;
  font-size: 10px;
  letter-spacing: 0.05em;
  white-space: normal;
}

#err {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 20;
  max-width: 420px;
  background: rgba(80, 10, 20, 0.85);
  color: #ffd7d7;
  font: 12px/1.5 ui-monospace, Menlo, monospace;
  padding: 10px 12px;
  border-radius: 8px;
  white-space: pre-wrap;
}

@media (max-width: 760px) {
  #panel { font-size: 10px; width: calc(100vw - 24px); }
  #privacy { max-width: 220px; }
}

/* ---------- window view ---------- */

[hidden] { display: none !important; }

#calib {
  position: fixed;
  left: 16px;
  bottom: 122px;
  z-index: 13;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 300px;
  padding: 12px 14px;
  background: rgba(8, 22, 30, 0.94);
  border: 1px solid rgba(120, 220, 240, 0.22);
  border-radius: 8px;
  backdrop-filter: blur(8px);
  font-size: 12px;
  color: #9fcbd8;
}
.calib-head {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #7fd4ea;
}
.calib-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
}
.calib-row input[type=range],
.calib-row select { grid-column: 1 / -1; width: 100%; accent-color: #2ec4e6; }
.calib-row select {
  grid-column: 2;
  background: rgba(20, 45, 55, 0.8);
  color: #9fdceb;
  border: 1px solid rgba(120, 220, 240, 0.3);
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 12px;
}
.calib-val { font-variant-numeric: tabular-nums; color: #cdeff7; }
.calib-note { font-size: 10.5px; line-height: 1.5; color: #5e8f9d; }
.calib-readout {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10.5px;
  color: #ffc46b;
}
.calib-buttons { display: flex; gap: 8px; justify-content: flex-end; }

#credits {
  position: fixed;
  top: 12px;
  right: 16px;
  z-index: 10;
  max-width: 420px;
  text-align: right;
  font-size: 10px;
  line-height: 1.5;
  color: #4e7f8d;
  pointer-events: none;
}

body.dragging #stage { outline: 2px dashed rgba(46, 196, 230, 0.6); outline-offset: -10px; }
