:root {
  --bg: #f5f4fa; --card: #fff; --ink: #17141f; --mut: #6f6b7d; --line: #e8e5f0;
  --acc: #6b46ff; --ok: #12b76a; --pink: #ff4f9a;
  --grad: linear-gradient(135deg, #7b4dff, #ff4f9a);
  --nav: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: #e9e7f1; overflow-x: hidden; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans SC", "Noto Sans", sans-serif;
  color: var(--ink); overscroll-behavior-y: none;
}
html[dir="rtl"] body { font-family: system-ui, "Noto Sans Arabic", sans-serif; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
#app { max-width: 480px; margin: 0 auto; min-height: 100vh; background: var(--bg); position: relative; overflow-x: hidden; }

.top {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; gap: 10px; min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.brand b { font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
.brand b span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo {
  width: 32px; height: 32px; border-radius: 10px; background: var(--grad); color: #fff;
  display: grid; place-items: center; box-shadow: 0 4px 12px rgba(123,77,255,.35); flex: none;
}
.logo svg { width: 18px; height: 18px; }
.pill {
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 99px;
  background: #e6f8ee; color: #0b7a46; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }

main { padding: 4px 16px calc(var(--nav) + 48px + env(safe-area-inset-bottom)); overflow-x: hidden; }
.page { display: none; min-width: 0; }
.page.on { display: block; }

nav.tabs {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  height: calc(var(--nav) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff; border-top: 1px solid var(--line); display: flex; z-index: 30;
}
nav.tabs button {
  flex: 1; border: 0; background: none; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px; font-weight: 600; font-size: 11.5px; color: var(--mut);
}
nav.tabs button svg { width: 24px; height: 24px; }
nav.tabs button.on { color: var(--acc); }
nav.tabs .cr .ic {
  width: 46px; height: 46px; border-radius: 15px; background: var(--grad); color: #fff;
  display: grid; place-items: center; margin-top: -20px; box-shadow: 0 6px 16px rgba(123,77,255,.4);
}
nav.tabs .cr.on { color: var(--pink); }

.h1 { font-size: 26px; font-weight: 800; margin: 6px 0 8px; }
.lead { color: var(--mut); margin: 0 0 14px; font-size: 14px; }
.h2 { font-size: 17px; font-weight: 800; margin: 22px 0 10px; }
.mut { color: var(--mut); }

.hero {
  padding: 12px; border-radius: 22px; background: var(--card);
  border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(60,40,140,.08);
}
.hero .cap { display: flex; align-items: center; gap: 8px; margin: 2px 4px 10px; font-size: 13px; color: var(--mut); }
.hero .cap b { color: var(--ink); font-size: 15px; }
.hero .cap .sp { flex: 1; }
.lnk { border: 0; background: none; color: var(--acc); font-weight: 700; font-size: 13.5px; padding: 6px 4px; }
.hint { text-align: center; color: var(--mut); font-size: 12px; margin: 10px 0 4px; }

.kb {
  position: relative; overflow: hidden; border-radius: 16px; padding: 10px 8px 12px;
  background: #1b1433;
}
.kb .fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.sug { display: flex; justify-content: space-around; color: rgba(255,255,255,.75); font-size: 13px; padding: 2px 6px 8px; position: relative; z-index: 1; }
.sug em { font-style: italic; font-family: Georgia, serif; }
.krow { display: flex; justify-content: center; gap: 5px; margin: 4px 0; position: relative; z-index: 1; }
.key {
  border: 0; flex: 1 1 0; min-width: 0; max-width: 34px; height: 38px; border-radius: 8px;
  background: rgba(20,14,40,.55); color: #fff; font-size: 16px; font-weight: 600;
  text-transform: lowercase; box-shadow: 0 2px 0 rgba(0,0,0,.18);
}
.key.pressed { transform: scale(.94); filter: brightness(1.3); }
.key.wide { max-width: 48px; font-size: 12px; text-transform: none; }
.key.space { max-width: none; flex: 4; font-size: 12px; text-transform: none; }
.key.enter { max-width: 46px; background: var(--acc); font-size: 16px; text-transform: none; }
.kb.light .key { background: rgba(255,255,255,.72); color: #3d2a62; }
.kb.light .sug { color: rgba(60,40,90,.7); }
.kb.compact .key { height: 32px; font-size: 14px; }
.kb.onehand { margin-inline-end: 18%; }
.kb.shape-round .key { border-radius: 14px; }
.kb.shape-square .key { border-radius: 4px; }
.tog { display: flex; gap: 8px; margin: 8px 0 12px; }
.tog button { flex: 1; border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 12px 8px; font-weight: 700; font-size: 13px; }
.tog button.on { border-color: var(--acc); background: #f6f2ff; color: var(--acc); }

.pagetitle { font-size: 22px; font-weight: 800; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 4px 16px 8px; position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 10; background: var(--bg); }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 99px;
  padding: 7px 14px; font-size: 13.5px; font-weight: 600; color: #3d3950; white-space: nowrap;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tcard { border: 0; padding: 0; background: none; text-align: start; position: relative; }
.tcard .th {
  border-radius: 14px; overflow: hidden; box-shadow: 0 4px 14px rgba(30,20,70,.12);
  position: relative; aspect-ratio: 1.45;
}
.tcard .nm { font-size: 13.5px; font-weight: 700; margin: 7px 2px 0; }
.badge {
  font-size: 10px; font-weight: 800; letter-spacing: .04em; padding: 2px 6px; border-radius: 6px;
  background: #ff3d71; color: #fff; position: absolute; top: 7px; inset-inline-start: 7px; z-index: 3;
}
.used {
  position: absolute; top: 7px; inset-inline-end: 7px; z-index: 3; width: 24px; height: 24px;
  border-radius: 50%; background: var(--ok); color: #fff; display: grid; place-items: center;
}
.mini { position: absolute; inset: 18px 10px 10px; display: flex; flex-direction: column; justify-content: end; gap: 3px; }
.mini i { display: flex; gap: 3px; justify-content: center; }
.mini i b { flex: 1; height: 7px; border-radius: 2px; background: rgba(255,255,255,.28); max-width: 18px; }
.kb.light .mini i b, .th.light .mini i b { background: rgba(255,255,255,.55); }

.myrow { display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none; }
.create-tile {
  width: 112px; height: 112px; flex: none; border: 1.5px dashed #cfc8f0; border-radius: 16px;
  background: #f7f5ff; color: var(--acc); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-weight: 700;
}
.create-tile .plus { font-size: 28px; line-height: 1; }
.mine {
  width: 112px; flex: none; border: 0; background: none; text-align: start; padding: 0;
}
.mine .th { aspect-ratio: 1; }

.fin { display: flex; gap: 8px; margin-bottom: 12px; min-width: 0; }
.fin input {
  flex: 1; min-width: 0; border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 12px 14px; outline: none;
}
.fin .x { border: 0; flex: none; padding: 0 12px; border-radius: 14px; background: #f3f1f8; font-weight: 700; }
.flist { display: grid; gap: 8px; min-width: 0; }
.flist.tall { max-height: 42vh; overflow: auto; }
.fitem {
  display: flex; align-items: center; gap: 10px; width: 100%; max-width: 100%; min-width: 0;
  text-align: start; overflow: hidden;
  border: 1.5px solid var(--line); background: #fff; border-radius: 16px; padding: 12px;
}
.fitem.on { border-color: var(--acc); background: #f6f2ff; }
.fitem .dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #d9d5e6; flex: none; }
.fitem.on .dot { border-color: var(--acc); background: var(--acc); box-shadow: inset 0 0 0 3px #fff; }
.fitem .txt { flex: 1; min-width: 0; overflow: hidden; }
.fitem small { display: block; color: var(--mut); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fitem b {
  display: block; font-size: 18px; font-weight: 600; margin-top: 2px; line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.fitem .copy {
  flex: none; display: grid; place-items: center; border: 0; background: #f3f1ff; color: var(--acc);
  border-radius: 10px; width: 36px; height: 36px; padding: 0;
}
.fitem .copy svg { width: 16px; height: 16px; display: block; }
.note { display: flex; gap: 10px; align-items: flex-start; margin-top: 16px; color: var(--mut); font-size: 13px; }
.note input { margin-top: 3px; }

.ff-script { font-family: "Segoe Script", "Ma Shan Zheng", cursive; }
.ff-bold { font-weight: 900; }
.ff-outline { color: #fff; -webkit-text-fill-color: #fff; -webkit-text-stroke: 1.5px #1c1730; }
.ff-small { font-size: 13px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
.ff-gothic { font-family: "Palatino Linotype", "Noto Serif SC", serif; font-weight: 900; }
.ff-naskh { font-family: "Noto Naskh Arabic", "Noto Sans Arabic", serif; font-size: 20px; }
.ff-kufi { font-family: "Reem Kufi", "Noto Sans Arabic", sans-serif; font-size: 20px; }
.ff-lateef { font-family: "Lateef", "Noto Naskh Arabic", serif; font-size: 22px; }
.ff-mashan { font-family: "Ma Shan Zheng", cursive; font-size: 22px; font-weight: 400; }
.ff-kuaile { font-family: "ZCOOL KuaiLe", cursive; font-size: 20px; }
.ff-longcang { font-family: "Long Cang", cursive; font-size: 22px; }
.ff-yomogi { font-family: Yomogi, cursive; font-size: 20px; }
.ff-pixel { font-family: "Press Start 2P", ui-monospace, monospace; font-size: 11px; line-height: 1.6; }
.ff-italic, .ff-boldItalic, .ff-sansItalic, .ff-sansBI { font-style: italic; }
.ff-wide { letter-spacing: .12em; }
.ff-square, .ff-squareNeg, .ff-paren { letter-spacing: .06em; }
.ff-tiny, .ff-small, .ff-super { font-size: 13px; letter-spacing: .08em; }
.ff-bubble { letter-spacing: .04em; }
.kb.ff-naskh, .kb.ff-naskh .key,
.kb.ff-kufi, .kb.ff-kufi .key,
.kb.ff-lateef, .kb.ff-lateef .key { font-family: "Noto Naskh Arabic", "Noto Sans Arabic", serif; }
.kb.ff-mashan, .kb.ff-mashan .key { font-family: "Ma Shan Zheng", cursive; }
.kb.ff-kuaile, .kb.ff-kuaile .key { font-family: "ZCOOL KuaiLe", cursive; }
.kb.ff-longcang, .kb.ff-longcang .key { font-family: "Long Cang", cursive; }
.kb.ff-pixel, .kb.ff-pixel .key { font-family: "Press Start 2P", monospace; font-size: 10px; }
.bub {
  display: inline-flex; width: 1.65em; height: 1.65em; border: 2px solid #2a2340; border-radius: 50%;
  align-items: center; justify-content: center; font-style: normal; font-size: 12px; font-weight: 800;
}

.ctabs { display: flex; background: #fff; border-radius: 16px; padding: 4px; margin: 12px 0; border: 1px solid var(--line); }
.ctabs button {
  flex: 1; border: 0; background: none; border-radius: 12px; padding: 8px 4px; font-size: 11px; font-weight: 700; color: var(--mut);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.ctabs button.on { background: #f3efff; color: var(--acc); }
.photo {
  display: block; width: 100%; border: 1.5px dashed #cfc8f0; background: linear-gradient(90deg, #f7f5ff, #fff); border-radius: 16px;
  padding: 14px; text-align: start; margin: 8px 0;
}
.photo b { color: var(--acc); display: block; }
.photo small { color: var(--mut); }
.fxgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.fxgrid button, .swatch, .snd {
  border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 12px 6px; font-size: 12px; font-weight: 700;
}
.fxgrid button.on, .snd.on { border-color: var(--acc); background: #f6f2ff; color: var(--acc); }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.swatch { aspect-ratio: 1; padding: 0; border-radius: 12px; }
.swatch.on { outline: 2px solid var(--acc); outline-offset: 2px; }
.save {
  position: sticky; bottom: calc(var(--nav) + 28px); width: 100%; border: 0; border-radius: 14px; padding: 14px;
  color: #fff; font-weight: 800; background: var(--grad); margin-top: 16px; box-shadow: 0 8px 20px rgba(123,77,255,.3);
}

.banner { background: #e6f8ee; color: #0b7a46; border-radius: 16px; padding: 14px; margin-bottom: 18px; }
.banner b { display: block; }
.sec { font-size: 11px; font-weight: 800; letter-spacing: .08em; color: var(--mut); margin: 16px 4px 8px; }
.slist { background: #fff; border-radius: 18px; border: 1px solid var(--line); overflow: hidden; }
.srow {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: start; border: 0; background: #fff;
  padding: 14px 12px; border-bottom: 1px solid var(--line);
}
.srow:last-child { border-bottom: 0; }
.sico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: #fff; flex: none; font-weight: 800; }
.srow .meta { flex: 1; min-width: 0; }
.srow small { display: block; color: var(--mut); font-size: 12px; }
.srow .val { color: var(--mut); margin-inline-end: 6px; max-width: 42%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet {
  position: fixed; inset: 0; z-index: 40; background: rgba(20,16,30,.4); display: none; align-items: flex-end; justify-content: center;
}
.sheet.on { display: flex; }
.sheet .box { width: 100%; max-width: 480px; background: #fff; border-radius: 20px 20px 0 0; padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); }
.sheet h3 { margin: 8px 12px 12px; }
.sheet button.opt { display: block; width: 100%; text-align: start; border: 0; background: none; padding: 12px; border-radius: 10px; font-weight: 600; }
.sheet button.opt.on { background: #f6f2ff; color: var(--acc); }

.spark { position: absolute; pointer-events: none; z-index: 3; transform: translate(-50%,-50%); }
.fx-stars { color: #ffe9a0; font-size: 16px; text-shadow: 0 0 10px #fff; animation: twinkle 1.2s ease-in-out forwards; }
.fx-snow { color: #fff; font-size: 16px; animation: snowfall 2.8s linear forwards; }
.fx-bubbles { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #fff; background: rgba(180,220,255,.3); animation: bubbleup 2.2s ease-out forwards; }
.fx-hearts { font-size: 16px; animation: heartfloat 1.7s ease-out forwards; }
.fx-fireflies { width: 7px; height: 7px; border-radius: 50%; background: #fff6a8; box-shadow: 0 0 10px 4px rgba(255,220,80,.9); animation: firefly 2s ease-in-out forwards; }
.fx-aurora { width: 40px; height: 10px; border-radius: 20px; background: linear-gradient(90deg, #7bffd0, #7b6cff, #ff7ad9); filter: blur(2px); opacity: .7; animation: aur 2.4s ease-in-out forwards; }
@keyframes twinkle {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(.2); }
  40% { opacity: 1; transform: translate(-50%,-50%) scale(1.2); }
  100% { opacity: 0; transform: translate(-50%,-50%) scale(.2); }
}
@keyframes snowfall { to { opacity: .15; transform: translate(calc(-50% + var(--drift,20px)), 180px) rotate(160deg); } }
@keyframes bubbleup { to { opacity: 0; transform: translate(-50%, -140px) scale(1.4); } }
@keyframes heartfloat { to { opacity: 0; transform: translate(calc(-50% + var(--drift,16px)), -110px); } }
@keyframes firefly {
  0% { opacity: 0; } 30% { opacity: 1; transform: translate(calc(-50% + var(--dx,12px)), calc(-50% + var(--dy,-20px))); }
  100% { opacity: 0; transform: translate(calc(-50% - 8px), calc(-50% + var(--dy,-70px))); }
}
@keyframes aur { 0% { opacity: 0; transform: translate(-50%,-50%) scaleX(.4); } 40% { opacity: .8; } 100% { opacity: 0; transform: translate(-50%,-40px) scaleX(1.4); } }
.fx-rain { width: 2px; height: 14px; border-radius: 2px; background: rgba(255,255,255,.7); animation: rain 1.1s linear forwards; }
@keyframes rain { to { opacity: .1; transform: translate(-50%, 170px); } }
.fx-fireworks { font-size: 18px; color: #ffe08a; text-shadow: 0 0 12px #ff7ad9; animation: boom 1.15s ease-out forwards; }
@keyframes boom {
  0% { opacity: 1; transform: translate(-50%,-50%) scale(.2); }
  40% { opacity: 1; transform: translate(-50%,-50%) scale(1.3); }
  100% { opacity: 0; transform: translate(-50%,-50%) scale(1.9); }
}
.fx-code { font: 11px/1 ui-monospace, Menlo, monospace; color: #5dff8a; text-shadow: 0 0 8px #5dff8a; animation: codedrop 1.8s linear forwards; }
@keyframes codedrop { to { opacity: 0; transform: translate(-50%, 150px); } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav) + 24px); transform: translateX(-50%) translateY(8px);
  background: #2a2340; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 13px; z-index: 50;
  opacity: 0; transition: .25s; pointer-events: none; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 380px) {
  main { padding-left: 12px; padding-right: 12px; }
  .chips { margin-left: -12px; margin-right: -12px; padding-left: 12px; padding-right: 12px; }
  .key { height: 34px; font-size: 14px; }
  .fxgrid { grid-template-columns: repeat(3, 1fr); }
  .swatches { grid-template-columns: repeat(5, 1fr); }
  .pagetitle { font-size: 20px; }
  .fitem { padding: 10px; gap: 8px; }
}
