:root {
  color-scheme: light;
  --logo-h: 150px; /* height of the whole logo.svg canvas */
  --bg: #ffffff;
  --surface: #f3f3f1;
  --line: #dcdcd8;
  --text: #0b0b0b;
  --muted: #6b6b66;
  --accent: #0b0b0b;
  --on-accent: #ffffff;
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --gutter: clamp(16px, 3vw, 32px);
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

button, input { font: inherit; color: inherit; }

/* No double-tap zoom delay on controls. */
button, input, summary, label { touch-action: manipulation; }

svg { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(14px, env(safe-area-inset-top)) var(--gutter) 14px;
}

.brand {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  line-height: 1.1;
}

.logo {
  display: block;
  width: auto;
  height: var(--logo-h);
}

/* The animated logo has a little room around it for the wave and the bulge; the negative margin cancels it. */
.logo-live { margin: calc(var(--logo-pad, 0px) * -1); pointer-events: none; }

.brand span {
  display: block;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: none;
  color: var(--muted);
  font-size: .8rem;
  margin-top: 2px;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  font-size: .82rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .12s ease, opacity .12s ease, background .12s ease;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .35; cursor: not-allowed; transform: none; }

.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
@media (hover: hover) { .btn-ghost:hover { border-color: var(--text); } }

.btn-block { flex: 1; }

.link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 4px;
  background: none;
  border: 0;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link:disabled { opacity: .4; cursor: not-allowed; }
@media (hover: hover) { .link:not(:disabled):hover { color: var(--text); } }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
}

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

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: var(--gutter);
  padding: var(--gutter);
  align-items: start;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.frame {
  --ratio: 1;
  --max-h: calc(100dvh - 130px);
  position: relative;
  width: min(100%, calc(var(--max-h) * var(--ratio)));
  aspect-ratio: var(--ratio);
  background: #fff;
}

.frame.interactive { touch-action: none; }

.frame canvas,
.frame .guides,
.frame .nubs {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.frame canvas { display: block; }

.guides { pointer-events: none; overflow: visible; }
.guides polygon {
  fill: none;
  stroke: #0b0b0b;
  stroke-width: 2;
  stroke-dasharray: 6 5;
  vector-effect: non-scaling-stroke;
}

.nubs { pointer-events: none; }

.nub {
  position: absolute;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  padding: 0;
  border: 0;
  background: none;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.nub::after {
  content: "";
  position: absolute;
  inset: 13px;
  border-radius: 50%;
  background: #0b0b0b;
  box-shadow: 0 0 0 3px #fff, 0 2px 10px rgb(0 0 0 / .35);
  transition: transform .12s ease;
}

.nub:hover::after, .nub.dragging::after { transform: scale(1.25); }
.nub.dragging { cursor: grabbing; }
.nub:focus-visible { outline: none; }
.nub:focus-visible::after { box-shadow: 0 0 0 3px #fff, 0 0 0 6px #0b0b0b; }

.hint {
  margin: 0;
  color: var(--muted);
  font-size: .85rem;
  text-align: center;
}

/* ---------- Panel ---------- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  position: sticky;
  top: var(--gutter);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--bg);
  box-shadow: inset 0 0 0 1px var(--line);
}

.tab {
  min-height: 40px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-weight: 700;
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab[aria-selected="true"] { background: var(--accent); color: var(--on-accent); }

.group { display: flex; flex-direction: column; gap: 12px; }

.section-title {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.text-section > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 28px;
  list-style: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.text-section > summary::-webkit-details-marker { display: none; }
.text-section > summary svg { color: var(--muted); transition: transform .2s ease; }
.text-section[open] > summary { margin-bottom: 12px; }
.text-section[open] > summary svg { transform: rotate(180deg); }

/* The recap only shows while the section is folded. */
.summary-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: right;
  font-size: .9rem;
  visibility: hidden;
}
.text-section:not([open]) .summary-value { visibility: visible; }

.text-input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  font-size: 1.05rem;
}
.text-input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.font-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  text-align: left;
  cursor: pointer;
}
@media (hover: hover) { .font-btn:hover { border-color: var(--text); } }
.font-btn-label { font-size: .85rem; color: var(--muted); }
.font-btn-name { flex: 1; text-align: right; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.font-btn svg { color: var(--muted); }

.panel-title {
  margin: 4px 0 -6px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.controls { display: flex; flex-direction: column; gap: 16px; min-height: 40px; }
.controls:empty::before {
  content: "Pick an effect to start.";
  color: var(--muted);
  font-size: .9rem;
}

.field { display: grid; gap: 8px; }
.field-head { display: flex; justify-content: space-between; font-size: .85rem; }
.field-head output { color: var(--muted); font-variant-numeric: tabular-nums; }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--bg);
  box-shadow: inset 0 0 0 1px var(--line);
}
.segmented button {
  min-height: 36px;
  border: 0;
  border-radius: 999px;
  background: none;
  font-size: .85rem;
  cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--text); color: var(--bg); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: var(--line); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--line); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--line);
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
}

