:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --ink: #1b2129;
  --muted: #5a6572;
  --line: #dde1e6;
  --field: #f7f8fa;
  --accent: #2c7a4b;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1e8;
  --warn: #8a5300;
  --warn-soft: #fff3de;
  --bad: #b3261e;
  --bad-soft: #fde8e6;
  --found: #2c7a4b;
  --adapted: #c27c0e;
  --made: #3a6db5;
  --missing: #b3261e;
  --check-a: #e6e9ed;
  --check-b: #f6f7f9;
  --grid: rgba(208, 43, 125, 0.55);
  --map-bg: #e8e4d8;
  --shadow: 0 1px 2px rgba(20, 28, 38, 0.06), 0 4px 16px rgba(20, 28, 38, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418;
    --panel: #1a1e24;
    --ink: #e7eaee;
    --muted: #9aa4b0;
    --line: #2b3139;
    --field: #22272e;
    --accent: #5ccb8b;
    --accent-ink: #0b1a11;
    --accent-soft: #1d3326;
    --warn: #f0b458;
    --warn-soft: #33270f;
    --bad: #ff8a80;
    --bad-soft: #3a1c1a;
    --found: #5ccb8b;
    --adapted: #f0b458;
    --made: #7aa7ec;
    --missing: #ff8a80;
    --check-a: #262b33;
    --check-b: #1f242b;
    --grid: rgba(255, 105, 180, 0.5);
    --map-bg: #2a2e27;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111418;
  --panel: #1a1e24;
  --ink: #e7eaee;
  --muted: #9aa4b0;
  --line: #2b3139;
  --field: #22272e;
  --accent: #5ccb8b;
  --accent-ink: #0b1a11;
  --accent-soft: #1d3326;
  --warn: #f0b458;
  --warn-soft: #33270f;
  --bad: #ff8a80;
  --bad-soft: #3a1c1a;
  --found: #5ccb8b;
  --adapted: #f0b458;
  --made: #7aa7ec;
  --missing: #ff8a80;
  --check-a: #262b33;
  --check-b: #1f242b;
  --grid: rgba(255, 105, 180, 0.5);
  --map-bg: #2a2e27;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { line-height: 1.2; margin: 0; text-wrap: balance; }
h1 { font-size: 1.75rem; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
code { font: 0.9em ui-monospace, "Cascadia Mono", Consolas, monospace; }

a { color: var(--accent); }

.top {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 16px 12px;
  display: flex;
  gap: 16px 32px;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
}

.lede { color: var(--muted); max-width: 62ch; margin-top: 6px; }
.source-link { font-weight: 600; white-space: nowrap; }

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 8px 16px 48px;
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.step {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 0.9rem;
}

.hint { color: var(--muted); font-size: 0.9rem; margin-top: 8px; }

button {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--accent); }
button.small { padding: 3px 10px; font-size: 0.9em; }
button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.button-row { display: flex; gap: 8px; flex-wrap: wrap; }

.field { display: grid; gap: 4px; font-size: 0.9rem; color: var(--muted); }
.field > span:first-child { font-weight: 600; }
.field.inline { min-width: 0; }
.field.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: normal; }
.field.check > span:first-child { font-weight: normal; }

select, input[type="number"], input:not([type]) {
  font: inherit;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
  width: 100%;
}
.with-unit { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.with-unit input { width: 110px; }
.frame-fields { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.frame-fields input { width: 72px; }

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid var(--line);
  vertical-align: -2px;
}

/* Step 1 */

.source-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
}

