@font-face {
  font-family: "Baloo2Popchi";
  src: url("assets/fonts/baloo2_xbold.ttf") format("truetype");
  font-weight: 800;
  font-display: swap;
}

:root {
  --plum: #6B4FA0;
  --plum-deep: #4E3878;
  --gold: #F2B544;
  --ink: #2A2024;
  --mist: #EDE8F3;
  --paper: #FFFFFF;
  --muted: #6E6478;
  --line: #D9D0E5;
  --bg: var(--mist);
  --tile: var(--paper);
  --text: var(--ink);
  --display: "Baloo2Popchi", ui-rounded, system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1E1B22;
    --tile: #2C2832;
    --text: #EDE7F3;
    --muted: #A99FB4;
    --line: #3D3745;
    --plum: #9C80D1;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--body);
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand {
  margin: 0;
  font: 800 34px/1 var(--display);
  color: var(--plum);
  letter-spacing: -0.01em;
}
.top-actions { display: flex; gap: 6px; }
.ghost, .lang {
  border: 1.5px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 4px 12px;
  min-height: 36px;
  font: 800 15px/1 var(--display);
}

/* typing box */
.compose { margin-top: 14px; }
textarea {
  width: 100%;
  resize: none;
  border: 2px solid var(--line);
  border-radius: 18px;
  background: var(--tile);
  padding: 12px 14px;
  font-size: 18px;
  line-height: 1.35;
}
textarea:focus { border-color: var(--plum); outline: none; }
.compose-foot { display: flex; justify-content: space-between; gap: 8px; padding: 4px 6px 0; font-size: 13px; color: var(--muted); }
.count.over { color: #C4302B; font-weight: 700; }

/* character picker */
.who { display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px 4px; scrollbar-width: none; }
.who::-webkit-scrollbar { display: none; }
.who button {
  flex: none;
  display: flex; align-items: center; gap: 6px;
  border: 2px solid transparent;
  background: var(--tile);
  border-radius: 999px;
  padding: 3px 12px 3px 4px;
  min-height: 40px;
  font: 800 15px/1 var(--display);
}
.who button img, .who button canvas { width: 32px; height: 32px; object-fit: contain; }
.who button[aria-pressed="true"] { border-color: var(--plum); }
.who .make { color: var(--plum); border: 1.5px dashed var(--plum); padding: 3px 14px; }

/* sticker strip: tiles about 20% bigger than the keyboard's */
.strip-wrap { margin-top: 8px; min-height: 104px; }
.strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px; scroll-snap-type: x proximity; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.tile {
  flex: none;
  width: 96px; height: 96px;
  padding: 3px;
  border: 2.5px solid transparent;
  border-radius: 16px;
  background: var(--tile);
  scroll-snap-align: start;
}
.tile canvas { width: 100%; height: 100%; display: block; }
.tile[aria-pressed="true"] { border-color: var(--gold); }
.strip-empty { margin: 12px 4px; color: var(--muted); }

/* preview, shown the way it will look once sent */
.chat {
  margin-top: 10px;
  border-radius: 24px;
  background: var(--tile);
  padding: 16px 14px 14px;
}
.chat-row { display: flex; justify-content: flex-end; }
.sent { position: relative; width: min(70%, 300px); }
.sent canvas { width: 100%; height: auto; display: block; touch-action: manipulation; }
.sent::after {
  content: "now";
  position: absolute; right: 4px; bottom: 2px;
  font-size: 11px; color: var(--muted);
}
.send-row { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; margin-top: 12px; }
.primary, .secondary {
  min-height: 46px;
  border-radius: 14px;
  font: 800 17px/1 var(--display);
  border: 0;
}
.primary { background: var(--plum); color: #fff; }
.secondary { background: transparent; border: 2px solid var(--line); }
.primary:active, .secondary:active { transform: translateY(1px); }
.toast { min-height: 1.4em; margin: 8px 2px 0; font-size: 14px; color: var(--muted); }

/* extras */
.extras { margin-top: 14px; }
.toggles { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.switch { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; }
.switch input { width: 20px; height: 20px; accent-color: var(--plum); }
.chip { border: 1.5px solid var(--line); background: var(--tile); border-radius: 999px; padding: 6px 12px; min-height: 40px; }
.more { margin-top: 10px; background: none; border: 0; color: var(--plum); font: 800 16px/1 var(--display); padding: 8px 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; margin-top: 8px; }
.grid .tile { width: auto; height: auto; aspect-ratio: 1; }

.foot { margin-top: 28px; font-size: 13px; color: var(--muted); }
.foot p { margin: 4px 0; }
.foot a { color: var(--plum); }
.smart { font-weight: 600; }

/* sheets */
dialog.sheet {
  width: min(520px, calc(100% - 24px));
  max-height: calc(100% - 48px);
  border: 0;
  border-radius: 22px;
  background: var(--bg);
  color: var(--text);
  padding: 18px 16px 16px;
}
dialog::backdrop { background: rgba(30, 20, 40, 0.45); }
.sheet h2 { margin: 0 0 6px; font: 800 24px/1.1 var(--display); color: var(--plum); }
.sheet h3 { margin: 0 0 4px; font: 800 19px/1.2 var(--display); }
.sheet .price { font: 600 15px var(--body); color: var(--muted); margin-left: 6px; }
.muted { color: var(--muted); font-size: 14px; }
.plan { background: var(--tile); border-radius: 16px; padding: 12px 14px; margin: 10px 0; }
.plan.pro { border: 2px solid var(--gold); }
.plan ul { margin: 0; padding-left: 18px; }
.status { font-weight: 700; }
.sheet .secondary, .sheet .primary { width: 100%; margin-top: 12px; }
.props-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; margin: 10px 0; }
.props-grid button {
  aspect-ratio: 1; border-radius: 14px; border: 2.5px solid transparent; background: var(--tile);
  padding: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 11px;
}
.props-grid img { width: 100%; height: 70%; object-fit: contain; }
.props-grid button[aria-pressed="true"] { border-color: var(--gold); }

/* welcome cards */
.welcome .cards { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 12px; scrollbar-width: none; }
.welcome .cards::-webkit-scrollbar { display: none; }
.card { flex: 0 0 100%; scroll-snap-align: center; text-align: center; padding: 4px 6px; }
.card canvas { width: 62%; max-width: 240px; height: auto; }
.card h2 { margin-top: 6px; }
.card p { margin: 6px 0 0; }
.cards-wrap { position: relative; }
.arrow {
  position: absolute; top: 34%; width: 40px; height: 40px; border-radius: 50%;
  border: 1.5px solid var(--line); background: var(--tile); color: var(--text);
  font: 800 26px/1 var(--display); display: flex; align-items: center; justify-content: center; padding: 0 0 3px;
}
.arrow.prev { left: 0; }
.arrow.next { right: 0; }
.arrow[disabled] { opacity: 0; pointer-events: none; }
.dots { display: flex; justify-content: center; gap: 4px; margin-top: 10px; }
.dots button { width: 24px; height: 24px; border: 0; background: none; padding: 0; display: flex; align-items: center; justify-content: center; }
.dots button::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots button.on::before { background: var(--plum); width: 20px; border-radius: 4px; }
.skip { display: block; margin: 6px auto 0; background: none; border: 0; color: var(--muted); font-size: 14px; padding: 8px 16px; }

/* None fit */
.tile.none-fit { display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.2; padding: 6px; }
.linkish { background: none; border: 0; padding: 0; color: var(--plum); text-decoration: underline; font-size: 13px; }
.report { display: flex; gap: 8px; align-items: center; justify-content: space-between; background: var(--tile); border-radius: 14px; padding: 8px 10px; margin: 8px 0; }
.report p { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.report .chip { flex: none; min-height: 36px; }
a.as-button { display: flex; align-items: center; justify-content: center; text-decoration: none; width: 100%; margin-top: 12px; }

/* packs */
.pack h3 { overflow-wrap: anywhere; }
.pack p { margin: 0 0 6px; }
.pack-preview { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding: 2px 0 6px; }
.pack-preview img { flex: none; width: 52px; height: 52px; object-fit: contain; }
.pack-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.pack-actions .chip { min-height: 38px; }
.text-input { width: 100%; border: 2px solid var(--line); border-radius: 14px; background: var(--tile); padding: 10px 12px; font-size: 16px; }
.text-input:focus { border-color: var(--plum); outline: none; }
.maker-picked { display: flex; gap: 4px; overflow-x: auto; min-height: 48px; scrollbar-width: none; }
.maker-picked button { flex: none; width: 46px; height: 46px; border: 0; padding: 2px; background: var(--tile); border-radius: 10px; }
.maker-picked img { width: 100%; height: 100%; object-fit: contain; }
.maker-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 4px; scrollbar-width: none; }
.maker-tabs .chip { flex: none; }
.maker-tabs .chip[aria-pressed="true"] { border-color: var(--plum); background: var(--plum); color: #fff; }
.maker-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); max-height: 46vh; overflow-y: auto; }
.maker-grid img { width: 100%; height: 100%; object-fit: contain; }
canvas.qr { display: block; width: min(280px, 100%); height: auto; margin: 8px auto; border-radius: 12px; }

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