/* ============================================================
   MOSABRICK
   Editorial-industrial. Cream paper, ink, signal red.
   ============================================================ */

:root {
  --paper:        #efe7d8;
  --paper-deep:   #e6dcc9;
  --paper-edge:   #d6cab2;
  --ink:          #1a1714;
  --ink-soft:     #4a423a;
  --muted:        #8a8175;
  --rule:         #2b2420;
  --accent:       #c9301c;     /* signal red */
  --accent-deep:  #952111;
  --hi:           #f7f1e3;
  --shadow:       rgba(26, 23, 20, 0.08);
  --shadow-deep:  rgba(26, 23, 20, 0.18);

  --serif:    'Instrument Serif', 'Newsreader', Georgia, serif;
  --serif-2:  'Newsreader', Georgia, serif;
  --mono:     'JetBrains Mono', ui-monospace, monospace;

  --r-sm: 2px;
  --r-md: 4px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

html {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,0.5), transparent 40%),
    radial-gradient(circle at 90% 90%, rgba(214,202,178,0.4), transparent 50%),
    var(--paper);
  display: flex;
  flex-direction: column;
}

/* Fine paper grain via SVG turbulence */
.grain {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.35;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.10  0 0 0 0 0.09  0 0 0 0 0.08  0 0 0 0.18 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* ============================================================
   HEADER
   ============================================================ */
.site-header {
  padding: 36px 56px 28px;
  border-bottom: 1px solid var(--rule);
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 56px;
  align-items: end;
}

.site-header::before {
  content: '';
  position: absolute;
  left: 56px; right: 56px;
  bottom: -4px;
  height: 1px;
  background: var(--rule);
}

.brand {
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand-mark {
  width: 56px; height: 56px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 3px;
  padding: 4px;
  background: var(--ink);
  border-radius: var(--r-sm);
  position: relative;
}
.brand-mark span {
  background: var(--paper);
  border-radius: 999px;
  position: relative;
}
/* spell out an "M" with the accent */
.brand-mark span:nth-child(1),
.brand-mark span:nth-child(4),
.brand-mark span:nth-child(5),
.brand-mark span:nth-child(6),
.brand-mark span:nth-child(7),
.brand-mark span:nth-child(8),
.brand-mark span:nth-child(9),
.brand-mark span:nth-child(12),
.brand-mark span:nth-child(13),
.brand-mark span:nth-child(16) {
  background: var(--accent);
}

.brand-text h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 44px;
  line-height: 0.95;
  margin: 0;
  letter-spacing: -0.01em;
}
.brand-text h1 em {
  font-style: italic;
  color: var(--accent);
}

.brand-meta {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 6px 0 0;
}

.tagline {
  font-family: var(--serif-2);
  font-size: 16px;
  line-height: 1.5;
  margin: 0;
  color: var(--ink-soft);
  text-align: right;
  max-width: 460px;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 18px;
}
.tagline-rule {
  height: 1px;
  background: var(--rule);
  flex: 1;
  display: block;
}

/* ============================================================
   STAGE — UPLOAD
   ============================================================ */
main { flex: 1; }

.stage {
  padding: 56px;
  position: relative;
}

.stage-upload {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 56px;
  min-height: calc(100vh - 220px);
}

/* Dropzone -------------------------------------------------- */
.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
}

.dropzone-frame {
  flex: 1;
  position: relative;
  background:
    linear-gradient(var(--paper-deep), var(--paper-deep)),
    radial-gradient(circle at center, var(--paper) 1.5px, transparent 2px) 0 0 / 22px 22px;
  background-blend-mode: multiply;
  border: 1px solid var(--rule);
  cursor: pointer;
  overflow: hidden;
  transition: background 180ms ease, transform 180ms ease;
  min-height: 480px;
}

.dropzone-frame::before {
  content: '';
  position: absolute; inset: 6px;
  border: 1px dashed rgba(26,23,20,0.35);
  pointer-events: none;
  transition: border-color 180ms ease;
}

.dropzone.dragover .dropzone-frame {
  background:
    linear-gradient(rgba(201,48,28,0.08), rgba(201,48,28,0.08)),
    var(--paper-deep);
}
.dropzone.dragover .dropzone-frame::before {
  border-color: var(--accent);
}

