@font-face { font-family: "Atkinson Hyperlegible Next"; font-weight: 400; font-style: normal; font-display: swap; src: url("fonts/atkinson-hyperlegible-next-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible Next"; font-weight: 500; font-style: normal; font-display: swap; src: url("fonts/atkinson-hyperlegible-next-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible Next"; font-weight: 700; font-style: normal; font-display: swap; src: url("fonts/atkinson-hyperlegible-next-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "STIX Two Text"; font-weight: 400; font-style: normal; font-display: swap; src: url("fonts/stix-two-text-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "STIX Two Text"; font-weight: 600; font-style: normal; font-display: swap; src: url("fonts/stix-two-text-latin-600-normal.woff2") format("woff2"); }

*, *::before, *::after { box-sizing: border-box; }

:root {
  --drape: #E2EBE8;
  --drape-2: #C9D8D4;
  --paper: #F7F9F8;
  --ink: #15211F;
  --ink-2: #4C5F5B;
  --line: #C6D2CE;
  --tool: #0B6E69;
  --tool-ink: #FFFFFF;
  --tool-soft: #D6E9E6;
  --warn: #8F4708;
  --warn-soft: #F6E8D4;
  --halo: rgba(226, 235, 232, 0.92);
  --serif: "STIX Two Text", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --drape: #16221F; --drape-2: #0D1615; --paper: #131D1B; --ink: #E5EDEB; --ink-2: #9CB0AB; --line: #2A3A37;
    --tool: #4CC4BA; --tool-ink: #062321; --tool-soft: #1C3633; --warn: #F2B375; --warn-soft: #382914;
    --halo: rgba(18, 28, 26, 0.9); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --drape: #16221F; --drape-2: #0D1615; --paper: #131D1B; --ink: #E5EDEB; --ink-2: #9CB0AB; --line: #2A3A37;
  --tool: #4CC4BA; --tool-ink: #062321; --tool-soft: #1C3633; --warn: #F2B375; --warn-soft: #382914;
  --halo: rgba(18, 28, 26, 0.9); color-scheme: dark;
}

html { height: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  height: 100%; margin: 0; background: var(--paper); color: var(--ink);
  font: 400 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; overflow: hidden;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--tool); outline-offset: 2px; }

#app { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr); }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font: 600 21px/1.15 var(--serif); letter-spacing: -0.005em; }
.top p { margin: 1px 0 0; font-size: 13px; color: var(--ink-2); }

main { display: grid; grid-template-columns: minmax(0, 1fr) 388px; min-height: 0; }

/* segmented controls and toggles: anything you operate is instrument teal */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); overflow: hidden; flex: none; }
.seg button { border: 0; background: none; padding: 6px 11px; font-size: 13.5px; line-height: 1.25; white-space: nowrap; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--tool); color: var(--tool-ink); }
.tog { border: 1px solid var(--line); border-radius: 6px; background: var(--paper); padding: 6px 11px; font-size: 13.5px; line-height: 1.25; white-space: nowrap; flex: none; }
.tog[aria-pressed="true"] { background: var(--tool-soft); border-color: var(--tool); }
.tog.plain { background: var(--paper); }

/* ------------------------------ stage ------------------------------ */
#stage {
  position: relative; min-height: 0; min-width: 0; overflow: hidden; touch-action: none;
  background: radial-gradient(115% 95% at 50% 44%, var(--drape) 0%, var(--drape) 38%, var(--drape-2) 100%);
}
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; outline: none; }
#gl:active { cursor: grabbing; }
#gl:focus-visible { outline: 2px solid var(--tool); outline-offset: -3px; }
#leaders { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
#leaders .lead { fill: none; stroke: var(--ink); stroke-opacity: 0.5; stroke-width: 1; }
#leaders .dot { fill: var(--ink); fill-opacity: 0.85; }
#leaders .on.lead { stroke: var(--tool); stroke-opacity: 1; stroke-width: 1.5; }
#leaders .on.dot { fill: var(--tool); }
#labels { position: absolute; inset: 0; pointer-events: none; }
.lbl {
  position: absolute; left: 0; top: 0; pointer-events: auto; border: 0; background: none; padding: 2px 3px; margin: 0;
  font: 400 13.5px/1.15 var(--serif); color: var(--ink); white-space: nowrap; will-change: transform;
  text-shadow: 0 0 3px var(--halo), 0 0 3px var(--halo), 0 0 6px var(--halo);
}
.lbl:hover, .lbl.on { color: var(--tool); }
.lbl.on { font-weight: 600; }
.compact .lbl { font-size: 12px; }

