@font-face { font-family: "Plex Latin"; src: url(fonts/plex-latin.woff2) format('woff2'); font-weight: 400 700; font-display: swap;
  unicode-range: U+0000-00FF, U+2013-2026, U+00D7, U+2212; }
@font-face { font-family: "Plex Arabic"; src: url(fonts/plex-ar-400.woff2) format('woff2'); font-weight: 400; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F; }
@font-face { font-family: "Plex Arabic"; src: url(fonts/plex-ar-600.woff2) format('woff2'); font-weight: 500 600; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F; }
@font-face { font-family: "Plex Arabic"; src: url(fonts/plex-ar-700.woff2) format('woff2'); font-weight: 700 900; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F; }
:root {
  --bg0: #0B1020; --bg1: #17203A; --panel: #141C31; --line: #222C4A; --ivory: #F4EFE6; --muted: #8F9BB8;
  --gold: #F1AE3A; --gold2: #FFD27A; --teal: #139E9C; --r: 24px;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  font-family: "Plex Latin", "Plex Arabic", system-ui, sans-serif;
}
[dir=rtl] { font-family: "Plex Arabic", "Plex Latin", system-ui, sans-serif; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg0); color: var(--ivory); overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
.ic { display: block; flex: none; }
[dir=rtl] .ic.flip { transform: scaleX(-1); }
#app { position: fixed; inset: 0; background: radial-gradient(120% 80% at 50% 30%, var(--bg1), var(--bg0)); }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; }
.screen.on { display: flex; animation: scrIn .38s cubic-bezier(.2,.8,.2,1); }
@keyframes scrIn { from { opacity: 0; transform: translateY(16px) scale(.985); } }