.corner {
  position: absolute;
  width: 14px; height: 14px;
  border: 1px solid var(--ink);
  z-index: 2;
}
.corner.tl { top: 12px; left: 12px; border-right: 0; border-bottom: 0; }
.corner.tr { top: 12px; right: 12px; border-left: 0; border-bottom: 0; }
.corner.bl { bottom: 12px; left: 12px; border-right: 0; border-top: 0; }
.corner.br { bottom: 12px; right: 12px; border-left: 0; border-top: 0; }

.dropzone-inner {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 40px;
  text-align: center;
}

.stud-grid {
  width: 220px;
  height: 220px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin-bottom: 36px;
  transform: rotate(-3deg);
}
.stud-grid::before {
  content: '';
  display: block;
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  background:
    radial-gradient(circle at 50% 30%, var(--accent) 0 6px, transparent 7px) 0 0 / 28px 28px,
    radial-gradient(circle at 50% 50%, var(--ink) 0 8px, transparent 9px) 0 0 / 28px 28px;
  opacity: 0.85;
}

.dropzone-copy { max-width: 460px; }

.kicker {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 14px;
}

.dropzone-copy h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 56px;
  line-height: 0.95;
  margin: 0 0 22px;
  letter-spacing: -0.015em;
}
.dropzone-copy h2 em {
  font-style: italic;
  color: var(--accent);
}

.dropzone-sub {
  font-family: var(--serif-2);
  font-size: 15px;
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.6;
}

.dropzone-formats {
  display: inline-block;
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.link {
  background: none;
  border: none;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  border-bottom: 1px solid currentColor;
  font-style: italic;
  font-family: var(--serif-2);
}
.link:hover { color: var(--accent-deep); }

.dropzone-error {
  margin: 12px 0 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  min-height: 16px;
}

/* Side --------------------------------------------------- */
.upload-side {
  display: flex;
  flex-direction: column;
  gap: 36px;
}

.side-block {
  border-top: 1px solid var(--rule);
  padding-top: 22px;
}

.process-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.process-list li {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 12px;
  align-items: baseline;
  font-family: var(--serif-2);
  font-size: 15px;
  color: var(--ink-soft);
  padding-bottom: 14px;
  border-bottom: 1px solid var(--paper-edge);
}
.process-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.process-list .num {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--accent);
}

.palette-strip {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 3px;
  margin-bottom: 12px;
}
.palette-strip .swatch {
  aspect-ratio: 1;
  border-radius: 999px;
  border: 1px solid rgba(26,23,20,0.18);
  position: relative;
}

.side-note {
  font-family: var(--serif-2);
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
  margin: 0;
}

/* ============================================================
   STAGE — WORKSPACE
   ============================================================ */
.stage-workspace { padding-top: 32px; }

.workspace-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 28px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--rule);
}
.workspace-head .kicker { margin: 0; }
.link-back { font-family: var(--mono); font-size: 11px; font-style: normal; }

.workspace {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 48px;
  align-items: start;
}

/* Controls -------------------------------------------------- */
.controls {
  display: flex;
  flex-direction: column;
  gap: 32px;
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding-right: 12px;
  margin-right: -12px;
}

/* Custom thin scrollbar for sticky controls */
.controls::-webkit-scrollbar { width: 6px; }
.controls::-webkit-scrollbar-track { background: transparent; }
.controls::-webkit-scrollbar-thumb {
  background: var(--paper-edge);
  border-radius: 999px;
}
.controls::-webkit-scrollbar-thumb:hover { background: var(--muted); }

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
}
.panel-head .kicker { margin: 0; }
.panel-head .panel-action {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-style: normal;
}
.panel-head .panel-meta {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
}

.control {
  display: flex;
  flex-direction: column;
}
.control.mini { gap: 4px; }

.control-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}
.control-head label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
}
.control-value {
  font-family: var(--serif);
  font-style: italic;
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
}
.control-value.sm {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.control-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.1em;
}

.control-note {
  font-family: var(--serif-2);
  font-style: italic;
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}

.auto-note { margin-top: -4px; }
.auto-status {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 12px 14px;
  background: var(--paper-edge);
  border-left: 2px solid var(--accent);
  animation: auto-status-in 320ms ease;
}
.auto-status .auto-headline {
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  color: var(--accent);
  line-height: 1.1;
}
.auto-status .auto-row {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
  line-height: 1.5;
}
.auto-status strong {
  color: var(--ink);
  font-weight: 500;
}
@keyframes auto-status-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Range slider — custom */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 1px;
  background: var(--rule);
}
input[type="range"]::-moz-range-track {
  height: 1px;
  background: var(--rule);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px; height: 14px;
  border-radius: 999px;
  background: var(--accent);
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 1px var(--accent);
  margin-top: -7px;
  transition: transform 120ms ease;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 999px;
  background: var(--accent);
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.15); }

