:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #5b6b7b;
  --line: #d9e0e7;
  --accent: #1565c0;
  --accent-ink: #ffffff;
  --num: #0b3d91;
  --shadow: 0 1px 3px rgba(20, 40, 70, 0.08), 0 4px 16px rgba(20, 40, 70, 0.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "Noto Sans", "Microsoft YaHei", "Hiragino Sans", "Malgun Gothic", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  font-size: 15px;
}

/* Top bar */
#site-header { position: sticky; top: 0; z-index: 50; background: var(--panel);
  border-bottom: 1px solid var(--line); box-shadow: var(--shadow); }
#site-header .bar { display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 18px; max-width: 1180px; margin: 0 auto; flex-wrap: wrap; }
#site-header .brand { font-weight: 700; font-size: 15px; color: var(--accent); }
#site-header .actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#site-header .btn { text-decoration: none; color: var(--accent); border: 1px solid var(--accent);
  padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 600; white-space: nowrap; }
#site-header .btn:hover { background: var(--accent); color: var(--accent-ink); }
#site-header select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 13px; background: #fff; color: var(--ink); }

/* Layout */
.container { max-width: 1180px; margin: 0 auto; padding: 22px 18px 40px; }
h1.page-title { font-size: 24px; margin: 6px 0 4px; }
.intro { color: var(--muted); margin: 0 0 22px; max-width: 820px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 18px 18px 20px; }
.card h2 { font-size: 17px; margin: 0 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.card h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; }

/* Form */
.form-row { display: grid; grid-template-columns: 1fr 160px; align-items: center; gap: 10px; margin: 9px 0; }
.form-row > label { font-size: 13.5px; color: var(--ink); }
.form-row .unit { color: var(--muted); font-size: 12.5px; margin-left: 6px; }
.form-row input, .form-row select { width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 7px; font-size: 14px; background: #fff; color: var(--ink); }
.form-row input:focus, .form-row select:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.15); }
.full { grid-template-columns: 1fr; }
.actions-row { margin-top: 14px; display: flex; gap: 10px; }
button.calc, button.reset { cursor: pointer; border-radius: 7px; padding: 9px 16px; font-size: 14px;
  font-weight: 600; border: 1px solid var(--accent); }
