/* ------------------------------------------------------------------ */
/* Fonts — subsetted WOFF2 (basic latin + latin-1), built from the     */
/* originals by scripts/build-web-fonts.py into public/fonts/. The     */
/* raw TTF/OTF files in /fonts are SERVER-side only (opentype.js +     */
/* @napi-rs/canvas need full files for engraving). If you replace a    */
/* font file, rebuild and BUMP THE ?v= — clients cache these for a     */
/* year (immutable).                                                   */
/* ------------------------------------------------------------------ */
@font-face { font-family: 'Boncegro';      src: url('/fonts/boncegro.woff2?v=2')       format('woff2'); font-display: block; }
@font-face { font-family: 'Marlboro';      src: url('/fonts/marlboro.woff2?v=2')       format('woff2'); font-display: block; }
@font-face { font-family: 'RusticRoadway'; src: url('/fonts/rustic-roadway.woff2?v=2') format('woff2'); font-display: block; }
/* Visible engraving fonts are loaded on demand by the customizer.
   Keeping them out of CSS also makes failed downloads retryable. */
@font-face { font-family: 'Pacifico';      src: url('/fonts/pacifico.woff2?v=2')       format('woff2'); font-display: block; }

:root {
  color-scheme: dark;
  --bg: #0f0f10;
  --panel: #18181a;
  --border: #2a2a2d;
  --text: #f0f0f2;
  --muted: #8c8c92;
  --accent: #ffb547;
  --accent-text: #1a1a1d;
  --danger: #ff6b6b;
  --surface: #232328;
  --surface-alt: #15151a;
  --surface-selected: #2a2a30;
  --secondary: #34343a;
  --input-border: #fff;
  --placeholder: #c8c8d0;
  --accent-ink: var(--accent);
  --heading-font: system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* ------------------------------------------------------------------ */
/* Layout — mobile-first single column, side-by-side on tablets+.      */
/* ------------------------------------------------------------------ */
.app {
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
  gap: 16px;
}

header {
  text-align: center;
}
header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
header p {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

#stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  background: #ffffff;
  border-radius: 10px;
  overflow: hidden;
}
#canvas {
  display: block;
  width: 100%;
  height: 100%;
}
#status {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  pointer-events: none;
}
#status:empty { display: none; }
/* Errors are tappable — the boot code arms a tap-to-retry on them. */
#status.error { background: var(--danger); color: white; pointer-events: auto; cursor: pointer; }

/* ------------------------------------------------------------------ */
/* Form                                                                */
/* ------------------------------------------------------------------ */
form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
/* Uniform spacing between every form section. Bumps the form's flex
   gap so fields breathe without per-row tweaks. */
form { gap: 24px; }

/* Segmented control — pill toggle between text/logo modes. */
.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.segmented button {
  flex: 1;
  width: auto;
  margin-top: 0;
  min-height: 40px;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 600;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 7px;
}
.segmented button.active {
  background: var(--accent);
  color: var(--accent-text);
}
.hidden { display: none !important; }

/* Logo picker — visual side-by-side buttons (replaces dropdown). */
.logo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.logo-grid button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 0;
  padding: 12px;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  min-height: auto;
}
.logo-grid button.active {
  border-color: var(--accent-ink);
  background: var(--surface-selected);
}
.logo-grid img {
  width: 100%;
  height: 90px;
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
}
.logo-grid .logo-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
.logo-grid button.active .logo-label { color: var(--accent-ink); }

/* ----- "Create your graphic" button + icon-picker modal ----- */
button.create {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border: 2px dashed var(--accent);
  border-radius: 10px;
  color: var(--accent-ink);
  font-size: 15px;
  font-weight: 700;
  min-height: 56px;
}
button.create .plus { font-size: 22px; line-height: 1; font-weight: 600; }
button.create.has-selection {
  border-style: solid;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
  gap: 12px;
}
button.create.has-selection .preview {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 26px; line-height: 1; background: #fff; color: #111;
  border-radius: 6px; padding: 6px 10px; flex: 1;
}
button.create.has-selection .hint {
  color: var(--muted); font-size: 11px; font-weight: 500; flex-shrink: 0;
}
button.create .preview img {
  width: 28px; height: 28px; object-fit: contain; display: block;
}

.picker-card {
  max-height: 94vh;
  max-width: 560px;
  border-radius: 14px 14px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}
