/* ============================================================
   PK Lab — styles
   색 토큰은 dataviz 레퍼런스 팔레트(검증 통과: blue/orange/aqua)
   light/dark 둘 다 선택된 값이며, OS 설정과 수동 토글 양쪽에 대응
   ============================================================ */

:root {
  color-scheme: light;

  --page:            #f9f9f7;
  --surface-1:       #fcfcfb;
  --surface-2:       #f2f1ed;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --grid:            #e1e0d9;
  --axis:            #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);
  --border-strong:   rgba(11, 11, 11, 0.18);

  --series-1:        #2a78d6;  /* blue   — 주 농도 곡선 */
  --series-2:        #eb6834;  /* orange — 두 번째 계열 */
  --series-3:        #1baf7a;  /* aqua   — 세 번째 계열 / 효과 */

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;

  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 4px 14px rgba(11, 11, 11, 0.05);

  --radius: 10px;
  --fs-base: 17px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:            #0d0d0d;
    --surface-1:       #1a1a19;
    --surface-2:       #232322;
    --text-primary:    #ffffff;
    --text-secondary:  #c3c2b7;
    --text-muted:      #898781;
    --grid:            #2c2c2a;
    --axis:            #383835;
    --border:          rgba(255, 255, 255, 0.10);
    --border-strong:   rgba(255, 255, 255, 0.20);
    --series-1:        #3987e5;
    --series-2:        #d95926;
    --series-3:        #199e70;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:            #0d0d0d;
  --surface-1:       #1a1a19;
  --surface-2:       #232322;
  --text-primary:    #ffffff;
  --text-secondary:  #c3c2b7;
  --text-muted:      #898781;
  --grid:            #2c2c2a;
  --axis:            #383835;
  --border:          rgba(255, 255, 255, 0.10);
  --border-strong:   rgba(255, 255, 255, 0.20);
  --series-1:        #3987e5;
  --series-2:        #d95926;
  --series-3:        #199e70;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 88px; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: var(--fs-base)/1.65 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  -webkit-text-size-adjust: 100%;
}

img { max-width: 100%; }
[hidden] { display: none !important; }

/* ---------- 헤더 / 내비 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1140px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.brand { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; margin-right: auto; }
.brand small { display: block; font-size: 0.72rem; font-weight: 500; color: var(--text-muted); letter-spacing: 0; }

.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a {
  display: inline-block; padding: 5px 11px; border-radius: 99px;
  font-size: 0.86rem; font-weight: 600; text-decoration: none;
  color: var(--text-secondary); border: 1px solid transparent;
}
.nav a:hover { background: var(--surface-2); color: var(--text-primary); }
.nav a.is-active { background: var(--series-1); color: #fff; }

.iconbtn {
  border: 1px solid var(--border-strong); background: var(--surface-1);
  color: var(--text-secondary); border-radius: 8px;
  padding: 6px 11px; font: inherit; font-size: 0.84rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.iconbtn:hover { color: var(--text-primary); border-color: var(--text-muted); }

/* ---------- 본문 ---------- */
main { max-width: 1140px; margin: 0 auto; padding: 24px 20px 120px; }

.hero { padding: 20px 0 8px; }
.hero h1 { font-size: 2rem; line-height: 1.2; margin: 0 0 10px; letter-spacing: -0.02em; }
.hero p { color: var(--text-secondary); margin: 0 0 6px; max-width: 76ch; }
.hero .scenario {
  margin-top: 16px; padding: 14px 18px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-left: 3px solid var(--series-1); border-radius: var(--radius);
}
.hero .scenario b { color: var(--text-primary); }

section.sec { margin-top: 44px; }
section.sec > h2 {
  font-size: 1.4rem; margin: 0 0 4px; letter-spacing: -0.015em;
  display: flex; align-items: baseline; gap: 10px;
}
section.sec > h2 .secnum {
  font-size: 0.78rem; font-weight: 700; color: var(--series-1);
  background: color-mix(in srgb, var(--series-1) 12%, transparent);
  padding: 3px 9px; border-radius: 99px; letter-spacing: 0.04em;
}
section.sec > .seclead { color: var(--text-secondary); margin: 0 0 18px; max-width: 78ch; }

