/* ---------------------------------------------------------------------------
   Fonts. Two groups:
   - Archivo / IBM Plex Sans dress the interface.
   - Metropolis / Liberation Sans are the faces the templates ask for. They are
     declared here so the live preview looks like the export; the export gets
     the very same files inlined as data URIs (see fonts/embedded-fonts.js).
   --------------------------------------------------------------------------- */

@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/archivo-latin-500-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/archivo-latin-ext-500-normal.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/archivo-latin-700-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/archivo-latin-ext-700-normal.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-latin-ext-400-normal.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-latin-600-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-latin-ext-600-normal.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Metropolis';
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url('fonts/Metropolis-Regular.woff2') format('woff2');
}
@font-face {
  font-family: 'Metropolis';
  font-style: normal;
  font-weight: 700;
  font-display: block;
  src: url('fonts/Metropolis-Bold.woff2') format('woff2');
}
@font-face {
  font-family: 'Liberation Sans';
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url('fonts/LiberationSans-Regular.woff2') format('woff2');
}

/* --------------------------------------------------------------------------- */

:root {
  --bg: #06070f;
  --ink: #eef1f8;
  --ink-dim: #97a0bb;
  --ink-faint: #6b7391;
  --glass: rgba(255, 255, 255, 0.055);
  --glass-strong: rgba(255, 255, 255, 0.085);
  --edge: rgba(255, 255, 255, 0.11);
  --edge-strong: rgba(255, 255, 255, 0.2);
  --blue: #3b6fe0;
  --blue-deep: #0055a4;
  --red: #ef4135;
  --amber: #f0b429;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.55);
  --ui: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Archivo', var(--ui);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* The FRAC background is a deep navy with a blue and a red bloom. Echo it. */
.glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(70% 55% at 12% 0%, rgba(0, 85, 164, 0.5), transparent 65%),
    radial-gradient(60% 50% at 92% 12%, rgba(239, 65, 53, 0.22), transparent 62%),
    radial-gradient(90% 70% at 50% 105%, rgba(59, 111, 224, 0.2), transparent 70%),
    linear-gradient(180deg, #0b1030 0%, #06070f 60%);
}

h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -0.02em; margin: 0; }

.muted { color: var(--ink-dim); margin: 0; }

.is-hidden { display: none !important; }

/* --- top bar --------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  max-width: 1400px;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  display: flex;
  gap: 3px;
  padding: 7px;
  border-radius: 10px;
  background: var(--glass);
  border: 1px solid var(--edge);
}
.brand-mark i { width: 5px; height: 20px; border-radius: 2px; display: block; }
.brand-mark i:nth-child(1) { background: var(--blue-deep); }
.brand-mark i:nth-child(2) { background: #fff; }
.brand-mark i:nth-child(3) { background: var(--red); }

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-family: var(--display); font-size: 19px; letter-spacing: -0.03em; }
.brand-text small { color: var(--ink-faint); font-size: 12px; }

/* --- notice ---------------------------------------------------------------- */

.notice {
  max-width: 1400px;
  margin: 0 auto 8px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  background: rgba(240, 180, 41, 0.12);
  border: 1px solid rgba(240, 180, 41, 0.35);
  color: #ffe6ae;
  font-size: 14px;
}
.notice code {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 6px;
  border-radius: 6px;
}

main { max-width: 1400px; margin: 0 auto; padding: 8px clamp(16px, 4vw, 40px) 60px; }

.section-title { font-size: clamp(22px, 3vw, 30px); margin-bottom: 6px; }

/* --- template picker -------------------------------------------------------- */

.group { margin-top: 30px; }
.group:first-child { margin-top: 22px; }

.group-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink-dim);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--edge);
}
.group-title svg { color: var(--ink-faint); flex: none; }

.group-count {
  font-family: var(--ui);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-faint);
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 1px 8px;
}

.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  align-items: start;
  gap: 18px;
  margin-top: 16px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  text-align: left;
  color: inherit;
  font: inherit;
  cursor: pointer;
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}
.card:hover { transform: translateY(-3px); border-color: var(--edge-strong); background: var(--glass-strong); }
.card:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
.card.is-unsupported { cursor: not-allowed; opacity: 0.62; }
.card.is-unsupported:hover { transform: none; }

.card-thumb {
  background: rgba(0, 0, 0, 0.35);
  border-bottom: 1px solid var(--edge);
  position: relative;
  min-height: 90px;
  display: grid;
}
.card-thumb img { display: block; width: 100%; height: auto; }
.card-thumb-fallback {
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 34px;
  color: var(--ink-faint);
}

