*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  --bg: #0c0d10;
  --surface: #131419;
  --raised: #1b1d24;
  --raised-2: #242731;
  --raised-3: #2d303b;
  --line: #262830;
  --line-strong: #383b47;
  --text: #f1f2f6;
  --muted: #a1a5b2;
  --faint: #6c707d;
  --accent: #ff7a59;
  --accent-hover: #ff8f73;
  --accent-ink: #1c0d07;
  --accent-soft: rgba(255, 122, 89, 0.14);
  --pink: #ff4f9a;
  --violet: #8b5cf6;
  --magic: linear-gradient(135deg, #ff8a5c 0%, #ff4f9a 52%, #8b5cf6 100%);
  --magic-soft: linear-gradient(135deg, rgba(255, 138, 92, 0.18), rgba(255, 79, 154, 0.16) 52%, rgba(139, 92, 246, 0.2));
  --radius-lg: 22px;
  --radius: 16px;
  --radius-sm: 11px;
  --topnav-h: 60px;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body { overflow: hidden; overscroll-behavior: none; }

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }

svg.i {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
svg.i--fill { fill: currentColor; stroke: none; }

/* ---------- shell ---------- */

.app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.topnav {
  display: none;
  align-items: center; gap: 28px;
  height: var(--topnav-h);
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 13, 16, 0.92);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 16px; letter-spacing: -0.01em; }
.brand__mark { display: grid; grid-template-columns: 9px 7px; grid-template-rows: 1fr 1fr; gap: 2px; width: 18px; height: 20px; }
.brand__mark i { border-radius: 2.5px; background: var(--accent); }
.brand__mark i:first-child { grid-row: 1 / 3; }
.brand__mark i:nth-child(2) { opacity: 0.65; }
.brand__mark i:nth-child(3) { opacity: 0.35; }
.topnav__links { display: flex; gap: 6px; }
.topnav__links a {
  padding: 8px 14px; border-radius: 999px;
  color: var(--muted); font-weight: 600; font-size: 14px;
}
.topnav__links a:hover { color: var(--text); background: var(--raised); }
.topnav__links a[aria-current="page"] { color: var(--text); background: var(--raised-2); }
.avatar-btn {
  margin-left: auto;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--magic);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px;
}

.topnav { grid-row: 1; }
.views { position: relative; min-height: 0; grid-row: 2; }
.view {
  position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 24px);
}
.view.is-entering { animation: view-in 0.22s ease-out; }
@keyframes view-in { from { opacity: 0; transform: translateY(8px); } }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  border-top: 1px solid var(--line);
  background: rgba(14, 15, 19, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--faint); font-size: 10.5px; font-weight: 600;
}
.tabbar a[aria-current="page"] { color: var(--text); }
.tabbar__icon svg.i { width: 23px; height: 23px; }
.tabbar__create .tabbar__icon {
  display: grid; place-items: center;
  width: 44px; height: 32px; margin-bottom: 1px;
  border-radius: 12px;
  background: var(--magic); color: #fff;
  box-shadow: 0 6px 18px rgba(255, 79, 154, 0.35);
}
.tabbar__create { color: var(--text) !important; }
.tabbar__create svg.i { width: 20px; height: 20px; stroke-width: 2.4; }

/* Focused flows take the whole screen on phones. */
.app.is-focused .tabbar { display: none; }
.app.is-focused .view { padding-bottom: calc(var(--safe-b) + 24px); }

@media (min-width: 900px) {
  .topnav { display: flex; }
  .tabbar { display: none; }
  .view { padding-bottom: 48px; }
  .app.is-focused .topnav { display: none; }
}

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 900px) { .wrap { padding: 0 32px; } }

/* ---------- type ---------- */

