:root {
  --bg: #0c0c0e;
  --bg2: #121216;
  --bg3: #17171c;
  --line: #26262e;
  --line2: #33333e;
  --ink: #ececf1;
  --ink2: #a5a5b4;
  --ink3: #6f6f7f;
  --amber: #ffb020;
  --amber-dim: #6b4a11;
  --cyan: #4fd1e0;
  --green: #3ecf8e;
  --red: #ff5d5d;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* class rules below set display, so make the attribute win */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; overflow: hidden; }

/* ------------------------------------------------------------------ topbar */

.topbar {
  height: 56px;
  flex: 0 0 56px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-size: 13px;
  letter-spacing: 0.14em;
  display: flex;
  gap: 4px;
  align-items: baseline;
  padding-right: 6px;
}
.brand b { color: var(--ink); font-weight: 700; }
.brand span { color: var(--amber); font-weight: 300; letter-spacing: 0.18em; }

.counter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 11px 5px 10px;
  border: 1px solid var(--line2);
  border-radius: 8px;
  background: var(--bg3);
}
.counter-value {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 700;
  line-height: 1;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
}
.counter-label {
  font-size: 9px;
  line-height: 1.2;
  letter-spacing: .11em;
  text-transform: uppercase;
  color: var(--ink3);
}

.toolbar { display: flex; align-items: center; gap: 8px; }
.toolbar.right { margin-left: auto; }

.btn {
  appearance: none;
  border: 1px solid var(--line2);
  background: var(--bg3);
  color: var(--ink);
  padding: 8px 13px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  line-height: 1;
  white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover:not(:disabled) { background: #1f1f26; border-color: #44444f; }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn.primary { background: var(--amber); border-color: var(--amber); color: #201500; font-weight: 650; }
.btn.primary:hover:not(:disabled) { background: #ffc043; border-color: #ffc043; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink2); }
.btn.ghost:hover:not(:disabled) { background: var(--bg3); color: var(--ink); }

.select { display: flex; align-items: center; gap: 8px; color: var(--ink3); font-size: 12px; }
.select select {
  background: var(--bg3);
  color: var(--ink);
  border: 1px solid var(--line2);
  border-radius: 8px;
  padding: 7px 8px;
  font-family: inherit;
  font-size: 13px;
}

.donate-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  appearance: none;
  border: 1px solid #7b302c;
  background: #32191a;
  color: #ffb7a2;
  padding: 6px 10px 6px 7px;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .12s;
}
.donate-btn:hover { background: #482022; border-color: #b34b3e; transform: translateY(-1px); }
.pumpkin { width: 25px; height: 23px; overflow: visible; }
.pumpkin-stem { fill: #6da34d; stroke: #b8d77d; stroke-width: 1; }
.pumpkin-body { fill: #e5662e; stroke: #ffb04e; stroke-width: 1.2; }
.pumpkin-ridge { fill: none; stroke: #a83d25; stroke-width: 1.2; opacity: .85; }
.pumpkin-face { fill: #261316; stroke: #12090b; stroke-width: .7; }

/* ------------------------------------------------------------------- main */

main {
  flex: 1 1 auto;
  min-height: 0;
  width: min(100%, 720px);
  margin-inline: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(420px, 72vh) auto;
  overflow-y: auto;
}

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-bottom: 1px solid var(--line);
}

.stagebar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
}

.outline-coverage {
  flex: 0 0 auto;
  padding: 5px 12px;
  color: var(--ink2);
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.sides { display: flex; align-items: center; gap: 2px; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink3);
  padding: 7px 12px;
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.tab:hover { color: var(--ink2); background: var(--bg3); }
.tab.active { color: var(--ink); background: var(--bg3); border-color: var(--line2); }
.tab.has { color: var(--ink2); }

.sideflag {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink3);
  letter-spacing: .08em;
  margin-left: 6px;
  text-transform: uppercase;
}

.stage-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; flex-wrap: wrap; }

.zoomgroup {
  display: flex;
  align-items: center;
  border: 1px solid var(--line2);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg3);
}
.zbtn {
  background: transparent;
  border: 0;
  color: var(--ink2);
  font-family: var(--mono);
  font-size: 13px;
  padding: 7px 9px;
  cursor: pointer;
  line-height: 1;
}
.zbtn:hover:not(:disabled) { background: #1f1f26; color: var(--ink); }
.zbtn:disabled { opacity: .38; cursor: not-allowed; }
.zbtn.wide { font-family: var(--sans); padding: 7px 10px; border-left: 1px solid var(--line2); }
.zlabel {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink3);
  min-width: 30px;
  text-align: center;
}

.chip {
  background: transparent;
  border: 1px solid var(--line2);
  color: var(--ink3);
  border-radius: 6px;
  padding: 6px 7px;
  font-family: var(--mono);
  font-size: 10.5px;
  cursor: pointer;
  line-height: 1;
}
.chip:hover { color: var(--amber); border-color: var(--amber-dim); }

.chk {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--ink3);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.chk input { accent-color: var(--amber); margin: 0; }
.chk:hover { color: var(--ink2); }

/* ------------------------------------------------------------------ stage */

.canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 50% 0%, #14141a 0%, #0a0a0c 70%),
    #0a0a0c;
}
canvas#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}
canvas#stage.panning { cursor: grabbing; }

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(10, 10, 12, .82);
  backdrop-filter: blur(2px);
}
.empty-inner { max-width: 460px; text-align: left; }
.empty-card { color: var(--amber); width: 54px; margin-bottom: 14px; opacity: .9; }
.empty-card svg { width: 100%; height: auto; display: block; }
.empty h2 { margin: 0 0 8px; font-size: 19px; font-weight: 600; letter-spacing: -.01em; }
.empty p { margin: 0 0 16px; color: var(--ink2); line-height: 1.55; font-size: 13.5px; }
.empty p.tiny { margin-top: 16px; color: var(--ink3); font-size: 11.5px; line-height: 1.5; }
.empty-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.busy {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(18, 18, 22, .94);
  border: 1px solid var(--line2);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--ink2);
  box-shadow: 0 18px 50px rgba(0,0,0,.5);
}
.spin {
  width: 13px; height: 13px;
  border: 2px solid var(--line2);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: absolute;
  left: 14px;
  bottom: 14px;
  max-width: 70%;
  background: rgba(24, 12, 12, .95);
  border: 1px solid #5a2a2a;
  color: #ffc9c9;
  padding: 10px 13px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.45;
}


