:root {
  --paper: #f8f1df;
  --panel: #fffdf8;
  --panel-2: #fbf3dd;
  --ink: #241d12;
  --ink-soft: #7a6f57;
  --line: #ece2c8;
  --line-strong: #ddceaa;
  --brand: #ffcf2e;      /* banana */
  --brand-deep: #e8a600; /* deeper yellow — highlights, borders */
  --accent: #ff5c39;     /* coral pop — the measured object */
  --accent-soft: rgba(255, 92, 57, 0.12);
  --shadow: 0 16px 34px rgba(120, 88, 18, 0.12);
  --shadow-sm: 0 6px 16px rgba(120, 88, 18, 0.10);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  background-color: var(--paper);
  background-image: radial-gradient(rgba(36, 29, 18, 0.05) 1.3px, transparent 1.3px);
  background-size: 22px 22px;
}

.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 40px 22px 56px;
}

/* Masthead */
.masthead { position: relative; margin: 0 0 30px; padding-right: 110px; }
.wordmark {
  font-family: "Fredoka", "Inter", sans-serif;
  font-size: clamp(34px, 6vw, 58px);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.02;
  margin: 0 0 12px;
}
.wordmark .emoji { font-size: 0.86em; }
/* marker-swash highlight behind the brand word */
.hl { position: relative; z-index: 0; white-space: nowrap; }
.hl::before {
  content: "";
  position: absolute;
  left: -6px; right: -6px; top: 12%; bottom: 6%;
  background: var(--brand);
  border-radius: 8px 10px 7px 9px;
  transform: rotate(-1.6deg);
  z-index: -1;
}
.tagline {
  color: var(--ink-soft);
  font-size: clamp(15px, 1.9vw, 18px);
  line-height: 1.5;
  margin: 0;
  max-width: 62ch;
  font-weight: 500;
}

/* Rotated “stamp” sticker */
.stamp {
  position: absolute;
  top: 4px; right: 6px;
  width: 92px; height: 92px;
  display: grid;
  place-items: center;
  text-align: center;
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.05;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: var(--brand);
  border: 2px dashed var(--ink);
  border-radius: 50%;
  transform: rotate(-9deg);
  box-shadow: var(--shadow-sm);
}
@media (max-width: 620px) {
  .stamp { display: none; }
  .masthead { padding-right: 0; }
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 26px;
  align-items: start;
}
@media (max-width: 840px) {
  .layout { grid-template-columns: 1fr; }
}

