:root {
  --ink: #000000;
  --paper: #f4f3ef;
  --panel: #ffffff;
  --line: #dcdad3;
  --accent: #000000;
  --accent-contrast: #ffffff;
  --mono: "SF Mono", "Roboto Mono", Consolas, monospace;
  --face: "Satoshi", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --tracking: 0.015em; /* +15 */
  --w: 500; /* every text, uniform weight */

  /* type scale: % of screen width */
  --fs-title: 4vw;     /* CRISP */
  --fs-heading: 1.6vw; /* section headings, sub */
  --fs-btn: 1vw;       /* buttons, controls */
  --fs-note: 0.8vw;    /* explanatory texts */

  --panel-w: 25vw;                              /* sidebar = 25% of screen width */
  --edge: calc(var(--panel-w) * 0.05);          /* 5% of sidebar width */
  --btn-w: calc(var(--panel-w) * 0.5 - var(--edge)); /* 50% of sidebar - edge padding */

  /* Native form controls (select, range, checkbox, color) should stay
     light-themed even when the OS/browser is set to dark mode — the rest
     of the UI is a fixed light design, and letting native chrome switch
     to dark independently (as Chrome/Safari do by default) looks broken
     and inconsistent. */
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--face);
  font-weight: var(--w);
  letter-spacing: var(--tracking);
  color: var(--ink);
  background: var(--paper);
}

.app {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.panel {
  width: var(--panel-w);
  flex: 0 0 var(--panel-w);
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: var(--edge);
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 100vh;
}

.panel-header h1 {
  font-size: var(--fs-title);
  font-weight: var(--w);
  text-transform: uppercase;
  line-height: 0.92;
  color: var(--ink);
  margin: 0 0 8px;
}

.panel-header .sub {
  font-size: var(--fs-heading);
  font-weight: var(--w);
  text-transform: none;
  line-height: 1.2;
  color: var(--ink);
  margin: 0 0 16px;
}

.panel-header .sub a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.panel-header .sub a:hover {
  opacity: 0.6;
}

.hidden {
  display: none;
}

.modeToggle {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 14px;
  padding-bottom: 14px;
}

.group {
  margin-bottom: 21px;
  padding-bottom: 18px;
}

.group.divider {
  border-bottom: 1px solid var(--line);
}

.group h2 {
  font-size: var(--fs-heading);
  font-weight: var(--w);
  text-transform: uppercase;
  color: var(--ink);
  margin: 0 0 10px;
}

.hint {
  font-size: var(--fs-note);
  font-weight: var(--w);
  text-transform: none;
  color: var(--ink);
  margin: -4px 0 10px;
  line-height: 1.5;
}

.field {
  display: block;
  margin-bottom: 11px;
}

.field:last-child {
  margin-bottom: 0;
}

.field span {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-btn);
  font-weight: var(--w);
  text-transform: uppercase;
  color: var(--ink);
  margin-bottom: 6px;
}

.field b {
  font-family: var(--mono);
  font-weight: var(--w);
  color: var(--ink);
}

select {
  width: 100%;
  font-family: var(--face);
  font-size: var(--fs-btn);
  font-weight: var(--w);
  letter-spacing: var(--tracking);
  text-transform: uppercase;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0.08em;
  cursor: pointer;
}

select:hover {
  border-color: var(--ink);
}

input[type="range"] {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--ink);
  cursor: pointer;
  border: 2px solid var(--panel);
  box-shadow: 0 0 0 1px var(--ink);
}

input[type="range"]::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--ink);
  cursor: pointer;
  border: 2px solid var(--panel);
  box-shadow: 0 0 0 1px var(--ink);
}

/* Firefox does not apply `background` on the plain <input type="range">
   to its native track the way Chrome/Safari do — without an explicit
   ::-moz-range-track rule it falls back to its own grey groove, ignoring
   our styling entirely and looking inconsistent with other browsers. */