.block {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px; margin-bottom: 18px;
}
.block > h3 {
  font-size: 1.06rem; margin: 0 0 10px; letter-spacing: -0.01em;
  display: flex; align-items: baseline; gap: 9px;
}
.block > h3 .q { color: var(--series-1); font-variant-numeric: tabular-nums; }
.block p { margin: 0 0 9px; color: var(--text-secondary); max-width: 80ch; }
.block p.lead { color: var(--text-primary); }
.block p:last-child { margin-bottom: 0; }
.block ul { color: var(--text-secondary); margin: 0 0 10px; padding-left: 1.3em; }
.block li { margin-bottom: 4px; }
.block strong { color: var(--text-primary); }

.formula {
  display: inline-block; margin: 6px 0 12px; padding: 9px 16px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; font-size: 1.06rem; font-weight: 600;
  font-variant-numeric: tabular-nums; letter-spacing: 0.01em;
}
.formula .op { color: var(--text-muted); font-weight: 500; padding: 0 2px; }
.formula.center { display: block; text-align: center; }

.callout {
  margin: 12px 0; padding: 12px 16px; border-radius: 8px;
  background: color-mix(in srgb, var(--series-1) 7%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--series-1) 24%, transparent);
  color: var(--text-secondary); font-size: 0.95rem;
}
.callout b, .callout strong { color: var(--text-primary); }
.callout.warn {
  background: color-mix(in srgb, var(--status-warning) 12%, var(--surface-1));
  border-color: color-mix(in srgb, var(--status-warning) 40%, transparent);
}
.callout .ctitle {
  display: block; font-weight: 700; color: var(--text-primary);
  font-size: 0.86rem; letter-spacing: 0.02em; margin-bottom: 3px;
}

/* ---------- 컨트롤 ---------- */
.controls {
  display: flex; flex-wrap: wrap; gap: 16px 26px;
  margin: 14px 0 6px; padding: 14px 16px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
}
.ctrl { display: flex; flex-direction: column; gap: 3px; min-width: 215px; flex: 1 1 215px; }
.ctrl label {
  font-size: 0.8rem; font-weight: 700; color: var(--text-secondary);
  display: flex; justify-content: space-between; gap: 8px; align-items: baseline;
}
.ctrl label .val {
  color: var(--text-primary); font-variant-numeric: tabular-nums;
  font-size: 0.94rem; font-weight: 700;
}
.ctrl input[type=range] { width: 100%; accent-color: var(--series-1); height: 22px; }
.ctrl.narrow { flex: 0 0 150px; min-width: 150px; }

