:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1d232b;
  --muted: #5f6b7a;
  --line: #e1e5ea;
  --field: #f8f9fb;
  --accent: #c92a2a;
  --ok: #2b8a3e;
  --warn: #d9480f;
  --stage: #23272e;
  --cal: #e8590c;
  --time: #1c7ed6;
  --amp: #ae3ec9;
  --radius: 10px;
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --panel: #1b1f25;
    --text: #e6e9ee;
    --muted: #9aa5b1;
    --line: #2d333b;
    --field: #14171c;
    --ok: #51cf66;
    --warn: #ff922b;
    --stage: #0d0f12;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 16px; }
.logo { width: 28px; height: 18px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.privacy { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ok); }
.topbar .small { width: auto; padding: 4px 8px; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }

.layout { display: grid; grid-template-columns: 1fr 340px; min-height: 0; }

.stage { position: relative; background: var(--stage); min-height: 0; overflow: hidden; }
.stage.dragover { outline: 3px dashed var(--accent); outline-offset: -10px; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  color: #e9ecef;
  padding: 24px;
}
.empty h1 { margin: 0 0 8px; font-size: 24px; font-weight: 650; }
.empty p { margin: 6px 0; }
.empty .small { font-size: 12px; color: #adb5bd; margin-top: 14px; }

.zoombar { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 4px; }
.zoombar button { background: rgba(255, 255, 255, 0.92); color: #111; border: none; min-width: 36px; }

.toast {
  position: absolute;
  left: 50%;
  top: 12px;
  max-width: calc(100% - 32px);
  transform: translate(-50%, -8px);
  background: rgba(16, 18, 22, 0.94);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.panel {
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-left: 1px solid var(--line);
}
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.step {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--line);
  color: var(--text);
  font-size: 11px;
}
.card.done .step { background: var(--ok); color: #fff; }

button {
  font: inherit;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.icon { padding: 4px 9px; }
.wide { width: 100%; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.nowrap { flex-wrap: nowrap; }
.row.center { justify-content: center; margin-top: 6px; }
.row input[type="range"] { flex: 1; min-width: 60px; }

.field { margin-top: 12px; }
.persp-actions { margin-top: 10px; }
.label, label { font-size: 12px; color: var(--muted); }
.label { display: block; margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.grid2 label { display: flex; flex-direction: column; gap: 4px; }
label.check { display: flex; align-items: center; gap: 6px; margin-top: 10px; color: var(--text); }

select, input[type="number"] {
  width: 100%;
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  color: var(--text);
}
select:disabled, input:disabled { opacity: 0.55; }

.hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.hint.first { margin: 0 0 10px; }
.readout { margin: 10px 0; font-size: 12px; font-variant-numeric: tabular-nums; }
.readout p { margin: 2px 0; }
.warn { color: var(--warn); }

.cal-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cal-item {
  display: grid;
  grid-template-columns: 10px 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 5px 6px 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.cal-item.selected { border-color: var(--time); box-shadow: inset 0 0 0 1px var(--time); }
.cal-item select { padding: 3px 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; }
.swatch.time { background: var(--time); }
.swatch.amp { background: var(--amp); }
.val { font-weight: 650; font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-variant-numeric: tabular-nums; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 650; text-align: right; }
.kv dd.big { font-size: 18px; }

table.qtc { width: 100%; margin-top: 10px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.qtc th, table.qtc td { padding: 4px 0; border-top: 1px solid var(--line); text-align: left; }
table.qtc th { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
table.qtc td:last-child, table.qtc th:last-child { text-align: right; font-weight: 650; }

.axis { display: grid; grid-template-columns: 1fr 110px; gap: 10px; align-items: center; }
.axis .grid2 { grid-template-columns: 1fr; }
#dial { width: 110px; height: 110px; }
.dial-ring { fill: none; stroke: var(--line); stroke-width: 1.5; }
.dial-normal { fill: var(--ok); opacity: 0.16; }
.dial-axis { stroke: var(--muted); stroke-width: 0.8; opacity: 0.6; }
.dial-text { font-size: 9px; fill: var(--muted); }
.dial-text.mid { text-anchor: middle; }
.dial-text.end { text-anchor: end; }
.dial-vec { stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; }
.dial-tip { fill: var(--accent); }

.disclaimer {
  padding: 8px 16px;
  font-size: 12px;
  text-align: center;
  color: var(--muted);
  background: var(--panel);
  border-top: 1px solid var(--line);
}

/* ---------- results: contribute prompt ---------- */
.contribute { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.contribute p { margin: 0 0 8px; font-size: 12px; color: var(--muted); }

/* ---------- share page ---------- */
body.doc { display: flex; flex-direction: column; height: auto; min-height: 100%; }
main.share { flex: 1; width: 100%; max-width: 900px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
main.share h1 { margin: 4px 0 0; font-size: 22px; }
.lead { margin: 0; color: var(--muted); }
.back { color: var(--muted); text-decoration: none; font-size: 13px; }
.back:hover { color: var(--text); }
a.button { display: inline-block; padding: 7px 12px; border-radius: 8px; text-decoration: none; border: 1px solid var(--line); color: var(--text); }
a.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { border-color: var(--accent); color: var(--accent); }
.redact-wrap { margin: 10px 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
#redact { display: block; width: 100%; height: auto; touch-action: none; cursor: crosshair; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 10px; }
.grid3 label, label.stack { display: flex; flex-direction: column; gap: 4px; }
label.stack { margin-top: 12px; }
input[type="text"], .manage input { width: 100%; font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); color: var(--text); }
fieldset.findings { border: 1px solid var(--line); border-radius: 8px; margin: 12px 0 0; padding: 8px 10px; }
fieldset.findings legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.chips label.check { margin-top: 4px; }
#summary { margin: 0 0 8px; padding-left: 18px; }
#summary li { margin: 4px 0; }
pre.terms { white-space: pre-wrap; font: 12px/1.5 ui-monospace, Consolas, monospace; max-height: 280px; overflow: auto;
  background: var(--field); border: 1px solid var(--line); border-radius: 6px; padding: 10px; }
#declarations label.check, .share label.check { align-items: flex-start; }
.share label.check input { margin-top: 3px; }
dl.receipt { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 10px 0; }
dl.receipt dt { color: var(--muted); }
dl.receipt dd { margin: 0; font: 600 16px ui-monospace, Consolas, monospace; word-break: break-all; }
details.manage summary { cursor: pointer; font-weight: 600; }
details.manage .row { margin-top: 10px; }

@media (max-width: 860px) {
  .grid3 { grid-template-columns: 1fr; }
  body { display: block; }
  .layout { display: block; }
  .stage { height: 62vh; }
  .panel { overflow: visible; border-left: none; }
  .privacy { display: none; }
}