.drop {
  border: 2px dashed var(--line);
  border-radius: 10px;
  min-height: 240px;
  display: grid;
  place-items: center;
  padding: 16px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  min-width: 0;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-empty { display: grid; gap: 12px; justify-items: center; }
.source-view { display: grid; gap: 12px; justify-items: center; width: 100%; min-width: 0; }
.source-view canvas { max-width: 100%; }

.source-controls { display: grid; gap: 14px; align-content: start; min-width: 0; }

.status { display: grid; gap: 8px; }

.pick { display: grid; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.pick-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.pick-title { font-weight: 600; }
.pick .seg { margin-left: 0; }
.pick .hint { margin-top: 0; }
.pick-board { display: grid; gap: 6px; justify-content: start; }
.pick-slot {
  position: relative;
  padding: 3px;
  border-radius: 6px;
  border: 2px solid var(--line);
  background: var(--field);
  line-height: 0;
}
.pick-slot canvas { display: block; image-rendering: pixelated; }
.pick-slot.empty canvas { opacity: 0.4; }
.pick-slot[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.pick-slot .need {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 14px;
  height: 14px;
  border-radius: 99px;
  background: var(--warn);
  border: 2px solid var(--panel);
}
.pick-readout { font-size: 0.8rem; color: var(--muted); min-height: 1.5em; }
.source-view canvas.picking { cursor: pointer; }

.plain { display: grid; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.plain-title { font-weight: 600; }
.plain-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 12px; align-items: center; font-size: 0.9rem; }
.plain-row canvas { grid-row: span 2; border-radius: 4px; border: 1px solid var(--line); image-rendering: pixelated; }
.plain-row .plain-how.picking { color: var(--accent); font-weight: 600; }
.status .line { padding: 10px 12px; border-radius: 8px; background: var(--field); border: 1px solid var(--line); }
.status .line.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.status .line.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }

details { border-top: 1px solid var(--line); padding-top: 10px; }
summary { cursor: pointer; font-weight: 600; }

.pieces {
  margin-top: 10px;
  display: grid;
  grid-template-columns: minmax(96px, auto) repeat(4, max-content);
  gap: 4px 8px;
  align-items: center;
  font-size: 0.8rem;
  overflow-x: auto;
}
.pieces .head { color: var(--muted); font-weight: 600; text-align: center; }
.pieces .kind { color: var(--muted); }
.pieces canvas {
  display: block;
  border: 2px solid var(--found);
  border-radius: 4px;
  image-rendering: pixelated;
}
.pieces canvas.adapted { border-color: var(--adapted); }
.pieces canvas.made { border-color: var(--made); }
.pieces canvas.missing { border-color: var(--missing); border-style: dashed; }

.legend { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.8rem; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.dot.found { background: var(--found); }
.dot.adapted { background: var(--adapted); }
.dot.made { background: var(--made); }
.dot.missing { background: transparent; border: 2px dashed var(--missing); }

/* Step 2 */

.seg {
  margin-left: auto;
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 3px;
  background: var(--field);
}
.seg button {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 6px;
  padding: 5px 12px;
}
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }

.godot-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 12px; }

.cards {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  grid-auto-flow: row dense;
  gap: 14px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  display: grid;
  gap: 10px;
  align-content: start;
  min-width: 0;
}
.card.wide { grid-column: span 2; }
.card header { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.card h3 { font-size: 0.98rem; }
.card .blurb { color: var(--muted); font-size: 0.86rem; }
.card .sheet { display: grid; place-items: center; min-height: 80px; min-width: 0; }
.card .sheet canvas { max-width: 100%; cursor: crosshair; }
.card .readout { font-size: 0.8rem; color: var(--muted); min-height: 1.5em; }
.card .note { font-size: 0.82rem; padding: 8px 10px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); }

.badge {
  flex: none;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--field);
  color: var(--muted);
  border: 1px solid var(--line);
}
.badge.dual { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.checker {
  background-color: var(--check-b);
  background-image: repeating-conic-gradient(var(--check-a) 0 25%, transparent 0 50%);
  background-size: 16px 16px;
  image-rendering: pixelated;
}

/* Step 3 */

.map-controls { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: end; }
.map-controls .field.inline { width: min(100%, 320px); }
.map-wrap { margin-top: 12px; display: grid; place-items: center; min-width: 0; }
.map-wrap canvas {
  max-width: 100%;
  background: var(--map-bg);
  border-radius: 6px;
  cursor: cell;
  touch-action: none;
  image-rendering: pixelated;
}

/* How it works */

.how-grid { margin-top: 12px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.how-grid p { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }

@media (max-width: 760px) {
  .source-grid, .godot-row, .how-grid { grid-template-columns: minmax(0, 1fr); }
  .card.wide { grid-column: auto; }
  .seg { margin-left: 0; }
  .panel { padding: 16px; }
}