@media (min-width: 600px) {
  .picker-card { border-radius: 14px; max-height: 86vh; }
}
.modal-header {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.modal-header .title { flex: 1; }
.modal-header h2 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-header .modal-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.counter {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 13px;
  padding: 6px 10px; background: var(--surface); border-radius: 999px;
  color: var(--muted);
}
.counter.ok { color: var(--accent-ink); }
.counter.full { background: var(--accent); color: var(--accent-text); }
.close-btn {
  width: auto; min-height: auto; background: transparent;
  color: var(--muted); border: 0; font-size: 22px; padding: 6px 10px;
  cursor: pointer;
}
.selection {
  padding: 10px 14px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  min-height: 64px;
  display: flex; align-items: center; overflow-x: auto; gap: 8px;
}
.selection .empty-hint {
  color: var(--muted); font-size: 13px; font-style: italic; margin: 0 auto;
}
.chip {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 6px;
  background: #fff; color: #111;
  border-radius: 8px; padding: 6px 10px;
  font-size: 22px; line-height: 1;
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--accent);
  user-select: none;
}
.chip img { width: 28px; height: 28px; object-fit: contain; display: block; }
.chip .x {
  font-size: 12px; background: var(--surface); color: var(--text);
  border-radius: 50%; width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: monospace;
}
.categories { flex: 1; overflow-y: auto; padding: 14px 14px 16px; }
.picker-hint { color: var(--muted); font-size: 14px; text-align: center; padding: 28px 0; cursor: pointer; }
.category { margin: 0 0 18px; }
.category h3 {
  margin: 0 0 10px; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--muted); font-weight: 600;
}
.picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.tile-wrap { position: relative; }
.tile {
  width: 100%; aspect-ratio: 5 / 4;
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; line-height: 1; color: #111;
  cursor: pointer; transition: transform 0.06s ease;
  user-select: none;
  padding: 0;
  margin-top: 0;
  min-height: auto;
}
.tile:active { transform: scale(0.94); }
.tile.selected {
  border-color: var(--accent-ink);
  box-shadow: inset 0 0 0 3px var(--accent), 0 0 0 1px var(--accent);
}
.tile.disabled { opacity: 0.4; pointer-events: none; }
.tile img { width: 70%; height: 70%; object-fit: contain; }
.tile-badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--accent); color: var(--accent-text);
  border-radius: 50%; width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}
.picker-actions {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  display: flex; gap: 10px;
}
.picker-actions button { flex: 1; }
.picker-actions .picker-cancel {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
}

/* Generate Barcode result modal. */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 20px 20px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  max-height: 96vh;
  overflow-y: auto;
}
.modal-card h2 {
  margin: 0 0 4px;
  font-size: 20px;
}
.modal-card .modal-sub {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 18px;
}
.result-content {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: center;
  margin: 0 0 18px;
}
.result-content .qr {
  background: white;
  padding: 8px;
  border-radius: 8px;
  width: 220px;
  max-width: 50%;
  height: auto;
}
.result-content .thumb {
  max-width: 45%;
  max-height: 220px;
  object-fit: contain;
  background: white;
  border-radius: 8px;
}
.barcode-text {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 15px;
  color: var(--accent-ink);
  background: var(--surface-alt);
  padding: 10px 14px;
  border-radius: 6px;
  letter-spacing: 0.04em;
  margin: 0 0 14px;
  word-break: break-all;
}
.modal-hint {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 16px;
  line-height: 1.4;
}
@media (max-width: 480px) {
  .result-content { flex-direction: column; }
  .result-content canvas, .result-content img { max-width: 70%; }
}
/* High-contrast form labels — readable in direct sunlight at the
   festival. Pure white + heavier weight + a touch larger than the
   previous muted-gray treatment. */
.field-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text);
  font-weight: 700;
}
.field-counter {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 600;
}
.field-counter.over { color: var(--danger); }

input[type="text"], select {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px; /* >= 16px keeps iOS from auto-zooming on focus */
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  /* Stronger border + thicker stroke so the input box stays visible
     against bright ambient light. */
  border: 2px solid var(--input-border);
  border-radius: 8px;
  min-height: 48px; /* comfy touch target */
}
input[type="text"]:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
/* Bright placeholder so empty fields are still scannable in sunlight,
   and visually distinct from typed input (which is pure white). */
input[type="text"]::placeholder {
  color: var(--placeholder);
  opacity: 1; /* Firefox dims placeholders by default; undo it. */
}

/* Custom font picker — button trigger styled like the inputs above,
   opens a modal where each row is rendered in that font. */
