/* rPPG web UI — two-column layout (video + overlay | controls + results).
   No framework, no web fonts; system CJK font for Korean labels. */

:root {
  --accent: #e23b3b;          /* red Start button + result numbers */
  --panel-bg: #ffffff;
  --page-bg: #2b2f36;
  --text: #1c2127;
  --muted: #8a94a3;
  --line: #e3e7ee;
  --panel-w: 396px;           /* right panel width — 360 base, +10% */
}

* { box-sizing: border-box; }

/* `display:grid/flex` on a rule beats the UA [hidden] rule, so the attribute
   silently stops hiding. Force it so hidden rows/blocks/notes truly disappear. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--page-bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic",
    "Noto Sans KR", "Segoe UI", sans-serif;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  gap: 0;
  height: 100vh;
  width: 100%;
}

/* ---------------------------------------------------------------- left: video */
.stage-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
  padding: 0;
}

/* Fills the left column; the video object-fit:contain letterboxes inside, and the
   overlay (same box) maps the face box / waveform onto that contained area. */
.stage {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
}

#preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;     /* never distort; overlay math handles letterbox */
  background: #000;
}

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* --------------------------------------------------------------- right: panel */
.panel {
  /* --fs scales every font-size below uniformly; +10% across the whole panel */
  --fs: 1.2;
  background: var(--panel-bg);
  padding: 28px 26px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}

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

.field {
  display: grid;
  grid-template-columns: 70px 1fr;
  align-items: center;
  gap: 12px;
}

.field-label {
  font-weight: 700;
  font-size: calc(15px * var(--fs));
}

.field input,
.field select {
  width: 100%;
  padding: 9px 11px;
  font-size: calc(14px * var(--fs));
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f6f8fb;
  color: var(--text);
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.field input.invalid {
  border-color: var(--accent);
  background: #fff0f0;
}

.btn-start {
  margin-top: 4px;
  padding: 13px;
  font-size: calc(17px * var(--fs));
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: filter 0.15s;
}
.btn-start:hover:not(:disabled) { filter: brightness(1.07); }
.btn-start:disabled { opacity: 0.55; cursor: default; }

.progress {
  height: 6px;
  border-radius: 4px;
  background: var(--line);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.12s linear;
}

.status {
  margin: 0;
  font-size: calc(13px * var(--fs));
  color: var(--muted);
  min-height: 18px;
}
.status.error { color: var(--accent); font-weight: 700; }
.status.busy { color: #c77700; font-weight: 600; }

/* ------------------------------------------------------------------- results */
.results {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
}

.result-row {
  display: grid;
  grid-template-columns: 1fr auto 56px;
  align-items: baseline;
  gap: 10px;
  padding: 14px 2px;
  border-bottom: 1px solid var(--line);
}

.result-label {
  font-weight: 700;
  font-size: calc(16px * var(--fs));
}
.result-value {
  font-size: calc(26px * var(--fs));
  font-weight: 800;
  color: var(--accent);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.result-unit {
  font-size: calc(13px * var(--fs));
  color: var(--muted);
  text-align: left;
}

/* ------------------------------------------------ HRV score explainer (3 rows) */
/* Each HRV score is a block: the score row (with a caption sub-line) + an inline
   explanation card. The block carries the divider so the card sits above it. */
.hrv-block { border-bottom: 1px solid var(--line); }
.hrv-block .result-row { border-bottom: none; row-gap: 3px; }

/* label becomes a flex row so the "?" button sits next to the score name */
.hrv-block .result-label { display: flex; align-items: center; gap: 6px; }

/* always-on direction caption — spans the full row width under the number.
   Static muted text (never changes with the value, so it can never mis-judge). */
.result-caption {
  grid-column: 1 / -1;
  font-size: calc(12px * var(--fs));
  font-weight: 400;
  line-height: 1.4;
  color: var(--muted);
  text-align: left;
}

/* circular "?" affordance: faint by default, red when its card is open */
.info-btn {
  flex: none;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid var(--muted);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: calc(12px * var(--fs));
  font-weight: 700;
  line-height: 1;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  position: relative;
}
.info-btn::before {            /* 44x44 finger-friendly hit area (touch mirror) */
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 44px; height: 44px;
  transform: translate(-50%, -50%);
}
.info-btn[aria-expanded="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.info-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* inline explanation card — collapsed by default, .open expands it (accordion) */
.result-explain {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  visibility: hidden;
  margin: 0;
  padding: 0 12px;
  background: #f6f8fb;
  border-radius: 8px;
  font-size: calc(13px * var(--fs));
  line-height: 1.55;
  color: var(--text);
  transition: max-height 0.18s ease, opacity 0.18s ease,
    padding 0.18s ease, margin 0.18s ease, visibility 0.18s linear;
}
.result-explain.open {
  max-height: 480px;     /* room for the zone gauge + the 3 text lines */
  opacity: 1;
  visibility: visible;
  padding: 12px;
  margin: 0 0 10px;
}

/* 5-zone result gauge inside the card: ticks on top, segmented bar, labels below.
   Only the cell the value falls into is tinted (no marker dot). Cell index 0 is
   always 매우나쁨 (left) .. 4 매우좋음 (right); the tick numbers differ per metric
   so 좋음/매우좋음 always sit on the right (see panel.js GAUGES for direction). */
.gauge { margin: 0 0 10px; }
.gauge-ticks {
  display: flex;
  justify-content: space-between;
  margin-bottom: 3px;
  font-size: calc(10px * var(--fs));
  line-height: 1;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.gauge-cells {
  display: flex;
  height: 16px;
  border: 1px solid #c4ccd6;
  border-radius: 3px;
  overflow: hidden;
}
.gauge-cell { flex: 1 1 0; border-right: 1px solid #c4ccd6; }
.gauge-cell:last-child { border-right: none; }
.gauge-cell.on.gz0 { background: #d9342b; }   /* 매우나쁨 */
.gauge-cell.on.gz1 { background: #ef8a3c; }   /* 나쁨 */
.gauge-cell.on.gz2 { background: #2fa85a; }   /* 정상 */
.gauge-cell.on.gz3 { background: #3a93c9; }   /* 좋음 */
.gauge-cell.on.gz4 { background: #2f6fb0; }   /* 매우좋음 */
.gauge-labels {
  display: flex;
  margin-top: 3px;
  font-size: calc(9px * var(--fs));
  line-height: 1;
  color: var(--muted);
}
.gauge-labels span { flex: 1 1 0; text-align: center; }
.result-explain .explain-src {
  display: block;
  margin-top: 6px;
  font-size: calc(12px * var(--fs));
  color: var(--muted);
}
@media (prefers-reduced-motion: reduce) { .result-explain { transition: none; } }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .panel { order: 2; }
  .stage-wrap { order: 1; height: 60vh; }
}