/* Cards */
.controls, .stage-wrap {
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

/* Controls */
.controls {
  position: relative;
  padding: 24px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
/* washi-tape strip peeking over the top edge */
.controls::before {
  content: "";
  position: absolute;
  top: -11px; left: 26px;
  width: 96px; height: 22px;
  background: rgba(255, 207, 46, 0.72);
  border: 1px solid rgba(232, 166, 0, 0.4);
  transform: rotate(-3.5deg);
  box-shadow: 0 2px 6px rgba(120, 88, 18, 0.14);
}

.field { display: flex; flex-direction: column; gap: 8px; }
.field label, .field-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.01em;
}
.muted { color: var(--ink-soft); font-weight: 500; }

input[type="text"], input[type="number"] {
  width: 100%;
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 500;
  color: var(--ink);
  background: #fffdf7;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder { color: #b6a988; }
input:focus {
  border-color: var(--brand-deep);
  box-shadow: 0 0 0 3px rgba(255, 207, 46, 0.4);
}

.dims { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.input-unit { position: relative; }
.input-unit input { padding-right: 46px; }
.unit-suffix {
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--ink-soft);
  pointer-events: none;
  font-weight: 600;
}

/* Segmented control */
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: #f1e7cd;
  border-radius: 12px;
  padding: 4px;
}
.seg {
  border: none;
  background: transparent;
  padding: 9px 6px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s;
}
.seg:hover { color: var(--ink); }
.seg.active {
  background: var(--brand);
  color: var(--ink);
  box-shadow: 0 2px 5px rgba(120, 88, 18, 0.22);
}

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

/* Two-column segmented (view toggle) */
.segmented.seg-2 { grid-template-columns: repeat(2, 1fr); }

/* Distance controls */
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; }
.preset {
  flex: 1 1 46%;
  border: 1.5px solid var(--line-strong);
  background: #fffdf7;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.preset:hover { border-color: var(--brand-deep); background: #fff6d9; }
.preset.active { background: var(--brand); border-color: var(--brand); }
.dist-slider {
  width: 100%;
  margin: 2px 0 0;
  accent-color: var(--brand-deep);
  cursor: pointer;
}
.dist-input-row { display: flex; gap: 8px; align-items: center; }
.dist-input-row .input-unit { flex: 1; }
.dist-unit-seg {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  background: #f1e7cd;
  border-radius: 12px;
  padding: 4px;
  width: 96px;
  flex: 0 0 auto;
}

/* Custom image upload */
.bg-row { display: flex; gap: 8px; align-items: center; }
.upload-btn {
  flex: 1;
  text-align: center;
  border: 1.5px dashed var(--brand-deep);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  background: #fffaea;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.upload-btn:hover { background: #fff2c9; }
.remove-btn {
  border: 1.5px solid var(--line-strong);
  background: var(--panel);
  color: var(--ink-soft);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.remove-btn:hover { color: var(--ink); border-color: var(--brand-deep); }

.readout {
  background: var(--panel-2);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.5;
  min-height: 20px;
  font-weight: 500;
}
.readout strong { color: var(--ink); font-weight: 700; }

/* Primary button — tactile, hard bottom shadow */
.download {
  border: none;
  background: var(--ink);
  color: #fff6df;
  padding: 13px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  font-family: "Fredoka", sans-serif;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 4px 0 #120d06;
  transition: transform 0.08s, box-shadow 0.08s, background 0.15s;
}
.download:hover { background: #322816; transform: translateY(-1px); box-shadow: 0 5px 0 #120d06; }
.download:active { transform: translateY(2px); box-shadow: 0 2px 0 #120d06; }

/* Stage */
.stage-wrap {
  padding: 18px;
  min-height: 500px;
  display: flex;
}
.stage { flex: 1; display: flex; }
.stage svg { width: 100%; height: auto; display: block; border-radius: 12px; }

/* Footer */
.foot { text-align: center; margin-top: 30px; }
.foot p { color: var(--ink-soft); font-size: 13px; margin: 0; font-weight: 500; }

/* “Lights out” flashlight mode ------------------------------------------- */
.lights-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;        /* the page stays interactive underneath */
  opacity: 0;
  transition: opacity 0.35s ease;
  /* warm flashlight tint over a pitch-black mask with a see-through hole */
  background:
    radial-gradient(circle 360px at var(--mx, 50vw) var(--my, 42vh),
      rgba(255, 216, 140, 0.12), rgba(255, 216, 140, 0) 65%),
    radial-gradient(circle 340px at var(--mx, 50vw) var(--my, 42vh),
      rgba(0, 0, 0, 0) 0,
      rgba(0, 0, 0, 0) 30%,
      rgba(0, 0, 0, 0.45) 55%,
      rgba(0, 0, 0, 0.8) 76%,
      rgba(0, 0, 0, 0.985) 100%);
}
.lights-out .lights-overlay { opacity: 1; }

/* flashlight cursor (dark mode) */
.flashlight {
  position: fixed;
  left: 0;
  top: 0;
  width: 150px;
  height: 64px;
  transform-origin: 12px 32px; /* the lens */
  pointer-events: none;
  z-index: 9999;
  display: none;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.55));
}
.flashlight svg { width: 100%; height: 100%; display: block; }
.lights-out .flashlight { display: block; }
/* hide the real cursor while the lights are out */
.lights-out, .lights-out * { cursor: none; }
.lights-out .lights-toggle { cursor: pointer; }

.lights-toggle {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10000;            /* stays above the overlay and flashlight, always findable */
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  background: var(--panel);
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, background 0.2s, color 0.2s, border-color 0.2s;
}
.lights-toggle:hover { border-color: var(--brand-deep); }
.lights-out .lights-toggle {
  background: var(--brand);
  color: #241d12;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(255, 207, 46, 0.5), 0 0 26px 7px rgba(255, 207, 46, 0.55);
}
