/* Layout: one column — top bar, title, the live cat with its name, undo · Verras me · redo, save and export, the tabbed editor, examples and the gallery */
:root {
  --bg: #17110e;
  --surface: #241a15;
  --surface-2: #2f231c;
  --line: #4a3a30;
  --accent: #ff6b2c;
  --accent-text: #ff8a55;
  --accent-deep: #b8461c;
  --on-accent: #17110e;
  --focus: #ffbd4a;
  --text: #f7ede1;
  --muted: #b5a191;
  --bust: #c0392b;
  --on-bust: #ffffff;
  --danger-text: #ff9a8f;
  --glow: rgba(255, 107, 44, .16);
  --scrim: rgba(8, 5, 4, .6);
  --shadow: rgba(0, 0, 0, .5);
  --toast-bg: #f3e7cf;
  --toast-ink: #2b1d14;
  --switch-off: #4a3a30;
  --switch-knob: #f7ede1;
  --stage-ring: rgba(255, 237, 214, .14);
  --heart: #ff5d7a;
  --display: 'Bagel Fat One', 'Arial Black', system-ui, sans-serif;
  --body: 'Rethink Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { overflow-x: hidden; }
body {
  margin: 0; min-height: 100vh; overflow-x: hidden;
  background: radial-gradient(130% 55% at 50% 105%, var(--glow), transparent 62%), var(--bg);
  color: var(--text); font-family: var(--body); font-size: 16px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible, .stage:focus-visible, .swatch:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
#app {
  max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 14px;
}

/* ---------- buttons and controls ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer; width: 100%; min-height: 52px; padding: 0 18px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; font-size: 17px;
}
.btn:active { transform: translateY(2px); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn svg { flex: none; width: 20px; height: 20px; }
.btn.primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 3px 0 var(--accent-deep); }
.btn.ghost { background: var(--surface); color: var(--text); border: 1.5px solid var(--line); }
.btn.bust { background: var(--bust); color: var(--on-bust); }
.btn.big { min-height: 60px; font-family: var(--display); font-weight: 400; font-size: 23px; }
.icon-btn { appearance: none; flex: none; width: 46px; height: 46px; border-radius: 14px; cursor: pointer; border: 1.5px solid var(--line); background: var(--surface); color: var(--text); display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:disabled { opacity: .4; cursor: default; }
.segmented { display: inline-flex; flex: none; gap: 2px; padding: 3px; border-radius: 13px; background: var(--bg); max-width: 100%; }
.segmented button { appearance: none; border: 0; cursor: pointer; min-height: 44px; padding: 0 12px; border-radius: 10px; background: none; color: var(--muted); font-weight: 700; font-size: 15px; }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--on-accent); }
.segmented.wrap { display: flex; flex-wrap: wrap; width: 100%; }
.segmented.wrap button { flex: 1 1 0; min-width: 0; padding: 0 6px; }
.switch { position: relative; flex: none; width: 52px; height: 32px; border-radius: 999px; background: var(--switch-off); transition: background-color .2s ease; }
.switch::after { content: ''; position: absolute; left: 4px; top: 4px; width: 24px; height: 24px; border-radius: 50%; background: var(--switch-knob); box-shadow: 0 2px 4px var(--shadow); transition: translate .2s ease; }
[aria-checked="true"] > .switch { background: var(--accent); }
[aria-checked="true"] > .switch::after { translate: 20px 0; }

/* ---------- top ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; }
.top-actions { display: flex; gap: 8px; flex: none; }
.back-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; color: var(--muted); font-weight: 700; text-decoration: none; }
.hero { display: grid; gap: 12px; }
.hero h1 { font-family: var(--display); font-weight: 400; font-size: clamp(36px, 11vw, 52px); line-height: 1; }
.box { background: var(--surface); border-radius: 18px; padding: 14px; display: grid; gap: 14px; min-width: 0; }
.box h2 { font-size: 17px; font-weight: 800; padding-left: 2px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 14.5px; font-weight: 600; }
.hint b { color: var(--text); }
.label { font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

/* ---------- stage ---------- */
.stage-card { position: relative; display: grid; gap: 8px; justify-items: center; min-width: 0; }
.name-tag {
  appearance: none; border: 0; cursor: pointer; position: relative; z-index: 2; margin-bottom: -26px; max-width: calc(100% - 40px);
  min-height: 48px; padding: 4px 22px 6px; border-radius: 999px; background: var(--toast-bg); color: var(--toast-ink);
  font-family: var(--display); font-weight: 400; font-size: 26px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  box-shadow: 0 6px 18px var(--shadow); rotate: -2deg;
}
.name-tag.empty { opacity: .85; }
.stage {
  position: relative; width: 100%; aspect-ratio: 1; max-height: 62vh; border-radius: 28px; overflow: hidden; cursor: grab;
  background: var(--surface); box-shadow: 0 0 0 2px var(--stage-ring), 0 18px 40px var(--shadow);
  touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.stage:active { cursor: grabbing; }
.stage .cat-svg { display: block; width: 100%; height: 100%; }
.stage-hint { color: var(--muted); font-size: 14px; font-weight: 600; text-align: center; }
.hearts { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: 28px; }
.heart { position: absolute; width: 26px; height: 26px; margin: -13px 0 0 -13px; color: var(--heart); fill: currentColor; animation: float-up 1.3s cubic-bezier(.2, .7, .4, 1) forwards; }
.heart svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .25)); }
.boop-bubble {
  position: absolute; translate: -50% -100%; padding: 4px 12px; border-radius: 999px; background: #ffffff; color: #3a2418;
  font-family: var(--display); font-size: 22px; box-shadow: 0 4px 12px rgba(0, 0, 0, .25); animation: boop-pop 1.1s ease forwards; white-space: nowrap;
}
.stage-bar { display: grid; grid-template-columns: 52px 1fr 52px; gap: 10px; align-items: center; }
.stage-bar .icon-btn { width: 52px; height: 52px; border-radius: 16px; }
.save-bar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.save-bar .btn { min-height: 50px; padding: 0 6px; font-size: 15px; gap: 6px; }
.save-bar .btn svg { width: 18px; height: 18px; }

