:root {
  --bg: #f4f3f0;
  --panel: #ffffff;
  --ink: #1f1f1f;
  --muted: #6b6b6b;
  --line: #dddad3;
  --accent: #2f6f62;
  --accent-ink: #ffffff;
  --error: #b3261e;
  --ok: #2f6f62;
  --checker: repeating-conic-gradient(#e6e6e6 0% 25%, #ffffff 0% 50%) 50% / 16px 16px;
  --line-hover: #b9b5ab;
  --invalid-bg: #fdf0ef;
  --highlight: #fff6dc;
  --highlight-line: #ecd9a0;
  --accent-tint: rgba(47, 111, 98, .08);
  --toast: #222;
  color-scheme: light dark;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--ink);
}

/* Dark mode uses the same colors as app-icon-maker's dark mode and the site's dark p5 pages */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --panel: #2c2c2e;
    --ink: #f5f5f7;
    --muted: #98989d;
    --line: #3a3a3c;
    --accent: #5bb8a3;
    --accent-ink: #1c1c1e;
    --error: #ff6961;
    --ok: #5bb8a3;
    --checker: repeating-conic-gradient(#2c2c2e 0% 25%, #3a3a3c 0% 50%) 50% / 16px 16px;
    --line-hover: #636366;
    --invalid-bg: #3d2322;
    --highlight: #3a3220;
    --highlight-line: #6b5a2e;
    --accent-tint: rgba(91, 184, 163, .12);
    --toast: #3a3a3c;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); }
h1 { font-size: 18px; margin: 0 0 12px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
code { font-family: ui-monospace, Consolas, monospace; }

button, .button {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
button:hover:not(:disabled), .button:hover { border-color: var(--line-hover); }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.primary:hover { filter: brightness(1.08); }
.back-link { display: block; margin-bottom: 8px; color: var(--muted); text-decoration: none; }
.back-link:hover { color: var(--accent); }
.link-button { border: none; background: none; padding: 0 4px; color: var(--accent); text-decoration: underline; }

input[type="url"], input[type="text"], input[type="number"] {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

/* The app fills the window; panels and the queue scroll internally instead of the page.
   Below min-height the page itself scrolls. */
.app { display: grid; grid-template-columns: 240px 1fr; height: 100vh; min-height: 560px; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.queue { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.queue-list { list-style: none; margin: 0; padding: 0; flex: 1; min-height: 0; overflow-y: auto; }
.sidebar-actions { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.placeholder { color: var(--muted); font-style: italic; }

.workspace {
  position: relative; padding: 14px 20px; min-width: 900px; min-height: 0;
  display: flex; flex-direction: column;
}

.loadbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.url-form { display: flex; gap: 6px; }
.url-form input { width: 320px; }
.hint { color: var(--muted); }

.load-status { margin: 0; flex: 1 1 240px; }
.load-status[data-kind="error"] { color: var(--error); }
.load-status[data-kind="ok"] { color: var(--ok); }
.pending-link { margin: 6px 0 0; color: var(--muted); }
.pending-link [data-url] {
  display: inline-block; max-width: 420px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; vertical-align: bottom; color: var(--ink);
}

.panels { flex: 1; min-height: 0; display: flex; gap: 16px; margin-top: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; min-height: 0; }
.source-panel { flex: 0 1 440px; min-width: 300px; display: flex; flex-direction: column; }
.preview-panel { flex: 1; min-width: 360px; overflow: auto; }
.h2-note { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 8px; }

/* The frame takes whatever height is left; sourcePanel.js fits the image into it. */
.source-frame {
  flex: 1 1 0;
  min-height: 120px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--checker);
  border-radius: 4px;
  padding: 8px;
}
.source-canvas { display: block; }
.source-frame.is-picking .source-canvas { cursor: crosshair; }
.source-info { color: var(--muted); margin: 6px 0; font-size: 12px; overflow-wrap: anywhere; }

.readout { display: flex; gap: 10px; align-items: center; }
.readout-text { flex: 1; min-width: 0; }
.loupe {
  width: 77px; height: 77px;
  image-rendering: pixelated;
  border: 1px solid var(--line);
  background: var(--checker);
  flex: none;
}
.readout-color { display: flex; align-items: center; gap: 8px; font-size: 18px; }
.swatch { width: 28px; height: 28px; border-radius: 4px; border: 1px solid rgba(0,0,0,.2); display: inline-block; }
.readout-detail { color: var(--muted); font-size: 12px; margin-top: 4px; }
.readout.is-empty .swatch { background: var(--checker) !important; }
/* No color needed right now: hide the readout but keep its space so the image doesn't move. */
.readout.is-inactive { visibility: hidden; }

.muted { color: var(--muted); }
.placeholder-box {
  border: 1px dashed var(--line); border-radius: 6px; padding: 40px; text-align: center; color: var(--muted);
}

.segmented { border: none; padding: 0; margin: 0; display: flex; }
.segmented legend { font-size: 12px; color: var(--muted); padding: 0; margin-bottom: 4px; }
.segmented label {
  border: 1px solid var(--line); padding: 5px 12px; cursor: pointer; background: var(--panel);
  margin-left: -1px; user-select: none;
}
.segmented label:first-of-type { border-radius: 6px 0 0 6px; margin-left: 0; }
.segmented label:last-of-type { border-radius: 0 6px 6px 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.segmented-sm label { padding: 3px 8px; font-size: 12px; }
.sample-size { align-self: flex-start; flex: none; }

.scaled-info { margin: 8px 0; }
.preview-stage {
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 8px;
  background: var(--checker);
  border-radius: 4px;
  overflow: auto;
}
.preview-canvas { display: block; image-rendering: pixelated; }
/* 1× zoom: shrink (keeping aspect ratio) so the step's controls and preview fit the window.
   The 300px roughly covers the load bar, panel heading, controls and buttons around the
   preview. 2× keeps its size and scrolls. */
.preview-canvas.fit { width: auto; height: auto; max-width: 100%; max-height: max(220px, calc(100vh - 300px)); }
.preview-figure { margin: 0; min-width: 0; flex: 0 1 auto; }

/* Step 1: preview left, options stacked on the right. */
.preview-layout { display: flex; gap: 16px; align-items: flex-start; margin-top: 8px; }
.side-controls { flex: none; display: flex; flex-direction: column; gap: 12px; }
.side-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.crop-controls { display: flex; gap: 6px; align-items: center; }
.crop-controls button { padding: 4px 10px; }
.side-field .key-hint { display: block; margin: 6px 0 0; }

.control-row { display: flex; align-items: center; gap: 6px; margin: 6px 0; flex-wrap: wrap; }
.control-label { min-width: 170px; }
.offset-input { width: 72px; text-align: right; }
.control-row button { padding: 4px 10px; }

.color-field { display: inline-flex; align-items: center; gap: 8px; }
.hex-input { width: 90px; font-family: ui-monospace, Consolas, monospace; }
.hex-input.is-invalid { border-color: var(--error); outline-color: var(--error); background: var(--invalid-bg); }
.swatch-sm { width: 14px; height: 14px; border-radius: 3px; vertical-align: middle; }

figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
.step-actions { display: flex; gap: 8px; margin-top: 12px; }
.checkbox { display: inline-flex; align-items: center; gap: 6px; margin-left: 16px; color: var(--muted); user-select: none; }
.label-figure { margin: 8px 0 0; }
.name-input { width: 300px; }

.editing-banner {
  background: var(--highlight); border: 1px solid var(--highlight-line); border-radius: 6px;
  padding: 6px 12px; margin-top: 8px;
}

.queue-item {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 8px; align-items: center;
  padding: 6px; border-radius: 6px; margin: 0 0 4px;
}
.queue-item:hover { background: var(--bg); }
.queue-item.is-editing { background: var(--highlight); outline: 1px solid var(--highlight-line); }
.queue-thumb { width: 64px; height: auto; display: block; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0,0,0,.1); }
.queue-text { min-width: 0; }
.queue-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-meta { font-size: 11px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.more-button { padding: 2px 8px; line-height: 1; font-weight: 700; }

.menu {
  position: fixed; z-index: 20; min-width: 190px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15); padding: 4px; display: flex; flex-direction: column;
}
.menu button { border: none; border-radius: 4px; text-align: left; padding: 6px 10px; justify-content: flex-start; }
.menu button:hover, .menu button:focus-visible { background: var(--bg); outline: none; }
.menu .danger { color: var(--error); }
.menu hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; }

.drop-overlay {
  display: none;
  position: absolute; inset: 8px;
  border: 3px dashed var(--accent); border-radius: 12px;
  background: var(--accent-tint);
  align-items: center; justify-content: center;
  font-size: 22px; color: var(--accent);
  pointer-events: none;
}
.workspace.is-dragging .drop-overlay { display: flex; }

.toast-host { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 10; }
.toast {
  background: var(--toast); color: #fff; padding: 8px 14px; border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,.2); transition: opacity .25s, transform .25s;
}
.toast-error { background: var(--error); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); }

.small { font-size: 12px; }

.export-dialog {
  border: none; border-radius: 10px; padding: 0;
  background: var(--panel); color: var(--ink);
  width: min(1200px, 94vw); max-height: 92vh;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.export-dialog::backdrop { background: rgba(0,0,0,.4); }
.export-form { display: flex; flex-direction: column; max-height: 92vh; }
.dialog-header, .dialog-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.dialog-header h2 { margin: 0; color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 16px; }
.dialog-footer { border-bottom: none; border-top: 1px solid var(--line); justify-content: flex-end; }
.export-body { display: grid; grid-template-columns: 360px 1fr; gap: 20px; padding: 16px 20px; overflow: auto; min-height: 0; }
.export-options .control-label { min-width: 150px; }
.export-options input[type="number"] { width: 72px; }
.export-options .segmented { flex-wrap: wrap; margin: 8px 0 12px; }
.copies-table { border-collapse: collapse; width: 100%; }
.copies-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 4px; }
.copies-table td { padding: 4px; border-top: 1px solid var(--line); vertical-align: middle; }
.copies-thumb { width: 56px; display: block; }
.copies-input { width: 64px; }
.export-summary { font-weight: 600; }
.export-pages { display: flex; flex-wrap: wrap; gap: 16px; align-content: flex-start; background: var(--bg); padding: 16px; border-radius: 6px; }
.page-preview { margin: 0; }
.page-preview canvas { display: block; box-shadow: 0 2px 8px rgba(0,0,0,.15); }

kbd {
  font: 11px ui-monospace, Consolas, monospace;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px;
  padding: 0 4px; margin: 0 1px; background: var(--panel);
}
.key-hint { align-self: center; margin-left: 8px; }