.eyebrow { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.h1 { font-size: clamp(28px, 7vw, 46px); line-height: 1.08; letter-spacing: -0.03em; font-weight: 800; text-wrap: balance; }
.h2 { font-size: clamp(22px, 5vw, 30px); line-height: 1.15; letter-spacing: -0.02em; font-weight: 800; text-wrap: balance; }
.h3 { font-size: 18px; line-height: 1.25; letter-spacing: -0.01em; font-weight: 750; }
.lead { color: var(--muted); font-size: 16px; text-wrap: pretty; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.magic-text { background: var(--magic); -webkit-background-clip: text; background-clip: text; color: transparent; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px;
  border: 1px solid transparent; border-radius: 999px;
  font-weight: 700; font-size: 15px; white-space: nowrap;
  transition: transform 0.12s, background-color 0.15s, border-color 0.15s, opacity 0.15s;
  user-select: none; -webkit-user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn--magic { background: var(--magic); color: #fff; box-shadow: 0 10px 28px rgba(255, 79, 154, 0.28); }
.btn--magic:hover:not(:disabled) { filter: brightness(1.06); }
.btn--secondary { background: var(--raised-2); border-color: var(--line-strong); }
.btn--secondary:hover:not(:disabled) { background: var(--raised-3); }
.btn--ghost { background: transparent; border-color: var(--line-strong); }
.btn--ghost:hover:not(:disabled) { background: var(--raised); }
.btn--quiet { background: transparent; color: var(--muted); }
.btn--quiet:hover:not(:disabled) { color: var(--text); background: var(--raised); }
.btn--small { min-height: 36px; padding: 0 14px; font-size: 13.5px; }
.btn--block { width: 100%; }
.btn--lg { min-height: 54px; padding: 0 26px; font-size: 16.5px; }
.btn .i { width: 18px; height: 18px; }

.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 42px; height: 42px;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--text);
}
.icon-btn:hover:not(:disabled) { background: var(--raised); }
.icon-btn--filled { background: var(--raised-2); }
.icon-btn[aria-pressed="true"] { color: var(--accent); }

.link-btn { padding: 0; border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 700; }
.link-btn:hover { text-decoration: underline; }

/* ---------- chips ---------- */

.chip-row {
  display: flex; gap: 8px;
  overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px; padding: 2px 16px 6px;
  scroll-padding-inline: 16px;
}
.chip-row::-webkit-scrollbar { display: none; }
@media (min-width: 900px) { .chip-row { margin: 0; padding: 2px 0 6px; flex-wrap: wrap; } }
.chip {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  height: 38px; padding: 0 15px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--raised); color: var(--text);
  font-size: 14px; font-weight: 600; white-space: nowrap;
}
.chip:hover { background: var(--raised-2); }
.chip[aria-pressed="true"] { border-color: transparent; background: var(--text); color: #111; }
.chip--small { height: 32px; padding: 0 12px; font-size: 13px; }
.chip--magic[aria-pressed="true"] { background: var(--magic); color: #fff; }
.chip__x { margin-right: -4px; opacity: 0.6; }

/* ---------- headers ---------- */

.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: calc(var(--safe-t) + 6px) 8px 6px;
  background: linear-gradient(var(--bg) 70%, rgba(12, 13, 16, 0));
}
.appbar__title { flex: 1; min-width: 0; font-weight: 750; font-size: 16px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar__side { display: flex; align-items: center; gap: 4px; min-width: 42px; }
.appbar__side--end { justify-content: flex-end; }
@media (min-width: 900px) { .appbar { padding: 12px 24px 8px; } }

.section { margin-top: 28px; }
.section__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

/* ---------- home ---------- */

.home-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 14px) 16px 4px;
}
@media (min-width: 900px) { .home-top { display: none; } }
.home-hero { padding: 18px 0 6px; }
.home-hero .lead { margin-top: 10px; max-width: 560px; }
@media (min-width: 900px) { .home-hero { padding: 48px 0 12px; } }

.create-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 22px; }
@media (min-width: 900px) { .create-grid { grid-template-columns: 1.6fr 1fr 1fr; gap: 16px; } }
.create-card {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 4px;
  min-height: 140px; padding: 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-lg);
  background: var(--raised); text-align: left;
  transition: transform 0.15s, border-color 0.15s;
}
.create-card:hover { border-color: var(--faint); }
.create-card:active { transform: scale(0.985); }
.create-card__icon { font-size: 26px; line-height: 1; margin-bottom: auto; }
.create-card__title { font-weight: 800; font-size: 18px; letter-spacing: -0.01em; }
.create-card__text { color: var(--muted); font-size: 13.5px; }
.create-card--magic {
  grid-column: 1 / -1;
  min-height: 210px;
  border: 0;
  background: var(--magic);
  color: #fff;
}
@media (min-width: 900px) { .create-card--magic { grid-column: auto; grid-row: span 1; min-height: 240px; } }
.create-card--magic .create-card__title { font-size: 26px; }
.create-card--magic .create-card__text { color: rgba(255, 255, 255, 0.86); font-size: 15px; }
.create-card--magic .cta {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 10px; padding: 9px 16px;
  border-radius: 999px; background: rgba(255, 255, 255, 0.95); color: #1a0f1f;
  font-weight: 750; font-size: 14px;
}
.magic-art {
  position: absolute; right: -10px; top: 14px;
  width: 46%; max-width: 230px; aspect-ratio: 3 / 4;
  transform: rotate(6deg);
  pointer-events: none;
}
.magic-art canvas { width: 100%; height: 100%; border-radius: 14px; box-shadow: 0 18px 40px rgba(40, 0, 40, 0.35); }
.create-card--magic .create-card__body { position: relative; max-width: 58%; }