/* ---------- editor ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs button {
  appearance: none; flex: 1 1 auto; min-height: 44px; padding: 0 12px; border-radius: 12px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--bg); color: var(--muted); font-weight: 800; font-size: 14.5px;
}
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.panel { display: grid; gap: 16px; min-width: 0; }
.panel:focus { outline: none; }
.field { display: grid; gap: 8px; min-width: 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  appearance: none; position: relative; flex: none; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 3px solid var(--surface); background: var(--sw); box-shadow: 0 0 0 1.5px var(--line); display: grid; place-items: center; color: var(--text);
}
.swatch[aria-checked="true"], .swatch.custom.on { box-shadow: 0 0 0 3px var(--accent); }
.swatch[aria-checked="true"]::after { content: ''; width: 12px; height: 12px; border-radius: 50%; background: #ffffff; box-shadow: 0 0 0 2px rgba(0, 0, 0, .35); }
.swatch.custom { background: conic-gradient(#ff6b6b, #ffd36b, #8fe3b0, #6bc4ff, #b9a3ff, #ff8fab, #ff6b6b); }
.swatch.custom.on { background: var(--sw); }
.swatch.custom svg { width: 20px; height: 20px; color: #1a1210; filter: drop-shadow(0 0 2px #ffffff); pointer-events: none; }
.swatch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.thumbs { display: grid; gap: 8px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.thumbs.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.thumb, .preset {
  appearance: none; position: relative; min-width: 0; padding: 4px 4px 6px; border-radius: 16px; cursor: pointer;
  border: 2px solid var(--line); background: var(--bg); display: grid; gap: 4px; justify-items: center; color: var(--text);
}
.thumb[aria-checked="true"], .thumb[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--bg)); }
.thumb-art { display: block; width: 100%; aspect-ratio: 1; border-radius: 12px; overflow: hidden; }
.thumb-art .cat-svg { display: block; width: 100%; height: 100%; }
.thumb-label { max-width: 100%; font-size: 13px; font-weight: 700; line-height: 1.2; text-align: center; hyphens: manual; }
.thumb-check { position: absolute; top: -6px; right: -6px; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: none; place-items: center; box-shadow: 0 2px 6px var(--shadow); }
.thumb-check svg { width: 16px; height: 16px; }
.thumb[aria-pressed="true"] .thumb-check { display: grid; }
.toggles { display: grid; gap: 6px; }
.name-input {
  width: 100%; min-width: 0; height: 52px; padding: 0 14px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: 18px; font-weight: 700;
}
.name-input::placeholder { color: var(--muted); font-weight: 500; }

/* ---------- presets and gallery ---------- */
.presets { display: grid; gap: 8px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.preset { padding: 3px 3px 5px; border-radius: 14px; }
.preset .thumb-art { border-radius: 10px; }
.preset .thumb-label { font-size: 13px; }
.gallery { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.g-item { min-width: 0; display: grid; gap: 6px; padding: 6px; border-radius: 18px; background: var(--bg); }
.g-thumb { appearance: none; border: 0; padding: 0; cursor: pointer; display: block; width: 100%; aspect-ratio: 1; border-radius: 13px; overflow: hidden; background: var(--surface-2); }
.g-thumb .cat-svg { display: block; width: 100%; height: 100%; }
.g-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; min-width: 0; }
.g-name { grid-column: 1 / -1; min-width: 0; padding: 0 4px; text-align: center; font-weight: 800; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-btn { appearance: none; width: 100%; height: 44px; border: 0; border-radius: 12px; background: var(--surface); color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.mini-btn svg { width: 20px; height: 20px; }
.mini-btn.danger { color: var(--danger-text); }
.g-empty { grid-column: 1 / -1; color: var(--muted); font-weight: 600; font-size: 15px; padding: 14px; border-radius: 14px; border: 2px dashed var(--line); text-align: center; }
.g-empty b { color: var(--text); }

/* ---------- sheets, modal, toast ---------- */
.backdrop { position: fixed; inset: 0; z-index: 20; background: var(--scrim); animation: fade .2s ease; }
.sheet {
  position: fixed; z-index: 21; bottom: 0; left: 50%; translate: -50% 0; width: min(100%, 560px); max-height: 86%; overflow-y: auto;
  border-radius: 22px 22px 0 0; background: var(--surface); display: grid; gap: 14px;
  padding-top: 10px; padding-left: max(18px, env(safe-area-inset-left, 0px)); padding-right: max(18px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -10px 40px var(--shadow); animation: rise .25s cubic-bezier(.2, .9, .3, 1);
}
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); justify-self: center; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h3 { font-family: var(--display); font-weight: 400; font-size: 24px; }
.close-btn { appearance: none; border: 0; width: 44px; height: 44px; border-radius: 12px; background: var(--surface-2); color: var(--text); cursor: pointer; display: grid; place-items: center; }
.close-btn svg { width: 18px; height: 18px; }
.menu-list { display: grid; gap: 6px; }
.menu-list:empty { display: none; }
.menu-item {
  appearance: none; border: 0; cursor: pointer; width: 100%; min-height: 54px; padding: 8px 14px; border-radius: 14px;
  background: var(--surface-2); color: var(--text); text-align: left; font-weight: 700; font-size: 16.5px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.menu-item.static { cursor: default; }
.menu-item[role="switch"] { flex-wrap: nowrap; }
.menu-sub { display: block; color: var(--muted); font-size: 14px; font-weight: 600; }
.menu-item.home { color: var(--accent-text); }
.menu-item.toggle { background: var(--bg); }
.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: var(--scrim); animation: fade .2s ease; }
.modal {
  position: fixed; z-index: 41; left: 50%; top: 50%; translate: -50% -50%; width: min(calc(100% - 48px), 360px); margin: 0;
  padding: 20px; border-radius: 20px; background: var(--surface); box-shadow: 0 20px 60px var(--shadow);
  display: grid; gap: 10px; animation: pop .2s ease;
}
.modal h3 { font-family: var(--display); font-weight: 400; font-size: 24px; line-height: 1.1; overflow-wrap: anywhere; }
.modal p { color: var(--muted); }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.modal-actions .btn { min-height: 48px; font-size: 16px; padding: 0 10px; }
.toast {
  position: fixed; z-index: 30; left: 50%; translate: -50% 0; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: min(calc(100% - 32px), 528px); display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 16px; background: var(--toast-bg); color: var(--toast-ink);
  box-shadow: 0 12px 30px var(--shadow); font-weight: 600; font-size: 15px; min-height: 52px;
}
.toast span { flex: 1; min-width: 0; }

/* ---------- the living cat ---------- */
.stage .cat-breathe { animation: breathe 3.8s ease-in-out infinite; }
.stage .cat-head { animation: head-tilt 9s ease-in-out infinite; }
.stage .eye { transform-box: fill-box; transform-origin: center; animation: blink 5.2s infinite; }
.stage .ear-twitch { animation: twitch 7.5s ease-in-out infinite; }
.stage .tail-swish { animation: swish 4.2s ease-in-out infinite alternate; }
.stage .rain { animation: rain .7s linear infinite; }
.stage .twinkle { animation: twinkle 2.4s ease-in-out infinite alternate; }
.stage .confetti-bit { animation: sway 2.6s ease-in-out infinite alternate; }
.stage.happy .eyes-open { display: none; }
.stage.happy .eyes-happy { display: inline; }
.stage.happy .cat-breathe { animation: purr .14s linear infinite; }
.stage.happy .cat-head { animation: nuzzle 1.4s ease-in-out infinite; }
.stage.happy .tail-swish { animation-duration: 1.1s; }
.stage .nose { transform-box: fill-box; transform-origin: center; }
.stage.boop .nose { animation: boop .45s cubic-bezier(.3, 1.6, .5, 1); }
.stage.shuffling .cat-svg { animation: shuffle .16s ease-in-out infinite alternate; }
.stage.landed .cat-svg { animation: land .6s cubic-bezier(.3, 1.5, .5, 1); }

@keyframes breathe { 50% { transform: scale(1.012, 1.024); } }
@keyframes head-tilt { 0%, 30%, 100% { transform: rotate(0deg); } 40%, 52% { transform: rotate(-3deg); } 62%, 74% { transform: rotate(2deg); } }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 95.5% { transform: scaleY(.08); } }
@keyframes twitch { 0%, 86%, 100% { transform: rotate(0deg); } 88% { transform: rotate(-12deg); } 90% { transform: rotate(2deg); } 92% { transform: rotate(-7deg); } 94% { transform: rotate(0deg); } }
@keyframes swish { from { transform: rotate(-6deg); } to { transform: rotate(7deg); } }
@keyframes rain { from { transform: translate(2px, -14px); } to { transform: translate(-3px, 14px); } }
@keyframes twinkle { from { opacity: .2; } to { opacity: 1; } }
@keyframes sway { from { transform: rotate(-24deg) translateY(-3px); } to { transform: rotate(24deg) translateY(3px); } }
@keyframes purr { 0% { transform: translate(0, 0) scale(1.01, 1.02); } 50% { transform: translate(.8px, .4px) scale(1.012, 1.022); } 100% { transform: translate(-.8px, 0) scale(1.01, 1.02); } }
@keyframes nuzzle { 50% { transform: rotate(-5deg); } }
@keyframes boop { 40% { transform: scale(.7, .6); } 100% { transform: scale(1); } }
@keyframes shuffle { from { transform: translateY(0) rotate(-3deg) scale(.97); } to { transform: translateY(-8px) rotate(3deg) scale(1.01); } }
@keyframes land { 0% { transform: scale(.92, 1.06); } 45% { transform: scale(1.05, .95); } 100% { transform: scale(1); } }
@keyframes float-up { 0% { opacity: 0; transform: translate(0, 0) scale(calc(var(--s) * .4)); } 15% { opacity: 1; transform: translate(0, -10px) scale(var(--s)); } 100% { opacity: 0; transform: translate(var(--dx), -120px) scale(var(--s)) rotate(12deg); } }
@keyframes boop-pop { 0% { opacity: 0; transform: translateY(6px) scale(.6); } 20% { opacity: 1; transform: translateY(-10px) scale(1.08); } 75% { opacity: 1; transform: translateY(-16px) scale(1); } 100% { opacity: 0; transform: translateY(-26px) scale(.95); } }
@keyframes rise { from { translate: -50% 30px; opacity: 0; } to { translate: -50% 0; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; scale: .95; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .boop-bubble { opacity: 1; translate: -50% -130%; }
}