.bar { position: absolute; left: 12px; right: 12px; display: flex; gap: 8px; align-items: center; pointer-events: none; overflow-x: auto; scrollbar-width: none; padding: 1px; }
.bar::-webkit-scrollbar { display: none; }
.bar > * { pointer-events: auto; }
.bar.scenes { top: 12px; }
.bar.display { bottom: 12px; right: 136px; }
.bar .cap { font-size: 13px; color: var(--ink-2); flex: none; margin-left: 4px; text-shadow: 0 0 4px var(--halo); }

#compass { position: absolute; right: 8px; bottom: 6px; width: 124px; height: 92px; pointer-events: none; overflow: visible; }
#compass line { stroke: var(--ink); stroke-width: 1.4; stroke-linecap: round; }
#compass text { font: 500 11px var(--sans); fill: var(--ink); dominant-baseline: middle; }

#hint {
  position: absolute; left: 50%; top: 56px; transform: translateX(-50%); margin: 0; padding: 5px 12px; border-radius: 6px;
  font-size: 13px; color: var(--ink-2); background: var(--halo); pointer-events: none; transition: opacity 0.4s; width: max-content; max-width: calc(100% - 24px); text-align: center;
}
#hint.gone { opacity: 0; }
#tip {
  position: absolute; left: 0; top: 0; pointer-events: none; padding: 3px 8px; border-radius: 4px; white-space: nowrap;
  font: 400 13.5px/1.3 var(--serif); background: var(--ink); color: var(--paper);
}
#fail { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--ink-2); }

/* ------------------------------ panel ------------------------------ */
#panel { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-left: 1px solid var(--line); background: var(--paper); }
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tabs { overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 1 0 auto; border: 0; border-bottom: 2px solid transparent; background: none; padding: 11px 9px 9px; font-weight: 500; font-size: 14.5px; white-space: nowrap; color: var(--ink-2); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--tool); }
#scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 16px 28px; touch-action: pan-y; }
#scroll section { padding-top: 14px; }
#scroll h2 { font: 600 17px/1.25 var(--serif); margin: 20px 0 6px; }
#scroll h2:first-child { margin-top: 2px; }
#scroll p { margin: 0 0 10px; max-width: 62ch; }
#scroll ul { margin: 0 0 10px; padding-left: 18px; max-width: 62ch; }
#scroll li { margin-bottom: 5px; }
.muted { color: var(--ink-2); }
.small { font-size: 13.5px; }

/* selected structure: the left rule carries the structure's colour in the model */
#detail { margin: 14px 0 2px; padding: 2px 0 4px 13px; border-left: 5px solid var(--c, var(--line)); }
#detail .role { display: inline-block; font-size: 12.5px; padding: 1px 8px; border-radius: 10px; background: var(--tool-soft); margin-bottom: 5px; }
#detail .role.avoid { background: var(--warn-soft); color: var(--warn); }
#detail h2 { font: 600 22px/1.15 var(--serif); margin: 0; }
#detail .aka { font-size: 13.5px; color: var(--ink-2); margin: 1px 0 8px; }
#detail p { margin: 0 0 8px; }
#detail .wand b, #detail .where b { font-weight: 700; }
#detail .warn { background: var(--warn-soft); color: var(--warn); padding: 7px 10px; border-radius: 5px; font-size: 14px; }
#detail .acts { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 6px; }
.group { margin-top: 14px; }
.group > header { display: flex; align-items: baseline; gap: 8px; padding: 4px 0 5px; border-bottom: 1px solid var(--line); }
.group > header label { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14.5px; flex: 1; cursor: pointer; }
.group > header .note { font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.row { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent); }
.row input, .group > header input { accent-color: var(--tool); width: 16px; height: 16px; flex: none; margin: 0; }
.row button { flex: 1; display: flex; align-items: center; gap: 9px; border: 0; background: none; text-align: left; padding: 7px 2px; font-size: 14.5px; min-width: 0; }
.row button:hover { color: var(--tool); }
.row.on button { font-weight: 700; }
.row.off button { color: var(--ink-2); }
.sw { width: 12px; height: 12px; border-radius: 3px; flex: none; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18); }