.continue-card {
  display: flex; align-items: center; gap: 14px;
  padding: 12px; margin-top: 16px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
}
.continue-card canvas, .continue-card img { width: 54px; height: 72px; border-radius: 8px; object-fit: cover; background: var(--raised); }
.continue-card__text { flex: 1; min-width: 0; }
.continue-card__name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- template cards ---------- */

.row-scroll {
  display: flex; gap: 12px;
  overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px; padding: 4px 16px 12px;
  scroll-snap-type: x proximity; scroll-padding-inline: 16px;
}
.row-scroll::-webkit-scrollbar { display: none; }
.row-scroll > * { flex: none; scroll-snap-align: start; }
@media (min-width: 900px) { .row-scroll { margin: 0 -32px; padding: 4px 32px 12px; scroll-padding-inline: 32px; } }

.tgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; }
@media (min-width: 640px) { .tgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .tgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 22px 18px; } }
.tgrid--designs { gap: 18px 12px; }
@media (min-width: 1000px) { .tgrid--designs { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.tcard { position: relative; display: flex; flex-direction: column; gap: 8px; text-align: left; border: 0; padding: 0; background: none; min-width: 0; }
.row-scroll .tcard { width: 138px; }
@media (min-width: 900px) { .row-scroll .tcard { width: 176px; } }
.tcard__frame {
  position: relative; overflow: hidden;
  border-radius: 14px;
  background: var(--raised);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 10px 24px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
}
.tcard:hover .tcard__frame { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16), 0 14px 30px rgba(0, 0, 0, 0.45); }
.tcard:active .tcard__frame { transform: scale(0.98); }
.tcard__frame canvas { display: block; width: 100%; height: 100%; }
/* Labels and the heart sit at the bottom: most designs put their title on top. */
.tcard__label {
  position: absolute; left: 8px; bottom: 8px;
  display: inline-flex; align-items: center; gap: 4px;
  max-width: calc(100% - 16px);
  padding: 4px 9px; border-radius: 999px;
  background: rgba(10, 10, 14, 0.72); color: #fff;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-size: 11.5px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tcard__label--best { background: var(--magic); }
.tcard__label { max-width: calc(100% - 52px); }
.tcard__fav {
  position: absolute; right: 6px; bottom: 6px;
  display: grid; place-items: center;
  width: 32px; height: 32px; border: 0; border-radius: 50%;
  background: rgba(10, 10, 14, 0.55); color: #fff;
}
.tcard__fav[aria-pressed="true"] { color: #ff5d8f; }
.tcard__fav .i { width: 17px; height: 17px; }
.tcard__name { font-weight: 700; font-size: 14.5px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tcard__meta { color: var(--muted); font-size: 12.5px; margin-top: -6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tcard--skeleton .tcard__frame { background: linear-gradient(100deg, var(--raised) 30%, var(--raised-2) 50%, var(--raised) 70%) 0 0 / 300% 100%; animation: shimmer 1.3s ease-in-out infinite; }
@keyframes shimmer { to { background-position: -150% 0; } }

/* ---------- create (media selection) ---------- */

.create-empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 18px 12px 12px;
}
.dropzone {
  width: 100%; max-width: 560px;
  margin-top: 22px; padding: 30px 18px;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius-lg);
  background: var(--surface);
}
.dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .btn { margin-top: 4px; }
.intent-row { margin-top: 18px; }

.selection-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 6px 0 12px; }
.media-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
@media (min-width: 640px) { .media-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .media-grid { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; } }
.media-tile {
  position: relative; aspect-ratio: 1; overflow: hidden;
  border-radius: 10px; background: var(--raised);
  touch-action: pan-y; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.media-tile canvas, .media-tile img { display: block; width: 100%; height: 100%; object-fit: cover; }
.media-tile.is-waiting { background: linear-gradient(100deg, var(--raised) 30%, var(--raised-2) 50%, var(--raised) 70%) 0 0 / 300% 100%; animation: shimmer 1.2s ease-in-out infinite; }
.media-tile.is-dragging { opacity: 0.35; }
.media-tile.is-drop-target { box-shadow: inset 0 0 0 3px var(--accent); }
.media-tile.is-hero { box-shadow: inset 0 0 0 3px #ffd166; }
.media-tile__badge {
  position: absolute; left: 5px; bottom: 5px;
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 6px; border-radius: 6px;
  background: rgba(0, 0, 0, 0.66); color: #fff;
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.media-tile__badge .i { width: 10px; height: 10px; }
.media-tile__remove, .media-tile__star {
  position: absolute; top: 4px;
  display: grid; place-items: center;
  width: 28px; height: 28px; padding: 0; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, 0.6); color: #fff;
}
.media-tile__remove { right: 4px; }
.media-tile__star { left: 4px; }
.media-tile__star[aria-pressed="true"] { background: #ffd166; color: #332200; }
.media-tile__remove .i, .media-tile__star .i { width: 14px; height: 14px; stroke-width: 2.4; }
.media-tile__num {
  position: absolute; right: 5px; bottom: 5px;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}
.media-add-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  aspect-ratio: 1; border: 1.5px dashed var(--line-strong); border-radius: 10px;
  background: transparent; color: var(--muted); font-size: 12px; font-weight: 600;
}
.media-add-tile:hover { border-color: var(--accent); color: var(--text); }

.sticky-footer {
  position: sticky; bottom: 0; z-index: 5;
  margin-top: 18px;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: linear-gradient(rgba(12, 13, 16, 0), var(--bg) 30%);
}
.creating {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 54px; border-radius: 999px;
  background: var(--raised-2); color: var(--text); font-weight: 650;
}
.sparkle-spin { width: 20px; height: 20px; animation: sparkle 1.6s ease-in-out infinite; }
@keyframes sparkle { 50% { transform: rotate(90deg) scale(0.8); opacity: 0.6; } }

/* ---------- designs ---------- */

.designs-head { padding: 4px 0 6px; }
.designs-head .muted { margin-top: 6px; }
.topic-card {
  margin-top: 16px; padding: 16px;
  border-radius: var(--radius);
  background: var(--magic-soft);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.topic-card .chip-row { margin-top: 10px; }
.designs-actions {
  position: sticky; bottom: 0; z-index: 6;
  display: flex; gap: 10px; justify-content: center;
  padding: 14px 16px calc(14px + var(--safe-b));
  background: linear-gradient(rgba(12, 13, 16, 0), var(--bg) 35%);
}
.designs-actions .btn { flex: 1; max-width: 220px; }
.format-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--raised); color: var(--text);
  font-size: 13px; font-weight: 650;
}
.format-pill .shape { display: inline-block; border: 1.6px solid currentColor; border-radius: 2px; }

/* ---------- search ---------- */

.searchbar {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  height: 48px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--raised);
}
.searchbar:focus-within { border-color: var(--accent); }
.searchbar input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; font-size: 16px; }
.searchbar input::placeholder { color: var(--faint); }
.parsed { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; align-items: center; }
.tag-pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; background: var(--raised-2); font-size: 12px; font-weight: 650; color: var(--muted); }
.tag-pill b { color: var(--text); font-weight: 700; }
.facets { display: grid; gap: 18px; }
.facet h3 { margin-bottom: 8px; }
.facet .chip-row { flex-wrap: wrap; margin: 0; padding: 0; }
.empty-state { padding: 40px 12px; text-align: center; color: var(--muted); }

