*, *::before, *::after { box-sizing: border-box; }
:root { color-scheme: light; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
body { margin: 0; }
[hidden] { display: none !important; }

/* Layout: specimen viewer on the left, a parameter drawer on the right; stacks on phones. */
:root {
  --bg: #e9edee;
  --panel: #f7f9f9;
  --fg: #1a2327;
  --muted: #5a6a71;
  --line: #d0d8db;
  --accent: #2b6b70;
  --accent-soft: #d6e7e7;
  --track: #c5d0d3;
  --stage-a: #f3f6f6;
  --stage-b: #dbe2e4;
  --warn: #a4471f;
  --f-display: "Spectral", "Iowan Old Style", Georgia, serif;
  --f-body: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101518; --panel: #161d21; --fg: #e1e7e9; --muted: #8b9aa1; --line: #29353b;
    --accent: #72b8b7; --accent-soft: #1f3536; --track: #34434a; --stage-a: #1b2428; --stage-b: #0e1214; --warn: #e3946b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101518; --panel: #161d21; --fg: #e1e7e9; --muted: #8b9aa1; --line: #29353b;
  --accent: #72b8b7; --accent-soft: #1f3536; --track: #34434a; --stage-a: #1b2428; --stage-b: #0e1214; --warn: #e3946b;
  color-scheme: dark;
}
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--fg); font-family: var(--f-body); font-size: 14px;
  display: flex; flex-direction: column; overflow: hidden;
}
header {
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  padding-block: 12px 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  border-bottom: 1px solid var(--line);
}
header h1 { font-family: var(--f-display); font-weight: 600; font-size: 1.45rem; margin: 0; letter-spacing: -0.01em; }
header p { margin: 0; color: var(--muted); font-size: 0.82rem; min-width: 0; }
header p i { font-family: var(--f-display); font-size: 0.92rem; }
main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 360px; }
#stage {
  position: relative; min-width: 0; min-height: 0;
  background: radial-gradient(ellipse at 50% 40%, var(--stage-a), var(--stage-b));
}
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.readout {
  position: absolute; top: 12px; left: 14px; font-family: var(--f-mono); font-size: 0.74rem;
  color: var(--muted); display: grid; grid-template-columns: auto auto; gap: 2px 12px;
  font-variant-numeric: tabular-nums; pointer-events: none;
}
.readout b { color: var(--fg); font-weight: 500; }
.hint { position: absolute; bottom: 10px; left: 14px; font-size: 0.74rem; color: var(--muted); pointer-events: none; }
.stage-tools { position: absolute; top: 10px; right: 12px; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  font: 500 0.78rem var(--f-body); color: var(--fg); background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 11px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--panel); border-color: var(--accent); }
#panel {
  border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; min-height: 0;
  padding-block: 14px 28px; padding-left: 16px; padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 18px;
}
section h2 {
  font: 600 0.7rem var(--f-body); text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted);
  margin: 0 0 8px; display: flex; justify-content: space-between; align-items: baseline;
}
section h2 span { text-transform: none; letter-spacing: 0; font-weight: 400; font-style: italic; font-family: var(--f-display); font-size: 0.85rem; }
.pgroup { font-size: 0.7rem; color: var(--muted); margin: 8px 0 4px; }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.preset {
  text-align: left; background: transparent; border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; cursor: pointer; color: var(--fg); display: flex; flex-direction: column; gap: 1px; min-width: 0;
}
.preset i { font-family: var(--f-display); font-size: 0.95rem; }
.preset small { color: var(--muted); font-size: 0.7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preset:hover { border-color: var(--accent); }
.preset.active { background: var(--accent-soft); border-color: var(--accent); }
.ctl { display: grid; grid-template-columns: 1.2rem minmax(0,1fr) 5.4rem; align-items: center; gap: 2px 8px; padding: 3px 0; }
.ctl .sym { font-family: var(--f-display); font-style: italic; font-size: 1rem; color: var(--accent); }
.ctl label { font-size: 0.8rem; min-width: 0; }
.ctl label small { color: var(--muted); }
.ctl input[type=range] { grid-column: 1 / 3; width: 100%; accent-color: var(--accent); margin: 0; }
.ctl input[type=number] {
  grid-column: 3; grid-row: 1 / 3; width: 100%; font: 0.8rem var(--f-mono); font-variant-numeric: tabular-nums;
  background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 4px; padding: 4px 6px; text-align: right;
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 4px 0; font-size: 0.8rem; }
.row label { color: var(--fg); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { font: 500 0.78rem var(--f-body); background: transparent; color: var(--fg); border: 0; padding: 5px 10px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--panel); }
select, input[type=color] {
  font: 0.8rem var(--f-body); background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 4px; padding: 4px 6px;
}
input[type=color] { width: 2.4rem; height: 1.8rem; padding: 1px 2px; }
.note { font-size: 0.74rem; color: var(--muted); line-height: 1.45; margin: 4px 0 0; }
details { font-size: 0.8rem; }
details summary { cursor: pointer; font-weight: 600; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.eq { font-family: var(--f-mono); font-size: 0.72rem; line-height: 1.6; overflow-x: auto; white-space: pre; background: var(--bg); padding: 8px 10px; border-radius: 6px; margin-top: 8px; }
.btn { font: 500 0.8rem var(--f-body); color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 12px; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--panel); border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
#inSizeMm { width: 5.5rem; font: 0.8rem var(--f-mono); background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 4px; padding: 4px 6px; text-align: right; }
.unit { color: var(--muted); font-size: 0.8rem; }
#exportStatus:empty { display: none; }
#exportStatus { color: var(--fg); }
#exportStatus[data-kind="warn"], #exportStatus[data-kind="err"] { color: var(--warn); }
#exportStatus[data-kind="ok"] { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 760px) {
  body { overflow: auto; height: auto; }
  main { grid-template-columns: 1fr; }
  #stage { height: 56vh; min-height: 320px; }
  #panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; padding-left: max(16px, env(safe-area-inset-left, 0px)); }
}