/* probe */
.field { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; margin: 10px 0; }
.field label { font-weight: 700; font-size: 14px; }
.field output { font-variant-numeric: tabular-nums; font-size: 14px; }
.field input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--tool); margin: 2px 0; }
#map { display: block; width: 100%; max-width: 330px; margin: 6px auto 0; touch-action: none; cursor: crosshair; user-select: none; -webkit-user-select: none; }
#map text { font: 500 11px var(--sans); fill: var(--ink-2); text-anchor: middle; dominant-baseline: middle; }
#map text.num { font: 600 13px var(--serif); fill: var(--ink); }
#map .cell { stroke: var(--paper); stroke-width: 0.6; }
#map .none { fill: var(--line); fill-opacity: 0.55; }
#map .ring { fill: none; stroke: var(--ink); stroke-opacity: 0.55; stroke-width: 0.8; stroke-dasharray: 2 2; }
#map .mark { fill: var(--tool); stroke: var(--paper); stroke-width: 2; }
#map .spoke { stroke: var(--tool); stroke-width: 1.5; }
#hits { list-style: none; padding: 0; margin: 4px 0 10px; }
#hits li { margin: 0; }
#hits button { display: grid; grid-template-columns: auto 1fr auto; gap: 9px; align-items: center; width: 100%; border: 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent); background: none; padding: 7px 2px; text-align: left; font-size: 14.5px; }
#hits button:hover { color: var(--tool); }
#hits .d { color: var(--ink-2); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
#hits .far { opacity: 0.6; }
#hits .empty { color: var(--ink-2); padding: 7px 2px; }
#probeWarn { background: var(--warn-soft); color: var(--warn); padding: 7px 10px; border-radius: 5px; font-size: 14px; margin: 0 0 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 8px 0; cursor: pointer; }
.check input { accent-color: var(--tool); width: 16px; height: 16px; margin: 0; }
#legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--ink-2); margin: 8px 0 0; }
#legend span { display: inline-flex; align-items: center; gap: 5px; }

