/* Twist & Tile — warm workshop paper, enamel nuts, walnut planks. 8 px grid. */
/* IBM Plex Sans (Latin, variable 500-700) and IBM Plex Sans Arabic (500, 700): separate faces, SIL OFL 1.1 */
@font-face { font-family: 'TT Latin'; src: url(assets/fonts/plex-latin.woff2) format('woff2'); font-weight: 500 700; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: 'TT Arabic'; src: url(assets/fonts/plex-arabic-500.woff2) format('woff2'); font-weight: 400 600; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+200C-200F; }
@font-face { font-family: 'TT Arabic'; src: url(assets/fonts/plex-arabic-700.woff2) format('woff2'); font-weight: 700 900; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+200C-200F; }
:root {
  --bg: #F5EEE3; --paper: #FFFAF2; --ink: #2B2532; --muted: #8C8178; --line: #E6DBCB;
  --accent: #E8663D; --accent-d: #B9471F; --teal: #1F857D; --teal-d: #14605A; --gold: #E9B44C;
  --hard: #D9443B; --super: #7A3FD1;
  --r: 24px; --r-s: 16px;
  --font: 'TT Latin', 'TT Arabic', system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); overflow: hidden;
  overscroll-behavior: none; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
body { background:
  radial-gradient(circle at 18% 12%, rgba(255,255,255,.7), transparent 40%),
  radial-gradient(circle at 85% 90%, rgba(232,102,61,.07), transparent 45%), var(--bg); }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
button:focus-visible, label:focus-within { outline: 3px solid var(--teal); outline-offset: 2px; }
.num { font-family: 'TT Latin', sans-serif; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
svg { display: block; }
[dir=rtl] .flip { transform: scaleX(-1); }
#app { position: fixed; inset: 0; max-width: 560px; margin: 0 auto; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 16px);
  opacity: 0; pointer-events: none; transform: translateY(16px); transition: opacity .28s ease, transform .32s cubic-bezier(.2,.8,.2,1); }
.screen.on { opacity: 1; pointer-events: auto; transform: none; }

/* top bars */
.topbar, .hud { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.icon-btn { width: 48px; height: 48px; border-radius: 16px; display: grid; place-items: center; background: var(--paper);
  box-shadow: 0 2px 0 var(--line), 0 6px 16px rgba(60,40,20,.08); transition: transform .12s; }
.icon-btn:active { transform: scale(.92); }
.chip { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px 0 8px; border-radius: 20px; background: var(--paper);
  box-shadow: 0 2px 0 var(--line); font-weight: 700; font-size: 18px; }
.chip svg { width: 26px; height: 26px; }

/* home */
.brand { display: grid; place-items: center; margin: 8px 0 8px; }
.logo { display: flex; align-items: center; gap: 12px; }
.logo .emblem { width: 56px; height: 56px; filter: drop-shadow(0 4px 0 rgba(150,40,40,.25)); animation: spin-in 1s cubic-bezier(.3,1.4,.5,1); }
.logo .word { font-size: 40px; font-weight: 800; letter-spacing: -.01em; color: var(--ink); line-height: 1; }
@keyframes spin-in { from { transform: rotate(-180deg) scale(.4); opacity: 0 } }
.mosaic-card { background: var(--paper); border-radius: var(--r); padding: 16px; box-shadow: 0 3px 0 var(--line), 0 16px 40px rgba(60,40,20,.10);
  width: min(100%, 360px); margin: 0 auto; }
canvas.mosaic { width: 100%; aspect-ratio: 1; display: block; }
.ch-row { display: flex; justify-content: space-between; margin: 16px 4px 8px; font-weight: 700; font-size: 18px; }
.ch-row .num { color: var(--muted); }
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: var(--p, 0%); background: linear-gradient(90deg, var(--gold), var(--accent)); border-radius: 4px; transition: width .6s; }
[dir=rtl] .bar i { margin-inline-start: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 56px; padding: 0 24px; border-radius: 20px;
  font-weight: 800; font-size: 20px; transition: transform .1s, box-shadow .1s; position: relative; }
