:root {
  --ink: #5a4a6a;
  --ink-soft: #9c8dab;
  --bg: #fff7f1;
  --card: #ffffff;
  --pink: #ffb7c9;   --pink-d: #ee8fab;
  --peach: #ffd2b3;  --peach-d: #f2ab7f;
  --butter: #ffeaa0; --butter-d: #ecc95c;
  --mint: #b9ecd3;   --mint-d: #7fcfa8;
  --sky: #b8e0ff;    --sky-d: #80bdea;
  --lav: #d9ccff;    --lav-d: #ae9aec;
  --l0: #f48fb0; --l1: #f2a35e; --l2: #5fc79a; --l3: #62aee8; --l4: #a08be6;
  --r: 22px;
  --shadow: 0 10px 28px rgba(160, 130, 190, .18);
  --head: 'Baloo 2', 'Nunito', system-ui, sans-serif;
  --body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* touch-action: manipulation turns off double-tap zoom (fast tile taps were zooming the page); pinch zoom still works */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font: 700 16px/1.45 var(--body);
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 4%, #ffe0ea 0 22%, transparent 23%),
    radial-gradient(circle at 96% 14%, #dff3ff 0 20%, transparent 21%),
    radial-gradient(circle at 4% 82%, #e9e1ff 0 18%, transparent 19%),
    radial-gradient(circle at 92% 92%, #dcf6e8 0 24%, transparent 25%),
    var(--bg);
  background-attachment: fixed;
  overscroll-behavior-y: none;
}
#app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
h1, h2 { font-family: var(--head); margin: 0; line-height: 1.15; }
h2 { font-size: 1.25rem; }
section { display: flex; flex-direction: column; gap: 10px; }
section > h2 { font-size: 1.05rem; color: var(--ink-soft); padding-left: 6px; }
p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 3px solid var(--lav-d); outline-offset: 2px; }
.center { text-align: center; justify-content: center; }
.muted { color: var(--ink-soft); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

/* ---------- logo / auth ---------- */
.hero { text-align: center; padding: 26px 0 4px; }
.hero-art { font-size: 64px; animation: float 3.5s ease-in-out infinite; }
.logo { font-size: 4rem; font-weight: 800; letter-spacing: 1px; }
.logo span { display: inline-block; text-shadow: 0 4px 0 rgba(255, 255, 255, .9), 0 8px 14px rgba(160, 130, 190, .25); }
.logo span:nth-child(odd) { transform: rotate(-5deg); }
.logo span:nth-child(even) { transform: rotate(4deg); }
.logo span:nth-child(3) { width: .28em; }
.tagline { color: var(--ink-soft); margin-top: 2px; }

.card {
  background: var(--card);
  border-radius: 28px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card-title { font-family: var(--head); font-size: 1.05rem; }
.center-card { align-items: center; text-align: center; padding: 28px 20px; margin-top: 18px; }
.tabs { display: flex; background: #f6effb; border-radius: 16px; padding: 4px; }
.tab { flex: 1; border: 0; background: none; border-radius: 13px; padding: 9px; font-family: var(--head); color: var(--ink-soft); }
.tab.on { background: #fff; color: var(--ink); box-shadow: 0 2px 8px rgba(160, 130, 190, .22); }
.input {
  width: 100%; min-width: 0; flex: 1;
  border: 2.5px solid #efe6f7; border-radius: 16px;
  padding: 12px 14px; background: #fdfbff; outline: none;
}
.input:focus { border-color: var(--lav-d); background: #fff; }
.input::placeholder { color: #c3b8cf; }
.hint { color: var(--ink-soft); margin: -6px 0 0 6px; font-size: .8rem; }

/* ---------- buttons ---------- */
.btn {
  --c: var(--lav); --d: var(--lav-d);
  border: 0; border-radius: 18px;
  padding: 11px 18px;
  font-family: var(--head); font-weight: 700; font-size: 1.05rem;
  background: var(--c); color: var(--ink);
  box-shadow: 0 5px 0 var(--d);
  transition: transform .08s, box-shadow .08s;
  text-decoration: none; text-align: center;
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--d); }
.btn.pink { --c: var(--pink); --d: var(--pink-d); }
.btn.mint { --c: var(--mint); --d: var(--mint-d); }
.btn.sky { --c: var(--sky); --d: var(--sky-d); }
.btn.lav { --c: var(--lav); --d: var(--lav-d); }
.btn.butter { --c: var(--butter); --d: var(--butter-d); }
.btn.ghost { --c: #fff; --d: #e6dcf0; box-shadow: 0 5px 0 var(--d), inset 0 0 0 2px #efe6f7; }
.btn.small { padding: 7px 13px; font-size: .92rem; border-radius: 14px; box-shadow: 0 4px 0 var(--d); }
.btn.ghost.small { box-shadow: 0 4px 0 var(--d), inset 0 0 0 2px #efe6f7; }
.btn.big { padding: 14px 20px; font-size: 1.2rem; width: 100%; }
.row > .btn { flex: 1; }
.row.center > .btn, .setting .btn, .friend .btn, .add .btn, .tools .btn { flex: none; }
.link { border: 0; background: none; color: var(--l4); font-weight: 800; padding: 6px 8px; text-decoration: underline; text-underline-offset: 3px; }
.link.danger { color: var(--pink-d); }
.icon-btn {
  border: 0; width: 42px; height: 42px; border-radius: 14px; flex: none;
  background: #fff; box-shadow: 0 4px 0 #e6dcf0; font-size: 1.2rem; line-height: 1;
  display: grid; place-items: center; padding: 0; text-decoration: none; color: inherit;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #e6dcf0; }

/* ---------- top bar ---------- */
.top { display: flex; align-items: center; gap: 10px; }
.top-name { flex: 1; min-width: 0; font-family: var(--head); font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 42px; height: 42px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--head); font-weight: 800; font-size: 1.2rem; color: #fff;
  text-shadow: 0 1px 2px rgba(90, 74, 106, .35);
  border: 3px solid #fff; box-shadow: 0 3px 8px rgba(160, 130, 190, .25);
}
.pill { background: #fff; border-radius: 999px; padding: 5px 12px; font-family: var(--head); white-space: nowrap; box-shadow: 0 3px 8px rgba(160, 130, 190, .16); }
.pill.fire { background: #fff0e3; }
.pill.coin { background: #fff8d9; }
.pill.mint-pill { background: #e0f7ec; }
.pill.lav-pill { background: #eee8ff; }

/* ---------- home ---------- */
.friend {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: var(--r); padding: 12px;
  box-shadow: var(--shadow); border: 2.5px solid transparent;
}
.friend.turn { border-color: var(--pink); background: linear-gradient(100deg, #fff 55%, #fff0f4); }
.friend-main { flex: 1; min-width: 0; }
.friend-name { font-family: var(--head); font-size: 1.08rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friend-sub { font-size: .82rem; color: var(--ink-soft); }
.friend.turn .friend-sub { color: var(--pink-d); }
.streak { display: flex; flex-direction: column; align-items: center; line-height: 1.1; font-family: var(--head); }
.streak b { font-size: 1.1rem; white-space: nowrap; }
.streak small { font-size: .68rem; color: var(--ink-soft); white-space: nowrap; }
.x { border: 0; background: none; color: #cfc4da; font-size: .9rem; padding: 6px 2px; }
.empty { text-align: center; color: var(--ink-soft); padding: 26px 16px; background: rgba(255, 255, 255, .6); border-radius: var(--r); border: 2.5px dashed #e6dcf0; }
.empty-art { font-size: 46px; }

/* ---------- dialogs ---------- */
.modal { border: 0; padding: 0; background: none; width: min(92vw, 400px); color: var(--ink); }
.modal::backdrop { background: rgba(120, 100, 150, .35); backdrop-filter: blur(3px); }
.modal-in { background: #fff; border-radius: 28px; padding: 22px; display: flex; flex-direction: column; gap: 16px; box-shadow: var(--shadow); animation: pop .25s; }
.modal-text { font-family: var(--head); font-size: 1.15rem; text-align: center; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* ---------- drawing ---------- */
.prompt { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; justify-content: center; text-align: center; }
.prompt small { color: var(--ink-soft); }
.prompt b { font-family: var(--head); font-size: 1.45rem; text-transform: uppercase; letter-spacing: .5px; }
/* Game screens are exactly one viewport tall. The stage gets whatever height the controls leave,
   and the 4:5 canvas is the biggest one that fits inside it, so nothing is pushed below the fold. */
#app.fit { height: 100dvh; gap: 10px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
#app.fit > * { flex: none; }
#app.fit > .stage {
  flex: 1 1 0; min-height: 180px; margin: 0 -12px;
  container-type: size; display: grid; place-items: center;
}
.canvas {
  width: min(100cqw, 100cqh * .8); aspect-ratio: 4 / 5;
  background: #fff; border-radius: 18px;
  box-shadow: var(--shadow), 0 0 0 2px #f1e8f8;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.draw-word { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.draw-word small { color: var(--ink-soft); font-size: .75rem; }
.draw-word b { font-family: var(--head); font-size: 1.25rem; text-transform: uppercase; overflow-wrap: anywhere; }
.palette { display: flex; gap: 5px; justify-content: center; flex-wrap: wrap; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(160, 130, 190, .35); padding: 0; font-size: 15px; line-height: 1; }
.swatch.on { transform: scale(1.22); box-shadow: 0 0 0 3px var(--ink); }
.swatch.eraser { background: #fff; }
.tools { justify-content: center; }
.sizes { display: flex; gap: 6px; background: #fff; border-radius: 14px; padding: 4px; box-shadow: 0 4px 0 #e6dcf0; }
.size { width: 36px; height: 34px; border: 0; background: none; border-radius: 10px; display: grid; place-items: center; padding: 0; }
.size i { background: var(--ink); border-radius: 50%; display: block; }
.size.on { background: var(--lav); }

.choice {
  --c: var(--mint); --d: var(--mint-d);
  border: 0; border-radius: 24px; padding: 18px;
  background: var(--c); box-shadow: 0 6px 0 var(--d);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: transform .08s, box-shadow .08s;
}
.choice:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--d); }
.choice.butter { --c: var(--butter); --d: var(--butter-d); }
.choice.pink { --c: var(--pink); --d: var(--pink-d); }
.choice-word { font-family: var(--head); font-size: 1.6rem; font-weight: 800; text-transform: uppercase; }
.choice-meta { font-size: .85rem; opacity: .8; }

/* ---------- history gallery ---------- */
.gallery { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.shot {
  border: 0; padding: 8px 8px 10px; border-radius: 20px; background: #fff; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px; min-width: 0; text-align: left;
  transition: transform .08s;
}
.shot:active { transform: scale(.97); }
.thumb { width: 100%; aspect-ratio: 4 / 5; border-radius: 14px; background: #fff; box-shadow: inset 0 0 0 2px #f1e8f8; margin-bottom: 4px; }
.shot-word { font-family: var(--head); font-size: 1.05rem; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shot-meta { font-size: .78rem; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- letter board ---------- */
.board { display: flex; flex-direction: column; gap: 12px; }
.slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; }
.word { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.slot {
  width: clamp(24px, 8.4vw, 38px); aspect-ratio: 1; padding: 0;
  border: 2.5px dashed #d8cbe8; border-radius: 11px; background: rgba(255, 255, 255, .7);
  font-family: var(--head); font-weight: 800; font-size: clamp(.95rem, 4.6vw, 1.3rem); line-height: 1;
}
.slot.filled { border-style: solid; border-color: var(--lav-d); background: #fff; animation: pop .16s; }
.slot.locked { border-color: var(--mint-d); background: var(--mint); }
.tiles { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }
.tile {
  --c: var(--pink); --d: var(--pink-d);
  aspect-ratio: 1; padding: 0; border: 0; border-radius: 10px;
  background: var(--c); box-shadow: 0 3px 0 var(--d);
  font-family: var(--head); font-weight: 800; font-size: clamp(.95rem, 4.6vw, 1.3rem); line-height: 1;
  transition: transform .08s, opacity .25s;
}
.tile:nth-child(5n+2) { --c: var(--butter); --d: var(--butter-d); }
.tile:nth-child(5n+3) { --c: var(--mint); --d: var(--mint-d); }
.tile:nth-child(5n+4) { --c: var(--sky); --d: var(--sky-d); }
.tile:nth-child(5n+5) { --c: var(--lav); --d: var(--lav-d); }
.tile:active { transform: translateY(2px); }
.tile.used { visibility: hidden; }
.tile.gone { opacity: .22; transform: scale(.7); box-shadow: none; pointer-events: none; }
.badges { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.badges:empty { display: none; }
.items { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.item {
  border: 0; border-radius: 16px; padding: 7px 2px 6px; background: #fff;
  box-shadow: 0 4px 0 #e6dcf0; display: flex; flex-direction: column; align-items: center;
  font-size: .72rem; line-height: 1.25; min-width: 0;
}
.item:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #e6dcf0; }
.item-icon { font-size: 1.35rem; }
.item small { color: var(--ink-soft); font-size: .7rem; }
.pb-status { text-align: center; font-family: var(--head); font-size: 1.1rem; background: #fff; border-radius: 16px; padding: 8px 12px; box-shadow: var(--shadow); }
.pb-status.good { background: #e0f7ec; }
.pb-status.bad { background: #ffe6ec; }

/* ---------- result ---------- */
.big-emoji { font-size: 72px; line-height: 1.1; }
.answer { font-family: var(--head); font-size: 2rem; font-weight: 800; text-transform: uppercase; color: var(--l4); }
.streak-big { font-family: var(--head); font-size: 2.4rem; font-weight: 800; background: #fff0e3; border-radius: 999px; padding: 2px 26px; }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.confetti i { position: absolute; top: -20px; width: 12px; height: 12px; border-radius: 4px; animation: fall linear forwards; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 16px; max-width: 88vw; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- admin ---------- */
.admin { max-width: 860px !important; }
.user-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; background: #fff; border-radius: var(--r); padding: 12px 14px; box-shadow: var(--shadow); }
.user-row.off { opacity: .6; }
.user-meta { font-size: .8rem; color: var(--ink-soft); }
.user-actions { display: flex; gap: 6px; flex-wrap: wrap; grid-column: 1 / -1; }
.tag { font-size: .7rem; border-radius: 8px; padding: 1px 7px; margin-left: 6px; background: var(--lav); vertical-align: middle; }
.tag.red { background: var(--pink); }

/* ---------- motion ---------- */
@keyframes float { 50% { transform: translateY(-8px) rotate(4deg); } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.08); } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); } }
.float { animation: float 3s ease-in-out infinite; }
.pop { animation: pop .45s; }
.shake { animation: shake .4s; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
