:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --raised: #ffffff;
  --sunken: #eceef1;
  --hover: #f3f5f7;
  --ink: #1b1f24;
  --ink-2: #57606a;
  --ink-3: #68717b;
  --line: #dfe3e8;
  --line-2: #c4cad1;
  --check: rgba(27, 31, 36, 0.06);
  --accent: #2459a8;
  --on-accent: #ffffff;
  --accent-soft: #e6eef9;
  --accent-ink: #1d4a8c;
  --press: #1c4788;
  --good: #1a7f4b;
  --good-soft: #e0f3e8;
  --bad: #b3261e;
  --bad-soft: #fbe3df;
  --on-ink: #ffffff;
  --lift: 0 1px 2px rgba(27, 31, 36, 0.16);
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --gutter: clamp(16px, 4vw, 40px);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16181b;
  --surface: #1f2226;
  --raised: #3d434b;
  --sunken: #2a2e33;
  --hover: #262a2f;
  --ink: #e8eaed;
  --ink-2: #aab1b9;
  --ink-3: #8b939d;
  --line: #30353b;
  --line-2: #474d55;
  --check: rgba(255, 255, 255, 0.05);
  --accent: #7aaef0;
  --on-accent: #10161f;
  --accent-soft: #1d2f4a;
  --accent-ink: #9cc2f5;
  --press: #9cc2f5;
  --good: #5bcb98;
  --good-soft: #173020;
  --bad: #ff8a7d;
  --bad-soft: #3b1c18;
  --on-ink: #16181b;
  --lift: 0 1px 2px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p, ul, fieldset { margin: 0; padding: 0; }
fieldset { border: 0; min-width: 0; }
ul { list-style: none; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
img, canvas, svg { display: block; }

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

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

.head-inner, main, .site-foot {
  width: 100%;
  max-width: 1120px;
  margin-inline: auto;
  padding-inline: var(--gutter);
}

main { flex: 1; }

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

.site-head { border-bottom: 1px solid var(--line); background: var(--surface); }

.head-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand-mark { width: 24px; height: 24px; color: var(--accent); }
.brand-cut { stroke: var(--on-accent); }
.brand-fill { fill: var(--on-accent); }

.head-side { display: flex; align-items: center; gap: 16px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  color: var(--ink-2);
  cursor: pointer;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-2); }
.icon-sun, :root[data-theme="dark"] .icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }

.back-link {
  color: var(--ink-2);
  font-size: 0.85rem;
  text-decoration: none;
  white-space: nowrap;
}
.back-link:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }

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

.home {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  grid-template-areas: "intro tools" "files tools" "promises tools";
  grid-template-rows: auto auto 1fr;
  gap: 24px 48px;
  padding-block: clamp(24px, 5vw, 48px) 56px;
}
.intro { grid-area: intro; }
.home-files { grid-area: files; }
.home-tools { grid-area: tools; }
.promises { grid-area: promises; }

