:root {
  --paper: #f4f0e6;
  --card: #fffdf8;
  --ink: #1d2125;
  --muted: #62676b;
  --line: #d9d3c4;
  --accent: #0b5d52;
  --accent-soft: #dcebe6;
  --gold: #d99a06;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --mono: Consolas, "SF Mono", Menlo, monospace;
  --checker: repeating-conic-gradient(#d9d6cd 0 25%, #f4f2eb 0 50%) 0 0 / 22px 22px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
html, body { margin: 0; height: 100%; }
body { background: var(--paper); color: var(--ink); font: 15px/1.5 var(--sans); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }

.row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row.even > * { flex: 1; }
.push { margin-left: auto; }
.link { border: 0; background: none; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 0; font-size: 13.5px; }

.btn { display: inline-block; border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 6px; cursor: pointer; text-align: center; }
.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #084a41; border-color: #084a41; }
.btn.big { padding: 11px 22px; font-size: 16px; font-weight: 600; }
.btn.danger { color: #a3301c; }
.icon { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); cursor: pointer; font-size: 17px; line-height: 1; padding: 0; }
.icon:hover { border-color: var(--ink); }

/* Landing */
#landing { max-width: 1120px; margin: 0 auto; padding: 16px 24px 70px; }
.site-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.logo { font: 600 25px var(--serif); text-decoration: none; }
.site-nav { display: flex; gap: 18px; flex-wrap: wrap; font-size: 14.5px; }
.site-nav a { text-decoration: none; }
.site-nav a:hover { text-decoration: underline; }
.hero { display: grid; grid-template-columns: 1fr 1.05fr; gap: 38px; padding: 34px 0 40px; align-items: start; }
.eyebrow { font: 12.5px var(--mono); letter-spacing: .04em; color: var(--accent); }
.hero h1 { font-size: clamp(36px, 5.4vw, 58px); letter-spacing: -.015em; margin-top: 8px; }
.lead { margin-top: 14px; color: var(--muted); font-size: 16.5px; }
.drop { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-top: 20px; padding: 20px; border: 2px dashed #a79f8b; border-radius: 10px; background: var(--card); cursor: pointer; }
.drop-text strong { display: block; font: 600 20px var(--serif); }
.drop small, .drop-text small { color: var(--muted); font-size: 13.5px; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.small-drop { display: block; margin-top: 16px; padding: 12px 14px; text-align: center; }
.small-drop strong { display: block; }
.formats { margin-top: 8px; font-size: 13px; color: var(--muted); }
.demo-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; font: 12.5px var(--mono); align-items: baseline; }
.demo-stage { position: relative; aspect-ratio: 4 / 3; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--checker); touch-action: none; cursor: ew-resize; }
#demo-vector, #demo-vector svg, #demo-pixels { position: absolute; inset: 0; width: 100%; height: 100%; display: block; transform-origin: var(--ox, 50%) var(--oy, 50%); }
#demo-pixels { image-rendering: pixelated; }
#demo-handle { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); pointer-events: none; }
#demo-handle span { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); white-space: nowrap; padding: 2px 8px; color: #fff; background: var(--ink); border-radius: 4px; font-size: 12px; }
#demo-wait { position: absolute; left: 10px; top: 10px; padding: 2px 8px; font-size: 12.5px; background: var(--card); border-radius: 4px; }
.demo-zoom { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.sample-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.sample { padding: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--card); cursor: pointer; text-align: left; }
.sample:hover { border-color: var(--ink); }
.sample.on { outline: 2px solid var(--accent); outline-offset: 1px; }
.sample canvas { display: block; width: 100%; height: auto; background: var(--checker); }
.sample span { display: block; padding: 3px 6px; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.band { padding: 40px 0 8px; border-top: 1px solid var(--line); margin-top: 8px; scroll-margin-top: 10px; }
.band h2 { font-size: 30px; }
.section-lead { margin-top: 8px; color: var(--muted); max-width: 72ch; }
.three { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 24px; margin-top: 20px; }
.three h3 { font-size: 19px; }
.three p { margin-top: 6px; color: var(--muted); font-size: 14.5px; }
.step { display: inline-block; font: 600 34px var(--serif); color: var(--accent); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 12px; margin-top: 20px; }
.use { padding: 14px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
.use small { font: 12px var(--mono); color: var(--accent); }
.use h3 { margin-top: 4px; font-size: 18px; }
.use p { margin-top: 5px; color: var(--muted); font-size: 14px; }
.feature-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 0 28px; margin-top: 16px; }
.feature { padding: 14px 0; border-top: 1px solid var(--line); }
.feature h3 { font-size: 17px; }
.feature p { color: var(--muted); font-size: 14px; margin-top: 4px; }
#faq-list { margin-top: 16px; max-width: 820px; }
#faq-list details { border-top: 1px solid var(--line); padding: 11px 0; }
#faq-list summary { cursor: pointer; font-weight: 600; }
#faq-list p { margin-top: 7px; color: var(--muted); font-size: 14.5px; }
.cta { text-align: center; padding-bottom: 20px; }
.cta .section-lead { margin: 8px auto 16px; }

/* Crop */
#crop { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--paper); z-index: 5; }
.crop-bar { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: center; padding: 12px 18px; background: var(--card); border-bottom: 1px solid var(--line); }
.crop-bar h2 { font-size: 20px; }
.crop-bar p { color: var(--muted); font-size: 13px; }
.crop-stage { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 18px; min-height: 0; }
.crop-wrap { position: relative; line-height: 0; touch-action: none; cursor: crosshair; background: var(--checker); }
#crop-canvas { display: block; max-width: 100%; }
#crop-box { position: absolute; border: 2px solid var(--accent); box-shadow: 0 0 0 9999px rgba(20, 24, 28, .5); cursor: move; }

/* Workspace */
#workspace { position: fixed; inset: 0; display: flex; flex-direction: column; z-index: 5; background: var(--paper); }
.toolbar { display: flex; gap: 8px 14px; align-items: center; flex-wrap: wrap; padding: 7px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.segmented button { border: 0; background: transparent; padding: 5px 12px; cursor: pointer; font-size: 13px; border-right: 1px solid var(--line); }
.segmented button:last-child { border-right: 0; }
.segmented button.on { background: var(--ink); color: #fff; }
.zoom-label { min-width: 50px; text-align: center; font: 13px var(--mono); }
.work { position: relative; flex: 1; display: grid; grid-template-columns: 310px 1fr; min-height: 0; }
.work.collapsed { grid-template-columns: 0 1fr; }
.work.collapsed #side { display: none; }
#side { display: flex; flex-direction: column; min-height: 0; background: var(--card); border-right: 1px solid var(--line); }
#panel { flex: 1; overflow-y: auto; padding: 14px; min-height: 0; }
#panel-foot { display: flex; flex-direction: column; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
#hide-tools { position: absolute; left: 310px; top: 10px; z-index: 3; width: 22px; height: 34px; border: 1px solid var(--line); border-left: 0; border-radius: 0 6px 6px 0; background: var(--card); cursor: pointer; padding: 0; }
.work.collapsed #hide-tools { left: 0; }
#panel h2 { font-size: 24px; margin-bottom: 8px; }
#panel h3 { font: 600 13px var(--sans); margin: 16px 0 6px; }
#panel p.hint { color: var(--muted); font-size: 13px; }
#panel p.italic { font-style: italic; }
.tool-item { display: flex; gap: 10px; width: 100%; padding: 11px 6px; border: 0; border-top: 1px solid var(--line); background: none; text-align: left; cursor: pointer; }
.tool-item:hover { background: var(--paper); }
.tool-item b { display: block; font-size: 15px; }
.tool-item small { color: var(--muted); font-size: 12.5px; line-height: 1.35; display: block; }
.badge { align-self: center; font: 12px var(--mono); padding: 1px 7px; background: var(--paper); border-radius: 10px; margin-left: auto; }
.chev { align-self: center; color: var(--muted); }
.back { border: 1px solid var(--line); border-radius: 6px; background: none; color: var(--accent); cursor: pointer; padding: 3px 9px; margin-bottom: 10px; font-size: 13px; }
.panel-top { display: flex; gap: 6px; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.panel-top .back { margin-bottom: 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { position: relative; width: 34px; height: 34px; border-radius: 6px; border: 1px solid rgba(0, 0, 0, .25); cursor: pointer; padding: 0; overflow: hidden; font-size: 13px; }
.swatch.sel { outline: 3px solid var(--accent); outline-offset: 1px; }
.swatch.off { opacity: .42; }
.swatch.clear { background: var(--checker); background-size: 12px 12px; }
.swatch.suggest::after { content: "•"; position: absolute; right: 2px; top: -3px; color: #fff; text-shadow: 0 0 2px #000; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; background: none; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; font-size: 13px; }
.chip i { width: 12px; height: 12px; border: 1px solid rgba(0, 0, 0, .3); display: inline-block; }
.opt { display: flex; gap: 7px; align-items: baseline; padding: 3px 0; cursor: pointer; font-size: 14px; }
.opt input { margin: 0; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.stat { display: flex; justify-content: space-between; font-size: 13.5px; padding: 3px 0; border-bottom: 1px dotted var(--line); }
.stat b { font: 13px var(--mono); }
.field { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; font-size: 13.5px; }
.inline-input { width: 72px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
.hex-input { width: 82px; font-family: var(--mono); }
.note { padding: 8px 10px; background: var(--accent-soft); border-radius: 6px; font-size: 13px; margin: 8px 0; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; }
.mark { width: 14px; height: 14px; display: inline-block; border: 1.5px solid #fff; box-shadow: 0 0 0 1px #555; }
.mark.sharp { background: #12a150; transform: rotate(45deg) scale(.8); }
.mark.round { background: #f0b429; border-radius: 50%; }
.mark.manual { background: #1668dc; border-radius: 50%; }
.line-mark { width: 26px; height: 0; border-top: 3px solid #666; display: inline-block; }

/* Palette bubbles */
#bubbles { position: relative; height: 170px; margin-bottom: 6px; touch-action: none; }
.bubble { position: absolute; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .25); box-shadow: 0 2px 5px rgba(0, 0, 0, .3); cursor: grab; padding: 0; }
.bubble i { position: absolute; right: 8%; bottom: 8%; width: 56%; height: 56%; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .18); }
.bubble.sel { outline: 3px solid var(--accent); outline-offset: 2px; }
.bubble.target { outline: 3px dashed var(--gold); outline-offset: 2px; }
.bubble.drag { cursor: grabbing; z-index: 4; }
.palette-actions { display: flex; justify-content: space-around; align-items: center; gap: 6px; padding: 6px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 13px; font-style: italic; text-align: center; flex-wrap: wrap; }
.palette-edit { display: grid; grid-template-columns: auto 1fr; gap: 5px 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.palette-edit input[type=color] { width: 44px; height: 26px; padding: 0; border: 1px solid var(--line); }
.presets { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.preset { width: 28px; height: 28px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .3); font-size: 11px; cursor: pointer; padding: 0; color: #111; text-shadow: 0 0 2px #fff, 0 0 2px #fff; }
.preset.on { outline: 3px solid var(--accent); outline-offset: 1px; }
.preset.auto { box-shadow: 0 0 0 2px var(--gold); }

/* Stage */
#stage { position: relative; overflow: hidden; min-height: 0; touch-action: none; cursor: grab; background: var(--checker); display: flex; }
#stage.panning { cursor: grabbing; }
#stage.pick { cursor: crosshair; }
.pane { position: relative; flex: 1; overflow: hidden; min-width: 0; }
#pane-a { border-right: 2px solid var(--ink); }
.vp { position: absolute; left: 0; top: 0; line-height: 0; }
#vector-layer, #vector-layer svg, #original-under, #original-side, #palette-layer, #overlay { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; }
#original-under, #original-side, #palette-layer { image-rendering: pixelated; }
#overlay { overflow: visible; pointer-events: none; }
#overlay .hit { pointer-events: stroke; cursor: pointer; }
#overlay .marker { pointer-events: auto; cursor: pointer; }
.stage-title { position: absolute; top: 8px; left: 75%; transform: translateX(-50%); padding: 1px 10px; font-size: 13px; background: rgba(255, 253, 248, .9); border-radius: 4px; pointer-events: none; white-space: nowrap; }
.stage-title.single { left: 50%; }
#title-a { left: 25%; }
#legend { position: absolute; left: 34px; bottom: 34px; padding: 8px 10px; background: rgba(255, 253, 248, .95); border: 1px solid var(--line); border-radius: 6px; font-size: 12.5px; line-height: 1.6; pointer-events: none; }
#legend i { display: inline-block; width: 14px; height: 3px; margin-right: 6px; vertical-align: middle; }
#stage-size { position: absolute; left: 50%; transform: translateX(-50%); bottom: 8px; font: 12px var(--mono); background: rgba(255, 253, 248, .9); padding: 1px 7px; border-radius: 4px; pointer-events: none; }

/* Shape chooser */
#chooser { position: fixed; inset: 0; z-index: 12; display: flex; align-items: center; justify-content: center; padding: 18px; background: rgba(20, 24, 28, .45); }
.chooser-card { width: min(760px, 100%); max-height: 92%; overflow-y: auto; padding: 14px; background: var(--card); border-radius: 10px; }
.chooser-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 10px; align-items: start; }
#chooser-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.choice-card { display: block; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--checker); cursor: pointer; }
.choice-card span { display: block; padding: 5px 8px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 600; }
.choice-card.rec span { background: var(--accent); }
.choice-card.cur { outline: 3px solid var(--gold); outline-offset: 1px; }
.choice-card svg { display: block; width: 100%; height: auto; }

/* Export */
#export { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--paper); z-index: 6; }
.export-head { display: flex; gap: 14px; align-items: center; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.export-head h2 { font-size: 21px; margin-right: auto; }
.export-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); min-height: 0; }
#export-form { overflow-y: auto; padding: 16px 20px 40px; border-right: 1px solid var(--line); }
.export-preview { padding: 16px 20px; overflow-y: auto; }
#preview-box { background: var(--checker); border: 1px solid var(--line); border-radius: 6px; line-height: 0; }
#preview-box img { width: 100%; height: auto; display: block; }
#export-summary { margin-top: 12px; font-size: 14px; }
#export-note { margin-top: 6px; color: var(--muted); font-size: 13px; }
fieldset { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
legend { padding: 0; font-weight: 600; margin-bottom: 6px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.tiles.wide { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.tile { display: block; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); cursor: pointer; font-size: 13px; color: var(--muted); }
.tile b { display: block; color: var(--ink); font-size: 14px; }
.tile input { position: absolute; opacity: 0; pointer-events: none; }
.tile:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.tile:has(input:focus-visible) { outline: 2px solid var(--accent); }
.choice { display: flex; flex-wrap: wrap; gap: 0 14px; }
details.advanced { border-top: 1px solid var(--line); padding-top: 10px; }
details.advanced summary { cursor: pointer; font-weight: 600; margin-bottom: 12px; }
.adv-summary { display: block; font-weight: 400; font-size: 12.5px; color: var(--muted); }
.field-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 6px; font-size: 14px; }

#busy { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(29, 33, 37, .25); z-index: 20; }
.busy-card { display: flex; gap: 10px; align-items: center; padding: 14px 20px; background: var(--card); border-radius: 8px; border: 1px solid var(--line); }
.spin { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 3s; } }
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); max-width: 90vw; padding: 10px 16px; background: var(--ink); color: #fff; border-radius: 6px; z-index: 30; font-size: 14px; }

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; padding: 24px 0; gap: 22px; }
  .work { grid-template-columns: 1fr; grid-template-rows: 1fr minmax(210px, 46%); }
  .work.collapsed { grid-template-columns: 1fr; grid-template-rows: 1fr 0; }
  #side { order: 2; border-right: 0; border-top: 1px solid var(--line); }
  #hide-tools { display: none; }
  .export-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; overflow-y: auto; }
  #export-form { order: 2; border-right: 0; overflow: visible; }
  .export-preview { overflow: visible; }
  #preview-box { max-width: 300px; }
}