.btn svg { width: 22px; height: 22px; }
.btn:active { transform: translateY(3px); }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 5px 0 var(--accent-d), 0 12px 24px rgba(232,102,61,.3); }
.btn.primary:active { box-shadow: 0 2px 0 var(--accent-d); }
.btn.primary[disabled] { filter: grayscale(.7) opacity(.6); }
.btn.soft { background: var(--paper); box-shadow: 0 4px 0 var(--line); }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 2px var(--line); }
.btn small { font-size: 12px; font-weight: 700; opacity: .7; display: inline-flex; gap: 4px; align-items: center; }
.btn small svg { width: 16px; height: 16px; }
.btn.big { margin: 24px auto 0; width: min(100%, 360px); min-height: 72px; font-size: 26px; border-radius: 24px; }
.btn.big.hard { background: var(--hard); box-shadow: 0 5px 0 #9E2A23, 0 12px 24px rgba(217,68,59,.3); }
.btn.big.super { background: var(--super); box-shadow: 0 5px 0 #4F2591, 0 12px 24px rgba(122,63,209,.3); }
.tier-tag { font-style: normal; font-size: 13px; padding: 4px 8px; border-radius: 8px; background: rgba(255,255,255,.25); margin-inline-start: 8px; }
.home-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; width: min(100%, 360px); margin: 16px auto 0; }
.tile-btn { position: relative; display: flex; align-items: center; gap: 8px; height: 64px; padding: 0 16px; border-radius: 20px; background: var(--paper);
  box-shadow: 0 4px 0 var(--line); font-weight: 700; font-size: 18px; }
.tile-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--line); }
.tile-btn .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: #E7F3F1; color: var(--teal); }
#shopBtn .ico { background: #FCEBDD; color: var(--accent); }
.streak-chip { position: absolute; top: -8px; inset-inline-end: 8px; display: inline-flex; align-items: center; gap: 2px; height: 24px; padding: 0 8px;
  border-radius: 12px; background: var(--accent); color: #fff; font-style: normal; font-size: 13px; }
.streak-chip svg { width: 14px; height: 14px; }
.done-dot { position: absolute; bottom: -6px; inset-inline-end: 8px; width: 24px; height: 24px; border-radius: 12px; background: var(--teal); color: #fff; display: grid; place-items: center; }
.done-dot svg { width: 14px; height: 14px; }
#home { justify-content: flex-start; overflow-y: auto; }

/* game */
.level-pill { display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 16px; border-radius: 24px; background: var(--paper);
  box-shadow: 0 2px 0 var(--line); font-weight: 800; font-size: 20px; }
.tier { font-style: normal; font-size: 13px; color: #fff; padding: 4px 8px; border-radius: 8px; }
.tier.t1 { background: var(--hard); } .tier.t2 { background: var(--super); }
#game[data-tier="1"] { background: radial-gradient(circle at 50% 30%, rgba(217,68,59,.07), transparent 60%); }
#game[data-tier="2"] { background: radial-gradient(circle at 50% 30%, rgba(122,63,209,.09), transparent 60%); }
.board-wrap { position: relative; flex: 1; margin: 8px -8px; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.boosters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.boost { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 72px;
  border-radius: 20px; background: var(--paper); box-shadow: 0 4px 0 var(--line); font-weight: 700; font-size: 14px; transition: transform .1s; }
.boost svg { width: 28px; height: 28px; color: var(--teal); }
.boost:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--line); }
.boost[disabled] { opacity: .45; }
.badge { position: absolute; top: -6px; inset-inline-end: 6px; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px;
  background: var(--accent); color: #fff; font-style: normal; font-size: 13px; display: grid; place-items: center; box-shadow: 0 2px 0 var(--accent-d); }
.badge.plus { background: var(--teal); box-shadow: 0 2px 0 var(--teal-d); font-size: 16px; }
.banner { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%) scale(.6); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 8px; padding: 16px 24px; border-radius: 24px; color: #fff; font-weight: 800; font-size: 28px;
  transition: transform .4s cubic-bezier(.3,1.6,.5,1), opacity .25s; box-shadow: 0 16px 40px rgba(0,0,0,.18); white-space: nowrap; }
.banner.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.banner.t1 { background: var(--hard); } .banner.t2 { background: var(--super); }
.banner.intro { background: var(--teal); font-size: 22px; } .banner.intro small { display: block; font-size: 13px; opacity: .8; }
.banner svg { width: 28px; height: 28px; }
#coach { position: absolute; inset: 0; pointer-events: none; }
#coach .hand { position: absolute; left: 0; top: 0; transition: transform .45s cubic-bezier(.3,1.3,.5,1); animation: tapme 1.1s infinite; filter: drop-shadow(0 4px 6px rgba(0,0,0,.2)); }
#coach.flight .hand { opacity: 0; }
@keyframes tapme { 0%,100% { margin-top: 0 } 50% { margin-top: 10px } }
.coach-tip { position: absolute; left: 50%; transform: translateX(-50%); padding: 8px 16px; border-radius: 16px; background: var(--ink); color: #fff;
  font-weight: 700; font-size: 18px; white-space: nowrap; }

/* sheets */
.sheet-layer { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.sheet-layer.on { pointer-events: auto; }
.scrim { position: absolute; inset: 0; background: rgba(43,37,50,.45); opacity: 0; transition: opacity .25s; }
.sheet-layer.on .scrim { opacity: 1; }
.sheet { position: absolute; left: 50%; bottom: 0; width: min(100%, 520px); transform: translate(-50%, 100%); background: var(--paper);
  border-radius: 32px 32px 0 0; padding: 24px 24px calc(var(--safe-b) + 24px); transition: transform .34s cubic-bezier(.2,.9,.25,1.05);
  max-height: 92vh; overflow-y: auto; text-align: center; }
.sheet-layer.on .sheet { transform: translate(-50%, 0); }
.sheet.out { transform: translate(-50%, 100%) !important; }
.sheet h2 { margin: 0 0 16px; font-size: 28px; font-weight: 800; }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.sheet-head h2 { margin: 0; flex: 1; text-align: start; }
.sheet-icon { width: 72px; height: 72px; margin: 0 auto 8px; border-radius: 24px; display: grid; place-items: center; background: #E7F3F1; color: var(--teal); }
.sheet-icon svg { width: 36px; height: 36px; } .sheet-icon.warn { background: #FCEBDD; color: var(--accent); }
.actions { display: flex; gap: 16px; justify-content: center; margin-top: 24px; }
.actions .btn { flex: 1; } .actions.col { flex-direction: column; }
.win-title { font-size: 36px !important; color: var(--accent); animation: pop .5s cubic-bezier(.3,1.6,.5,1); }
@keyframes pop { from { transform: scale(.4); opacity: 0 } }
.mosaic-frame { width: min(70vw, 280px); margin: 0 auto; padding: 8px; border-radius: 24px; background: var(--bg); }
.sub { margin: 16px 0 0; color: var(--muted); font-weight: 700; font-size: 18px; }
.reward { margin-top: 16px; } .reward .chip { font-size: 24px; height: 48px; background: #FFF3D6; }
.streak { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 22px; font-weight: 800; color: var(--accent); }
.streak svg { width: 40px; height: 40px; } .streak b { font-size: 44px; }
.row-set { display: flex; align-items: center; gap: 16px; min-height: 64px; border-bottom: 1px solid var(--line); text-align: start; font-weight: 700; font-size: 18px; cursor: pointer; }
.row-set .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--bg); color: var(--teal); }
.row-set .lbl { flex: 1; }
.row-set input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sw { width: 52px; height: 32px; border-radius: 16px; background: var(--line); position: relative; transition: background .2s; }
.sw::after { content: ''; position: absolute; top: 4px; inset-inline-start: 4px; width: 24px; height: 24px; border-radius: 12px; background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: inset-inline-start .2s; }
input:checked + .sw { background: var(--teal); } input:checked + .sw::after { inset-inline-start: 24px; }
.seg { display: flex; background: var(--bg); border-radius: 14px; padding: 4px; }
.seg button { height: 36px; padding: 0 12px; border-radius: 10px; font-weight: 700; font-size: 15px; color: var(--muted); }
.seg button.on { background: var(--paper); color: var(--ink); box-shadow: 0 2px 0 var(--line); }
.fine { margin: 16px 0 0; font-size: 14px; color: var(--muted); } .fine a { color: var(--teal); }
.test-note { margin: -8px 0 8px; font-size: 12px; font-weight: 800; letter-spacing: .08em; color: var(--accent); }
.shop-item { width: 100%; display: flex; align-items: center; gap: 16px; min-height: 72px; padding: 0 16px; margin-top: 8px; border-radius: 20px;
  background: var(--bg); text-align: start; font-weight: 700; font-size: 18px; }
.shop-item .ico { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--paper); color: var(--accent); }
.shop-item .ico svg { width: 26px; height: 26px; }
.shop-item .lbl { flex: 1; display: flex; flex-direction: column; } .shop-item small { font-size: 13px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.shop-item small svg { width: 14px; height: 14px; }
.shop-item .price { min-width: 72px; height: 40px; padding: 0 12px; border-radius: 14px; background: var(--teal); color: #fff; display: grid; place-items: center; }
.shop-item[disabled] { opacity: .6; }
.link { margin-top: 16px; color: var(--teal); font-weight: 700; }
.test-ad { position: fixed; inset: 0; z-index: 30; background: rgba(20,16,26,.92); display: grid; place-items: center; opacity: 0; transition: opacity .2s; }
.test-ad.on { opacity: 1; }
.ad-card { position: relative; width: min(80vw, 320px); aspect-ratio: 9 / 14; border-radius: 24px; background: #2E2838; color: #fff; display: grid; place-items: center; }
.ad-card .tag { position: absolute; top: 16px; inset-inline-start: 16px; font-size: 12px; font-weight: 800; letter-spacing: .08em; color: var(--gold); }
.ad-art svg { width: 72px; height: 72px; opacity: .5; }
.ad-count { position: absolute; bottom: 24px; font-size: 32px; font-weight: 800; }
.ad-x { position: absolute; top: 8px; inset-inline-end: 8px; background: #fff; color: var(--ink); }
#toast { position: fixed; left: 50%; top: calc(var(--safe-t) + 72px); transform: translate(-50%, -20px); opacity: 0; z-index: 40; padding: 12px 24px;
  border-radius: 20px; background: var(--ink); color: #fff; font-weight: 700; transition: .25s; pointer-events: none; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 900px) {
  #app { max-width: none; }
  #home { align-items: center; justify-content: center; }
  #home .topbar { position: absolute; top: 24px; left: 32px; right: 32px; }
  #game { padding: 24px 15vw 32px; }
  .boosters { width: 520px; margin: 0 auto; }
  .hud { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition-duration: .01s !important; animation: none !important; } }

/* lives, live mosaic, flying tiles */
.chips { display: flex; gap: 8px; }
.chip.lives svg { width: 24px; height: 24px; }
.chip.lives small { font-size: 13px; color: var(--muted); font-weight: 700; }
.live-card { position: absolute; top: 0; left: 50%; margin-left: -64px; width: 128px; padding: 6px; border-radius: 18px; background: var(--paper);
  box-shadow: 0 3px 0 var(--line), 0 8px 20px rgba(60,40,20,.10); z-index: 2; }
.live-card.pulse { animation: cardpulse .45s cubic-bezier(.3,1.6,.5,1); }
@keyframes cardpulse { 50% { transform: scale(1.12); } }
.fly-tiles { position: absolute; left: -14px; top: -14px; width: 28px; height: 28px; border-radius: 6px; pointer-events: none; z-index: 3;
  background:
    linear-gradient(90deg, transparent 31%, rgba(255,250,242,.9) 31%, rgba(255,250,242,.9) 36%, transparent 36%, transparent 64%, rgba(255,250,242,.9) 64%, rgba(255,250,242,.9) 69%, transparent 69%),
    linear-gradient(0deg, transparent 31%, rgba(255,250,242,.9) 31%, rgba(255,250,242,.9) 36%, transparent 36%, transparent 64%, rgba(255,250,242,.9) 64%, rgba(255,250,242,.9) 69%, transparent 69%),
    var(--c);
  box-shadow: 0 6px 14px rgba(0,0,0,.2), 0 0 0 2px rgba(255,255,255,.6); }
.boost.locked { opacity: .55; }
.boost.locked .badge svg { width: 14px; height: 14px; color: #fff; }
.hearts { display: flex; justify-content: center; gap: 8px; margin-bottom: 8px; }
.hearts span { opacity: .25; filter: grayscale(1); } .hearts span.on { opacity: 1; filter: none; }
.hearts svg { width: 40px; height: 40px; }
.timer { font-size: 28px; font-weight: 800; margin: 0 0 8px; color: var(--muted); }
.lose svg { width: 16px; height: 16px; }
.fine svg { width: 16px; height: 16px; display: inline-block; vertical-align: -3px; margin-inline-end: 4px; }
.shop-item .lbl { display: block; } .shop-item .lbl small { margin-top: 2px; }