/* Select */
.select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--hi);
  border: 1px solid var(--ink);
  padding: 10px 32px 10px 12px;
  cursor: pointer;
  border-radius: 0;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink) 50%),
    linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) center,
    calc(100% - 9px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  transition: background-color 140ms ease;
}
.select:hover { background-color: var(--paper); }
.select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Crop preview */
.crop-preview {
  border: 1px solid var(--rule);
  overflow: hidden;
  background: #111;
  user-select: none;
}
.crop-preview canvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: grab;
}
.crop-preview canvas.dragging { cursor: grabbing; }

.crop-hint {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  background: var(--ink);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.crop-hint .link {
  color: var(--paper-edge);
  border-color: var(--paper-edge);
  font-style: normal;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.crop-hint .link:hover { color: var(--paper); border-color: var(--paper); }

/* Presets */
.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.chip {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 6px 10px;
  border: 1px solid var(--ink);
  background: var(--hi);
  color: var(--ink);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.chip:hover { background: var(--ink); color: var(--paper); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--paper); }

/* Palette grid (toggleable) */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}
.palette-grid .pchip {
  position: relative;
  aspect-ratio: 1;
  border-radius: 999px;
  border: 1px solid rgba(26,23,20,0.25);
  cursor: pointer;
  padding: 0;
  background: transparent;
  transition: transform 120ms ease, box-shadow 140ms ease;
}
.palette-grid .pchip:hover {
  transform: scale(1.12);
  z-index: 2;
}
.palette-grid .pchip.disabled {
  opacity: 0.25;
  filter: grayscale(0.6);
}
.palette-grid .pchip.disabled::after {
  content: '';
  position: absolute;
  left: 10%; right: 10%;
  top: 50%;
  height: 1px;
  background: var(--ink);
  transform: rotate(-45deg);
  transform-origin: center;
}
.palette-grid .pchip.brush {
  box-shadow:
    0 0 0 2px var(--paper),
    0 0 0 3px var(--accent);
  transform: scale(1.18);
}
.palette-grid .pchip.unavailable {
  opacity: 0.18;
  filter: grayscale(0.85);
  cursor: not-allowed;
}
.palette-grid .pchip.unavailable::after {
  content: '';
  position: absolute;
  inset: 25%;
  border: 1px dashed var(--ink);
  border-radius: 50%;
  background: transparent;
  transform: none;
  height: auto;
  left: 25%;
  right: 25%;
  top: 25%;
}

/* Toggles */
.toggles { display: flex; flex-direction: column; gap: 14px; }

.toggle {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 12px;
  align-items: start;
  cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }

.toggle-mark {
  width: 22px; height: 22px;
  border: 1px solid var(--ink);
  border-radius: var(--r-sm);
  background: var(--hi);
  position: relative;
  transition: background 140ms ease;
  margin-top: 2px;
}
.toggle input:checked + .toggle-mark {
  background: var(--accent);
}
.toggle input:checked + .toggle-mark::after {
  content: '';
  position: absolute;
  left: 6px; top: 2px;
  width: 6px; height: 12px;
  border-right: 2px solid var(--paper);
  border-bottom: 2px solid var(--paper);
  transform: rotate(45deg);
}

.toggle-text strong {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--ink);
}
.toggle-text em {
  display: block;
  margin-top: 2px;
  font-family: var(--serif-2);
  font-style: italic;
  font-size: 12px;
  color: var(--muted);
}

/* Buttons */
.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.btn {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 14px 18px;
  border: 1px solid var(--ink);
  background: var(--hi);
  color: var(--ink);
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, transform 80ms ease;
  text-align: left;
  position: relative;
}
.btn::after {
  content: '→';
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  transition: transform 140ms ease;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn:hover::after { transform: translateY(-50%) translateX(3px); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--paper);
}
.btn-primary:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  color: var(--paper);
}