input[type="range"]::-moz-range-track {
  width: 100%;
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  border: none;
}

/* ---------- Swatches ---------- */

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.swatch {
  position: relative;
  width: 22px;
  height: 22px;
}

.swatch input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 100%;
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 0;
  padding: 0;
  cursor: pointer;
  background: none;
}

.swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.swatch input[type="color"]::-webkit-color-swatch { border: none; }

.swatch .remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  border: none;
  font-size: 8px;
  line-height: 14px;
  text-align: center;
  padding: 0;
  cursor: pointer;
}

.bulkPaste {
  margin-top: 10px;
}

.bulkPaste summary {
  font-size: var(--fs-note);
  font-weight: var(--w);
  color: var(--ink);
  cursor: pointer;
  opacity: 0.7;
}

.bulkPaste summary:hover {
  opacity: 1;
}

.bulkPaste textarea {
  width: 100%;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: var(--fs-note);
  font-weight: var(--w);
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 6px;
  resize: vertical;
  box-sizing: border-box;
}

.bulkPaste textarea:focus {
  outline: none;
  border-color: var(--ink);
}

/* ---------- Buttons ---------- */

.btn {
  font-family: var(--face);
  font-size: var(--fs-btn);
  font-weight: var(--w);
  letter-spacing: var(--tracking);
  text-transform: uppercase;
  text-align: center;
  padding: 0.08em;
  border-radius: 0;
  border: 1px solid transparent;
  cursor: pointer;
  width: 100%;
}

/* buttons that sit two-in-a-row: 50% of the sidebar width minus the edge padding */
.preset-row .btn {
  width: var(--btn-w);
}

/* the mode switcher sits three-in-a-row: an even third of the sidebar's
   content width (panel width minus the edge padding on both sides) */
.modeToggle .btn {
  width: calc((var(--panel-w) - 2 * var(--edge)) / 3);
}

.btn-outline {
  background: var(--panel);
  border-color: var(--ink);
  color: var(--ink);
}

.btn-outline:hover {
  background: var(--ink);
  color: #fff;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  margin-bottom: 8px;
}