.home h1 {
  font-weight: 600;
  font-size: clamp(1.6rem, 3vw, 2rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.lede { margin-top: 12px; color: var(--ink-2); }

.dropzone {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 28px 20px;
  border: 1.5px dashed var(--line-2);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-2);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone svg { margin-bottom: 8px; color: var(--ink-3); }
.dropzone .btn { margin-top: 14px; }
.dropzone-title { color: var(--ink); font-weight: 600; }
.dropzone-sub { font-size: 0.875rem; }
.dropzone-sub:empty { display: none; }

.tray {
  display: flex;
  align-items: center;
  gap: 12px 14px;
  flex-wrap: wrap;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.tray-thumbs { display: flex; }
.tray-thumbs > * {
  width: 40px;
  height: 40px;
  margin-left: -10px;
  border: 2px solid var(--surface);
  border-radius: 6px;
  background: var(--sunken);
  object-fit: cover;
}
.tray-thumbs > :first-child { margin-left: 0; }
.tray-text { flex: 1; min-width: 11rem; }
.tray-title { font-weight: 600; }
.tray-sub { color: var(--ink-2); font-size: 0.875rem; }
.tray-actions, .files-actions { display: flex; gap: 16px; }

.tool-index {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.tool-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  text-decoration: none;
  transition: opacity 0.2s;
}
.tool-row + .tool-row { border-top: 1px solid var(--line); }
.tool-row:hover { background: var(--hover); }
.tool-row:focus-visible { outline-offset: -2px; }
.tool-icon { color: var(--accent); }
.tool-text { display: grid; min-width: 0; }
.tool-name { font-weight: 600; }
.tool-desc { color: var(--ink-2); font-size: 0.875rem; }
.tool-arrow { color: var(--ink-3); }
.tool-row.is-dim { opacity: 0.4; }

.promises { display: grid; align-content: start; gap: 8px; color: var(--ink-2); font-size: 0.875rem; }
.promises strong { color: var(--ink); font-weight: 600; }

/* ---------- workspace ---------- */

.workspace { padding-block: 0 56px; }

.tool-nav {
  display: flex;
  gap: 24px;
  box-shadow: inset 0 -1px var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tool-nav::-webkit-scrollbar { display: none; }
.tool-nav a {
  padding: 14px 0 12px;
  border-bottom: 2px solid transparent;
  color: var(--ink-2);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.tool-nav a:hover { color: var(--ink); }
.tool-nav a:focus-visible { outline-offset: -2px; }
.tool-nav a[aria-current="page"] { border-bottom-color: var(--accent); color: var(--ink); }

.tool-head { margin: 28px 0 20px; }
.tool-head h1 {
  font-weight: 600;
  font-size: 1.5rem;
  line-height: 1.25;
  letter-spacing: -0.015em;
}
.tool-head p { max-width: 60ch; margin-top: 4px; color: var(--ink-2); }

.work {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-areas: "stage panel" "results panel";
  grid-template-rows: auto 1fr;
  gap: 20px;
  align-items: start;
}
.stage { grid-area: stage; display: grid; gap: 16px; min-width: 0; }
.panel { grid-area: panel; }
.results { grid-area: results; min-width: 0; }

.files-wrap, .editor, .panel, .results {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

/* ---------- files ---------- */

.files-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 16px;
  color: var(--ink-2);
  font-size: 0.85rem;
  font-weight: 500;
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-ink);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }

.file {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
}
.file-main {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
}
button.file-main { cursor: pointer; }
.file.is-active { background: var(--accent-soft); box-shadow: inset 3px 0 var(--accent); }

.file-thumb {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 4px;
  background: var(--sunken);
  color: var(--ink-2);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  overflow: hidden;
}
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-thumb.is-loading { animation: pulse 1.1s ease-in-out infinite; }

@keyframes pulse {
  50% { opacity: 0.45; }
}

.file-text { display: grid; min-width: 0; }
.file-name { overflow: hidden; font-size: 0.9rem; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { color: var(--ink-2); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.file-meta.is-bad { color: var(--bad); }
.file-note { color: var(--ink-2); font-size: 0.8rem; }

.file-actions { display: flex; align-items: center; gap: 2px; }
.mini-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink-3);
  cursor: pointer;
}
.mini-btn:hover { background: var(--sunken); color: var(--ink); }
.mini-btn[disabled] { opacity: 0.3; cursor: default; background: none; }

.delta {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 4px;
  background: var(--sunken);
  color: var(--ink-2);
  font-size: 0.74rem;
  font-weight: 600;
}
.delta.is-good { background: var(--good-soft); color: var(--good); }

.file-detail {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 2px 14px;
  margin: 4px 0 2px 52px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--sunken);
  font-size: 0.82rem;
}
.file-detail dt { color: var(--ink-2); }
.file-detail dd { margin: 0; overflow-wrap: anywhere; }
.file-detail .is-alert { color: var(--bad); font-weight: 600; }
.file-detail .is-clear { grid-column: 1 / -1; color: var(--good); font-weight: 600; }
.file-detail .is-more { grid-column: 1 / -1; color: var(--ink-2); }

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

.editor { overflow: hidden; }
.editor-frame {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 14px;
  background-color: var(--sunken);
  background-image: linear-gradient(45deg, var(--check) 25%, transparent 25%, transparent 75%, var(--check) 75%), linear-gradient(45deg, var(--check) 25%, transparent 25%, transparent 75%, var(--check) 75%);
  background-position: 0 0, 8px 8px;
  background-size: 16px 16px;
}
.editor-frame canvas {
  max-width: 100%;
  max-height: min(62vh, 620px);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
}
.editor.is-draw canvas { cursor: crosshair; touch-action: none; }
.editor-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--sunken);
  color: var(--ink-2);
  font-size: 0.9rem;
  text-align: center;
}
.editor-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
}
.editor-hint { flex: 1 1 16rem; color: var(--ink-2); font-size: 0.85rem; }
.editor-tools { display: flex; flex-wrap: wrap; gap: 6px; }

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