/* ---------- template preview ---------- */

.preview-layout { display: grid; gap: 20px; }
@media (min-width: 900px) { .preview-layout { grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 40px; align-items: start; padding-top: 12px; } }
.preview-stage { display: flex; justify-content: center; }
.preview-stage .tcard__frame { width: min(100%, 360px); }
@media (min-width: 900px) { .preview-stage .tcard__frame { width: 100%; } }
.preview-info { display: flex; flex-direction: column; gap: 12px; }
.format-list { display: flex; flex-wrap: wrap; gap: 6px; }
.action-row { display: flex; flex-wrap: wrap; gap: 10px; }

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

.view--editor { overflow: hidden; padding-bottom: 0 !important; }
.editor {
  position: absolute; inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
}
.editor__main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.editor__main .editor__stage { flex: 1; }
.editor__side { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--surface); }
.editor__bar {
  display: flex; align-items: center; gap: 4px;
  padding: calc(var(--safe-t) + 6px) 8px 6px;
}
.editor__name {
  flex: 1; min-width: 0;
  padding: 6px 8px; border: 0; border-radius: 8px; background: transparent;
  font-weight: 750; font-size: 15px; text-align: left;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.editor__name:hover { background: var(--raised); }
.editor__stage { position: relative; min-height: 0; margin: 4px 12px; }
.editor__stage canvas {
  position: absolute; inset: 0; margin: auto;
  display: block; border-radius: 6px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06);
  touch-action: none;
}
.editor__stage .stage-hint {
  position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%);
  padding: 4px 10px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 12px; pointer-events: none;
  white-space: nowrap;
}
.editor__ai { display: flex; gap: 8px; align-items: center; padding: 8px 12px 4px; overflow-x: auto; scrollbar-width: none; }
/* Centred when everything fits, scrollable from the start when it doesn't. */
.editor__ai > :first-child, .context-bar > :first-child { margin-left: auto; }
.editor__ai > :last-child, .context-bar > :last-child { margin-right: auto; }
.editor__ai::-webkit-scrollbar { display: none; }
.ai-btn {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  height: 36px; padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 999px;
  background: var(--magic-soft); color: var(--text);
  font-size: 13.5px; font-weight: 700;
}
.ai-btn:hover { border-color: rgba(255, 255, 255, 0.25); }
.ai-btn .i { width: 16px; height: 16px; }
.context-bar { display: flex; gap: 6px; padding: 6px 12px 2px; overflow-x: auto; scrollbar-width: none; }
.context-bar::-webkit-scrollbar { display: none; }
.context-bar .btn { flex: none; }
.pages-strip { display: flex; gap: 8px; padding: 6px 12px 2px; overflow-x: auto; scrollbar-width: none; align-items: center; }
.pages-strip::-webkit-scrollbar { display: none; }
.page-thumb { position: relative; flex: none; padding: 0; border: 0; background: none; border-radius: 6px; }
.page-thumb canvas { display: block; height: 58px; border-radius: 6px; box-shadow: 0 0 0 1px var(--line-strong); }
.page-thumb[aria-pressed="true"] canvas { box-shadow: 0 0 0 2px var(--accent); }
.page-thumb span { position: absolute; left: 4px; bottom: 3px; font-size: 10px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px #000; }
.page-add { flex: none; width: 34px; height: 58px; border: 1.5px dashed var(--line-strong); border-radius: 6px; background: none; color: var(--muted); }

.toolbar {
  display: flex; justify-content: space-around; gap: 2px;
  padding: 6px 4px calc(6px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: var(--surface);
  overflow-x: auto; scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
@media (max-width: 899px) {
  /* Phones: an open panel gets the room; the AI row comes back when it closes. */
  .editor.has-panel .editor__ai { display: none; }
}
.editor__playback { display: flex; gap: 2px; flex: none; margin-right: 2px; }
.editor__playback .icon-btn { width: 36px; height: 36px; background: var(--raised); }
.editor__playback .icon-btn .i { width: 17px; height: 17px; }
.editor__bar .icon-btn { width: 38px; height: 38px; }
.editor__bar .format-pill { flex: none; max-width: 112px; padding: 0 10px; }
.format-pill__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 420px) {
  .editor__bar .format-pill__label { display: none; }
  .editor__bar .format-pill { padding: 0 9px; }
  .editor__export { padding: 0 12px; }
}
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 3px; flex: 1 0 auto;
  min-width: 50px; padding: 6px 2px;
  border: 0; border-radius: 12px; background: none;
  color: var(--muted); font-size: 11px; font-weight: 650;
}
.tool .i { width: 22px; height: 22px; }
.tool[aria-pressed="true"] { color: var(--text); background: var(--raised-2); }

.panel {
  position: relative;
  max-height: 46svh; overflow-y: auto; overscroll-behavior: contain;
  padding: 4px 16px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.panel__head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0 8px; background: var(--surface); }
.panel__title { font-weight: 800; font-size: 15px; }
.panel__tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 10px; }
.panel__tabs::-webkit-scrollbar { display: none; }
.panel__section { margin-top: 14px; }
.panel__section:first-child { margin-top: 0; }
.panel__label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }

@media (min-width: 900px) {
  .editor {
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .editor__bar { grid-column: 1 / -1; padding: 10px 16px; border-bottom: 1px solid var(--line); }
  .editor__main { grid-column: 1; grid-row: 2; padding-bottom: 12px; }
  .editor__main .editor__stage { margin: 24px 24px 8px; }
  .editor__side { grid-column: 2; grid-row: 2; border-left: 1px solid var(--line); }
  /* Desktop: tools on top, the open panel fills the column below. */
  .editor__side .toolbar { order: -1; justify-content: stretch; border-top: 0; border-bottom: 1px solid var(--line); padding: 8px 6px; }
  .editor__side .tool { flex: 1 1 0; min-width: 0; font-size: 10.5px; }
  .editor__side .tool span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .editor__side .panel { flex: 1; max-height: none; border-top: 0; }
}

/* ---------- form controls ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field__label { color: var(--muted); font-size: 12.5px; font-weight: 650; }
.field__help { color: var(--faint); font-size: 12px; text-wrap: pretty; }
.field__help:empty { display: none; }
.input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line-strong); border-radius: 11px;
  background: var(--raised); color: var(--text); font-size: 16px;
}
.input::placeholder { color: var(--faint); }
.input:focus { outline: none; border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 70px; line-height: 1.4; }
select.input { padding-right: 8px; }
.input-row { display: flex; align-items: flex-start; gap: 8px; }
.input-row .input { flex: 1; min-width: 0; }
.range { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.range__label { width: 92px; flex: none; color: var(--muted); font-size: 13px; font-weight: 600; }
.range input[type="range"] { flex: 1; min-width: 0; height: 32px; accent-color: var(--accent); }
.range__value { width: 38px; text-align: right; color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }

.segmented {
  display: flex; gap: 2px; padding: 3px;
  border: 1px solid var(--line-strong); border-radius: 12px;
  background: var(--bg);
}
.segmented button {
  flex: 1; min-height: 34px; padding: 0 10px;
  border: 0; border-radius: 9px;
  background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 650; white-space: nowrap;
}
.segmented button[aria-pressed="true"] { background: var(--raised-3); color: var(--text); }

.switch { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; color: var(--text); font-size: 14px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track { position: relative; flex: none; width: 44px; height: 26px; border-radius: 999px; background: var(--line-strong); transition: background-color 0.15s; }
.switch__track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }

.mic-btn {
  flex: none; display: grid; place-items: center;
  width: 44px; height: 44px;
  border: 1px solid var(--line-strong); border-radius: 11px;
  background: var(--raised); color: var(--muted);
}
.mic-btn.is-listening { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); animation: mic-pulse 1.4s ease-in-out infinite; }
@keyframes mic-pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 122, 89, 0.14); } }

/* ---------- pickers ---------- */

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 8px; }
.swatch {
  aspect-ratio: 1; border: 0; border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text); }