.btn-primary:hover {
  opacity: 0.85;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.preset-row .btn,
.modeToggle .btn {
  margin-left: -1px; /* collapse the touching borders instead of leaving a gap */
}

.preset-row .btn:first-child,
.modeToggle .btn:first-child {
  margin-left: 0;
}

.group.hidden {
  display: none;
}

.preset-row .btn.active,
.btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.shapePreviewWrap {
  position: relative;
  width: 42px;
  height: 42px;
  margin-top: 10px;
  border: 1px solid var(--line);
  background-image:
    linear-gradient(45deg, #eee 25%, transparent 25%),
    linear-gradient(-45deg, #eee 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eee 75%),
    linear-gradient(-45deg, transparent 75%, #eee 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
}

.shapePreviewWrap.hidden {
  display: none;
}

.shapePreview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 6px;
  box-sizing: border-box;
}

.shapePreviewWrap .remove {
  position: absolute;
  top: -6px;
  right: -6px;
}

.checkbox input:disabled + span {
  color: #b6b4ad;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-btn);
  font-weight: var(--w);
  text-transform: uppercase;
  color: var(--ink);
  cursor: pointer;
}

.checkbox input {
  width: 13px;
  height: 13px;
  accent-color: var(--accent);
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row input[type="color"] {
  width: 22px;
  height: 22px;
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 0;
  padding: 0;
  cursor: pointer;
}

.value {
  font-family: var(--mono);
  font-size: var(--fs-btn);
  font-weight: var(--w);
  color: var(--ink);
}

.actions {
  margin-top: 3px;
}

.footnote {
  font-size: var(--fs-note);
  font-weight: var(--w);
  text-transform: none;
  color: var(--ink);
  text-align: center;
  margin: 12px 0 0;
}

/* ---------- Stage ---------- */

.stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  overflow: auto;
}

.stage.interactive canvas {
  cursor: crosshair;
  touch-action: none;
}

.stage-hint {
  position: absolute;
  pointer-events: none;
  font-family: var(--face);
  font-size: var(--fs-note);
  font-weight: var(--w);
  letter-spacing: var(--tracking);
  text-transform: none;
  color: var(--ink);
  text-align: center;
  transition: opacity 0.4s ease;
}

.stage-hint.hidden {
  opacity: 0;
}

canvas {
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 20px 60px rgba(20, 22, 26, 0.18);
}

/* ---------- Site credit (bottom-right corner) ---------- */

.siteCredit {
  position: fixed;
  right: 10px;
  bottom: 8px;
  font-family: var(--face);
  font-size: 10px;
  font-weight: var(--w);
  letter-spacing: var(--tracking);
  color: var(--ink);
  opacity: 0.45;
  text-decoration: none;
  z-index: 10;
}

.siteCredit:hover {
  opacity: 0.85;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- Lead-capture modal (SVG export gate) ---------- */

.modalOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modalOverlay.hidden {
  display: none;
}

.modalBox {
  background: var(--panel);
  width: min(360px, 100%);
  padding: 24px;
  box-shadow: 0 24px 70px rgba(20, 22, 26, 0.35);
}

.modalBox h3 {
  font-size: var(--fs-heading);
  font-weight: var(--w);
  text-transform: uppercase;
  color: var(--ink);
  margin: 0 0 10px;
}

.modalBox .hint {
  margin: 0 0 16px;
}

.leadInput {
  width: 100%;
  font-family: var(--face);
  font-size: var(--fs-btn);
  font-weight: var(--w);
  letter-spacing: var(--tracking);
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0.6em 0.6em;
}

.leadInput:focus {
  outline: none;
  border-color: var(--ink);
}

.leadError {
  color: #c12026;
  text-align: left;
  margin: 8px 0 0;
}

.leadError.hidden {
  display: none;
}

@media (max-width: 900px) {
  /* Below this breakpoint the panel switches from a 25vw sidebar to a
     full-width block (see .panel below), but --fs-title/--fs-heading/
     --fs-btn/--fs-note and --edge/--btn-w are all defined as fractions of
     that original 25vw sidebar width. Left unchanged, they'd still be
     tiny fractions of the *full* viewport width, not of the now much
     wider panel — e.g. --fs-note (0.8vw) is a comfortable ~4px on a
     360px-wide sidebar (25vw of 1440px) but shrinks to an unreadable
     ~2.5px once that same 0.8vw is measured against a 320px-wide phone
     screen. clamp() keeps things readable at every width instead of a
     hard cliff at exactly 900px, and a fixed --edge plus percentage-based
     button widths replace the sidebar-relative formulas that no longer
     apply once the panel is full width.
     Keep MOBILE_BREAKPOINT in script.js (fitCanvasToStage) equal to this
     900px value — that constant re-derives the same row/column layout
     decision in JS and must always match this media query. */
  :root {
    --fs-title: clamp(24px, 7vw, 36px);
    --fs-heading: clamp(13px, 3.4vw, 18px);
    --fs-btn: clamp(11px, 2.8vw, 14px);
    --fs-note: clamp(10px, 2.4vw, 13px);
    --edge: 16px;
  }
  .app { flex-direction: column; }
  .panel { width: 100%; flex: none; max-height: none; border-right: none; border-bottom: 1px solid var(--line); }
  .stage { padding: 24px; }

  /* The desktop formulas above size these against --panel-w (a 25vw
     sidebar); on the full-width mobile panel, sizing them as a plain
     percentage of their own flex row is simpler and stays correct at
     any phone/tablet width. */
  .preset-row .btn { width: calc(50% - 1px); }
  .modeToggle .btn { width: calc(33.333% - 1px); }
}