/* top bars */
.top { width: 100%; max-width: 560px; display: flex; gap: 8px; padding: calc(16px + var(--sat)) 16px 0; }
.sp { flex: 1; }
.ib { width: 48px; height: 48px; border-radius: 16px; display: grid; place-items: center; background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.07); transition: transform .12s; }
.ib:active, .boost:active, .card:active, .sq:active, .row:active { transform: scale(.92); }
.gift { color: var(--gold); position: relative; }
.gift:not(.used)::after { content: ''; position: absolute; top: 9px; inset-inline-end: 9px; width: 8px; height: 8px; border-radius: 50%; background: #E2563D; }
.gift.used { color: var(--muted); }

/* home */
.hero { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 0; }
#emblem { width: min(64vw, 280px, 34vh); height: min(64vw, 280px, 34vh); filter: drop-shadow(0 16px 32px rgba(0,0,0,.5)); }
.mark { margin: 8px 0 0; font-size: 56px; font-weight: 800; letter-spacing: -1px; line-height: 1;
  background: linear-gradient(180deg, #FFF6E2, #F1AE3A); -webkit-background-clip: text; background-clip: text; color: transparent; }
[dir=rtl] .mark { font-size: 60px; letter-spacing: 0; font-weight: 700; line-height: 1.3; }
.bestline { display: flex; gap: 8px; align-items: center; color: var(--gold2); font-size: 20px; }
.actions { width: 100%; max-width: 420px; padding: 0 24px calc(32px + var(--sab)); display: flex; flex-direction: column; gap: 16px; }
.cta { height: 72px; border-radius: 36px; display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%;
  font-size: 26px; font-weight: 700; color: #22160A; background: linear-gradient(180deg, #FFD98A, #F1AE3A 55%, #D98E1F);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.6), inset 0 -4px 0 rgba(120,60,0,.35), 0 12px 28px rgba(241,174,58,.28);
  transition: transform .12s; }
.cta:active { transform: scale(.95) translateY(2px); }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card { height: 88px; border-radius: var(--r); background: linear-gradient(180deg, #1B2541, #141C31); border: 1px solid var(--line);
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: 1fr 1fr; align-items: center; column-gap: 12px; padding: 0 16px;
  text-align: start; transition: transform .12s; }
.card .ic { grid-row: span 2; color: var(--gold); }
.card span { font-size: 18px; font-weight: 600; align-self: end; }
.card b { font-size: 16px; color: var(--muted); font-weight: 500; align-self: start; display: flex; gap: 8px; align-items: center; }
.card b em { font-style: normal; display: flex; gap: 2px; color: #FF8A4C; align-items: center; }
.card.done b { color: #5FD39A; }

/* path */
.tabs { display: flex; gap: 8px; padding: 16px; }
.tab { height: 40px; padding: 0 16px; border-radius: 20px; background: rgba(255,255,255,.05); color: var(--muted); font-weight: 600; }
.tab.on { background: var(--ivory); color: var(--bg0); }
#mosaic { width: min(72vw, 300px, 36vh); height: min(72vw, 300px, 36vh); filter: drop-shadow(0 12px 24px rgba(0,0,0,.45)); }
.grid { display: grid; grid-template-columns: repeat(4, 64px); gap: 16px; padding: 24px 16px calc(24px + var(--sab)); }
.node { width: 64px; height: 64px; border-radius: 20px; background: linear-gradient(180deg, #22305A, #18213D); border: 1px solid #2C3A66;
  display: grid; place-items: center; position: relative; font-size: 22px; font-weight: 700; box-shadow: 0 4px 0 #0A0F1E; }
.node.hard { background: linear-gradient(180deg, #5A2A2A, #3D1B1F); border-color: #7A3A33; }
.node.fin { background: linear-gradient(180deg, #6B4A12, #4A320C); border-color: #A47422; }
.node.cur { outline: 3px solid var(--gold); outline-offset: 3px; animation: bob 1.6s ease-in-out infinite; }
.node.lock { opacity: .4; box-shadow: none; }
.node i { position: absolute; bottom: -6px; display: flex; gap: 2px; }
.node i s { width: 10px; height: 10px; background: var(--gold); clip-path: polygon(50% 0, 63% 35%, 100% 38%, 72% 60%, 82% 100%, 50% 78%, 18% 100%, 28% 60%, 0 38%, 37% 35%); }
@keyframes bob { 50% { transform: translateY(-4px); } }

/* game */
#gameScreen { justify-content: space-between; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#hud { position: relative; width: 100%; max-width: 600px; padding: calc(12px + var(--sat)) 16px 0; pointer-events: none; }
#hud button { pointer-events: auto; }
.hrow { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.scorebox { text-align: center; }
#score { font-size: 48px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; font-family: "Plex Latin", sans-serif; text-shadow: 0 4px 16px rgba(0,0,0,.4); }
#score.pop { animation: pop .28s cubic-bezier(.3,1.6,.5,1); }
@keyframes pop { 40% { transform: scale(1.12); } }
#streak { direction: ltr; height: 24px; font-weight: 800; font-size: 18px; font-family: "Plex Latin", sans-serif; }
#streak.hot1 { color: #F1AE3A; } #streak.hot2 { color: #FF7A3D; } #streak.hot3 { color: #BFE6FF; text-shadow: 0 0 12px #7FC8FF; }
.best { justify-self: end; display: flex; gap: 6px; align-items: center; color: var(--gold2); font-weight: 600; font-family: "Plex Latin", sans-serif; }
#goals { display: flex; justify-content: center; gap: 8px; margin-top: 8px; }
.chip { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: 18px; background: rgba(20,28,49,.85);
  border: 1px solid var(--line); font-family: "Plex Latin", sans-serif; font-size: 18px; }
.chip .ic { color: var(--gold); } .chip.ok { border-color: #2E9E63; } .chip.ok .ic { color: #5FD39A; }
.chip.warn { border-color: #DC5F3E; animation: pop .6s infinite; }
#bar { position: relative; display: flex; gap: 24px; justify-content: center; padding: 0 16px calc(16px + var(--sab)); pointer-events: none; }
.boost { pointer-events: auto; position: relative; width: 60px; height: 60px; border-radius: 20px; display: grid; place-items: center;
  background: linear-gradient(180deg, #22305A, #18213D); border: 1px solid #2C3A66; color: var(--ivory); box-shadow: 0 4px 0 #0A0F1E; transition: transform .12s; }
.boost b { direction: ltr; position: absolute; top: -6px; inset-inline-end: -6px; min-width: 24px; height: 24px; border-radius: 12px; background: var(--gold); color: #22160A;
  font-size: 14px; font-weight: 800; display: grid; place-items: center; padding: 0 6px; font-family: "Plex Latin", sans-serif; }
.boost.on { background: linear-gradient(180deg, #FFD98A, #F1AE3A); color: #22160A; animation: pop .8s infinite; }
body[data-mode=tutorial] #bar, body[data-mode=tutorial] #bestWrap { visibility: hidden; }

/* sheets */
#sheet { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#sheet.on { pointer-events: auto; }
.scrim { position: absolute; inset: 0; background: rgba(5,8,18,.6); opacity: 0; transition: opacity .25s; backdrop-filter: blur(3px); }
#sheet.on .scrim { opacity: 1; }
.panel { position: absolute; left: 50%; bottom: 0; width: min(100%, 480px); transform: translate(-50%, 110%);
  background: linear-gradient(180deg, #1A2340, #121A2F); border: 1px solid #2A3558; border-bottom: 0; border-radius: 32px 32px 0 0;
  padding: 24px 24px calc(24px + var(--sab)); display: flex; flex-direction: column; gap: 16px; align-items: stretch;
  transition: transform .34s cubic-bezier(.2,.9,.25,1.05); box-shadow: 0 -20px 60px rgba(0,0,0,.5); }
#sheet.on .panel { transform: translate(-50%, 0); }
@media (min-width: 700px) { .panel { bottom: 50%; border-radius: 32px; border-bottom: 1px solid #2A3558; transform: translate(-50%, 60%) scale(.96); opacity: 0;
  transition: transform .3s cubic-bezier(.2,.9,.25,1.05), opacity .2s; } #sheet.on .panel { transform: translate(-50%, 50%); opacity: 1; } }
.panel .h { text-align: center; font-size: 26px; font-weight: 700; display: flex; justify-content: center; align-items: center; gap: 8px; }
.panel .h.big { font-size: 36px; }
.panel .test { font-style: normal; font-size: 12px; font-weight: 700; color: #22160A; background: var(--gold); padding: 4px 8px; border-radius: 8px; }
.row { display: flex; align-items: center; gap: 16px; height: 56px; padding: 0 16px; border-radius: 16px; background: rgba(255,255,255,.04); font-size: 18px; text-align: start; transition: transform .12s; }
.row span { flex: 1; } .row .ic { color: var(--gold); }
.row.buy b { font-family: "Plex Latin", sans-serif; color: var(--gold2); }
.sw { width: 48px; height: 28px; border-radius: 14px; background: #2A3558; position: relative; transition: background .2s; }
.sw::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--ivory); transition: inset-inline-start .2s; }
.sw.on { background: var(--teal); } .sw.on::after { inset-inline-start: 23px; }
.seg { display: flex; background: #0F1628; border-radius: 12px; padding: 4px; }
.seg button { height: 36px; padding: 0 14px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--ivory); color: var(--bg0); }
.seg button[lang=ar] { font-family: "Plex Arabic", sans-serif; }
.ghost { height: 48px; color: var(--muted); font-size: 17px; display: flex; gap: 8px; justify-content: center; align-items: center; }
.btnrow { display: flex; gap: 16px; align-items: center; }
.btnrow .cta { flex: 1; }
.sq { width: 88px; height: 72px; border-radius: 22px; background: rgba(255,255,255,.06); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 13px; color: var(--muted); }
.sq .ic { color: var(--ivory); }
.goals { display: flex; justify-content: center; gap: 16px; }
.goal { width: 88px; height: 96px; border-radius: 22px; background: rgba(255,255,255,.05); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; font-size: 24px; font-weight: 700; font-family: "Plex Latin", sans-serif; }
.goal .ic { color: var(--gold); }
.sc { text-align: center; font-size: 40px; font-weight: 800; font-family: "Plex Latin", sans-serif; }
.sc.big { font-size: 64px; background: linear-gradient(180deg, #fff, #F1AE3A); -webkit-background-clip: text; background-clip: text; color: transparent; }
.nb { display: flex; justify-content: center; gap: 8px; color: var(--gold2); font-weight: 700; font-size: 20px; animation: pop .6s 3; }
.panel .bestline { justify-content: center; }
.lvl { text-align: center; color: var(--muted); }
.stars { display: flex; justify-content: center; gap: 8px; }
.st { color: #2A3558; } .st .ic { fill: currentColor; }
.st.on { color: var(--gold); animation: starIn .5s cubic-bezier(.3,1.7,.5,1) both; animation-delay: calc(450ms + var(--k) * 260ms); }
@keyframes starIn { from { transform: scale(0) rotate(-40deg); color: #2A3558; } }
.ring { position: relative; width: 120px; height: 120px; margin: 0 auto; display: grid; place-items: center; color: var(--gold); }
.ring svg.rg { position: absolute; inset: 0; transform: rotate(-90deg); } .ring circle { fill: none; stroke: var(--gold); stroke-width: 6; stroke-dasharray: 277; stroke-linecap: round; animation: ring 6s linear forwards; }
@keyframes ring { to { stroke-dashoffset: 277; } }

#toast { position: fixed; top: calc(96px + var(--sat)); left: 50%; transform: translate(-50%, -20px); opacity: 0; z-index: 20; display: flex; gap: 8px; align-items: center;
  background: var(--ivory); color: var(--bg0); padding: 10px 16px; border-radius: 20px; font-weight: 600; transition: all .25s; pointer-events: none; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#ad { position: fixed; inset: 0; z-index: 30; display: none; place-items: center; background: rgba(3,5,12,.92); }
#ad.on { display: grid; }
.adcard { width: 240px; padding: 32px; border-radius: 28px; background: #141C31; border: 1px dashed var(--gold); display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--gold); }
.adcard b { color: var(--ivory); }
.adcard i { width: 100%; height: 6px; border-radius: 3px; background: #2A3558; position: relative; overflow: hidden; }
.adcard i::after { content: ''; position: absolute; inset: 0; background: var(--gold); transform-origin: left; animation: adbar var(--d) linear forwards; }
@keyframes adbar { from { transform: scaleX(0); } }
body.reduce *, body.reduce *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
#path { justify-content: center; }
#path > .top { position: absolute; top: 0; left: 50%; transform: translateX(-50%); }