.swatch--custom { display: grid; place-items: center; background: conic-gradient(#f44, #fd4, #4f4, #4df, #44f, #f4f, #f44); position: relative; overflow: hidden; }
.swatch--custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; }
.tile-grid--wide { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
.tile {
  position: relative; display: flex; flex-direction: column; gap: 5px; align-items: stretch;
  padding: 0; border: 0; background: none; color: var(--muted); font-size: 11.5px; font-weight: 600; text-align: center;
}
.tile canvas { display: block; width: 100%; aspect-ratio: 9 / 16; border-radius: 10px; box-shadow: 0 0 0 1px var(--line-strong); background: var(--raised); }
.tile--square canvas { aspect-ratio: 1; }
.tile[aria-pressed="true"] canvas { box-shadow: 0 0 0 2px var(--accent); }
.tile[aria-pressed="true"] { color: var(--text); }
.tile span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.sticker-btn { aspect-ratio: 1; padding: 4px; border: 0; border-radius: 12px; background: var(--raised); }
.sticker-btn:hover { background: var(--raised-2); }
.sticker-btn canvas { display: block; width: 100%; height: 100%; }

.font-list { display: grid; gap: 6px; }
.font-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 48px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--raised); color: var(--text); text-align: left;
}
.font-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.font-btn__name { font-size: 21px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.font-btn__cat { color: var(--faint); font-size: 11px; font-family: var(--font); flex: none; }

.text-layers { display: grid; gap: 6px; margin-bottom: 12px; }
.text-layer-btn {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--raised); text-align: left;
}
.text-layer-btn[aria-pressed="true"] { border-color: var(--accent); }
.text-layer-btn b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.add-text-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.add-text-btn { min-height: 64px; border: 1px solid var(--line); border-radius: 12px; background: var(--raised); display: grid; place-items: center; padding: 6px; }
.add-text-btn:hover { background: var(--raised-2); }