/* ------------------------------------------------------------------ panel */

.panel {
  overflow-x: hidden;
  padding: 14px;
  background: var(--bg2);
  min-height: 0;
}
.panel-empty { color: var(--ink3); font-size: 12.5px; line-height: 1.6; }
.panel-empty p { margin: 4px 0 0; }

.card {
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 12px 13px;
  margin-bottom: 10px;
}
.card h3 {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink3);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h3 .right { margin-left: auto; font-family: var(--mono); font-size: 11px; letter-spacing: 0; color: var(--ink3); }

.hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
}
.hero .big {
  font-family: var(--mono);
  font-size: 42px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: -.03em;
}
.hero .hero-meta { min-width: 0; }
.hero .hero-label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink3); }
.hero .hero-sub { font-size: 12px; color: var(--ink2); margin-top: 4px; }
.hero .hero-tag { margin-top: 7px; display: flex; gap: 5px; flex-wrap: wrap; }

.subgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.subcell {
  background: #101015;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 6px;
  text-align: center;
}
.subcell .k { font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink3); }
.subcell .v { font-family: var(--mono); font-size: 16px; margin-top: 3px; }

.row { display: flex; align-items: center; gap: 8px; margin: 7px 0; }
.row .label { width: 34px; color: var(--ink3); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.row .val { font-family: var(--mono); font-size: 12px; color: var(--ink2); white-space: nowrap; }
.row .val b { color: var(--ink); font-weight: 600; }

.bar {
  position: relative;
  flex: 1 1 auto;
  height: 8px;
  border-radius: 4px;
  background: #0a0a0d;
  border: 1px solid var(--line);
  overflow: hidden;
  min-width: 60px;
}
.bar .fill { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, var(--amber-dim), var(--amber)); }
.bar .mid { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--line2); }

