:root {
  --bg: #f4f1ea;
  --panel: #fbfaf7;
  --ink: #1b1f23;
  --muted: #5b626b;
  --line: #e2ddd1;
  --line-strong: #c9c3b4;
  --control: #8a8473;
  --input: #ffffff;
  --accent: #c8412b;
  --accent-soft: #f6e3de;
  --accent-ink: #ffffff;
  --warn: #8a5a0b;
  --warn-soft: #f7ecd5;
  --ok: #2f7d4f;
  --shadow: 0 1px 0 rgba(27, 31, 35, 0.04), 0 18px 40px -28px rgba(27, 31, 35, 0.4);
  --radius: 14px;
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", "Noto Serif CJK TC", "Noto Serif", Georgia, serif;
  --sans:
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans CJK TC", "Noto Sans CJK JP",
    "Noto Sans CJK KR", "Noto Sans CJK SC", sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1216;
  --panel: #161a20;
  --ink: #eef0f2;
  --muted: #a3abb5;
  --line: #262c35;
  --line-strong: #3a424d;
  --control: #6b7683;
  --input: #11151a;
  --accent: #ff7a59;
  --accent-soft: #3a2119;
  --accent-ink: #1a0d08;
  --warn: #e0a84a;
  --warn-soft: #33281a;
  --ok: #6cc38b;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 18px 40px -26px rgba(0, 0, 0, 0.9);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html {
  background: var(--bg);
}
body {
  margin: 0;
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  background: linear-gradient(var(--bg), var(--bg)), var(--bg);
  -webkit-font-smoothing: antialiased;
}
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 20;
  padding: 8px 12px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 8px;
}
.skip:focus {
  top: 12px;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* Focus lands here after Fix; they are not controls, so they carry no ring. */
#sheet:focus-visible,
#check-summary:focus-visible {
  outline: none;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 13px;
}

/* Header: the graticule motif sits faintly behind the brand. */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  padding: 0 clamp(16px, 3vw, 40px);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='64'%3E%3Cg fill='none' stroke='%23c8412b' stroke-opacity='.10' stroke-width='1'%3E%3Cpath d='M0 21.5h160M0 42.5h160'/%3E%3Cpath d='M20.5 0v64M60.5 0v64M100.5 0v64M140.5 0v64'/%3E%3C/g%3E%3C/svg%3E"),
    color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}
.brand img {
  display: block;
  transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.brand:hover img {
  transform: rotate(60deg);
}
.brand-name {
  margin: 0;
  font: 600 23px/1 var(--serif);
  letter-spacing: -0.01em;
}
.brand-tag {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tools {
  display: flex;
  align-items: center;
  gap: 10px;
}
.link {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  padding: 6px 8px;
  border-radius: 8px;
}
.link:hover {
  color: var(--ink);
  background: var(--line);
}
.select-chip select,
.icon-btn {
  height: 34px;
  border: 1px solid var(--control);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}
.select-chip select {
  padding: 0 12px;
  cursor: pointer;
}
.icon-btn {
  width: 34px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition:
    transform 0.15s,
    background 0.15s;
}
.icon-btn:hover {
  background: var(--line);
}
.icon-btn:active {
  transform: scale(0.94);
}

/* Layout */
.app {
  display: grid;
  grid-template-columns: minmax(330px, 400px) minmax(0, 1fr);
  gap: 24px;
  max-width: 1500px;
  margin: 0 auto;
  padding: 22px clamp(16px, 3vw, 40px) 40px;
}
.panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-content: start;
}
.card {
  min-width: 0;
}
.stage {
  position: sticky;
  top: 86px;
  align-self: start;
  display: grid;
  gap: 12px;
}
@media (max-width: 960px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    padding-top: 12px;
  }
  .stage {
    position: sticky;
    top: 64px;
    z-index: 5;
    order: -1;
    padding-top: 6px;
    background: var(--bg);
  }
  .stage:has(.has-note) {
    position: static;
  }
  .sheet svg {
    max-height: 42vh;
  }
  .brand-tag {
    display: none;
  }
  .link {
    display: none;
  }
}

/* Cards */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  box-shadow: var(--shadow);
  animation: rise 0.4s ease both;
}
.card h2 {
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font: 600 17px/1.2 var(--serif);
}
.n {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  color: var(--accent);
  font: 600 12px/1 var(--sans);
}
.field {
  display: grid;
  gap: 5px;
  margin: 0 0 12px;
  border: 0;
  padding: 0;
  min-width: 0;
}
.field > span,
.field > legend {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  padding: 0;
}
.row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--control);
  border-radius: 8px;
  background: var(--input);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
