/* ---------- Tokens ---------------------------------------------------- */

:root {
  --paper:      #efece3;
  --paper-lift: #faf9f4;
  --ink:        #17181d;
  --ink-soft:   #5c5f68;
  --line:       #d7d2c3;
  --line-soft:  #e3dfd2;
  --toner:      #2b49f0;
  --toner-deep: #1731b8;
  --verify:     #1f8a5f;
  --alert:      #c4501b;

  --font-display: "IBM Plex Mono", "Roboto Mono", ui-monospace, Menlo, monospace;
  --font-body:    "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono:    "IBM Plex Mono", "Roboto Mono", ui-monospace, Menlo, monospace;

  --radius-sm: 3px;
  --radius-md: 6px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

html {
  background: var(--paper);
}

body {
  margin: 0;
  background: var(--paper);
  background-image:
    radial-gradient(var(--line-soft) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--font-body);
  min-height: 100vh;
}

::selection { background: var(--toner); color: #fff; }

:focus-visible {
  outline: 2px solid var(--toner);
  outline-offset: 2px;
}

/* ---------- Shell ------------------------------------------------------- */

.sheet {
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 24px 72px;
}

/* ---------- Masthead ----------------------------------------------------- */

.masthead {
  position: relative;
  padding: 4px 0 26px 0;
  margin-bottom: 36px;
  border-bottom: 1px solid var(--ink);
}

.masthead__mark {
  position: absolute;
  top: 6px;
  right: 0;
  display: grid;
  grid-template-columns: repeat(4, 5px);
  gap: 4px;
}

.masthead__mark span {
  width: 5px;
  height: 5px;
  background: var(--ink);
}
.masthead__mark span:nth-child(2) { background: var(--toner); }
.masthead__mark span:nth-child(3) { background: transparent; border: 1px solid var(--ink); }

.masthead__title {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(26px, 3.4vw, 36px);
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: var(--ink);
}

.masthead__subtitle {
  margin: 0;
  max-width: 56ch;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink-soft);
}

/* ---------- Workbench layout --------------------------------------------- */

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 660px) 1fr;
  gap: 28px;
  align-items: start;
}

@media (max-width: 1180px) {
  .workbench { grid-template-columns: 1fr; }
}

/* ---------- Control rail -------------------------------------------------- */

.rail {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.field-group,
.tab-panel {
  background: var(--paper-lift);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  margin: 0;
  padding: 18px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.field-group legend {
  padding: 0 2px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
}

/* Tabs — switch which settings panel is showing, instead of stacking every
   category at once. Underline style keeps them quiet next to the mono/production
   look elsewhere (spec-strip, reg-marks) rather than reaching for pill buttons. */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
}

.tab {
  flex: 1;
  padding: 10px 4px 11px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}

.tab:hover { color: var(--ink); }

.tab.is-active {
  color: var(--toner-deep);
  border-bottom-color: var(--toner);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  min-width: 0;
}

.field-row--indent {
  padding-left: 12px;
  border-left: 2px solid var(--line);
  margin-left: 2px;
}

.field-row:has(.btn) {
  display: flex;
  gap: 10px;
}
.field-row .btn { flex: 1; }

label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}

/* ---------- Theme presets (one-click soft color+gradient combos) ----------- */

.theme-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.theme-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 5px;
  background: var(--paper-lift);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.theme-chip:hover {
  border-color: var(--ink-soft);
  background: #fff;
}

.theme-chip__swatch {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.theme-chip__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
}

/* ---------- Style pickers (module/eye shape galleries) --------------------- */

.style-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 5px;
  min-width: 0;
}

.style-grid--eye {
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
}

.style-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 3px 5px;
  background: var(--paper-lift);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.style-swatch:hover {
  border-color: var(--ink-soft);
}

.style-swatch.is-active {
  border-color: var(--toner);
  background: #eef0fe;
}

.style-swatch canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  display: block;
}

.style-swatch__label {
  font-size: 8.5px;
  line-height: 1.2;
  color: var(--ink-soft);
  text-align: center;
}

.style-swatch.is-active .style-swatch__label {
  color: var(--toner-deep);
}

label output {
  font-family: var(--font-mono);
  color: var(--ink);
  font-weight: 600;
}

/* ---------- Inputs --------------------------------------------------------- */

textarea,
select,
input[type="file"] {
  font: inherit;
  font-size: 14px;
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  resize: vertical;
  font-family: var(--font-body);
}

textarea { font-family: var(--font-mono); font-size: 13px; line-height: 1.5; }

