:root {
  --bg: #fbf3e7; --card: #fffaf2; --ink: #2b211c; --soft: #7a685c; --line: #ead9c3;
  --accent: #e2583e; --accent-ink: #fff; --teal: #1f8a83; --gold: #f2b233; --bad: #d23a3a;
  --radius: 18px; --shadow: 0 2px 0 rgba(43,33,28,.08), 0 10px 30px -12px rgba(43,33,28,.25);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Arial Rounded MT Bold", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); touch-action: manipulation; -webkit-user-select: none; user-select: none;
  background-image: radial-gradient(circle at 12% 8%, #ffe9d0 0, transparent 38%), radial-gradient(circle at 92% 0%, #fde0dc 0, transparent 34%); background-attachment: fixed; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
.wrap { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(28px + env(safe-area-inset-bottom)); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 13px 20px; border-radius: 14px; font-weight: 800;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 0 #b53f2a; transition: transform .08s, box-shadow .08s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #b53f2a; }
.btn.ghost { background: var(--card); color: var(--ink); box-shadow: 0 4px 0 var(--line); border: 2px solid var(--line); }
.btn.ghost:active { box-shadow: 0 1px 0 var(--line); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; }

/* brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 900; font-size: 26px; letter-spacing: -.02em; }
.brand img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 3px solid #fff; box-shadow: var(--shadow); }
.brand b { color: var(--accent); }

/* auth */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(430px, 100%); background: var(--card); border-radius: 28px; box-shadow: var(--shadow); overflow: hidden; border: 2px solid var(--line); }
.auth-hero { height: 230px; background: url(/img/hero.jpg) center 22% / cover; position: relative; }
.auth-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 45%, var(--card)); }
.auth-body { padding: 4px 26px 26px; margin-top: -34px; position: relative; }
.auth-body .brand { font-size: 38px; }
.auth-body .tag { color: var(--soft); margin: 4px 0 18px; font-weight: 600; }
.tabs { display: flex; background: #f3e6d3; border-radius: 14px; padding: 4px; margin-bottom: 16px; }
.tabs button { flex: 1; padding: 9px; border-radius: 11px; font-weight: 800; color: var(--soft); }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(43,33,28,.15); }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; font-weight: 800; color: var(--soft); margin: 0 0 5px 4px; }
.field input { width: 100%; padding: 13px 14px; border-radius: 13px; border: 2px solid var(--line); background: #fff; outline: none; font-weight: 700; -webkit-user-select: text; user-select: text; }
.field input:focus { border-color: var(--accent); }
.err { color: var(--bad); font-weight: 700; min-height: 22px; margin: 2px 4px 10px; font-size: 14px; }

/* top bar */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.chip { display: flex; align-items: center; gap: 10px; background: var(--card); border: 2px solid var(--line); border-radius: 999px; padding: 5px 14px 5px 5px; box-shadow: var(--shadow); text-align: left; }
.chip img, .ava { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: none; }
.chip .nm { font-weight: 900; line-height: 1.1; }
.chip .rk { font-size: 12px; font-weight: 700; color: var(--soft); white-space: nowrap; }
.chip .nm { white-space: nowrap; }
@media (max-width: 480px) { .top .brand { font-size: 19px; gap: 6px; } .top .brand img { width: 34px; height: 34px; } .chip { padding-right: 11px; gap: 8px; } }
.xpbar { height: 7px; width: 96px; background: #f0e2cd; border-radius: 9px; margin-top: 3px; overflow: hidden; }
.xpbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--accent)); border-radius: 9px; transition: width .8s cubic-bezier(.2,.8,.2,1); }
.nav { display: flex; gap: 6px; background: #f3e6d3; border-radius: 16px; padding: 5px; margin-bottom: 18px; }
.nav button { flex: 1; padding: 10px 6px; border-radius: 12px; font-weight: 800; color: var(--soft); font-size: 15px; }
.nav button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(43,33,28,.15); }