textarea {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  resize: vertical;
}
input:hover,
select:hover,
textarea:hover {
  border-color: var(--muted);
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
input[type="range"] {
  width: calc(100% - 34px);
  accent-color: var(--accent);
  vertical-align: middle;
}
output {
  display: inline-block;
  width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
button {
  font: inherit;
}
.btn {
  min-height: 38px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--control);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition:
    transform 0.12s,
    background 0.15s,
    border-color 0.15s;
}
.btn:hover {
  background: var(--line);
}
.btn:active {
  transform: translateY(1px);
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn.primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, black);
}
.btn[disabled] {
  opacity: 0.5;
  cursor: progress;
}
.btn.small {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12.5px;
  border-radius: 8px;
}

/* Data card */
.drop {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 1.5px dashed var(--control);
  border-radius: 12px;
  cursor: pointer;
  color: var(--muted);
  transition:
    border-color 0.15s,
    background 0.15s,
    transform 0.15s;
}
.drop strong {
  color: var(--ink);
}
.drop:hover {
  border-color: var(--accent);
}
.drop.over {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.01);
}
.paste {
  margin: 10px 0 12px;
}
.paste summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13.5px;
}
.paste textarea {
  margin-top: 8px;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--control);
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    transform 0.12s;
}
.chip:hover {
  border-color: var(--accent);
}
.chip:active {
  transform: scale(0.97);
}
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.status {
  margin: 10px 0 0;
  min-height: 20px;
  font-size: 13px;
  color: var(--muted);
}
.status.error {
  color: var(--accent);
}

/* Segmented control, palettes, checkbox list */
.segmented {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 6px;
}
.segmented label {
  position: relative;
}
.segmented input {
  position: absolute;
  opacity: 0;
  inset: 0;
}
.segmented span {
  display: block;
  text-align: center;
  padding: 7px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  font-size: 13px;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
}
.segmented input:checked + span {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}
.segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.palettes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 8px;
}
.palettes label {
  position: relative;
  display: grid;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  transition:
    border-color 0.15s,
    background 0.15s;
}
.palettes input {
  position: absolute;
  opacity: 0;
  inset: 0;
}
.palettes label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
}
.palettes label:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  height: 12px;
  border-radius: 4px;
  overflow: hidden;
}
.checks {
  display: grid;
  gap: 4px;
  max-height: 160px;
  overflow: auto;
}
.checks label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
}

/* Checks card */
.summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  margin-bottom: 10px;
  font-weight: 600;
}
.summary .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
  flex: none;
}
.summary.error .dot {
  background: var(--accent);
}
.summary.warn .dot {
  background: var(--warn);
}
.findings {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.finding {
  position: relative;
  padding: 9px 12px 9px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13.5px;
}
.findings.enter .finding {
  animation: slide 0.25s ease both;
}
.finding::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--line-strong);
}
.finding.error::before {
  background: var(--accent);
}
.finding.warn::before {
  background: var(--warn);
}
.finding .head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
}
.finding .tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.finding.error .tag {
  color: var(--accent);
}
.finding.warn .tag {
  color: var(--warn);
}
.finding code {
  font-size: 12px;
  color: var(--muted);
}
.finding p {
  margin: 4px 0 0;
}
.finding details {
  margin-top: 4px;
  color: var(--muted);
}
.finding summary {
  cursor: pointer;
}
.finding .actions {
  margin-top: 6px;
  display: flex;
  gap: 6px;
}

