:root {
  --maroon: #5E0E1C;
  --maroon-dark: #3f0812;
  --gold: #D4AF37;
  --gold-dark: #a8801f;
  --ivory: #fbf6ec;
  --paper: #ffffff;
  --ink: #2a1a1c;
  --muted: #6f5d5f;
  --line: #e8dccb;
  --danger: #b3261e;
  --radius: 14px;
  --serif: "Cormorant Garamond", Georgia, serif;
  --display: "Cinzel", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 var(--sans);
  color: var(--ink);
  background: var(--ivory);
  min-height: 100vh;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.small { font-size: 0.86rem; color: var(--muted); margin: 0; }
.mono { font-variant-numeric: tabular-nums; }
.error { color: var(--danger); min-height: 1.4em; margin: 0.5rem 0 0; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--maroon); color: #f6e7c8;
  border-bottom: 2px solid var(--gold);
}
.topbar .btn { white-space: nowrap; flex: none; }
.brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; flex-wrap: wrap; }
.brand-mark { color: var(--gold); }
.brand-name { font-family: var(--display); font-weight: 600; letter-spacing: 0.06em; }
.brand-sub { font-family: var(--serif); font-style: italic; opacity: 0.85; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px;
  border-radius: 999px; border: 1.5px solid transparent;
  font: 600 0.98rem var(--sans); text-decoration: none; cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease, background 0.15s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(212,175,55,0.6); outline-offset: 2px; }
.btn-gold { background: linear-gradient(180deg, #e9cd6b, var(--gold) 55%, #b8922c); color: #3a0a12; border-color: #b8922c; }
.btn-gold:hover:not(:disabled) { filter: brightness(1.05); }
.btn-maroon { background: var(--maroon); color: #fbeacb; }
.btn-maroon:hover:not(:disabled) { background: #74172a; }
.btn-outline { background: transparent; color: var(--maroon); border-color: var(--maroon); }
.btn-outline:hover:not(:disabled) { background: rgba(94,14,28,0.06); }
.btn-ghost { background: transparent; color: var(--maroon); }
.btn-ghost-light { background: transparent; color: #f6e7c8; border-color: rgba(246,231,200,0.4); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 0.86rem; }
.btn-block { width: 100%; }

/* ---------- screens ---------- */
.screen.center { min-height: calc(100vh - 60px); display: grid; place-items: center; padding: 24px 16px; text-align: center; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(94,14,28,0.08); }
.start-card { width: 100%; max-width: 420px; padding: 32px 24px; border-top: 4px solid var(--gold); }
.eyebrow { font-family: var(--display); letter-spacing: 0.2em; color: var(--gold-dark); margin: 0; font-size: 0.8rem; text-transform: uppercase; }
h1 { font-family: var(--serif); font-weight: 600; font-size: 2.1rem; color: var(--maroon); margin: 4px 0 8px; line-height: 1.15; }
h2 { font-family: var(--serif); font-weight: 600; font-size: 1.5rem; color: var(--maroon); margin: 0; }
.lead { color: var(--muted); margin: 0 0 20px; }
.code-input {
  width: 100%; padding: 14px; margin-bottom: 14px;
  font: 600 1.3rem/1 ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: 0.12em; text-align: center; text-transform: uppercase;
  border: 1.5px solid var(--line); border-radius: 10px; background: #fffdf8;
}
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--maroon); animation: spin 0.9s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- editor layout (mobile first: form above, preview below) ---------- */
.editor { display: flex; flex-direction: column; gap: 16px; padding: 16px; max-width: 1200px; margin: 0 auto; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel-head { margin-bottom: 8px; }

.group { border: 0; padding: 0; margin: 18px 0 0; }
.group legend { font-family: var(--display); font-size: 0.78rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold-dark); padding: 0; margin-bottom: 8px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 0.9rem; font-weight: 600; margin-bottom: 4px; }
.field input[type="text"], .field input[type="date"], .field input[type="time"], .field textarea, .field input:not([type]) {
  width: 100%; padding: 11px 12px; font: 16px/1.35 var(--sans); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 10px; background: #fffdf8;
}
.field textarea { resize: vertical; }
.help { font-size: 0.8rem; color: var(--muted); margin: 4px 0 0; }
.photo-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.photo-row input[type="file"] { max-width: 100%; font-size: 0.9rem; }
.photo-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 50%; border: 2px solid var(--gold); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-2 .field { margin-bottom: 12px; }
.event-card { border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: 10px; padding: 12px; margin-bottom: 12px; background: #fffcf5; }
.event-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; color: var(--maroon); }
.save-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.save-row .error, #save-status.error { color: var(--danger); }

.stage { display: flex; justify-content: center; }
#preview {
  /* fits the phone screen: never taller than ~72% of the viewport */
  width: min(100%, 380px, calc(72vh * 9 / 16)); aspect-ratio: 9 / 16; height: auto;
  border-radius: 12px; background: var(--maroon);
  box-shadow: 0 14px 40px rgba(63,8,18,0.35);
}
.player { display: flex; align-items: center; gap: 10px; margin: 14px auto 0; max-width: 380px; }
.player input[type="range"] { flex: 1; accent-color: var(--maroon); min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 12px auto 0; max-width: 420px; }
.chip { border: 1px solid var(--line); background: #fffaf0; color: var(--maroon); border-radius: 999px; padding: 6px 12px; font-size: 0.82rem; cursor: pointer; }
.chip.active { background: var(--maroon); color: #fbeacb; border-color: var(--maroon); }
.downloads { display: grid; gap: 10px; margin: 18px auto 0; max-width: 380px; }
.export { max-width: 380px; margin: 14px auto 0; }
.progress { height: 12px; border-radius: 999px; background: #f0e6d5; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--maroon), var(--gold)); transition: width 0.15s linear; }
.export-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 8px 0 4px; }
.result { max-width: 380px; margin: 14px auto 0; padding: 12px 14px; border-radius: 10px; background: #fff8e6; border: 1px solid #ecd9a4; font-size: 0.92rem; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.fab {
  position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom));
  border: 0; border-radius: 999px; padding: 12px 18px;
  background: var(--maroon); color: #fbeacb; font: 600 0.95rem var(--sans);
  box-shadow: 0 8px 24px rgba(63,8,18,0.35); z-index: 5;
}

/* ---------- wider screens: form on the left, preview on the right ---------- */
@media (min-width: 900px) {
  .editor { display: grid; grid-template-columns: minmax(0, 1fr) 440px; align-items: start; padding: 24px; gap: 24px; }
  .preview-panel { position: sticky; top: 16px; }
  .fab { display: none; }
}
@media (max-width: 420px) {
  .brand-sub { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .btn, #progress-bar { transition: none; }
}