.card-body { padding: 12px 14px 14px; }
.card-name { font-family: var(--display); font-weight: 700; font-size: 15px; }
.card-meta { color: var(--ink-faint); font-size: 12px; margin-top: 2px; }
.card-warn { color: var(--amber); font-size: 12px; margin-top: 6px; line-height: 1.35; }

.ratio-tag {
  position: absolute;
  right: 8px;
  top: 8px;
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 999px;
  background: rgba(6, 7, 15, 0.72);
  border: 1px solid var(--edge);
  color: var(--ink-dim);
}

/* --- editor ----------------------------------------------------------------- */

.editor {
  display: grid;
  grid-template-columns: minmax(0, 400px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.pane {
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

.pane-form { padding: 22px; }
.pane-head { margin-bottom: 18px; }
.pane-foot { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--edge); }

.pane-preview { padding: 18px; background: rgba(255, 255, 255, 0.03); }
.preview-sticky { position: sticky; top: 18px; }

.fields { display: flex; flex-direction: column; gap: 18px; }

.field label,
.field .field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 7px;
}

.field input[type='text'],
.field textarea {
  width: 100%;
  padding: 11px 13px;
  color: var(--ink);
  font: inherit;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field textarea { min-height: 82px; line-height: 1.45; }
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: rgba(59, 111, 224, 0.8);
  box-shadow: 0 0 0 3px rgba(59, 111, 224, 0.22);
}

.field-note { font-size: 12px; color: var(--ink-faint); margin: 6px 0 0; }

.field-warn {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 8px 0 0;
  padding: 8px 10px;
  font-size: 12.5px;
  line-height: 1.4;
  color: #ffdf9e;
  background: rgba(240, 180, 41, 0.12);
  border: 1px solid rgba(240, 180, 41, 0.32);
  border-radius: 10px;
}
.field-warn.is-error { color: #ffc9c4; background: rgba(239, 65, 53, 0.14); border-color: rgba(239, 65, 53, 0.4); }
.field-warn::before { content: '▲'; font-size: 10px; line-height: 1.5; }

/* photo slot */

.photo-slot { display: flex; flex-direction: column; gap: 10px; }
.photo-row { display: flex; gap: 12px; align-items: center; }

.photo-preview {
  width: 74px;
  height: 74px;
  flex: none;
  border-radius: 10px;
  border: 1px solid var(--edge);
  background: rgba(0, 0, 0, 0.35) center / cover no-repeat;
  display: grid;
  place-items: center;
  color: var(--ink-faint);
  font-size: 11px;
}

.photo-actions { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.photo-name { font-size: 12px; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-label {
  width: 36px;
  flex: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-dim);
}
.slider-readout {
  width: 66px;
  flex: none;
  text-align: right;
  font-size: 12px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

input[type='range'] {
  flex: 1;
  min-width: 0;
  accent-color: var(--blue);
  height: 22px;
}

/* --- stage ------------------------------------------------------------------ */

.stage {
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--edge);
  /* Flex, not grid: an auto-sized grid track grows to the intrinsic 1080 px
     of the preview, which makes the child's max-width:100% resolve against
     itself and lets the page overflow sideways on a phone. */
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
}
.stage svg { display: block; width: 100%; height: auto; max-width: 100%; min-width: 0; }

.actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.export-status { font-size: 12.5px; margin-top: 8px; min-height: 18px; }

/* --- buttons ----------------------------------------------------------------- */

.btn {
  font-family: var(--display);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--edge);
  background: var(--glass);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.btn:hover { background: var(--glass-strong); border-color: var(--edge-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.btn[disabled] { opacity: 0.5; cursor: progress; }

.btn-primary {
  background: linear-gradient(180deg, #4a7cf0, #2857c4);
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: 0 8px 24px rgba(40, 87, 196, 0.4);
}
.btn-primary:hover { background: linear-gradient(180deg, #5786f5, #2f61d6); }

.btn-small { padding: 7px 12px; font-size: 13px; }

.footer {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 40px) 40px;
  color: var(--ink-faint);
  font-size: 12.5px;
}

/* --- responsive -------------------------------------------------------------- */

@media (max-width: 940px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .pane-preview { order: -1; padding: 12px; }
  .preview-sticky { position: static; }
  /* min-width:0 matters: a replaced element in a grid keeps its intrinsic
     width otherwise, and a 1080 px wide preview runs off a phone screen. */
  .stage svg { width: auto; height: auto; max-width: 100%; max-height: 56vh; min-width: 0; }
  .stage { padding: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