button.calc { background: var(--accent); color: #fff; }
button.calc:hover { background: #0d4ea3; }
button.reset { background: #fff; color: var(--accent); }
button.reset:hover { background: #eef4fb; }

/* Results table */
table.res { width: 100%; border-collapse: collapse; margin-top: 6px; }
table.res td { padding: 7px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
table.res td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--num); }
table.res td.unit { text-align: right; color: var(--muted); width: 70px; font-size: 12.5px; }
.out-empty { color: var(--muted); font-size: 13px; font-style: italic; }

.note { margin-top: 16px; font-size: 12.8px; color: var(--muted); background: #f0f5fb;
  border-left: 3px solid var(--accent); padding: 9px 12px; border-radius: 0 6px 6px 0; }
.note b { color: var(--ink); }

/* Scan: hint, comparison block, live validation */
.scan-hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.cmp-block { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #f7fafd; }
.cmp-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 8px 0; font-size: 12.5px; }
.cmp-row > label { display: flex; align-items: center; gap: 5px; font-weight: 600; color: var(--ink); }
.cmp-row .unit { color: var(--muted); font-size: 12px; }
.cmp-row input { width: 72px; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; background: #fff; color: var(--ink); }
.cmp-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.15); }
.invalid-note { font-size: 12.5px; color: #d32f2f; margin-top: 8px; font-weight: 600; }
.form-row input.invalid, .form-row select.invalid, .cmp-row input.invalid {
  border-color: #d32f2f; box-shadow: 0 0 0 3px rgba(211, 47, 47, 0.15); }
.formula { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 12.5px;
  color: var(--muted); margin-top: 8px; }

/* Oil library / suction check / measured-data benchmark */
textarea.fit-csv { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 12.5px;
  background: #fff; color: var(--ink); resize: vertical; }
textarea.fit-csv:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.15); }
table.res thead th { text-align: left; font-size: 11.5px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .03em; padding: 4px 8px; border-bottom: 1px solid var(--line); font-weight: 600; }
.verdict-ok { color: #2e7d32; font-weight: 700; }
.verdict-warn { color: #ef6c00; font-weight: 700; }
.verdict-bad { color: #d32f2f; font-weight: 700; }
td.verdict-ok, td.verdict-warn, td.verdict-bad { font-weight: 700; }


/* Scan result table: clickable rows (row → convergence trace) + per-OP group header */
table.res tbody tr.rowlink { cursor: pointer; }
table.res tbody tr.rowlink:hover td { background: #eef5ff; }
table.res tbody tr.rowlink.sel td { background: #e3efff; box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
table.res tbody tr.dom td { background: #e3efff; box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
table.res tbody tr.grp td { background: #f4f8fd; color: var(--ink); font-weight: 700; font-size: 13px; padding: 6px 8px; }
.actions-row select#em_pngMode { padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 13px; background: #fff; color: var(--ink); }
.actions-row .unit { color: var(--muted); font-size: 12.5px; }

/* Footer */
#site-footer { border-top: 1px solid var(--line); background: var(--panel); margin-top: 30px;
  padding: 18px; text-align: center; color: var(--muted); font-size: 12.5px; }
#site-footer .fbuilt { margin-top: 4px; opacity: .8; }

@media (max-width: 560px) {
  .form-row { grid-template-columns: 1fr; }
  .form-row > label { margin-bottom: 2px; }
  h1.page-title { font-size: 20px; }
}

/* Report area — print only */
#reportArea { display: none; }
#reportArea h1 { font-size: 20px; color: var(--ink); margin: 0 0 4px; }
#reportArea h2 { font-size: 15px; margin: 16px 0 6px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
#reportArea table.res td { font-size: 12px; padding: 5px 8px; }
@media print {
  body > #site-header, body > main, body > #site-footer { display: none !important; }
  #reportArea { display: block !important; padding: 0 12px; }
}


/* F1 / F2 / F4 / F5 / F6 tooling */
.unit-bar { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; margin: 0 0 18px; box-shadow: var(--shadow); }
.unit-bar label { font-size: 13px; font-weight: 600; }
.unit-bar select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 13px; background: #fff; color: var(--ink); }
.unit-bar .scan-hint { margin: 0; flex: 1 1 320px; }

.pset-row { display: grid; grid-template-columns: 1fr 200px; align-items: center; gap: 10px; margin: 9px 0; }
.pset-row > label { font-size: 13.5px; color: var(--ink); }
.pset-row input, .pset-row select, .pset-row textarea { width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 7px; font-size: 14px; background: #fff; color: var(--ink); }
.pset-row input[readonly] { color: var(--muted); font-size: 12.5px; }
.pset-row input:focus, .pset-row select:focus, .pset-row textarea:focus { outline: none;
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.15); }
textarea.pset-json { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12.5px; resize: vertical; min-height: 64px; margin-top: 8px; }

.actions-row.wrap { flex-wrap: wrap; }
button.mini { cursor: pointer; border-radius: 7px; padding: 8px 13px; font-size: 13px;
  font-weight: 600; border: 1px solid var(--accent); background: #fff; color: var(--accent); }
button.mini:hover { background: #eef4fb; }

canvas.tool-chart { display: block; width: 100%; max-width: 600px; height: auto;
  margin: 8px auto; background: #fbfdff; border: 1px solid var(--line); border-radius: 8px; }

.bounds-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 4px 14px; }
.bounds-grid .form-row { grid-template-columns: 1fr 82px; margin: 6px 0; }
.bounds-grid .form-row > label { font-size: 12.5px; }

/* ---------- P8: accessibility polish ---------- */
.form-row input.in-bad, .bounds-grid input.in-bad, .cmp-row input.in-bad, .pset-row input.in-bad {
  border-color: #d32f2f;
  box-shadow: 0 0 0 3px rgba(211, 47, 47, 0.12);
}
/* every plotted canvas is focusable (a11yInit gives it tabindex=0), so every one
   needs a visible focus ring — not just the three that carry .tool-chart */
canvas:focus, canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
@media (max-width: 560px) {
  .pset-row { grid-template-columns: 1fr; }
}
/* ---------- P9: load spectrum, shear chart, VI blocks ---------- */
textarea.spec-csv { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 12.5px;
  background: #fff; color: var(--ink); resize: vertical; min-height: 96px; }
textarea.spec-csv:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.15); }