.source-preview {
  margin-top: 8px;
  border-top: 1px solid var(--rule);
  padding-top: 14px;
}
.source-preview summary {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  color: var(--ink);
}
.source-preview summary::-webkit-details-marker { display: none; }
.source-preview summary::after { content: '+'; font-family: var(--mono); }
.source-preview[open] summary::after { content: '−'; }
.source-image {
  margin-top: 12px;
  border: 1px solid var(--rule);
  background: var(--hi);
  overflow: hidden;
}
.source-image img {
  display: block;
  width: 100%;
  height: auto;
}

/* Output -------------------------------------------------- */
.output {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* Canvas toolbar — brush indicator + edit actions */
.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  border: 1px solid var(--rule);
  background: var(--hi);
}

.brush-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
  flex: 1;
  min-width: 0;
}
.brush-indicator[data-empty="true"] .brush-swatch {
  background: repeating-linear-gradient(
    45deg,
    var(--paper-edge),
    var(--paper-edge) 3px,
    var(--hi) 3px,
    var(--hi) 6px
  );
  border-color: var(--paper-edge);
}
.brush-indicator[data-empty="true"] .brush-clear { display: none; }
.brush-indicator[data-empty="true"] .brush-text { color: var(--muted); }

.brush-swatch {
  width: 22px; height: 22px;
  border-radius: 999px;
  border: 1px solid rgba(26,23,20,0.3);
  flex-shrink: 0;
  transition: background 120ms ease;
}
.brush-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brush-clear {
  background: none;
  border: none;
  font-family: var(--mono);
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 999px;
}
.brush-clear:hover { color: var(--accent); background: var(--paper-deep); }

.toolbar-actions {
  display: flex;
  gap: 6px;
}
.ghost-btn {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 6px 12px;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.ghost-btn:hover:not(:disabled) {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}
.ghost-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Cursor on canvas reflects edit state */
#mosaicCanvas { cursor: default; }
.editing #mosaicCanvas { cursor: crosshair; }

.mosaic-frame {
  margin: 0;
  background: var(--hi);
  border: 1px solid var(--ink);
  padding: 28px;
  position: relative;
  box-shadow:
    0 1px 0 var(--paper-edge),
    0 24px 48px -16px var(--shadow-deep),
    0 8px 16px -8px var(--shadow);
}

.frame-tag {
  position: absolute;
  top: -1px; left: 28px;
  transform: translateY(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 5px 12px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 10px;
}
.frame-dot {
  width: 4px; height: 4px;
  border-radius: 999px;
  background: var(--accent);
  display: inline-block;
}

.frame-canvas-wrap {
  background: var(--paper-deep);
  border: 1px solid var(--paper-edge);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
}
#mosaicCanvas {
  display: block;
  max-width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.mosaic-frame figcaption {
  margin-top: 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.caption-rule {
  flex: 1;
  height: 1px;
  background: var(--rule);
}

/* Parts list */
.parts-head { margin-bottom: 22px; }
.parts-head h3 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 36px;
  line-height: 1;
  margin: 0;
  letter-spacing: -0.01em;
}
.parts-head h3 em { font-style: italic; color: var(--accent); }

.parts-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0 24px;
  border-top: 1px solid var(--rule);
}

.parts-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px 12px 0;
  border-bottom: 1px solid var(--paper-edge);
}

.parts-list .piece-select,
.parts-list .piece-static {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: none;
  white-space: nowrap;
}
.parts-list .piece-select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 1px solid var(--paper-edge);
  border-radius: var(--r-sm);
  padding: 3px 18px 3px 6px;
  cursor: pointer;
  color: var(--ink);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 9px) 50%,
    calc(100% - 5px) 50%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  transition: border-color 120ms ease, color 120ms ease;
}
.parts-list .piece-select:hover { border-color: var(--accent); color: var(--accent-deep); }
.parts-list .piece-select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.parts-list .buy-link {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  padding-bottom: 1px;
  white-space: nowrap;
  transition: color 120ms ease;
}
.parts-list .buy-link:hover { color: var(--accent-deep); }

.parts-sub {
  font-family: var(--serif-2);
  font-style: italic;
  font-size: 13px;
  color: var(--muted);
  margin: 8px 0 0;
}
.parts-sub .link { font-size: inherit; }