.font-trigger {
  width: 100%;
  padding: 12px 14px;
  font-size: 18px;
  font-family: inherit;
  /* Custom display fonts only ship a regular face — without this the
     global button rule forces faux bold and decorative fonts (Far Out
     in particular) render as broken outlines. */
  font-weight: 400;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--input-border);
  border-radius: 8px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  cursor: pointer;
}
.font-trigger:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.font-trigger-caret { color: var(--muted); font-size: 14px; }

.font-card {
  padding: 0;
  max-width: 480px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.font-rows {
  overflow-y: auto;
  padding: 8px 10px 14px;
}
.font-row {
  width: 100%;
  background: transparent;
  color: var(--text);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 14px 16px;
  min-height: 64px;
  font-size: 32px;
  /* See note on .font-trigger — same faux-bold issue. */
  font-weight: 400;
  line-height: 1.1;
  text-align: left;
  cursor: pointer;
  display: block;
  margin: 6px 0;
}
.font-row:active { transform: scale(0.99); }
.font-row.selected {
  border-color: var(--accent-ink);
  background: var(--surface);
}

button {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  min-height: 52px;
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
button.secondary {
  background: var(--secondary);
  color: var(--text);
}

.event-header {
  max-width: 1052px; margin: 0 auto; padding: 18px 0;
  color: var(--page-ink, var(--text)); text-align: left;
}
.event-lockup { display: flex; align-items: center; gap: 20px; }
.event-lockup h1 { min-width: 0; font-family: var(--heading-font); font-size: clamp(24px, 4.8vw, 54px); line-height: 1; }
.event-short-year { white-space: nowrap; }
.event-partner { display: flex; align-items: center; gap: 20px; flex-shrink: 0; }
.event-collab { font-size: clamp(20px, 3vw, 32px); font-weight: 400; }
.pirani-logo { display: block; width: clamp(76px, 10vw, 120px); height: auto; filter: var(--pirani-logo-filter, brightness(0)); }
.app > .right { min-width: 0; }
.design-intro { margin-bottom: 18px; color: var(--page-ink, var(--text)); }
.design-intro h2 { margin: 0; font-family: var(--heading-font); font-size: clamp(28px, 3vw, 36px); line-height: 1.05; }
.draft-notice { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; color: var(--page-ink, var(--text)); font-size: 12px; }
.draft-notice button { width: auto; flex-shrink: 0; padding: 8px; min-height: 44px; font-size: 12px; background: transparent; color: inherit; text-decoration: underline; }
.asset-status { margin-top: 8px; font: 12px/1.4 system-ui, sans-serif; }
button.asset-status { background: transparent; color: var(--text); text-align: left; text-decoration: underline; }
.draft-notice.hidden, .asset-status.hidden { display: none; }
#designForm { padding: 22px; gap: 20px; }
.field-label { font-size: 12px; letter-spacing: .09em; }
.field-counter { font-size: 12px; }
.modal-card.picker-card { padding: 0; max-width: 560px; overflow: hidden; max-height: 90dvh; }
.modal-header { text-align: left; }
.modal-card .modal-header .modal-sub { margin: 3px 0 0; font-size: 12px; line-height: 1.4; }
.modal-header .close-btn { min-height: 44px; min-width: 44px; }
.category h3 { text-align: left; font-weight: 800; }
.categories { min-height: 0; overscroll-behavior: contain; }
.picker-actions, .selection { flex-shrink: 0; }
button:focus-visible { outline: 3px solid var(--accent-ink); outline-offset: 3px; }
.site-footer { max-width: 1052px; margin: 4px auto 0; padding: 0 0 24px; text-align: center; color: var(--page-ink, var(--text)); font-size: 11px; line-height: 1.5; }
.site-footer::before { content: ''; display: block; width: 72px; height: 3px; margin: 0 auto 14px; }
@media (max-width: 1100px) {
  .event-header { margin-left: 24px; margin-right: 24px; }
}
@media (max-width: 599px) {
  .event-header { margin-left: 16px; margin-right: 16px; padding: 12px 0; }
  .event-lockup, .event-partner { gap: 10px; }
  .design-intro { margin: 8px 0 18px; }
  #designForm { padding: 18px; }
  .modal { padding: 10px; }
  .modal-header { padding: 12px; gap: 6px; }
  .modal-header h2 { font-size: 18px; }
  .modal-header .modal-sub { max-width: 230px; }
  .counter { padding: 6px 8px; white-space: nowrap; }
}

/* On wider screens lay it out side-by-side. */
@media (min-width: 900px) {
  .app {
    flex-direction: row;
    align-items: flex-start;
    padding: 24px;
    gap: 24px;
  }
  .app > #stage { flex: 0 0 55%; }
  .app > .right { flex: 1; display: flex; flex-direction: column; }
}