.togglerow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  border: 1px solid var(--border-strong); background: var(--surface-1);
  color: var(--text-secondary); border-radius: 99px;
  padding: 5px 13px; font: inherit; font-size: 0.84rem; font-weight: 600; cursor: pointer;
}
.chip:hover { color: var(--text-primary); }
.chip.is-on { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.chip.is-on-2 { background: var(--series-2); border-color: var(--series-2); color: #fff; }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 0.88rem; font-weight: 600; color: var(--text-secondary); cursor: pointer; }
.switch input { accent-color: var(--series-1); width: 17px; height: 17px; }

/* ---------- 수치 타일 ---------- */
.readout {
  display: grid; gap: 10px; margin: 14px 0 4px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.stat {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 13px;
}
.stat .k { font-size: 0.76rem; font-weight: 700; color: var(--text-muted); letter-spacing: 0.02em; }
.stat .v { font-size: 1.32rem; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
.stat .u { font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); margin-left: 3px; }
.stat .sub { font-size: 0.76rem; color: var(--text-muted); }
.stat.hl { background: color-mix(in srgb, var(--series-1) 10%, var(--surface-1)); border-color: color-mix(in srgb, var(--series-1) 30%, transparent); }
.stat.hl .v { color: var(--series-1); }

.hero-num { font-size: 2.1rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }

/* 판정 배지 — 색 단독으로 의미를 전달하지 않도록 아이콘 + 라벨 동반 */
.verdict {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 15px; border-radius: 8px; font-weight: 700; font-size: 0.95rem;
  border: 1px solid; margin: 6px 0;
}
.verdict .ico { font-size: 1.05rem; line-height: 1; }
.verdict.ok { color: var(--status-good); border-color: color-mix(in srgb, var(--status-good) 45%, transparent); background: color-mix(in srgb, var(--status-good) 10%, var(--surface-1)); }
.verdict.bad { color: var(--status-critical); border-color: color-mix(in srgb, var(--status-critical) 45%, transparent); background: color-mix(in srgb, var(--status-critical) 10%, var(--surface-1)); }
.verdict.warn { color: var(--text-primary); border-color: color-mix(in srgb, var(--status-warning) 55%, transparent); background: color-mix(in srgb, var(--status-warning) 14%, var(--surface-1)); }

/* ---------- 답 입력 / 확인 ---------- */
.answer { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin: 14px 0 4px; }
.answer .field { display: flex; flex-direction: column; gap: 3px; }
.answer .field label { font-size: 0.8rem; font-weight: 700; color: var(--text-secondary); }
.answer input[type=text], .answer input[type=number] {
  width: 130px; padding: 7px 10px; font: inherit; font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: 7px;
}
.answer input:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
.answer .unit { font-size: 0.85rem; color: var(--text-muted); font-weight: 600; padding-bottom: 8px; }

.reveal {
  margin-top: 12px; padding: 14px 16px; border-radius: 8px;
  background: var(--surface-2); border: 1px dashed var(--border-strong);
}
.reveal h4 { margin: 0 0 8px; font-size: 0.88rem; letter-spacing: 0.02em; color: var(--text-muted); }
.reveal ol { margin: 0; padding-left: 1.4em; color: var(--text-secondary); }
.reveal li { margin-bottom: 5px; }
.reveal .final { margin-top: 10px; font-size: 1.05rem; font-weight: 700; color: var(--text-primary); }

/* ---------- 표 ---------- */
.tablewrap { overflow-x: auto; margin: 12px 0; }
table.data {
  border-collapse: collapse; font-size: 0.9rem; width: 100%;
  font-variant-numeric: tabular-nums;
}
table.data th, table.data td {
  padding: 6px 12px; text-align: right; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data th {
  color: var(--text-muted); font-size: 0.78rem; font-weight: 700;
  letter-spacing: 0.02em; text-align: right;
}
table.data td:first-child, table.data th:first-child { text-align: left; }
table.data tr.is-answer td { background: color-mix(in srgb, var(--series-1) 10%, transparent); font-weight: 700; }
table.data tr.is-fail td { color: var(--text-muted); }
table.data td .flag { font-weight: 700; }
table.data td .flag.ok { color: var(--status-good); }
table.data td .flag.bad { color: var(--status-critical); }

/* ---------- 차트 ---------- */
.plot-host {
  position: relative; margin: 14px 0 4px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px;
}
.plot-svg { display: block; width: 100%; height: auto; }
.plot-capture { cursor: crosshair; }

.plot-grid { stroke: var(--grid); stroke-width: 1; }
.plot-grid-v { opacity: 0.55; }
.plot-axis { stroke: var(--axis); stroke-width: 1.5; }
.plot-tick { fill: var(--text-muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.plot-tick-y { text-anchor: end; }
.plot-tick-x { text-anchor: middle; }
.plot-axlabel { fill: var(--text-secondary); font-size: 13px; font-weight: 600; text-anchor: middle; }
.plot-serieslabel { fill: var(--text-secondary); font-size: 12.5px; font-weight: 700; }
.plot-reflabel { fill: var(--text-secondary); font-size: 12px; font-weight: 700; }
.plot-bandlabel { fill: var(--text-muted); font-size: 12px; font-weight: 700; }
.plot-note { fill: var(--text-secondary); font-size: 12.5px; }
.plot-crosshair { stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 3 3; }

.plot-legend {
  display: flex; flex-wrap: wrap; gap: 6px 18px;
  padding: 8px 6px 2px; font-size: 0.85rem; color: var(--text-secondary); font-weight: 600;
}
.plot-legend-item { display: inline-flex; align-items: center; gap: 7px; }
.plot-swatch {
  width: 14px; height: 3.5px; border-radius: 2px; background: var(--sw);
  display: inline-block; flex: none;
}
.plot-swatch.is-block { height: 12px; border-radius: 3px; opacity: 0.45; }
.plot-swatch.is-dash {
  background: repeating-linear-gradient(90deg, var(--sw) 0 5px, transparent 5px 8px);
}

.plot-tip {
  position: absolute; z-index: 5; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: 8px; box-shadow: var(--shadow);
  padding: 8px 11px; font-size: 0.84rem; min-width: 150px;
  font-variant-numeric: tabular-nums;
}
.plot-tip-x { font-weight: 700; color: var(--text-primary); margin-bottom: 4px; font-size: 0.8rem; }
.plot-tip-row { display: flex; align-items: center; gap: 7px; margin-top: 2px; }
.plot-tip-name { color: var(--text-secondary); margin-right: auto; }
.plot-tip-val { font-weight: 700; color: var(--text-primary); }
.plot-tip-extra { margin-top: 6px; padding-top: 5px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 0.78rem; }

/* ---------- Vd 비교 막대 ---------- */
.vdbars { display: grid; gap: 8px; margin: 14px 0; }
.vdbar { display: grid; grid-template-columns: 120px 1fr auto; gap: 12px; align-items: center; }
.vdbar .nm { font-size: 0.88rem; font-weight: 700; }
.vdbar .track { background: var(--surface-2); border-radius: 4px; height: 22px; position: relative; overflow: hidden; }
.vdbar .fill { height: 100%; border-radius: 3px 4px 4px 3px; background: var(--bar); }
.vdbar .num { font-size: 0.88rem; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 116px; text-align: right; }
.vdbar .sub { display: block; font-size: 0.74rem; color: var(--text-muted); font-weight: 500; }

/* ---------- 요약 / footer ---------- */
.summary-out {
  width: 100%; min-height: 200px; font: 0.82rem/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
  background: var(--surface-2); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 12px;
  white-space: pre; overflow: auto; resize: vertical;
}
footer.pagefoot {
  max-width: 1140px; margin: 0 auto; padding: 26px 20px 60px;
  border-top: 1px solid var(--border); color: var(--text-muted); font-size: 0.84rem;
}
footer.pagefoot a { color: var(--text-secondary); }

.srcnote { font-size: 0.8rem; color: var(--text-muted); margin-top: 8px; }
.srcnote b { color: var(--text-secondary); }

/* ---------- 발표 모드: 설명 텍스트를 접고 그래프를 키운다 ---------- */
body.present .block p:not(.keep),
body.present .block ul,
body.present .callout,
body.present .reveal,
body.present .answer,
body.present section.sec > .seclead,
body.present .hero p,
body.present .srcnote { display: none; }
body.present .block { padding: 14px 16px; }
body.present { --fs-base: 19px; }
body.present .stat .v { font-size: 1.5rem; }

@media (max-width: 720px) {
  :root { --fs-base: 16px; }
  main { padding: 16px 14px 90px; }
  .block { padding: 16px 14px; }
  .hero h1 { font-size: 1.6rem; }
  .vdbar { grid-template-columns: 1fr; gap: 3px; }
  .vdbar .num { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