.panel {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 16px;
  max-height: calc(100vh - 32px);
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.tool-panel { display: grid; gap: 16px; }
.tool-panel > div:not([class]) { display: grid; gap: 16px; }

.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .field legend, .field .label, .field-head label {
  padding: 0;
  color: var(--ink-2);
  font-size: 0.82rem;
  font-weight: 500;
}
.field legend { margin-bottom: 6px; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; }
.field-head output { font-size: 0.82rem; font-weight: 600; font-variant-numeric: tabular-nums; }

input[type="text"], input[type="number"], select {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background-color: var(--surface);
  font-size: 0.9rem;
}
input[type="text"]:hover, input[type="number"]:hover, select:hover { border-color: var(--ink-3); }
input::placeholder { color: var(--ink-3); }
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%237b838c' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 11px 7px;
  cursor: pointer;
}

.joined { display: flex; }
.joined input { border-radius: 6px 0 0 6px; }
.joined select { width: auto; flex: none; margin-left: -1px; border-radius: 0 6px 6px 0; }
.joined-suffix {
  display: grid;
  place-items: center;
  margin-left: -1px;
  padding: 0 11px;
  border: 1px solid var(--line-2);
  border-radius: 0 6px 6px 0;
  background: var(--sunken);
  color: var(--ink-2);
  font-size: 0.9rem;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.range-ends { display: flex; justify-content: space-between; color: var(--ink-3); font-size: 0.75rem; }

.seg, .tiles, .grid9 { position: relative; }
.seg input, .tiles input, .grid9 input { position: absolute; opacity: 0; pointer-events: none; }

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 2px;
  padding: 3px;
  border-radius: 7px;
  background: var(--sunken);
}
.seg span {
  display: block;
  padding: 7px 8px;
  border-radius: 5px;
  color: var(--ink-2);
  font-size: 0.85rem;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
}
.seg span:hover { color: var(--ink); }
.seg input:checked + span { background: var(--raised); color: var(--ink); box-shadow: var(--lift); }
.seg input:focus-visible + span, .tiles input:focus-visible + span, .grid9 input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg-modes { max-width: 520px; margin-bottom: 20px; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.tiles span {
  display: block;
  padding: 8px 2px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
}
.tiles span:hover { border-color: var(--ink-3); }
.tiles input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); box-shadow: inset 0 0 0 1px var(--accent); }
.tiles input:disabled + span { opacity: 0.35; cursor: not-allowed; border-color: var(--line-2); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  padding: 4px 10px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: none;
  color: var(--ink-2);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
}
.chips button:hover { border-color: var(--ink-3); color: var(--ink); }

.dims { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: end; gap: 8px; }
.lock {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: none;
  color: var(--ink-3);
  cursor: pointer;
}
.lock[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }

.check { display: flex; align-items: flex-start; gap: 10px; font-size: 0.9rem; cursor: pointer; }
.check input { flex: none; width: 16px; height: 16px; margin: 3px 0 0; accent-color: var(--accent); }
.check small { display: block; color: var(--ink-2); font-size: 0.8rem; }

.place { grid-template-columns: auto minmax(0, 1fr); align-items: end; gap: 16px; }
.grid9 { display: grid; grid-template-columns: repeat(3, 26px); gap: 3px; }
.grid9 span:first-of-type { display: block; width: 26px; height: 26px; border-radius: 3px; background: var(--sunken); cursor: pointer; }
.grid9 span:first-of-type:hover { background: var(--line-2); }
.grid9 input:checked + span { background: var(--accent); }

.colour-row { display: flex; align-items: center; gap: 10px; }
input[type="color"] {
  flex: none;
  width: 40px;
  height: 40px;
  padding: 3px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}

.panel-text { font-size: 0.9rem; }
.note { color: var(--ink-2); font-size: 0.82rem; }
.note:empty { display: none; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
@media (hover: hover) {
  .btn-primary:hover { background: var(--press); }
}
.btn-quiet { border-color: var(--line-2); background: var(--surface); }
.btn-quiet:hover { border-color: var(--ink-3); }
.btn-small { height: 32px; padding: 0 12px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn-primary[disabled] { background: var(--accent); }
.btn-quiet[disabled] { border-color: var(--line-2); }

.action {
  position: sticky;
  bottom: -16px;   /* the panel's padding, so it sits flush with the bottom edge */
  display: grid;
  gap: 10px;
  margin: 0 -16px -16px;
  padding: 14px 16px 16px;
  border-top: 1px solid var(--line);
  border-radius: 0 0 7px 7px;
  background: var(--surface);
}
.progress-track { height: 4px; border-radius: 2px; background: var(--sunken); overflow: hidden; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent); transition: width 0.2s; }
.progress p { margin-top: 6px; overflow: hidden; color: var(--ink-2); font-size: 0.8rem; text-overflow: ellipsis; white-space: nowrap; }

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

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 16px;
}
.results-head h2 { font-size: 1rem; font-weight: 600; }
.results-head p { color: var(--ink-2); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

/* ---------- footer, veil, toast ---------- */

.site-foot { padding-block: 22px 28px; color: var(--ink-3); font-size: 0.82rem; }
.site-foot p { padding-top: 20px; border-top: 1px solid var(--line); }
.site-foot a { color: var(--ink-2); text-underline-offset: 3px; }

.veil {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  pointer-events: none;
}
.veil p {
  padding: 28px 44px;
  border: 2px dashed var(--accent);
  border-radius: 8px;
  background: var(--surface);
  font-size: 1.25rem;
  font-weight: 600;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 60;
  width: max-content;
  max-width: min(92vw, 460px);
  padding: 10px 14px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--on-ink);
  font-size: 0.9rem;
  box-shadow: 0 6px 20px -8px rgba(0, 0, 0, 0.5);
  transform: translateX(-50%);
}

/* ---------- small screens ---------- */

/* One column. The stage dissolves so its parts can be ordered around the
   panel: when editing, the options sit right under the preview. */
@media (max-width: 880px) {
  .home { grid-template-columns: minmax(0, 1fr); grid-template-areas: "intro" "files" "tools" "promises"; grid-template-rows: none; }
  .work { display: flex; flex-direction: column; align-items: stretch; }
  .stage { display: contents; }
  .panel { position: static; order: 1; max-height: none; overflow: visible; }
  .action { position: static; }
  .is-editing .files-wrap { order: 2; }
  .results { order: 3; }
}

@media (max-width: 680px) {
  .tool-nav { gap: 20px; }
  .seg-modes { grid-auto-flow: row; grid-template-columns: 1fr 1fr; }
  .file { padding-inline: 12px; }
  .file-detail { margin-left: 0; }
  .results-head .btn { width: 100%; }
}

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