.track-list { display: grid; gap: 6px; }
.track {
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--raised); text-align: left;
}
.track[aria-pressed="true"] { border-color: var(--accent); }
.track__art { width: 42px; height: 42px; border-radius: 10px; background: var(--magic); display: grid; place-items: center; color: #fff; flex: none; }
.track__text { flex: 1; min-width: 0; }
.track__name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track__meta { color: var(--faint); font-size: 12px; }

/* ---------- export ---------- */

.export-layout { display: grid; gap: 20px; padding-top: 6px; }
@media (min-width: 900px) { .export-layout { grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 40px; align-items: start; } }
.export-stage { display: flex; justify-content: center; }
.export-stage canvas { display: block; max-width: 100%; max-height: 58svh; border-radius: 10px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55); }
.export-options { display: grid; gap: 4px; }
.progress { margin-top: 8px; }
.progress__track { height: 8px; overflow: hidden; border-radius: 999px; background: var(--raised-2); }
.progress__bar { width: 0; height: 100%; background: var(--magic); transition: width 0.2s linear; }
.progress__row { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- projects ---------- */

.project-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; }
@media (min-width: 640px) { .project-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .project-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.project-card { position: relative; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.project-card__open { padding: 0; border: 0; background: none; text-align: left; display: flex; flex-direction: column; gap: 6px; }
.project-card__thumb { aspect-ratio: 9 / 16; width: 100%; border-radius: 14px; background: var(--raised) center / cover no-repeat; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06); }
.project-card__name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-card__meta { color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.project-card__menu { position: absolute; right: 6px; top: 6px; background: rgba(0, 0, 0, 0.55); color: #fff; width: 34px; height: 34px; }

/* ---------- profile ---------- */

.profile-head { display: flex; align-items: center; gap: 14px; padding: 18px 0 4px; }
.profile-head .avatar-btn { margin: 0; width: 56px; height: 56px; font-size: 22px; }
.list-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 6px 16px; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row__text { min-width: 0; }
.list-row__sub { color: var(--faint); font-size: 12.5px; }

/* ---------- sheets and dialogs ---------- */

.sheet-layer {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  animation: fade-in 0.15s ease-out;
}
@keyframes fade-in { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 520px; max-height: 88svh; overflow-y: auto;
  padding: 10px 18px calc(18px + var(--safe-b));
  border-radius: 22px 22px 0 0;
  background: var(--raised);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
  animation: sheet-up 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.sheet::before { content: ""; display: block; width: 38px; height: 5px; margin: 0 auto 12px; border-radius: 3px; background: var(--line-strong); }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0.5; } }
@media (min-width: 700px) {
  .sheet-layer { align-items: center; padding: 24px; }
  .sheet { border-radius: 22px; padding-bottom: 20px; }
  .sheet::before { display: none; }
}
.sheet__title { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; margin-bottom: 6px; }
.sheet__text { color: var(--muted); margin-bottom: 14px; text-wrap: pretty; }
.sheet__actions { display: grid; gap: 8px; margin-top: 12px; }
.sheet__meta { margin-top: 8px; color: var(--faint); font-size: 12px; text-align: center; font-variant-numeric: tabular-nums; }
.menu-list { display: grid; gap: 2px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; min-height: 50px; padding: 0 12px;
  border: 0; border-radius: 12px; background: transparent; color: var(--text); font-weight: 600; text-align: left;
}
.menu-item:hover { background: var(--raised-2); }
.menu-item--danger { color: #ff6b6b; }
.format-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.format-option {
  display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 8px 12px;
  border: 1px solid var(--line-strong); border-radius: 14px; background: var(--raised-2); text-align: left;
}
.format-option[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.format-option .shape { flex: none; border: 2px solid currentColor; border-radius: 3px; opacity: 0.85; }
.format-option b { display: block; font-size: 14px; }
.format-option small { color: var(--faint); font-size: 11.5px; }

/* ---------- overlays ---------- */

.drop-veil {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center; padding: 16px;
  background: rgba(12, 13, 16, 0.8);
  opacity: 0; pointer-events: none; transition: opacity 0.15s;
}
.drop-veil div { padding: 28px 36px; border: 2px dashed var(--accent); border-radius: 18px; font-size: 18px; font-weight: 700; }
.drop-veil.is-visible { opacity: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); z-index: 70;
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 16px;
  transform: translate(-50%, 12px);
  border-radius: 14px;
  background: #f1f2f6; color: #111; font-weight: 600; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.app.is-focused ~ .toast { bottom: calc(var(--safe-b) + 90px); }

.install-tip {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); z-index: 45;
  display: flex; align-items: center; gap: 12px;
  width: min(460px, calc(100vw - 24px));
  padding: 12px 14px;
  transform: translateX(-50%);
  border: 1px solid var(--line-strong); border-radius: 14px;
  background: var(--raised-2); box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
}
.install-tip p { font-size: 13px; line-height: 1.4; }
.install-tip .link-btn { flex: none; padding: 8px; }

.spinner {
  width: 18px; height: 18px; flex: none;
  border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (pointer: coarse) {
  .chip { height: 40px; }
  .segmented button { min-height: 38px; }
}

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

.btn.is-on { border-color: var(--accent); color: var(--accent); }
.more-toggle { display: flex; align-items: center; gap: 6px; width: 100%; min-height: 40px; margin-top: 10px; padding: 0; border: 0; background: none; color: var(--muted); font-size: 13px; font-weight: 700; }
.more-toggle .i { width: 16px; height: 16px; transition: transform 0.15s; }
.more-toggle[aria-expanded="true"] .i { transform: rotate(180deg); }
.note-card { padding: 12px 14px; border-radius: 12px; background: var(--raised); color: var(--muted); font-size: 13px; text-wrap: pretty; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.media-pick { position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 10px; overflow: hidden; background: var(--raised); }
.media-pick canvas { display: block; width: 100%; height: 100%; }
.media-pick.is-used::after { content: "✓"; position: absolute; right: 4px; top: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 800; display: grid; place-items: center; }
.media-pick.is-missing { outline: 2px dashed #ff6b6b; outline-offset: -2px; }
.media-pick .media-tile__badge { font-size: 10px; }
.media-panel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.color-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.color-row input[type="color"] { width: 44px; height: 34px; padding: 0; border: 1px solid var(--line-strong); border-radius: 8px; background: none; }
