/* The tool's own UI (not the posts). Phone first. */
:root {
  --ui-bg: #F4F2EA; --ui-card: #fff; --ui-ink: #1B2733; --ui-mute: #66717C; --ui-line: #E2DED2;
  --ui-accent: #03263F; --ui-gold: #F5B818; --ui-danger: #C2372F;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--ui-bg); color: var(--ui-ink);
  font: 16px/1.4 "Source Sans 3", system-ui, sans-serif;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
body.noscroll { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.bar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--ui-accent); color: #fff; }
.bar-logo { width: 34px; height: 34px; border-radius: 50%; object-fit: contain; background: #fff; }
.bar-title { flex: 1; font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 20px; }
.icon-btn { background: none; border: 0; font-size: 22px; padding: 6px 8px; color: inherit; line-height: 1; }

.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 12px 16px 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; border: 2px solid var(--ui-line); background: var(--ui-card); border-radius: 999px; padding: 8px 16px; font-weight: 600; }
.tabs button.on { background: var(--ui-accent); border-color: var(--ui-accent); color: #fff; }

main { max-width: 1100px; margin: 0 auto; padding: 8px 16px 16px; }

.size-toggle { display: inline-flex; background: var(--ui-line); border-radius: 10px; padding: 3px; margin: 6px 0 10px; }
.size-toggle button { border: 0; background: none; padding: 6px 14px; border-radius: 8px; font-weight: 600; color: var(--ui-mute); }
.size-toggle button.on { background: var(--ui-card); color: var(--ui-ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.preview { position: relative; width: 100%; overflow: hidden; border-radius: 10px; box-shadow: 0 2px 14px rgba(0,0,0,.14); background: #ddd; }
.preview-inner { position: absolute; top: 0; left: 0; transform-origin: 0 0; }

@media (max-width: 899px) {
  /* "contents" lets the sticky preview stay pinned past the end of its section, all the way down the form */
  .preview-area { display: contents; }
  .preview-sticky { position: sticky; top: 54px; z-index: 10; background: var(--ui-bg); padding: 6px 0 8px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
}
.warn { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: #FDECEA; color: var(--ui-danger); font-weight: 600; }

.pages { margin-top: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 2px solid var(--ui-line); background: var(--ui-card); border-radius: 10px; padding: 6px 12px; font-weight: 600; font-size: 15px; }
.chip.on { border-color: var(--ui-accent); background: var(--ui-accent); color: #fff; }
.chip.add { border-style: dashed; color: var(--ui-mute); cursor: pointer; }
.page-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.page-tools button, .page-tools .file-btn { border: 1px solid var(--ui-line); background: var(--ui-card); border-radius: 8px; padding: 6px 12px; font-size: 14px; }
.page-tools button:disabled { opacity: .4; }
.danger { color: var(--ui-danger); }

.form { margin-top: 18px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 14px; font-weight: 600; color: var(--ui-mute); margin-bottom: 4px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--ui-line); border-radius: 10px; background: var(--ui-card);
  font-size: 17px; /* 16px+ stops iPhone zooming in */
}
.field textarea { resize: vertical; min-height: 96px; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid var(--ui-gold); border-color: transparent; }

.list { margin: 6px 0 16px; }
.list-label { font-weight: 700; margin-bottom: 8px; }
.item { background: var(--ui-card); border: 1px solid var(--ui-line); border-radius: 12px; margin-bottom: 10px; }
.item > summary { display: flex; align-items: center; gap: 8px; padding: 10px 12px; list-style: none; cursor: pointer; font-weight: 700; }
.item > summary::-webkit-details-marker { display: none; }
.item > summary::before { content: "▸"; color: var(--ui-mute); transition: transform .15s; }
.item[open] > summary::before { transform: rotate(90deg); }
.item-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-tools { display: flex; gap: 4px; }
.item-tools button { width: 34px; height: 34px; border: 1px solid var(--ui-line); background: var(--ui-bg); border-radius: 8px; font-size: 15px; }
.item-tools button:disabled { opacity: .35; }
.item-body { padding: 0 12px 4px; }
.item .item { background: var(--ui-bg); }
.add-btn { width: 100%; padding: 10px; border: 2px dashed var(--ui-line); background: none; border-radius: 12px; font-weight: 600; color: var(--ui-accent); }

.swatches { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }   /* minmax(0,…): wide samples can't push the row off-screen */
.swatches button { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 4px 5px; border: 2px solid var(--ui-line); background: var(--ui-card); border-radius: 12px; font-size: 13px; font-weight: 600; color: var(--ui-mute); }
.swatches button.on { border-color: var(--ui-accent); color: var(--ui-ink); box-shadow: 0 0 0 2px var(--ui-gold); }
/* Live mini-render of the post (1080 wide) shrunk to 64px */
.fs-sample { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 56px; color: var(--ui-accent); overflow: hidden; }
.fs-sample .display { font-size: 15px; line-height: 1; white-space: nowrap; }
.fs-sample .script { font-size: 18px; font-style: normal; color: #0A7493; white-space: nowrap; }
.sw-thumb { position: relative; display: block; width: 64px; max-width: 100%; height: 80px; overflow: hidden; border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.sw-inner { position: absolute; top: 0; left: 0; transform: scale(calc(64 / 1080)); transform-origin: 0 0; pointer-events: none; }
.sw-inner .overflowing { outline: none; }

.image-field { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.image-field img { width: 64px; height: 80px; object-fit: cover; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.image-field .file-btn, .image-field button { border: 1px solid var(--ui-line); background: var(--ui-card); border-radius: 10px; padding: 9px 14px; font-weight: 600; cursor: pointer; }
.toggle { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--ui-line); border-radius: 10px; padding: 3px; gap: 3px; }
.toggle button { border: 0; background: none; padding: 9px 8px; border-radius: 8px; font-weight: 600; color: var(--ui-mute); }
.toggle button.on { background: var(--ui-card); color: var(--ui-ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.range-field input[type=range] { width: 100%; accent-color: var(--ui-accent); height: 32px; }
.range-field b { color: var(--ui-ink); }

.icon-pick { display: inline-flex; align-items: center; gap: 10px; padding: 8px 14px 8px 10px; border: 1px solid var(--ui-line); background: var(--ui-card); border-radius: 10px; }
.icon-pick svg { width: 34px; height: 34px; color: var(--ui-accent); }
.icon-pick span { font-weight: 600; color: var(--ui-mute); }

.action-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: rgba(244,242,234,.94); backdrop-filter: blur(6px); border-top: 1px solid var(--ui-line); }
.primary { display: block; width: 100%; max-width: 520px; margin: 0 auto; padding: 14px; border: 0; border-radius: 12px; background: var(--ui-accent); color: #fff; font-weight: 700; font-size: 18px; }
.primary:disabled { opacity: .7; }

.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-card { width: 100%; max-width: 640px; max-height: 88vh; overflow: auto; background: var(--ui-card); border-radius: 18px 18px 0 0; padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; font-size: 18px; }
.sheet-card h3 { margin: 16px 0 4px; font-size: 16px; }
.sheet-card button:not(.icon-btn):not(.primary):not([data-icon]), .file-btn { border: 1px solid var(--ui-line); background: var(--ui-bg); border-radius: 10px; padding: 9px 14px; font-weight: 600; cursor: pointer; display: inline-block; }
.hint { color: var(--ui-mute); font-size: 14px; margin: 4px 0 10px; }
.logo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.logo-row img { width: 64px; height: 64px; border-radius: 50%; object-fit: contain; background: var(--ui-bg); }

.export-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin: 6px 0 14px; }
.export-grid.multi { grid-template-columns: repeat(3, 1fr); }
.export-grid figure { margin: 0; position: relative; }
.export-grid img { width: 100%; display: block; border-radius: 8px; box-shadow: 0 1px 6px rgba(0,0,0,.15); -webkit-touch-callout: default; }
.export-grid figcaption { position: absolute; top: 6px; left: 6px; background: var(--ui-accent); color: #fff; font-weight: 700; font-size: 13px; border-radius: 999px; min-width: 24px; text-align: center; padding: 1px 7px; }
.sheet-actions { display: grid; gap: 8px; }
.sheet-actions .primary { max-width: none; }
.sheet-actions button[hidden] { display: none; }

.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 8px; margin-top: 10px; }
.icon-grid button { aspect-ratio: 1; border: 1px solid var(--ui-line); background: var(--ui-bg); border-radius: 10px; padding: 10px; color: var(--ui-accent); }
.icon-grid svg { width: 100%; height: 100%; }

#stage { position: fixed; left: -30000px; top: 0; pointer-events: none; }

.storage-warn { position: fixed; left: 12px; right: 12px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 40; max-width: 620px; margin: 0 auto; background: #FDECEA; color: #7A1F1A; border: 2px solid var(--ui-danger); border-radius: 12px; padding: 12px 14px; font-size: 15px; line-height: 1.35; box-shadow: 0 4px 16px rgba(0,0,0,.18); }
.storage-warn[hidden] { display: none; }
.storage-warn b { color: var(--ui-danger); }

.toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; transition: .2s; background: var(--ui-ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Wider screens: preview left, form right */
@media (min-width: 900px) {
  main { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 28px; align-items: start; }
  .preview-area { position: sticky; top: 70px; }
  .form { margin-top: 0; }
}
