:root {
  --paper: #F6F4EC;
  --paper-dim: #EDEAE0;
  --ink: #1C1B19;
  --ink-soft: #55524A;
  --line: #D9D4C4;
  --brass: #A9793E;
  --brass-deep: #8A5F2C;
  --plum: #5B2333;
  --stamp-green: #2F5F4F;
  --radius: 3px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'IBM Plex Sans', sans-serif;
}

body {
  background-image:
    radial-gradient(circle at 1px 1px, rgba(28,27,25,0.05) 1px, transparent 0);
  background-size: 22px 22px;
}

h1, h2 { font-family: 'Fraunces', serif; margin: 0; }

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

.masthead {
  border-bottom: 3px solid var(--ink);
  padding: 48px 24px 32px;
}
.masthead-inner {
  max-width: 1180px;
  margin: 0 auto;
}
.wordmark-eyebrow {
  display: inline-block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass-deep);
  border: 1px solid var(--brass);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 16px;
}
.wordmark h1 {
  font-size: clamp(32px, 5vw, 56px);
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.01em;
}
.wordmark-sub {
  max-width: 640px;
  margin: 14px 0 0;
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 1.5;
}

/* ---------- Layout ---------- */

.layout {
  max-width: 1180px;
  margin: 40px auto 80px;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 32px;
  align-items: start;
}

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

/* ---------- Ticket (order form) ---------- */

.ticket {
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(28,27,25,0.04), 0 12px 24px -18px rgba(28,27,25,0.3);
  padding: 28px 26px 30px;
}
.ticket-notch {
  position: absolute;
  top: -10px; left: 50%;
  transform: translateX(-50%);
  width: 20px; height: 20px;
  background: var(--paper);
  border-radius: 50%;
  border: 1px solid var(--line);
}
.ticket-notch--bottom { top: auto; bottom: -10px; }

.ticket-step { padding: 18px 0; }
.ticket-step:first-of-type { padding-top: 4px; }
.ticket-divider {
  border: none;
  border-top: 1px dashed var(--line);
  margin: 0;
}

.step-label {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 17px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 4px;
}
.step-no {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--brass-deep);
  background: rgba(169,121,62,0.12);
  padding: 2px 6px;
  border-radius: 2px;
}
.step-hint {
  margin: 4px 0 12px;
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.45;
}

/* chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-row--wrap { margin-top: 10px; }
.chip {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  transition: all 0.12s ease;
  line-height: 1;
}
.chip:hover { border-color: var(--brass); color: var(--ink); }
.chip.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.chip.active.is-com { background: var(--plum); border-color: var(--plum); }

.text-toggle {
  margin-top: 10px;
  background: none;
  border: none;
  padding: 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  color: var(--brass-deep);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* length picker */
.length-row { display: flex; gap: 8px; margin-bottom: 12px; }
.length-btn {
  flex: 1;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  padding: 10px 0;
  border-radius: var(--radius);
  cursor: pointer;
}
.length-btn:hover { border-color: var(--brass); }
.length-btn.active { background: var(--ink); border-color: var(--ink); color: #fff; }

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-soft);
}

/* text input */
#base-string {
  width: 100%;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 20px;
  letter-spacing: 0.04em;
  text-transform: lowercase;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
}
#base-string:focus { outline: 2px solid var(--brass); outline-offset: 1px; }

/* position pills */
.position-row { display: flex; flex-direction: column; gap: 8px; }
.checkbox-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  font-size: 14px;
}
.checkbox-pill:hover { border-color: var(--brass); }
.checkbox-pill em {
  margin-left: auto;
  font-style: normal;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--ink-soft);
}

/* buttons */
.btn-primary, .btn-secondary {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: 0.01em;
  border-radius: var(--radius);
  padding: 13px 20px;
  cursor: pointer;
  border: none;
  width: 100%;
}
.btn-primary { background: var(--plum); color: #fff; }
.btn-primary:hover { background: #471c29; }
.btn-primary:disabled { background: #b9aeb0; cursor: not-allowed; }
.btn-secondary {
  background: none;
  border: 1px solid var(--ink);
  color: var(--ink);
  width: auto;
  padding: 12px 26px;
}
.btn-secondary:hover { background: var(--ink); color: #fff; }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.form-error {
  color: var(--plum);
  font-size: 13px;
  margin: 10px 0 0;
  min-height: 0;
}

/* ---------- Results ---------- */

.results-head { margin-bottom: 6px; }
.status-line {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--paper-dim);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 14px 0;
}
.status-line.error { color: var(--plum); border-color: var(--plum); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.card {
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 18px -14px rgba(28,27,25,0.4);
}
.card-canvas-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--paper-dim);
}
.card-canvas-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-top: 1px solid var(--line);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
}
.card-foot .ext-count { color: var(--ink-soft); }
.card-foot .dl-btn {
  background: none;
  border: none;
  color: var(--brass-deep);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-family: inherit;
  font-size: 12px;
  padding: 0;
}

.com-stamp {
  position: absolute;
  top: 10px; right: 10px;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 2px solid var(--stamp-green);
  color: var(--stamp-green);
  background: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  text-align: center;
  line-height: 1.1;
  transform: rotate(-8deg);
  letter-spacing: 0.02em;
}

.ext-tooltip {
  position: absolute;
  inset: 0;
  background: rgba(28,27,25,0.92);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  padding: 12px;
  text-align: center;
}
.card-canvas-wrap:hover .ext-tooltip { opacity: 1; }
.ext-tooltip-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #C9BFAE;
}
.ext-tooltip-list {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ext-price {
  font-weight: 400;
  color: #C9BFAE;
  font-size: 12px;
}

.more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 32px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
  margin-top: 18px;
}

/* ---------- Footer ---------- */

.foot {
  max-width: 1180px;
  margin: 0 auto 40px;
  padding: 20px 24px 0;
  border-top: 1px solid var(--line);
}
.foot p {
  font-size: 12.5px;
  color: var(--ink-soft);
  max-width: 760px;
}

/* ---------- Ad slots ---------- */
/* Populated client-side from /api/ads; collapse to nothing when empty so no
   gap shows on pages where the admin hasn't pasted a code yet. */

.ad-slot { display: none; }
.ad-slot.has-ad { display: block; }

.ad-slot--header {
  margin-top: 20px;
  width: 100%;
}
.ad-slot--results {
  margin: 18px 0;
  text-align: center;
}
.ad-slot--footer {
  margin-bottom: 18px;
  text-align: center;
}
.ad-slot iframe {
  border: 0;
  width: 100%;
  display: block;
  margin: 0 auto;
}