.row { display: flex; align-items: center; gap: 16px; }
.row-secondary { justify-content: space-between; padding-top: 8px; border-top: 1px solid var(--line); }

/* ---------- Picker dialog ---------- */

dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: min(86dvh, 900px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 30px 80px rgb(0 0 0 / .35);
}
dialog::backdrop { background: rgb(0 0 0 / .45); backdrop-filter: blur(4px); }
dialog[open] { display: flex; flex-direction: column; animation: pop .22s ease; }

@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } }

.picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px 24px;
}
.picker-head h2 { margin: 0; font-size: 1.1rem; }

.fonts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  padding: 0 24px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.font-group {
  grid-column: 1 / -1;
  margin: 14px 0 0;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.font-tile {
  display: grid;
  gap: 6px;
  padding: 16px 14px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  transition: border-color .12s ease, transform .12s ease;
}
.font-preview {
  font-size: 30px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  line-height: 1.25;
  color: #000;
}
.font-label { font-size: .75rem; color: var(--muted); }
@media (hover: hover) { .font-tile:hover { border-color: var(--text); transform: translateY(-2px); } }
.font-tile[aria-current="true"] { border: 2px solid var(--text); padding: 15px 13px 11px; }

/* ---------- Fallback ---------- */

.fallback {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-content: center;
  padding: 24px;
  text-align: center;
  background: var(--bg);
}
.fallback[hidden] { display: none; }
.sad { font-size: 80px; margin: 0 0 16px; font-weight: 800; }

#print-image { display: none; }

/* ---------- Download menu ---------- */

.menu {
  position: fixed;
  inset: auto;
  margin: 0;
  padding: 6px;
  min-width: 240px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 20px 50px -20px rgb(0 0 0 / .3);
}
.menu button {
  display: grid;
  width: 100%;
  gap: 2px;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.menu button span { font-size: .8rem; color: var(--muted); }
@media (hover: hover) { .menu button:hover { background: var(--surface); } }

/* ---------- Tablet / mobile ---------- */

/* ---------- Tablet / phone: the sheet stays in view while you tweak ---------- */

@media (max-width: 900px) {
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

  .topbar { justify-content: center; padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: 4px; }
  .brand { display: flex; justify-content: center; }
  :root { --logo-h: 82px; }

  .text-section > summary { min-height: 44px; margin: -8px 0; }
  .text-section[open] > summary { margin-bottom: 4px; }

  /* Download, Share, Print sit in a bar at the bottom, in reach of the thumb. */
  .actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 8px;
    padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
    background: rgb(255 255 255 / .92);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }

  .layout { grid-template-columns: 1fr; gap: 12px; padding-top: 0; }

  .stage {
    position: sticky;
    top: 0;
    z-index: 3;
    margin: 0 calc(var(--gutter) * -1);
    padding: max(8px, env(safe-area-inset-top)) var(--gutter) 8px;
    background: var(--bg);
    transition: box-shadow .2s ease;
  }
  .stage.stuck { box-shadow: 0 12px 20px -18px rgb(0 0 0 / .45); }

  .frame { --max-h: 40dvh; }
  .panel { position: static; }
}

@media (max-width: 640px) {
  body { font-size: 16px; }
  .actions .btn { padding: 0 8px; font-size: .72rem; letter-spacing: .04em; }
  .panel { padding: 16px; gap: 16px; }
  .tab { letter-spacing: .03em; font-size: .7rem; }
  .fonts { grid-template-columns: 1fr 1fr; padding-inline: 16px; gap: 8px; }
  .font-tile { padding: 12px 10px 10px; }
  .font-preview { font-size: 22px; }
  .font-tile[aria-current="true"] { padding: 11px 9px 9px; }
  .picker-head { padding-left: 16px; }
  dialog { width: 100vw; max-width: 100vw; max-height: 92dvh; margin: auto 0 0; border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom); }
}

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

/* ---------- Print: only the artwork ---------- */

@media print {
  @page { margin: 15mm; }
  body { background: #fff; }
  body > *:not(#print-image) { display: none !important; }
  #print-image {
    display: block !important;
    max-width: 100%;
    max-height: 250mm;
    margin: 0 auto;
    object-fit: contain;
  }
}