.parts-list .swatch {
  width: 22px; height: 22px;
  border-radius: var(--r-sm);
  border: 1px solid rgba(26,23,20,0.25);
  position: relative;
  overflow: hidden;
}
.parts-list .swatch::after {
  content: '';
  position: absolute;
  top: 25%; left: 50%;
  transform: translateX(-50%);
  width: 8px; height: 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.18);
  box-shadow: inset 0 -1px 0 rgba(0,0,0,0.15);
}

.parts-list .name {
  font-family: var(--serif-2);
  font-size: 14px;
  color: var(--ink);
}
.parts-list .pct {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.08em;
  margin-top: 1px;
}
.parts-list .count {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   FOOTER
   ============================================================ */
.site-footer {
  margin-top: 80px;
  padding: 24px 56px;
  border-top: 1px solid var(--rule);
  display: flex;
  align-items: center;
  gap: 18px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.footer-rule {
  flex: 1;
  height: 1px;
  background: var(--rule);
  display: block;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 960px) {
  .site-header,
  .stage,
  .site-footer { padding-left: 24px; padding-right: 24px; }

  .site-header {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .tagline { text-align: left; justify-self: start; max-width: none; }
  .tagline-rule { display: none; }

  .stage-upload,
  .workspace {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  .controls { position: static; }

  .brand-text h1 { font-size: 36px; }
  .dropzone-copy h2 { font-size: 40px; }
  .parts-head h3 { font-size: 28px; }
}

/* ============================================================
   PAGE LOAD ANIMATION
   ============================================================ */
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.site-header,
.stage-upload > * {
  animation: rise 600ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.stage-upload > *:nth-child(2) { animation-delay: 120ms; }

/* ============================================================
   AD SLOT — upload stage only
   ============================================================ */
.ad-slot {
  padding: 18px 56px 0;
  display: flex;
  justify-content: center;
}
.ad-slot ins { min-height: 90px; width: 100%; max-width: 970px; }
.ad-slot[hidden] { display: none; }

@media (max-width: 960px) {
  .ad-slot { padding: 14px 24px 0; }
}

/* ============================================================
   FOOTER — support link
   ============================================================ */
.footer-support {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  padding-bottom: 1px;
  transition: color 120ms ease;
}
.footer-support:hover { color: var(--accent-deep); }

/* ============================================================
   SUPPORT MODAL — pay-what-you-like gate on premium downloads
   ============================================================ */
.modal {
  position: fixed; inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(26, 23, 20, 0.55);
  backdrop-filter: blur(2px);
  cursor: pointer;
  animation: rise 220ms ease both;
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: var(--hi);
  border: 1px solid var(--ink);
  padding: 28px 28px 24px;
  box-shadow:
    0 24px 56px -16px var(--shadow-deep),
    0 8px 16px -8px var(--shadow);
  animation: rise 280ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.modal-head .kicker { margin: 0; }

.modal-close {
  background: none;
  border: none;
  font-family: var(--mono);
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.modal-close:hover { color: var(--accent); }

.modal-panel h3 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 32px;
  line-height: 1;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}
.modal-panel h3 em { font-style: italic; color: var(--accent); }

.modal-lede {
  font-family: var(--serif-2);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-soft);
  margin: 0 0 22px;
}

.support-amounts {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 14px;
}
@media (max-width: 480px) {
  .support-amounts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.amount-chip {
  appearance: none;
  background: var(--paper);
  border: 1px solid var(--rule);
  cursor: pointer;
  padding: 10px 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-family: var(--mono);
  color: var(--ink);
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}
.amount-chip:hover { background: var(--paper-deep); }
.amount-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.amount-chip.is-selected {
  background: var(--ink);
  color: var(--hi);
  border-color: var(--ink);
}
.amount-chip .amount-label {
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.amount-chip.is-selected .amount-label { color: var(--paper-deep); }
.amount-chip .amount-val {
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.support-custom {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  padding: 0 2px;
}
.support-custom[hidden] { display: none; }
.support-currency {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--muted);
}
.support-custom input {
  flex: 1;
  font-family: var(--mono);
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  border-radius: 0;
  outline: none;
}
.support-custom input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-actions .btn {
  text-decoration: none;
  display: block;
  width: 100%;
  text-align: center;
  padding: 14px 20px;
}
/* The global .btn style appends a → arrow; in the modal we want a
   clean centred CTA, so suppress it here. */
.modal-actions .btn::after { content: none; }

.modal-note {
  margin: 14px 0 0;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--muted);
  line-height: 1.5;
}