.exports {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.exports .btn {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 2px 8px;
  min-width: 0;
  padding: 6px 12px;
  text-align: left;
}
.exports .btn small {
  color: var(--muted);
  font-size: 11.5px;
}

/* Stage */
.sheet-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
/* Hold the stage open until the first drawing, so the form below it does not jump. */
html[data-start="note"] .sheet-wrap:not(.settled) {
  min-height: 340px;
}
html[data-start="map"] .sheet-wrap:not(.settled) {
  min-height: 230px;
}
html[data-start="map"] .sheet-wrap:not(.settled) .stage-note {
  display: none;
}
.sheet-wrap.has-note {
  display: grid;
  min-height: 340px;
}
.sheet-wrap.has-note > .sheet,
.sheet-wrap.has-note > .stage-note {
  grid-area: 1 / 1;
}
.sheet {
  line-height: 0;
}
.sheet svg {
  display: block;
  width: 100%;
  height: auto;
  transition:
    filter 0.25s,
    opacity 0.25s;
}
.sheet.fresh svg {
  animation: fade 0.3s ease both;
}
.sheet.stale {
  pointer-events: none;
}
.sheet.stale svg {
  filter: grayscale(0.85) blur(1.5px);
  opacity: 0.35;
}
.expand {
  display: none;
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--control);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  color: var(--ink);
  cursor: pointer;
}
.expand:hover {
  background: var(--line);
}
@media (max-width: 960px) {
  .expand {
    display: grid;
  }
}
.viewer {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--panel);
  color: var(--ink);
}
.viewer[open] {
  display: flex;
  flex-direction: column;
}
.viewer::backdrop {
  background: rgba(0, 0, 0, 0.5);
}
.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  font: 600 15px/1.2 var(--serif);
}
.viewer-bar span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.viewer-scroll {
  flex: 1;
  overflow: auto;
  touch-action: pan-x pan-y pinch-zoom;
}
.viewer-scroll svg {
  display: block;
  width: var(--viewer-width, 1000px);
  max-width: none;
  height: auto;
}
.stage-note {
  /* Above the greyed map under it, whose filter makes it paint over anything not positioned. */
  position: relative;
  z-index: 1;
  display: none;
  place-items: center;
  padding: 24px;
  text-align: center;
  font-size: 15px;
  color: var(--muted);
  line-height: 1.5;
}
.stage-note.show {
  display: grid;
  background: color-mix(in srgb, var(--panel) 78%, transparent);
  pointer-events: none;
}
.stage-note button {
  pointer-events: auto;
}
.stage-note .cta {
  margin-top: 16px;
}
.goto {
  margin-left: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.stage-errors {
  list-style: none;
  margin: 12px auto 0;
  padding: 0;
  max-width: 560px;
  display: grid;
  gap: 8px;
  text-align: left;
  font-size: 13.5px;
  line-height: 1.4;
}
.stage-errors li {
  display: grid;
  grid-template-columns: 9.5em 1fr;
  gap: 10px;
  align-items: baseline;
}
.stage-errors code {
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
}
.demo-note {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--muted);
}
.stage-note strong {
  display: block;
  color: var(--ink);
  font: 600 18px/1.3 var(--serif);
  margin-bottom: 6px;
}
.sheet-wrap.loading::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  height: 3px;
  width: 40%;
  background: var(--accent);
  animation: sweep 1s ease-in-out infinite;
}
.join {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 28px;
}
.join .pill {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 12.5px;
  color: var(--muted);
}
.join .pill.bad {
  border-color: var(--warn);
  color: var(--warn);
}
.foot {
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 40px) 36px;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  align-items: center;
}
.foot a {
  color: var(--muted);
  padding: 8px 0;
}
.foot a:hover {
  color: var(--ink);
}

.tip {
  position: fixed;
  z-index: 30;
  max-width: 260px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
[data-tip].hot {
  stroke: var(--ink);
  stroke-width: 1.6;
}
[data-tip]:focus {
  outline: none;
  stroke: var(--ink);
  stroke-width: 2;
}
.dim {
  opacity: 0.22;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 40;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  animation: rise 0.25s ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}
@keyframes slide {
  from {
    opacity: 0;
    transform: translateX(-6px);
  }
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
@keyframes sweep {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(250%);
  }
}
@media (max-width: 960px) {
  /* Three rows of pills fit under the map on a phone, so the form below does not move when they appear. */
  .join {
    min-height: 92px;
  }
}
@media (max-width: 520px) {
  .stage-errors li {
    grid-template-columns: 1fr;
    gap: 2px;
  }
  .stage-note {
    padding: 18px 16px;
  }
}
@media (pointer: coarse) {
  .chip,
  .btn.small {
    min-height: 44px;
  }
  .chip {
    padding: 0 14px;
  }
  input[type="text"],
  input[type="number"],
  select,
  textarea {
    min-height: 44px;
  }
  .select-chip select,
  .icon-btn {
    height: 44px;
  }
  .icon-btn {
    width: 44px;
  }
  .finding summary {
    padding: 10px 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