/* ------------------------------ notes ------------------------------ */
/* your own notes carry a solid teal rule; notes someone sent you carry a dashed grey one, so the two are never confused */
.row.noted button::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--tool); margin-left: auto; flex: none; }
textarea { display: block; width: 100%; font: inherit; font-size: 16px; /* under 16px, iOS zooms the page when the box is tapped */ color: inherit; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; resize: vertical; }
textarea.mono { font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; }
.acts { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.notesbox { margin: 12px 0 4px; }
#scroll h3 { font: 700 13.5px/1.3 var(--sans); margin: 12px 0 5px; }
#scroll ul.notes, #scroll ul.pick { list-style: none; padding: 0; margin: 0 0 8px; }
.anote { border-left: 3px solid var(--tool); padding: 3px 0 3px 10px; margin: 0 0 9px; }
.anote.shared { border-left: 3px dashed var(--ink-2); }
.anote .loc { font-weight: 700; font-size: 13.5px; }
#scroll .anote .txt, #scroll .msg { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 2px; }
.anote .acts { margin-top: 0; gap: 0; }
button.link { border: 0; background: none; padding: 3px 0; margin-right: 14px; color: var(--tool); font-size: 13.5px; text-decoration: underline; text-underline-offset: 2px; }
.tog.go { background: var(--tool); color: var(--tool-ink); border-color: var(--tool); }
.tog.go:disabled { opacity: 0.45; cursor: default; }
.tog.danger { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.editor { margin: 4px 0 8px; }
.editor .count { margin-left: auto; font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.lab { display: block; font-weight: 700; font-size: 14px; margin: 10px 0 4px; }
.work { margin-top: 10px; }
.pick .check { align-items: flex-start; margin: 6px 0; }
.pick .check input { margin-top: 3px; flex: none; }
.pick .check span { overflow-wrap: anywhere; }
#scroll p.warn { background: var(--warn-soft); color: var(--warn); padding: 7px 10px; border-radius: 5px; font-size: 14px; margin: 10px 0; }
#scroll .msg { font: 400 16px/1.45 var(--serif); margin: 0 0 8px; }
.incoming { border: 1px solid var(--tool); border-radius: 8px; background: var(--tool-soft); padding: 12px 14px 12px; margin: 14px 0 12px; }
#scroll .incoming h2 { margin-top: 0; }
.set { border-top: 1px solid var(--line); padding-top: 9px; margin-top: 10px; }
.flash { background: var(--tool-soft); padding: 6px 10px; border-radius: 5px; font-size: 14px; }
.qr { display: block; width: 216px; max-width: 100%; margin: 12px 0 6px; border-radius: 4px; }
#scroll .owner { border: 1px dashed var(--warn); color: var(--warn); padding: 7px 10px; border-radius: 5px; font-size: 13.5px; }
input[type="file"] { display: block; font-size: 13.5px; margin: 8px 0 2px; max-width: 100%; }
#map .pin { fill: var(--ink); stroke: var(--paper); stroke-width: 1.5; pointer-events: none; }
#map .pin.shared { fill: var(--paper); stroke: var(--ink); }

/* first-run notice */
#first { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: max(20px, env(safe-area-inset-top, 0px)) 20px max(20px, env(safe-area-inset-bottom, 0px)); background: rgba(8, 14, 13, 0.55); }
#first .sheet { background: var(--paper); color: var(--ink); border-radius: 10px; padding: 20px 22px 18px; max-width: 440px; box-shadow: 0 14px 44px rgba(0, 0, 0, 0.28); }
#first h2 { font: 600 22px/1.2 var(--serif); margin: 0 0 8px; }
#first p { margin: 0 0 10px; }
#first .go { border: 0; border-radius: 6px; background: var(--tool); color: var(--tool-ink); padding: 9px 16px; font-weight: 500; margin-top: 4px; }

[hidden] { display: none !important; }

/* ------------------------------ small screens ------------------------------ */
@media (max-width: 880px) {
  main { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(260px, 53%) minmax(0, 1fr); }
  #panel { border-left: 0; border-top: 1px solid var(--line); }
  .top { padding: 8px 12px; }
  .top h1 { font-size: 18px; }
  .top p { display: none; }
  .bar { left: 8px; right: 8px; }
  .bar.scenes { top: 8px; }
  .bar.display { bottom: 8px; right: 8px; }
  #compass { bottom: 44px; right: 2px; width: 108px; height: 80px; }
  #hint { top: 48px; font-size: 12px; }
  .seg button, .tog { padding: 6px 9px; font-size: 13px; }
  button.link { padding: 9px 0; }
  /* keyboard up while typing: trim the page to the visible area and let the panel cover the model */
  .kb body { height: var(--vvh, 100%); }
  .kb .top { display: none; }
  .kb main { position: relative; }
  .kb #panel { position: absolute; inset: 0; z-index: 6; background: var(--paper); border-top: 0; }
  .tabs button { padding: 11px 6px 9px; }
}
@media (prefers-reduced-motion: reduce) { #hint { transition: none; } }