/* home */
.continue { display: flex; align-items: center; gap: 16px; background: var(--ink); color: #fff; border-radius: 24px; padding: 16px; box-shadow: var(--shadow); margin-bottom: 22px; width: 100%; text-align: left; }
.continue img { width: 76px; height: 76px; border-radius: 20px; object-fit: cover; border: 3px solid #fff; }
.continue small { color: #e9c9a8; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; font-size: 11px; }
.continue h2 { font-size: 24px; margin: 2px 0; }
.continue p { color: #d9c8ba; font-weight: 600; font-size: 14px; }
.continue .go { margin-left: auto; width: 48px; height: 48px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; font-size: 22px; flex: none; }
.world { margin-bottom: 22px; }
.world-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 4px 10px; }
.world-head h3 { font-size: 19px; }
.world-head span { color: var(--soft); font-weight: 700; font-size: 13px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 9px; }
.tile { aspect-ratio: 1; border-radius: 16px; background: var(--card); border: 2px solid var(--line); font-weight: 900; font-size: 18px; display: grid; place-items: center; position: relative; box-shadow: 0 3px 0 var(--line); }
.tile:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.tile .st { position: absolute; bottom: 5px; left: 0; right: 0; font-size: 9px; letter-spacing: 1px; color: var(--gold); line-height: 1; }
.tile .st i { color: #e6d6c0; font-style: normal; }
.tile.done { background: #fff; padding-bottom: 8px; }
.tile.next { background: var(--accent); color: #fff; border-color: #b53f2a; box-shadow: 0 3px 0 #b53f2a; animation: pulse 1.6s infinite; }
.tile.lock { color: #cbb9a3; background: #f6ecdc; box-shadow: none; }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* leaderboard */
.card { background: var(--card); border: 2px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); padding: 8px; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 16px; }
.row + .row { margin-top: 2px; }
.row.me { background: #fff1dc; }
.row .pos { width: 26px; font-weight: 900; font-size: 18px; text-align: center; color: var(--soft); }
.row .ava { width: 48px; height: 48px; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(43,33,28,.2); }
.row .who { flex: 1; min-width: 0; }
.row .who b { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .who span { font-size: 12.5px; color: var(--soft); font-weight: 700; }
.row .xp { text-align: right; font-weight: 900; font-size: 18px; }
.row .xp small { display: block; font-size: 11px; color: var(--soft); font-weight: 700; }
.muted { color: var(--soft); font-weight: 600; }
.rules { padding: 14px 18px; line-height: 1.5; }
.rules h3 { margin: 14px 0 6px; }
.rules li { margin: 5px 0; font-weight: 600; }
.rules ul { padding-left: 20px; margin: 0; }
.credits { font-size: 12px; color: var(--soft); margin-top: 12px; -webkit-user-select: text; user-select: text; }
.credits a { color: inherit; }

/* game */
.game { max-width: 640px; margin: 0 auto; padding: 12px 12px calc(18px + env(safe-area-inset-bottom)); min-height: 100dvh; display: flex; flex-direction: column; }
.ghead { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.icon { width: 44px; height: 44px; border-radius: 14px; background: var(--card); border: 2px solid var(--line); font-size: 20px; font-weight: 900; display: grid; place-items: center; flex: none; }
.ghead .ttl { flex: 1; min-width: 0; }
.ghead .ttl b { display: block; font-size: 19px; line-height: 1.15; }
.ghead .ttl span { font-size: 13px; color: var(--soft); font-weight: 700; }
.stat { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 10px; font-weight: 900; }
.timer { font-variant-numeric: tabular-nums; font-size: 22px; }
.timer small { font-size: 12px; color: var(--soft); font-weight: 700; margin-left: 6px; }
.lives { font-size: 24px; letter-spacing: 2px; }
.lives i { font-style: normal; display: inline-block; transition: .3s; }
.lives i.gone { filter: grayscale(1); opacity: .22; transform: scale(.8) rotate(-20deg); }
.board-wrap { flex: 1; display: grid; place-items: center; }
.board { --n: 5; width: min(100%, 62dvh, 560px); aspect-ratio: 1; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); grid-template-rows: repeat(var(--n), minmax(0, 1fr)); border: 2px solid var(--ink); border-radius: 14px; overflow: hidden; touch-action: none; background: var(--ink); box-shadow: var(--shadow); }
.cell { position: relative; border: 0 solid rgba(43,33,28,.22); border-top-width: 1px; border-left-width: 1px; padding: 0; min-width: 0; min-height: 0; overflow: hidden; }
.cell > * { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.cell.tt { border-top: 1px solid rgba(43,33,28,.5); } .cell.tl { border-left: 1px solid rgba(43,33,28,.5); }
.cell.r0 { border-top-width: 0; } .cell.c0 { border-left-width: 0; }
.cell .x { font-size: calc(min(100vw, 62dvh, 560px) / var(--n) * .42); font-weight: 900; color: rgba(43,33,28,.5); line-height: 1; animation: pop .15s; }
.cell.wrong { animation: shake .35s; }
.cell.wrong .x { color: var(--bad); }
.pupwrap { overflow: visible; }
.fr { width: 98%; height: 98%; overflow: visible; filter: drop-shadow(0 2px 1.5px rgba(43,33,28,.4)); animation: discover .65s cubic-bezier(.3,1.6,.5,1), tilt 5s 1.4s ease-in-out infinite; }
.still .fr { animation: tilt 5s var(--d) ease-in-out infinite; }
.fr .ear { transform-box: fill-box; transform-origin: 50% 100%; animation: earL .32s .45s 4 ease-in-out; }
.fr .ear.r { animation-name: earR; }
.still .fr .ear, .still .fr .tongue { animation: none; }
.fr .eye { transform-box: fill-box; transform-origin: center; animation: blink 4.2s calc(1.5s + var(--d)) infinite; }
.fr .tongue { transform-box: fill-box; transform-origin: 50% 0; animation: pant .22s .55s 8 alternate ease-in-out; }
.cell.hint .pupwrap::before { content: ""; position: absolute; inset: 6%; border-radius: 50%; box-shadow: 0 0 0 3px var(--gold); }
.board.won .fr { animation: hop .45s ease-in-out 3; }
@keyframes discover { 0% { transform: scale(0) rotate(-30deg); } 55% { transform: scale(1.22) rotate(8deg); } 78% { transform: scale(.92) rotate(-3deg); } 100% { transform: none; } }
@keyframes tilt { 0%, 78%, 100% { transform: none; } 84% { transform: rotate(-9deg); } 92% { transform: rotate(7deg); } }
@keyframes earL { 50% { transform: rotate(-11deg); } }
@keyframes earR { 50% { transform: rotate(11deg); } }
@keyframes blink { 0%, 94%, 100% { transform: none; } 97% { transform: scaleY(.1); } }
@keyframes pant { to { transform: scaleY(1.35); } }
@keyframes hop { 50% { transform: translateY(-18%) scale(1.08); } }
#fx b { position: fixed; margin: -.6em 0 0 -.5em; color: #ff4d6d; font-weight: 400; line-height: 1; animation: burst .8s cubic-bezier(.2,.7,.3,1) forwards; }
@keyframes burst { from { transform: scale(.3); opacity: 1; } 70% { opacity: 1; } to { transform: translate(var(--x), var(--y)) scale(1.1); opacity: 0; } }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
@keyframes drop { from { transform: scale(.2) rotate(-30deg); opacity: 0; } }
@keyframes shake { 20%,60% { transform: translateX(-5px); } 40%,80% { transform: translateX(5px); } }
@keyframes wiggle { 25% { transform: rotate(-10deg) scale(1.08); } 75% { transform: rotate(10deg) scale(1.08); } }
.tools { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 14px; }
.tool { background: var(--card); border: 2px solid var(--line); border-radius: 15px; padding: 9px 2px 7px; font-weight: 800; font-size: 11.5px; color: var(--soft); box-shadow: 0 3px 0 var(--line); }
.tool:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.tool em { display: block; font-style: normal; font-size: 20px; line-height: 1.2; }
.tool.off em { filter: grayscale(1); opacity: .4; }
.help { text-align: center; color: var(--soft); font-weight: 700; font-size: 13px; margin-top: 12px; }

/* modal */
#modal:empty { display: none; }
#modal { position: fixed; inset: 0; background: rgba(43,33,28,.55); display: grid; place-items: center; padding: 18px; z-index: 20; animation: fade .2s; backdrop-filter: blur(3px); }
@keyframes fade { from { opacity: 0; } }
.sheet { width: min(400px, 100%); background: var(--card); border-radius: 28px; padding: 22px; text-align: center; box-shadow: 0 30px 80px -20px rgba(0,0,0,.5); animation: rise .35s cubic-bezier(.3,1.4,.5,1); max-height: 92dvh; overflow: auto; }
@keyframes rise { from { transform: translateY(40px) scale(.94); opacity: 0; } }
.sheet .big { width: 110px; height: 110px; border-radius: 50%; object-fit: cover; border: 5px solid #fff; box-shadow: var(--shadow); margin-top: -4px; }
.sheet h2 { font-size: 28px; margin: 10px 0 2px; }
.stars { font-size: 40px; letter-spacing: 6px; color: var(--gold); margin: 4px 0; }
.stars i { font-style: normal; color: #e6d6c0; }
.stars span { display: inline-block; animation: drop .5s backwards cubic-bezier(.3,1.6,.5,1); }
.facts { display: flex; gap: 8px; margin: 14px 0; }
.facts div { flex: 1; background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 9px 4px; }
.facts b { display: block; font-size: 20px; }
.facts span { font-size: 11.5px; color: var(--soft); font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.rankline { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 13px; margin: 6px 2px 14px; text-align: left; }
.rankline .xpbar { flex: 1; width: auto; height: 10px; }
.badge { display: inline-block; background: var(--gold); color: var(--ink); font-weight: 900; border-radius: 999px; padding: 5px 14px; margin: 6px 0; font-size: 14px; animation: pulse 1.2s infinite; }
.mini { text-align: left; margin: 0 0 14px; }
.mini .row { padding: 6px 8px; }
.mini .ava { width: 32px; height: 32px; }
.mini h4 { margin: 0 8px 4px; font-size: 12px; color: var(--soft); text-transform: uppercase; letter-spacing: .06em; }
.acts { display: flex; gap: 10px; }
.acts .btn { flex: 1; }
.pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0; }
.pick button img { width: 100%; aspect-ratio: 1; border-radius: 50%; object-fit: cover; border: 4px solid transparent; display: block; }
.pick button.on img { border-color: var(--accent); }
#fx { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 30; }
#fx span { position: absolute; top: -40px; font-size: 26px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
@media (min-width: 560px) { .tool { font-size: 13px; } .wrap { padding-top: 26px; } }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01s !important; } }
