:root {
  --in: #16a34a; --in-bg: #dcfce7; --out: #dc2626; --out-bg: #fee2e2;
  --ink: #0f172a; --muted: #64748b; --line: #cbd5e1; --bg: #f8fafc;
  --a: #2563eb; --b: #d97706; --c: #7c3aed;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
#app { display: flex; height: 100vh; }
#viewport { position: relative; flex: 1; min-width: 0; overflow: hidden; }
#viewport canvas { display: block; touch-action: none; }
.label-layer { position: absolute; inset: 0; pointer-events: none; }
#panel { width: 540px; overflow-y: auto; border-left: 3px solid var(--ink); background: #fff; padding: 14px 16px 30px; }

.overlay { position: absolute; top: 12px; left: 12px; z-index: 5; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.status-badge { font: 800 34px/1 system-ui; padding: 10px 16px; border: 4px solid var(--ink); border-radius: 10px; background: #fff; display: inline-flex; flex-direction: column; gap: 4px; width: fit-content; }
.status-badge small { font-size: 14px; font-weight: 600; }
.status-badge.pass { color: var(--in); border-color: var(--in); background: var(--in-bg); }
.status-badge.fail { color: var(--out); border-color: var(--out); background: var(--out-bg); }
.mag-badge { font: 700 13px system-ui; background: #fef3c7; border: 2px solid #b45309; color: #78350f; padding: 4px 8px; border-radius: 6px; width: fit-content; }

h1 { font-size: 20px; margin: 0 0 6px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; margin: 14px 0 6px; color: #334155; }
section { border-top: 2px solid var(--line); margin-top: 10px; padding-top: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spec { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }

.fcf { border-collapse: collapse; background: #fff; font: 700 15px/1 ui-monospace, Menlo, monospace; }
.fcf td { border: 2px solid var(--ink); padding: 4px 8px; text-align: center; }
.fcf td.sym { font-size: 18px; }
.fcf.big { font-size: 18px; }
.basic { border: 2px solid var(--ink); padding: 0 4px; font-weight: 700; background: #fff; }

.overall { border: 4px solid var(--ink); border-radius: 10px; padding: 8px 12px; margin-top: 12px; }
.overall.pass { border-color: var(--in); background: var(--in-bg); }
.overall.fail { border-color: var(--out); background: var(--out-bg); }
.pos-label { font-size: 12px; font-weight: 600; }
.pos-line { font: 800 24px system-ui; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.overall.pass #pos-status { color: var(--in); }
.overall.fail #pos-status { color: var(--out); }

.readout { width: 100%; border-collapse: collapse; font: 600 11.5px ui-monospace, Menlo, monospace; }
.readout th, .readout td { border: 1.5px solid var(--line); padding: 4px 3px; text-align: right; white-space: nowrap; }
.readout thead th { font-family: system-ui; font-size: 11px; color: #334155; text-align: center; }
.readout tbody th { text-align: left; font-family: system-ui; }
.readout tr.pass .mark { color: var(--in); }
.readout tr.fail .mark { color: var(--out); }
.readout tr.pass { background: #f0fdf4; }
.readout tr.fail { background: #fef2f2; }
.le { color: var(--in); } .gt { color: var(--out); font-weight: 800; }

.inset-wrap { display: flex; flex-direction: column; align-items: center; }
#inset { width: 260px; height: 260px; background: #fff; border: 2px solid var(--ink); border-radius: 8px; touch-action: none; user-select: none; }
#inset .grid { fill: none; stroke: #e2e8f0; stroke-width: 1; vector-effect: non-scaling-stroke; }
#inset .zone { fill-opacity: .25; stroke-width: 3; vector-effect: non-scaling-stroke; }
#inset .zone.pass { fill: var(--in); stroke: var(--in); }
#inset .zone.fail { fill: var(--out); stroke: var(--out); }
#inset .axis { stroke-width: 5; vector-effect: non-scaling-stroke; stroke-linecap: round; cursor: grab; }
#inset .axis.pass { stroke: var(--in); } #inset .axis.fail { stroke: var(--out); }
#inset .pt { stroke: var(--ink); stroke-width: 2.5; vector-effect: non-scaling-stroke; cursor: grab; }
#inset .pt.pass { fill: var(--in); } #inset .pt.fail { fill: var(--out); }
#inset .mid { fill: #fff; stroke: var(--ink); stroke-width: 2; vector-effect: non-scaling-stroke; cursor: grab; }
#inset text { font-family: system-ui; }
#inset .t-pt { font-size: .022px; font-weight: 800; }
#inset .t-zone { font-size: .018px; font-weight: 700; fill: #334155; }
#inset .t-small { font-size: .0115px; fill: var(--muted); }

.presets { display: flex; flex-wrap: wrap; gap: 6px; }
button { font: 600 13px system-ui; border: 2px solid var(--ink); background: #fff; border-radius: 6px; padding: 5px 9px; cursor: pointer; }
button:hover { background: #e2e8f0; }
.ctl { display: grid; grid-template-columns: 90px 1fr 84px; gap: 8px; align-items: center; font-size: 13px; font-weight: 600; margin: 4px 0; }
.ctl input[type=number] { font: 600 13px ui-monospace, monospace; width: 84px; padding: 3px; border: 2px solid var(--line); border-radius: 4px; }
.check { display: block; font-size: 13px; margin: 8px 0; }

/* 3D labels */
.label { font: 700 13px system-ui; color: var(--ink); white-space: nowrap; }
.label.datum { display: flex; align-items: center; gap: 6px; }
.label.datum small { font-weight: 600; font-size: 11px; background: rgba(255,255,255,.85); padding: 1px 4px; border-radius: 3px; }
.dfs { display: inline-block; border: 2.5px solid currentColor; background: #fff; padding: 1px 7px; font-size: 18px; }
.datum-a { color: var(--a); } .datum-b { color: var(--b); } .datum-c { color: var(--c); }
.axis-label { font-size: 13px; } .axis-label.small { font-size: 10px; color: var(--muted); }
.tp-label { text-align: center; font-size: 12px; background: rgba(255,255,255,.85); padding: 2px 5px; border: 1.5px dashed var(--ink); border-radius: 4px; }
.dim .basic { font-size: 15px; }
.fcf-label .callout { font: 700 14px ui-monospace, monospace; margin-bottom: 3px; background: rgba(255,255,255,.85); width: fit-content; }
.handle-label { font-size: 11px; background: rgba(255,255,255,.9); border: 1.5px solid var(--ink); border-radius: 4px; padding: 1px 4px; }
.handle-label.muted { color: var(--muted); border-color: var(--muted); }
.possym { width: 1.15em; height: 1.15em; vertical-align: middle; display: block; margin: auto; }
.size-note { font: 700 12px system-ui; color: #78350f; background: #fef3c7; border: 1.5px solid #b45309; border-radius: 5px; padding: 3px 6px; margin-top: 6px; width: fit-content; }
.status-badge .size-note { font-size: 12px; margin-top: 4px; }

.zone-label, .axis-name-label { font: 700 12px/1.25 system-ui; background: rgba(255,255,255,.93); border: 2px solid; border-radius: 5px; padding: 2px 6px; text-align: center; }
.zone-label.pass, .axis-name-label.pass { color: #166534; border-color: var(--in); }
.zone-label.fail, .axis-name-label.fail { color: #991b1b; border-color: var(--out); }

/* ---------------------------------------------------------------------------
   Responsive / touch (layout only; no content changes)
   --------------------------------------------------------------------------- */
#app { height: 100vh; height: 100dvh; }
/* CSS2DRenderer sets a z-index on every label; contain them so they never
   draw over the verdict badge overlay. */
.label-layer { z-index: 1; }
.overlay { z-index: 5; }
#panel { overscroll-behavior: contain; }

/* Compact: tablets, small laptops, phones in landscape */
@media (max-width: 1100px), (max-height: 500px) {
  #panel { width: clamp(300px, 46vw, 540px); padding: 10px 12px 24px; }
  .status-badge { font-size: 22px; padding: 6px 10px; border-width: 3px; }
  .status-badge small { font-size: 12px; }
  .status-badge .size-note, .size-note { font-size: 11px; }
  .mag-badge { font-size: 11px; }
  .overlay { top: 8px; left: 8px; right: 8px; gap: 6px; }
  .status-badge, .mag-badge { max-width: 100%; }
  .readout { font-size: 11px; }
  .readout th, .readout td { white-space: normal; padding: 3px 3px; }
  .pos-line { font-size: 20px; }
  .label { font-size: 11px; }
  .label.datum small { font-size: 9.5px; }
  .dfs { font-size: 14px; padding: 0 5px; }
  .fcf-label .callout { font-size: 12px; }
  .fcf-label .fcf { font-size: 12px; }
  .handle-label { font-size: 10px; }
  .zone-label, .axis-name-label { font-size: 10.5px; padding: 1px 4px; }
}

/* Stacked: phones in portrait, tablets in portrait, very narrow windows */
@media (max-width: 700px), (orientation: portrait) and (max-width: 1100px) {
  #app { flex-direction: column; }
  #viewport { flex: 0 0 48%; min-height: 240px; }
  #panel { width: 100%; flex: 1 1 auto; min-height: 0; border-left: none; border-top: 3px solid var(--ink); }
}

/* Finger-sized controls on touch screens */
@media (pointer: coarse) {
  button { min-height: 40px; padding: 8px 12px; }
  .presets { gap: 8px; }
  .ctl { grid-template-columns: 70px 1fr 92px; }
  .ctl input[type=range] { height: 32px; }
  .ctl input[type=number] { min-height: 36px; font-size: 16px; width: 92px; } /* 16px avoids iOS focus zoom */
  .check input { width: 22px; height: 22px; vertical-align: middle; }
}

/* Small 3D views (phones): keep the verdict + size note but make the overlay
   compact so it doesn't hide the part; exaggeration badge moves to bottom-left. */
@media (max-width: 700px), (max-height: 500px) {
  .overlay { bottom: 8px; justify-content: space-between; align-items: flex-start; }
  .status-badge { flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 0 8px; font-size: 18px; padding: 3px 8px; }
  .status-badge small { font-size: 11px; }
  .status-badge .size-note { flex-basis: 100%; font-size: 10px; padding: 1px 4px; margin: 2px 0 1px; }
  .mag-badge { font-size: 10px; padding: 2px 6px; }
  .zone-label { white-space: normal; max-width: 112px; }
}