.deviation {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line2);
}
.deviation .dev { font-family: var(--mono); font-size: 18px; color: var(--amber); }
.deviation .devsub { font-size: 11.5px; color: var(--ink3); line-height: 1.45; }

.quadgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.qcell {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #101015;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 9px;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font-family: inherit;
}
.qcell:hover { border-color: var(--amber-dim); }
.qcell.worst { border-color: #5a3a12; }
.qcell .qk { font-family: var(--mono); font-size: 10px; color: var(--ink3); width: 20px; }
.qcell .qmeta { min-width: 0; }
.qcell .qv { font-family: var(--mono); font-size: 14px; }
.qcell .qp { font-size: 10px; color: var(--ink3); }

.wear-list { display: grid; gap: 6px; }
.wear-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101015;
  overflow: hidden;
}
.wear-item.worst { border-color: #5a3a12; }
.wear-item.needs-improvement { border-left: 3px solid var(--amber); }
.wear-item > summary {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  list-style: none;
  cursor: pointer;
}
.wear-item > summary::-webkit-details-marker { display: none; }
.wear-item > summary::after { content: "▸"; color: var(--ink3); grid-column: 3; grid-row: 1; }
.wear-item[open] > summary::after { content: "▾"; }
.wear-id { font-family: var(--mono); color: var(--ink2); font-size: 11px; text-transform: uppercase; }
.wear-measure { min-width: 0; font-size: 10.5px; color: var(--ink3); line-height: 1.4; }
.wear-grade { font-family: var(--mono); font-size: 13px; padding-right: 12px; }
.wear-detail { padding: 2px 10px 9px; border-top: 1px solid var(--line); }
.wear-detail .kv { align-items: flex-start; }
.wear-detail .kv .v { max-width: 65%; text-align: right; white-space: normal; line-height: 1.4; }
.inspect-mark { margin-top: 7px; }
.propagation-box {
  margin-top: 9px;
  padding: 8px 9px;
  border: 1px solid var(--line2);
  border-radius: 8px;
  background: #101015;
  color: var(--ink2);
  font-size: 10.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.propagation-box b { color: var(--amber); font-weight: 650; }
.propagation-backward, .propagation-headroom, .propagation-note { margin-top: 5px; }

.edgegrid { display: grid; gap: 5px; }
.surface-toggle { width: 100%; margin-top: 8px; color: #ff83d2; border-color: rgba(255, 104, 202, .42); }
.surface-toggle:hover:not(:disabled) { background: rgba(255, 72, 190, .1); border-color: rgba(255, 104, 202, .8); }
.surface-findings { display: grid; gap: 5px; max-height: 260px; overflow-y: auto; }
.surface-mark {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #101015;
  color: var(--ink2);
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.surface-mark:hover { border-color: rgba(255, 104, 202, .7); background: rgba(255, 72, 190, .06); }
.surface-mark-number { display: grid; place-items: center; width: 21px; height: 21px; border-radius: 50%; background: rgba(255, 72, 190, .16); color: #ff83d2; font: 650 11px var(--mono); }
.surface-mark-copy { display: grid; gap: 3px; min-width: 0; }
.surface-mark-copy b { font-size: 11px; font-weight: 600; text-transform: capitalize; }
.surface-mark-copy small { color: var(--ink3); font: 10px var(--mono); overflow-wrap: anywhere; }
.erow {
  display: grid;
  grid-template-columns: 54px 1fr 42px;
  align-items: center;
  gap: 8px;
  background: #101015;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
  text-align: left;
}
.erow:hover { border-color: var(--amber-dim); }
.erow .en { font-size: 11px; color: var(--ink2); text-transform: capitalize; }
.erow .ebar { height: 5px; background: #0a0a0d; border-radius: 3px; overflow: hidden; border: 1px solid var(--line); }
.erow .ebar i { display: block; height: 100%; background: var(--amber); }
.erow .eg { font-family: var(--mono); font-size: 12px; text-align: right; }

.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; padding: 3px 0; color: var(--ink2); }
.kv .k { color: var(--ink3); }
.kv .v { font-family: var(--mono); font-size: 11.5px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 3px 6px;
  border-radius: 5px;
  border: 1px solid var(--line2);
  color: var(--ink3);
}
.pill.amber { color: var(--amber); border-color: var(--amber-dim); background: rgba(255,176,32,.06); }
.pill.blue { color: #7ab8ff; border-color: #26405e; background: rgba(70,140,255,.07); }
.pill.red { color: #ff9a9a; border-color: #5a2a2a; background: rgba(255,80,80,.07); }
.pill.green { color: var(--green); border-color: #1f4a38; background: rgba(62,207,142,.07); }

.notes { margin: 8px 0 0; padding-left: 16px; color: var(--ink3); font-size: 11.5px; line-height: 1.55; }
.notes li { margin: 3px 0; }

.btn-row { display: flex; gap: 7px; margin-top: 10px; flex-wrap: wrap; }
.btn-row .btn { padding: 7px 10px; font-size: 12px; }

details.raw summary {
  cursor: pointer;
  color: var(--ink3);
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  list-style: none;
}
details.raw summary::-webkit-details-marker { display: none; }
details.raw summary::before { content: "▸ "; }
details.raw[open] summary::before { content: "▾ "; }
details.raw { margin-top: 6px; }
details.raw .kv { font-size: 11px; }

.mono { font-family: var(--mono); }
.hintline { color: var(--ink3); font-size: 11.5px; line-height: 1.5; margin-top: 9px; }
.hintline .legend-red { color: #ff3b30; font-weight: 650; }
.hintline .legend-amber { color: var(--amber); font-weight: 650; }
.hintline .legend-cyan { color: var(--cyan); font-weight: 650; }
.grade-good { color: var(--green); }
.grade-mid { color: var(--amber); }
.grade-low { color: var(--red); }

/* ------------------------------------------------------------------ modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 7, .82);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal[hidden] { display: none; }
.modal-body {
  background: var(--bg2);
  border: 1px solid var(--line2);
  border-radius: 14px;
  padding: 12px;
  width: min(760px, 96vw);
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.modal-body video {
  width: 100%;
  max-height: 70vh;
  background: #000;
  border-radius: 9px;
  display: block;
  object-fit: contain;
}
.modal-actions { display: flex; gap: 8px; justify-content: center; margin-top: 11px; }
.tiny { font-size: 11.5px; color: var(--ink3); text-align: center; margin: 9px 0 0; min-height: 1em; }

/* ----------------------------------------------------------------- mobile */

@media (max-width: 980px) {
  html { height: 100%; overflow: hidden; }
  body { height: 100%; overflow: hidden; }
  main {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-width: none;
  }
  main::-webkit-scrollbar { display: none; }
  .stage {
    height: max(360px, min(72vh, 760px));
    min-height: 360px;
    border-bottom: 1px solid var(--line);
  }
  .canvas-wrap { flex: 1 1 0; min-height: 0; touch-action: none; }
  canvas#stage { touch-action: none; }
  .panel { overflow: visible; min-height: max-content; }
  .topbar { position: relative; z-index: 20; flex: 0 0 auto; gap: 8px; padding: 8px 10px; height: auto; flex-wrap: wrap; }
  .brand { display: none; }
  .stagebar { gap: 6px; padding: 6px 8px; }
  .stage-actions { width: 100%; margin-left: 0; justify-content: flex-start; }
  .empty-inner { text-align: left; }
  .hero .big { font-size: 34px; }
}

@media (min-width: 981px) {
  html, body { height: auto; overflow: auto; }
  main {
    flex: 0 0 auto;
    width: min(100%, 900px);
    grid-template-columns: 1fr;
    grid-template-rows: minmax(420px, 72vh) auto;
    overflow: visible;
  }
  .stage { min-height: min(72vh, 760px); }
  .panel { overflow: visible; padding: 18px 24px 28px; }
  .stagebar, .outline-coverage { padding-inline: 18px; }
}
