:root {
  color-scheme: light;
  --bg: #eef1ec;
  --surface: #ffffff;
  --sunken: #e3e8e3;
  --ink: #18241d;
  --muted: #56665c;
  --line: #cbd4cd;
  --accent: #1f6b4a;      /* solder-mask green */
  --accent-ink: #ffffff;
  --probe: #ffd21f;       /* marker yellow, same in both themes */
  --ok: #1f7444;
  --ok-bg: #dcf0e3;
  --off: #b3301f;
  --off-bg: #f9e0dc;
  --stage: #0c120f;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1612;
    --surface: #15201a;
    --sunken: #101a15;
    --ink: #e4ece6;
    --muted: #94a79a;
    --line: #2a3a31;
    --accent: #4fb386;
    --accent-ink: #08130d;
    --ok: #64d394;
    --ok-bg: #163524;
    --off: #f2806f;
    --off-bg: #3d1d18;
    --stage: #070c09;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
}

a { color: var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- header ---------- */

.site {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 14px 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand-mark {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 4px solid var(--probe);
  box-shadow: 0 0 0 1.5px #111, inset 0 0 0 1.5px #111;
}

.site-link { font-weight: 600; text-decoration: none; }
.site-link:hover { text-decoration: underline; }

/* ---------- page ---------- */

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 8px 16px 80px;
}

.loading, .page-narrow { max-width: 640px; }
.loading { margin: 40px auto; padding: 0 16px; color: var(--muted); }

h1 {
  font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.25rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 8px 0 10px;
  font-weight: 750;
  max-width: 28ch;
}

h2 { font-size: 1.15rem; margin: 32px 0 10px; letter-spacing: -0.01em; }

.lede { color: var(--muted); max-width: 60ch; margin: 0 0 24px; }

.desc {
  white-space: pre-wrap;
  max-width: 70ch;
  margin: 0 0 16px;
  color: var(--ink);
}

.note, .help { color: var(--muted); font-size: 0.92rem; margin: 6px 0 0; max-width: 65ch; }

/* ---------- forms ---------- */

.field { margin: 0 0 18px; border: 0; padding: 0; max-width: 640px; }
.field > label:not(.btn), .field > legend { display: block; font-weight: 600; margin-bottom: 6px; padding: 0; }

.input {
  width: 100%;
  font: inherit;
  font-size: 16px; /* keeps iOS from zooming on focus */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
.input::placeholder { color: var(--muted); opacity: 0.8; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 3.2em; }
.input-sm { padding: 7px 10px; }

.form-error { color: var(--off); font-weight: 600; margin: 8px 0; min-height: 0; }
.form-error:empty { display: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 650;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { border-color: var(--muted); }
.btn-quiet { background: transparent; color: var(--muted); padding-inline: 8px; }
.btn-quiet:hover { color: var(--off); }

.link-btn {
  background: none; border: 0; padding: 0;
  font: inherit; font-size: 0.85rem;
  color: var(--muted); text-decoration: underline; cursor: pointer;
}
.link-btn:hover { color: var(--off); }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 20px; }

.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.seg { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 600;
  font-size: 0.95rem;
}
.seg input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- share ---------- */

.share {
  display: grid;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 24px;
}
.share.is-new { border-left: 5px solid var(--probe); }
.share-intro { margin: 0; max-width: 70ch; }
.share .field { margin: 0; max-width: none; }

.copy-row { display: flex; gap: 8px; }
.copy-row .input { font-size: 15px; color: var(--muted); min-width: 0; }

.owner-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 20px; }

/* ---------- workspace: board + side panel ---------- */

.workspace { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; }

@media (min-width: 920px) {
  .workspace { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 28px; }
  .workspace-board { position: sticky; top: 12px; }
  .board-scroll { max-height: calc(100vh - 80px); }
}

.board-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.tool {
  min-width: 40px; height: 36px;
  padding: 0 10px;
  font: inherit; font-weight: 700;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.zoom-label { min-width: 3.5em; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.9rem; }
.board-hint { color: var(--muted); font-size: 0.9rem; margin-left: 6px; }

.board-scroll {
  overflow: auto;
  max-height: 72vh;
  background: var(--stage);
  border-radius: var(--radius);
  overscroll-behavior: contain;
}

.board-canvas {
  position: relative;
  width: 100%;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.board-canvas img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  -webkit-touch-callout: none;
}
.is-editable .board-canvas { cursor: crosshair; }

.markers { position: absolute; inset: 0; }

/* A hollow ring keeps the pad underneath visible; the number sits in a tag. */
.marker {
  --c: var(--probe);
  position: absolute;
  width: 24px; height: 24px;
  margin: 0; padding: 0;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: transparent;
  border: 3px solid var(--c);
  box-shadow: 0 0 0 1.5px #111, inset 0 0 0 1.5px #111;
  cursor: pointer;
  font: inherit;
}
.marker .tag {
  position: absolute;
  left: 15px; bottom: 15px;
  min-width: 20px;
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--c);
  color: #111;
  border: 1.5px solid #111;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.marker[data-status="ok"] { --c: #5fdc93; }
.marker[data-status="off"] { --c: #ff6f5e; }
.marker[data-status="done"] { --c: #c9d2cc; }
.marker.is-selected {
  width: 32px; height: 32px;
  z-index: 2;
  box-shadow: 0 0 0 1.5px #111, inset 0 0 0 1.5px #111, 0 0 0 6px rgba(255, 255, 255, 0.55);
}
.marker.is-selected .tag { left: 20px; bottom: 20px; font-size: 13px; }
.is-editable .marker { touch-action: none; cursor: grab; }
@media (pointer: coarse) {
  .marker { width: 28px; height: 28px; }
}

/* ---------- tabs ---------- */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab {
  font: inherit; font-weight: 650;
  background: none; border: 0;
  padding: 10px 12px;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- point list (measure) ---------- */

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 28px; height: 24px;
  padding: 0 6px;
  border-radius: 6px;
  background: var(--probe);
  color: #111;
  border: 1.5px solid #111;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.pt-list, .edit-list { list-style: none; margin: 0; padding: 0; }

.pt {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(7.5em, 34%);
  gap: 10px 12px;
  align-items: center;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  border-radius: 6px;
}
.pt.is-active { background: var(--sunken); }
.pt-label { font-weight: 650; overflow-wrap: anywhere; }
.pt-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 0.88rem; color: var(--muted); }
.pt-note { font-size: 0.88rem; color: var(--muted); }
.chip { font-weight: 600; color: var(--ink); }
.pt-ref { font-variant-numeric: tabular-nums; }

.value-input { font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }
.pt[data-status="ok"] .value-input { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.pt[data-status="off"] .value-input { border-color: var(--off); background: var(--off-bg); color: var(--off); }

.measure-form { margin-top: 24px; }
.mine {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  justify-items: start;
}
.mine p { margin: 0; color: var(--muted); font-size: 0.92rem; }
.mine .field { width: 100%; margin: 0; }

/* ---------- meter ---------- */

.meter {
  display: grid;
  gap: 10px;
  padding: 14px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.meter.is-on { border-left: 5px solid var(--probe); }
.meter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.meter-head { justify-content: space-between; }
.meter-name { font-weight: 700; }
.meter-mode { color: var(--muted); margin-right: auto; }
.meter-sub, .meter-help, .meter-hint { color: var(--muted); font-size: 0.9rem; margin: 0; max-width: 60ch; }
.meter-hint { margin-bottom: 14px; }
.meter-reading {
  display: block;
  font-size: clamp(2rem, 1.6rem + 1.5vw, 2.6rem);
  font-weight: 750;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.meter-next { margin-right: auto; }
.meter-hold { height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; }
.meter-hold-fill { display: block; height: 100%; width: 0; background: var(--probe); transition: width 0.15s linear; }
.input-inline { width: auto; padding: 4px 8px; }
.meter-warn { margin: 0; color: var(--off); font-weight: 600; }
.meter-warn:empty { display: none; }
.meter-warn.is-info { color: var(--muted); font-weight: 500; }
.link-strong { color: var(--accent); font-weight: 650; font-size: inherit; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 0.95rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.btn-sm { min-height: 38px; padding: 6px 14px; }
.meter-log summary { cursor: pointer; color: var(--muted); font-size: 0.88rem; }
.meter-log pre {
  margin: 8px 0 0;
  max-height: 14em;
  overflow: auto;
  padding: 8px;
  background: var(--sunken);
  border-radius: 6px;
  font-size: 12px;
  white-space: pre-wrap;
}

.pt.is-active { box-shadow: inset 4px 0 0 var(--probe); }
.pt.just-captured { animation: captured 0.8s ease-out; }
@keyframes captured {
  from { background: var(--ok-bg); }
  to { background: transparent; }
}

/* ---------- point editor ---------- */

.edit-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 12px 8px;
  border-bottom: 1px solid var(--line);
  border-radius: 6px;
}
.edit-row.is-selected { background: var(--sunken); }
.edit-row .badge { margin-top: 6px; }
.edit-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.edit-fields .input { font-size: 16px; }
.icon-btn {
  width: 36px; height: 36px;
  font: inherit; font-size: 1.3rem; line-height: 1;
  color: var(--muted);
  background: none; border: 1px solid transparent; border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover { color: var(--off); border-color: var(--line); }

.empty { color: var(--muted); padding: 8px 0; max-width: 50ch; }
.empty p { margin: 0 0 6px; }

/* ---------- results ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
table.results { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
.results th, .results td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
.results thead th { font-size: 0.85rem; background: var(--sunken); }
.results tbody tr { cursor: pointer; }
.results tbody tr:hover, .results tbody tr.is-active { background: var(--sunken); }
.results tbody tr:last-child > * { border-bottom: 0; }
.results .num { font-variant-numeric: tabular-nums; }
.results td[data-status="ok"] { color: var(--ok); background: var(--ok-bg); font-weight: 650; }
.results td[data-status="off"] { color: var(--off); background: var(--off-bg); font-weight: 700; }
.cell-sub { font-size: 0.8rem; color: var(--muted); font-weight: 400; }
.resp-name { font-weight: 700; color: var(--ink); }
.kind { font-weight: 500; color: var(--muted); }
.kind-good { color: var(--ok); }
.kind-faulty { color: var(--off); }
.missing { color: var(--muted); }

.legend { font-size: 0.88rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 10px 0 0; }
.lg::before {
  content: "";
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: -1px;
}
.lg-ok::before { background: var(--ok); }
.lg-off::before { background: var(--off); }

.resp-note { margin: 10px 0 0; font-size: 0.92rem; max-width: 65ch; }

.export {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.export-img { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
.export-img .input { width: auto; flex: 1 1 12em; }

/* ---------- home ---------- */

.my-sheets { list-style: none; padding: 0; margin: 0; max-width: 640px; }
.my-sheets li { border-bottom: 1px solid var(--line); }
.my-sheets a { display: block; padding: 10px 2px; font-weight: 600; text-decoration: none; }
.my-sheets a:hover { text-decoration: underline; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  z-index: 10;
  max-width: calc(100vw - 32px);
  transition: opacity 0.3s;
}
.toast-error { background: var(--off); color: #fff; }
.toast.out { opacity: 0; }

@media (max-width: 560px) {
  .edit-fields { grid-template-columns: 1fr; }
  .pt { grid-template-columns: auto minmax(0, 1fr); }
  .pt-value { grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------- library ---------- */

.site-nav { display: flex; gap: 18px; }

.crumbs { margin: 4px 0 6px; font-size: 0.92rem; color: var(--muted); }
.lib-badge { color: var(--ok); font-weight: 600; }

.lib-devices { display: grid; gap: 16px; max-width: 760px; margin: 16px 0; }
.lib-device, .lib-add {
  max-width: 760px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.lib-add { margin-top: 28px; }
.lib-device h2, .lib-add h2 { margin: 0 0 4px; font-size: 1.15rem; }
.lib-head, .lib-comp-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.lib-head h2 { flex: 1 1 auto; }
.lib-tools { display: flex; gap: 6px; margin-left: auto; }
.lib-boards { list-style: none; margin: 8px 0 0; padding: 0; }
.lib-boards li {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px;
  padding: 8px 0; border-top: 1px solid var(--line);
}
.lib-boards a { font-weight: 650; }
.lib-meta { font-size: 0.88rem; color: var(--muted); }
.lib-meta-note { flex-basis: 100%; }
.lib-form { display: grid; gap: 8px; }
.lib-inline { display: flex; gap: 8px; margin-top: 10px; }
.lib-inline .input { flex: 1 1 auto; min-width: 0; }

.lib-start {
  padding: 14px 16px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.lib-start h2, .lib-comps > h2 { margin: 0 0 6px; font-size: 1.15rem; }
.lib-start .help { margin: 0 0 12px; }
.lib-summary { margin: 12px 0 0; font-size: 0.95rem; }
.lib-select { margin-left: auto; font-size: 0.92rem; color: var(--muted); }
.seg input:disabled { cursor: not-allowed; }
.seg input:disabled + span { opacity: 0.45; }

.lib-comps { display: grid; gap: 14px; }
.lib-comp {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.lib-comp .table-wrap { margin-top: 8px; }
.lib-comp-head { margin-bottom: 2px; }
.lib-check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.lib-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.lib-comp-name { font-weight: 700; font-size: 1.05rem; }
.lib-table td.lib-note { white-space: normal; min-width: 9em; color: var(--muted); }
.lib-closeup-wrap { margin-top: 10px; }
.lib-closeup { margin-top: 10px; }

.lib-edit h1, .lib-edit h3 { margin-top: 0; }
.lib-edit h4 { margin: 18px 0 6px; }
.lib-photo-row { display: flex; flex-wrap: wrap; gap: 8px; }
.lib-thumb { display: block; max-width: 240px; max-height: 160px; margin-top: 10px; border-radius: 8px; border: 1px solid var(--line); }
.lib-photos { margin-bottom: 14px; }
.lib-photos .board { margin-bottom: 4px; }

.pos-chips { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.pos-chip {
  font: inherit; font-size: 0.85rem; font-weight: 600;
  padding: 3px 10px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.pos-chip.is-on { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.pos-chip:disabled { opacity: 0.45; cursor: not-allowed; }