textarea:focus,
select:focus {
  outline: 2px solid var(--toner);
  outline-offset: 1px;
  border-color: var(--toner);
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
                     linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: calc(100% - 16px) center, calc(100% - 11px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}

input[type="file"] {
  font-size: 12.5px;
  padding: 8px;
}

/* File picker — hides the native input behind a styled button */

.file-picker {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.file-picker__input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.file-picker__btn {
  flex: 0 0 auto;
  margin: 0;
}

.file-picker__input:focus-visible + .file-picker__btn {
  outline: 2px solid var(--toner);
  outline-offset: 2px;
}

.file-picker__name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* Range sliders — instrument-dial styling */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: var(--line);
}
input[type="range"]::-moz-range-track {
  height: 3px;
  background: var(--line);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5.5px;
  background: var(--toner);
  border: 2px solid var(--paper-lift);
  box-shadow: 0 0 0 1px var(--toner);
  border-radius: 2px;
}
input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: var(--toner);
  border: 2px solid var(--paper-lift);
  box-shadow: 0 0 0 1px var(--toner);
  border-radius: 2px;
}

input[type="color"] {
  width: 100%;
  height: 34px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
}

/* Checkboxes — small square toggles */

.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
}

.checkbox input {
  appearance: none;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  border: 1.5px solid var(--ink-soft);
  border-radius: 2px;
  background: #fff;
  display: grid;
  place-content: center;
  cursor: pointer;
}

.checkbox input::before {
  content: "";
  width: 8px;
  height: 8px;
  transform: scale(0);
  background: var(--toner);
  transition: transform 0.1s ease;
}

.checkbox input:checked {
  border-color: var(--toner);
}
.checkbox input:checked::before {
  transform: scale(1);
}

.hint {
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink-soft);
  margin: 0;
}

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

.btn {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
}

.btn:active { transform: translateY(1px); }

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

.btn--stamp {
  width: 100%;
  padding: 14px 16px;
  font-size: 13px;
  position: relative;
}
.btn--stamp::after {
  content: "↓ PNG";
  float: right;
  opacity: 0.6;
}

.btn--secondary {
  background: #fff;
  color: var(--toner-deep);
  border-color: var(--toner);
}
.btn--secondary:hover { background: #eef0fe; }
.btn--secondary.is-active {
  background: var(--toner);
  color: #fff;
}

.btn--ghost {
  background: transparent;
  color: var(--alert);
  border-color: var(--line);
}
.btn--ghost:hover { border-color: var(--alert); background: #fdf1ea; }

/* ---------- Proof / preview column -------------------------------------------- */

.proof {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 24px;
  min-width: 0;
}

.proof__card {
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 34px;
  display: flex;
  justify-content: center;
}

.reg-mark {
  position: absolute;
  width: 14px;
  height: 14px;
  pointer-events: none;
}
.reg-mark::before, .reg-mark::after {
  content: "";
  position: absolute;
  background: var(--ink-soft);
}
.reg-mark::before { width: 100%; height: 1px; top: 50%; left: 0; transform: translateY(-50%); }
.reg-mark::after { width: 1px; height: 100%; left: 50%; top: 0; transform: translateX(-50%); }

.reg-mark--tl { top: 10px; left: 10px; }
.reg-mark--tr { top: 10px; right: 10px; }
.reg-mark--bl { bottom: 10px; left: 10px; }
.reg-mark--br { bottom: 10px; right: 10px; }

.proof__stage {
  position: relative;
  line-height: 0;
  max-width: 100%;
}

#qr-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

#qr-canvas.editable { cursor: crosshair; }

/* While manual cell editing is on, the logo overlay must not intercept clicks —
   otherwise a click meant for a module ends up dragging/resizing the logo instead. */
.proof__stage.editing .logo-box {
  pointer-events: none;
  opacity: 0.35;
}

.logo-box {
  position: absolute;
  border: 1.5px dashed var(--toner);
  border-radius: 6px;
  cursor: move;
  background: rgba(43, 73, 240, 0.06);
}

.logo-box__handle {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--toner);
  border: 2px solid #fff;
  cursor: nwse-resize;
}

/* ---------- Spec strip (live readout) ------------------------------------------ */

.spec-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  background: var(--paper-lift);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 4px;
}

.spec-strip span {
  padding: 0 14px;
  border-right: 1px solid var(--line);
}
.spec-strip span:last-child { border-right: none; }

.proof__note {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--alert);
  min-height: 14px;
  margin: 0;
  line-height: 1.5;
}
.proof__note:not(:empty)::before {
  content: "! ";
}
