:root {
  --ink: #0b1510;
  --moss: #16231a;
  --gold: #e6c983;
  --gold-2: #b99a5a;
  --ivory: #f4eedc;
  --mist: #c9d3c0;
  --emerald: #8dffb0;
  --amber: #ffb35c;
  --danger: #ff7a54;
  --glass: rgba(10, 20, 14, 0.62);
  --hair: rgba(230, 201, 131, 0.38);
  --ar-display: 'Aref Ruqaa', 'Amiri', 'Cairo', serif;
  --ar-body: 'Cairo', 'Amiri', sans-serif;
  --ar-sub: 'Amiri', 'Cairo', serif;
  --en-display: 'Cinzel', 'Cormorant Garamond', Georgia, serif;
  --en-body: 'Cormorant Garamond', Georgia, serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: var(--ink); color: var(--ivory); font-family: var(--ar-body); user-select: none; -webkit-user-select: none; }
html[lang="en"] body { font-family: var(--en-body); }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible { outline: 1px solid var(--gold); outline-offset: 4px; }
kbd { font-family: var(--en-body); font-weight: 600; font-size: 12px; letter-spacing: .5px; padding: 2px 7px; border: 1px solid var(--hair); border-radius: 5px; background: rgba(0,0,0,.35); color: var(--gold); white-space: nowrap; }
.hidden { display: none !important; }
#game, #world, .screen, #vignette, #hurt, #fade { position: absolute; inset: 0; }
#world { display: block; width: 100%; height: 100%; touch-action: none; }
#vignette { pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 52%, rgba(4, 12, 7, .55) 100%); z-index: 1; }
#hurt { pointer-events: none; z-index: 2; opacity: 0; background: radial-gradient(ellipse at center, transparent 40%, rgba(120, 20, 30, .55) 100%); transition: opacity .5s; }
#hurt.on { opacity: 1; transition: opacity .05s; }
#fade { background: #050a07; z-index: 60; opacity: 0; pointer-events: none; transition: opacity .7s ease; }
#fade.on { opacity: 1; }

/* ---------- letterbox & cinematic text ---------- */
#letterbox i { position: absolute; left: 0; right: 0; height: 11vh; background: #000; z-index: 20; transition: transform .9s cubic-bezier(.7, 0, .2, 1); pointer-events: none; }
#letterbox .top { top: 0; transform: translateY(-100%); }
#letterbox .bottom { bottom: 0; transform: translateY(100%); }
body.cine #letterbox .top, body.cine #letterbox .bottom { transform: translateY(0); }
#subtitle { position: absolute; left: 50%; bottom: 13.5vh; transform: translateX(-50%); width: min(92vw, 980px); text-align: center; z-index: 25; pointer-events: none; }
#subtitle p { margin: 0; font-family: var(--ar-sub); font-size: clamp(20px, 2.3vw, 31px); line-height: 1.7; color: var(--ivory); text-shadow: 0 2px 18px rgba(0,0,0,.9), 0 0 2px #000; animation: rise .8s ease both; }
html[lang="en"] #subtitle p { font-family: var(--en-body); font-style: italic; font-size: clamp(20px, 2.1vw, 29px); }
#dialog { position: absolute; left: 50%; bottom: max(14vh, 120px); transform: translateX(-50%); width: min(92vw, 860px); display: flex; gap: 18px; align-items: center; z-index: 25; padding: 16px 22px; border-radius: 18px; background: linear-gradient(180deg, rgba(12, 22, 15, .78), rgba(8, 16, 11, .88)); border: 1px solid var(--hair); box-shadow: 0 20px 60px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.04); backdrop-filter: blur(8px); animation: rise .5s ease both; pointer-events: none; }
body:not(.cine) #dialog { bottom: 130px; }
#dialog .portrait { flex: 0 0 74px; height: 74px; border-radius: 50%; background-size: cover; background-position: center; border: 2px solid var(--gold); box-shadow: 0 0 0 4px rgba(230,201,131,.12), 0 0 26px rgba(255,170,80,.35); }
#dialog.heir .portrait { background-image: url(./assets/img/mask_close.webp); background-position: 50% 45%; background-size: 260%; box-shadow: 0 0 0 4px rgba(141,255,176,.1); border-color: #9fd9a8; }
#dialog.elder .portrait { background-image: url(./assets/img/elder_portrait.webp); }
#dialog b { display: block; font-family: var(--ar-body); font-weight: 700; color: var(--gold); font-size: 14px; letter-spacing: .5px; margin-bottom: 2px; }
html[lang="en"] #dialog b { font-family: var(--en-display); letter-spacing: 2px; font-size: 12px; }
#dialog p { margin: 0; font-family: var(--ar-sub); font-size: clamp(18px, 1.8vw, 24px); line-height: 1.6; }
html[lang="en"] #dialog p { font-family: var(--en-body); font-size: clamp(18px, 1.7vw, 23px); }
#skip { position: absolute; bottom: 3.5vh; inset-inline-end: 3vw; z-index: 30; padding: 9px 18px; border-radius: 40px; border: 1px solid var(--hair); background: rgba(0,0,0,.4); color: var(--mist); font-size: 13px; letter-spacing: 1px; transition: .2s; }
#skip:hover { color: var(--gold); border-color: var(--gold); }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; animation: fadein 1s ease both; }
.quest { position: absolute; top: 26px; inset-inline-start: 30px; max-width: 360px; padding-inline-start: 16px; border-inline-start: 2px solid var(--gold); }
.q-chapter { font-size: 11px; letter-spacing: 3px; color: var(--gold); text-transform: uppercase; font-weight: 600; }
html[lang="ar"] .q-chapter { letter-spacing: 0; font-size: 13px; }
.quest h2 { margin: 3px 0 4px; font-family: var(--ar-display); font-weight: 700; font-size: 30px; line-height: 1.15; text-shadow: 0 2px 14px rgba(0,0,0,.7); }
html[lang="en"] .quest h2 { font-family: var(--en-display); font-size: 21px; letter-spacing: 1px; }
.quest p { margin: 0; font-size: 15px; line-height: 1.6; color: var(--mist); text-shadow: 0 1px 8px rgba(0,0,0,.9); }
html[lang="en"] .quest p { font-size: 17px; }
.quest.flash h2 { animation: questflash 1.4s ease; }
.topend { position: absolute; top: 24px; inset-inline-end: 28px; display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }
html[dir="rtl"] .topend { align-items: flex-start; }
.powers { display: flex; gap: 10px; }
.pw { position: relative; width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; background: rgba(6, 14, 9, .55); border: 1px solid rgba(255,255,255,.12); opacity: .38; transition: .6s; }
.pw svg { width: 30px; height: 30px; fill: var(--mist); stroke: var(--mist); stroke-width: 2.2; stroke-linecap: round; }
.pw kbd { position: absolute; bottom: -9px; font-size: 9px; padding: 0 4px; }
.pw.on { opacity: 1; border-color: var(--emerald); box-shadow: 0 0 18px rgba(141,255,176,.35), inset 0 0 12px rgba(141,255,176,.18); }
.pw.on svg { fill: var(--emerald); stroke: var(--emerald); filter: drop-shadow(0 0 6px rgba(141,255,176,.8)); }
.seedcount { display: flex; align-items: baseline; gap: 6px; padding: 6px 14px; border-radius: 30px; background: rgba(6,14,9,.5); border: 1px solid var(--hair); font-family: var(--en-display); }
.seedcount b { font-size: 18px; color: #ffe39a; }
.seedcount small { color: var(--mist); font-size: 12px; }
.seed-ico { width: 10px; height: 10px; transform: rotate(45deg); background: #ffe39a; box-shadow: 0 0 10px #ffcf5a; align-self: center; }
.seedcount.pop { animation: pop .5s ease; }
.energy { position: absolute; bottom: 30px; inset-inline-start: 30px; width: min(320px, 34vw); }
.energy .lbl { display: block; font-size: 11px; letter-spacing: 3px; color: var(--gold); margin-bottom: 7px; font-weight: 600; }
html[lang="ar"] .energy .lbl { letter-spacing: 0; font-size: 13px; }
.energy .bar { position: relative; height: 9px; border-radius: 9px; background: rgba(0,0,0,.45); border: 1px solid rgba(230,201,131,.28); overflow: hidden; }
.energy .bar i { position: absolute; inset-block: 0; inset-inline-start: 0; width: 100%; border-radius: 9px; background: linear-gradient(90deg, #3f9a59, #8dffb0 70%, #e8ffe8); box-shadow: 0 0 14px rgba(141,255,176,.6); transition: width .25s; }
html[dir="rtl"] .energy .bar i { background: linear-gradient(270deg, #3f9a59, #8dffb0 70%, #e8ffe8); }
.energy.low .bar i { background: linear-gradient(90deg, #8a3a2a, #ff9a5a); box-shadow: 0 0 14px rgba(255,120,80,.6); }
.energy .bar s { position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 18px, rgba(0,0,0,.35) 18px 20px); }
#marker { position: absolute; left: 0; top: 0; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 3px; transition: opacity .3s; }
#marker .dia { width: 16px; height: 16px; transform: rotate(45deg); border: 2px solid var(--gold); background: rgba(230,201,131,.25); box-shadow: 0 0 14px rgba(255,210,120,.8); animation: breathe 1.8s ease-in-out infinite; }
#marker small { font-family: var(--en-display); font-size: 11px; color: var(--gold); text-shadow: 0 1px 6px #000; }
#marker.edge .dia { border-radius: 2px 50% 50% 50%; }
#minimap { position: absolute; bottom: 24px; inset-inline-end: 26px; width: 150px; height: 150px; border-radius: 50%; border: 1px solid var(--hair); box-shadow: 0 10px 30px rgba(0,0,0,.4); background: rgba(8,16,11,.55); transition: all .35s ease; pointer-events: auto; cursor: pointer; }
#minimap.big { width: min(70vh, 560px); height: min(70vh, 560px); bottom: 50%; inset-inline-end: 50%; transform: translate(50%, 50%); }
html[dir="rtl"] #minimap.big { transform: translate(-50%, 50%); }
#interact { position: absolute; left: 50%; bottom: 17vh; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; padding: 10px 20px 10px 12px; border-radius: 50px; background: var(--glass); border: 1px solid var(--hair); backdrop-filter: blur(6px); animation: rise .35s ease both; }
html[dir="rtl"] #interact { padding: 10px 12px 10px 20px; }
#interact .ring { position: relative; width: 48px; height: 48px; display: grid; place-items: center; }
#interact svg { position: absolute; inset: 0; transform: rotate(-90deg); }
#interact circle { fill: none; stroke-width: 4; }
#interact .bg { stroke: rgba(255,255,255,.12); }
#interact .fg { stroke: var(--emerald); stroke-dasharray: 170; stroke-dashoffset: 170; stroke-linecap: round; filter: drop-shadow(0 0 4px var(--emerald)); }
#interact strong { display: block; font-size: 16px; }
#interact small { color: var(--mist); font-size: 12px; }
#bossbar { position: absolute; top: 22px; left: 50%; transform: translateX(-50%); width: min(520px, 60vw); text-align: center; }
#bossbar span { font-size: 12px; color: var(--gold); letter-spacing: 1px; }
#bossbar .hearts { display: flex; justify-content: center; align-items: center; gap: 10px; margin-bottom: 8px; }
#bossbar .hearts i { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--emerald); background: rgba(0,0,0,.4); }
#bossbar .hearts i.on { background: var(--emerald); box-shadow: 0 0 12px var(--emerald); }
#bossbar .track { position: relative; height: 6px; margin-top: 6px; border-radius: 6px; background: rgba(0,0,0,.5); border: 1px solid rgba(255,140,90,.35); }
#bossbar .track b { position: absolute; inset-block: 0; inset-inline-start: 0; border-radius: 6px; background: linear-gradient(90deg, #6b3a24, var(--danger)); }
#bossbar .tree { position: absolute; inset-inline-end: -18px; top: -9px; font-style: normal; color: var(--emerald); font-size: 18px; }
#bossbar .dz { position: absolute; top: -5px; width: 14px; height: 14px; margin-inline-start: -7px; border-radius: 3px; background: #e0b030; box-shadow: 0 0 10px #ff9a40; }
#lockHint { position: absolute; left: 50%; top: 74%; transform: translateX(-50%); font-size: 14px; color: var(--mist); padding: 8px 16px; border-radius: 30px; background: rgba(0,0,0,.4); animation: breathe 2s infinite; }
#toast { position: absolute; left: 50%; top: 92px; transform: translate(-50%, -12px); z-index: 30; padding: 9px 22px; border-radius: 40px; background: var(--glass); border: 1px solid var(--hair); font-size: 15px; opacity: 0; transition: .4s; pointer-events: none; backdrop-filter: blur(6px); white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#toast.save::before { content: '❦ '; color: var(--emerald); }

/* touch */
#touch { display: none; }
body.touch #touch { display: block; pointer-events: auto; }
body.touch .energy { bottom: auto; top: 128px; width: 200px; }
body.touch #minimap { bottom: auto; top: 140px; width: 96px; height: 96px; }
body.touch .controls-hint, body.touch .pw kbd { display: none; }
#joystick { position: absolute; left: 34px; bottom: 34px; width: 132px; height: 132px; border-radius: 50%; border: 1px solid var(--hair); background: rgba(0,0,0,.25); }
#stick { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px; border-radius: 50%; background: rgba(230,201,131,.35); border: 1px solid var(--gold); }
.tbtns { position: absolute; right: 26px; bottom: 30px; display: grid; grid-template-columns: repeat(2, 66px); gap: 12px; }
.tbtns button, #tPause { width: 66px; height: 66px; border-radius: 50%; border: 1px solid var(--hair); background: rgba(6,14,9,.55); color: var(--gold); font-size: 22px; }
#tPause { position: absolute; top: 20px; left: 50%; width: 44px; height: 44px; margin-left: -22px; font-size: 16px; }
body.touch #interact { bottom: 190px; }

/* ---------- chapter card ---------- */
#chapter { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; background: #050a07; animation: fadein 1s ease both; }
#chapter.out { animation: fadeout 1s ease both; }
.ch-img { position: absolute; inset: 0; background-size: cover; background-position: center; opacity: .5; animation: kenburns 9s ease-out both; filter: saturate(.9); }
.ch-img::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(5,10,7,.25), rgba(5,10,7,.92) 75%); }
.ch-body { position: relative; text-align: center; padding: 0 6vw; }
#chLabel { font-size: 14px; letter-spacing: 6px; color: var(--gold); animation: rise 1.2s .3s ease both; display: inline-block; }
html[lang="ar"] #chLabel { letter-spacing: 1px; font-size: 18px; }
#chapter h2 { margin: 8px 0 0; font-family: var(--ar-display); font-size: clamp(48px, 8vw, 104px); font-weight: 700; line-height: 1.15; background: linear-gradient(180deg, #fff7df, #e6c983 60%, #a8874a); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 6px 30px rgba(0,0,0,.6)); animation: rise 1.3s .5s ease both; }
html[lang="en"] #chapter h2 { font-family: var(--en-display); letter-spacing: 4px; font-size: clamp(36px, 6vw, 76px); }
#chapter p { margin: 10px 0 0; font-family: var(--ar-sub); font-size: clamp(17px, 1.8vw, 24px); color: var(--mist); font-style: italic; animation: rise 1.3s .9s ease both; }
.orn { display: flex; align-items: center; justify-content: center; gap: 14px; color: var(--gold); margin: 14px auto; }
.orn i { width: 90px; height: 1px; background: linear-gradient(90deg, transparent, var(--gold)); }
.orn i:last-child { transform: scaleX(-1); }

/* ---------- power card ---------- */
#powercard { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 35; width: min(560px, 90vw); text-align: center; padding: 30px 34px 26px; border-radius: 22px; background: radial-gradient(ellipse at top, rgba(40, 90, 55, .55), rgba(8,16,11,.92) 70%); border: 1px solid rgba(141,255,176,.45); box-shadow: 0 0 60px rgba(141,255,176,.25), 0 30px 80px rgba(0,0,0,.6); animation: powerin .9s cubic-bezier(.2, 1.4, .4, 1) both; pointer-events: none; }
#powercard.out { animation: fadeout .8s ease both; }
#powercard > span { font-size: 12px; letter-spacing: 4px; color: var(--emerald); }
html[lang="ar"] #powercard > span { letter-spacing: 0; font-size: 15px; }
#powercard h3 { margin: 6px 0 8px; font-family: var(--ar-display); font-size: 44px; color: var(--ivory); text-shadow: 0 0 24px rgba(141,255,176,.6); }
html[lang="en"] #powercard h3 { font-family: var(--en-display); font-size: 32px; }
#powercard p { margin: 0; font-size: 16px; line-height: 1.7; color: var(--mist); }
.pc-glyph { width: 84px; height: 84px; margin: 0 auto 10px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--emerald); box-shadow: 0 0 40px rgba(141,255,176,.6); }
.pc-glyph svg { width: 50px; height: 50px; fill: var(--emerald); stroke: var(--emerald); stroke-width: 2.2; stroke-linecap: round; filter: drop-shadow(0 0 8px var(--emerald)); }

/* ---------- loading ---------- */
#loading { z-index: 70; display: grid; place-items: center; background: #060c08; }
.ld-bg { position: absolute; inset: 0; background: url(./assets/img/mask_close.webp) center/cover; opacity: .22; filter: blur(2px) saturate(.8); animation: kenburns 30s ease-out both; }
.ld-bg::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(6,12,8,.3), #060c08 75%); }
.ld-center { position: relative; text-align: center; }
.ld-ring { width: 120px; height: 120px; transform: rotate(-90deg); }
.ld-ring circle { fill: none; stroke-width: 2; }
.ld-ring .bg { stroke: rgba(230,201,131,.15); }
.ld-ring .fg { stroke: var(--gold); stroke-dasharray: 327; stroke-dashoffset: 327; transition: stroke-dashoffset .4s; filter: drop-shadow(0 0 6px rgba(230,201,131,.7)); }
.ld-leaf { position: absolute; top: 34px; left: 50%; transform: translateX(-50%); font-size: 40px; color: var(--gold); animation: breathe 2.4s ease-in-out infinite; }
.ld-center h3 { margin: 22px 0 6px; font-family: var(--ar-display); font-size: 30px; font-weight: 400; }
html[lang="en"] .ld-center h3 { font-family: var(--en-display); font-size: 18px; letter-spacing: 4px; }
.ld-center p { margin: 0; color: var(--mist); font-family: var(--ar-sub); font-size: 17px; min-height: 28px; animation: fadein 1s ease; }
.ld-center small { display: block; margin-top: 10px; color: var(--gold-2); font-family: var(--en-display); letter-spacing: 2px; }

/* ---------- title ---------- */
#title { z-index: 50; overflow: hidden; animation: fadein 1.4s ease both; }
.tt-bg { position: absolute; inset: -4%; background: url(./assets/img/hero_run.webp) 30% 40%/cover; animation: kenburns 40s ease-out both; }
.tt-bg::after { content: ''; position: absolute; inset: 0; background: linear-gradient(270deg, rgba(5,11,7,.92) 0%, rgba(5,11,7,.62) 34%, rgba(5,11,7,.05) 66%), linear-gradient(0deg, rgba(5,11,7,.85), transparent 30%, transparent 80%, rgba(5,11,7,.5)); }
html[dir="ltr"] .tt-bg::after { background: linear-gradient(90deg, rgba(5,11,7,.92) 0%, rgba(5,11,7,.62) 34%, rgba(5,11,7,.05) 66%), linear-gradient(0deg, rgba(5,11,7,.85), transparent 30%, transparent 80%, rgba(5,11,7,.5)); }
html[dir="ltr"] .tt-bg { inset: -4% -4% -4% 26%; background-position: 50% 40%; animation-name: kenburnsflip; -webkit-mask-image: linear-gradient(270deg, transparent 0%, #000 28%); mask-image: linear-gradient(270deg, transparent 0%, #000 28%); } /* mirrored: the hero runs in from the right, opposite the menu */
html[dir="ltr"] #title { background: #070d09; }
/* forest behind the menu side, softly darkened so the text stays readable */
html[dir="ltr"] #title::before { content: ''; position: absolute; inset: -3%; background: url(./assets/img/end_far.webp) 0% 50%/cover; filter: blur(3px) brightness(.55) saturate(.85); opacity: .9; }
html[dir="ltr"] .tt-bg::after { background: linear-gradient(90deg, rgba(5,11,7,.55) 0%, rgba(5,11,7,.25) 30%, rgba(5,11,7,0) 60%), linear-gradient(0deg, rgba(5,11,7,.7), transparent 30%, transparent 80%, rgba(5,11,7,.4)) !important; }
html[dir="ltr"] #title .tt-main::before { content: ''; position: absolute; inset: -12% -18% -12% -40%; z-index: -1; background: radial-gradient(ellipse at 40% 50%, rgba(5,11,7,.55), rgba(5,11,7,0) 70%); pointer-events: none; }
@media (max-aspect-ratio: 5/4) { html[dir="ltr"] .tt-bg { inset: -4% -4% -4% 30%; } }
.tt-grain { position: absolute; inset: 0; opacity: .06; background-image: url(./assets/img/grain.png); pointer-events: none; }
.tt-top { position: absolute; top: 28px; inset-inline: 5vw; display: flex; justify-content: space-between; align-items: center; }
.brand { font-family: var(--en-display); font-size: 11px; letter-spacing: 3px; color: var(--mist); }
.ghost { padding: 7px 16px; border-radius: 30px; border: 1px solid var(--hair); font-size: 13px; color: var(--gold); transition: .2s; }
.ghost:hover { background: rgba(230,201,131,.1); }
.tt-main { position: absolute; top: 50%; inset-inline-start: 7vw; transform: translateY(-50%); width: min(560px, 86vw); }
h1 { margin: 0; line-height: 1; }
h1 .ar { display: block; font-family: var(--ar-display); font-weight: 700; font-size: clamp(54px, 7.2vw, 108px); line-height: 1.25; background: linear-gradient(180deg, #fff9e6 0%, #efd79b 45%, #b8924c 100%); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 8px 30px rgba(0,0,0,.6)); animation: rise 1.6s .2s ease both; }
h1 .en { display: block; margin-top: 6px; font-family: var(--en-display); font-weight: 500; font-size: clamp(15px, 1.6vw, 22px); letter-spacing: 6px; color: var(--ivory); opacity: .85; animation: rise 1.6s .5s ease both; }
h1 .en small { font-size: .65em; letter-spacing: 3px; color: var(--gold); }
html[lang="en"] h1 .ar { font-size: clamp(36px, 4.6vw, 66px); }
.tt-main .orn { justify-content: flex-start; margin: 18px 0; }
.tagline { margin: 0 0 30px; font-family: var(--ar-sub); font-size: clamp(18px, 1.8vw, 24px); color: var(--mist); animation: rise 1.6s .7s ease both; }
html[lang="en"] .tagline { font-family: var(--en-body); font-style: italic; }
.menu { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; animation: rise 1.6s .9s ease both; }
.menu button { position: relative; padding: 9px 4px; font-size: 21px; color: var(--mist); transition: color .25s, transform .25s; }
html[lang="en"] .menu button { font-family: var(--en-display); font-size: 15px; letter-spacing: 3px; }
.menu button::before { content: '❦'; position: absolute; inset-inline-start: -26px; top: 50%; transform: translateY(-50%) scale(.6); opacity: 0; color: var(--gold); transition: .25s; }
.menu button:hover, .menu button:focus-visible { color: var(--ivory); transform: translateX(var(--nudge, 6px)); }
html[dir="rtl"] .menu button:hover { --nudge: -6px; }
.menu button:hover::before, .menu button:focus-visible::before { opacity: 1; transform: translateY(-50%) scale(1); }
.menu button.primary { color: var(--gold); font-size: 26px; font-weight: 700; }
html[lang="en"] .menu button.primary { font-size: 18px; }
.tt-foot { position: absolute; bottom: 26px; inset-inline-start: 7vw; font-size: 12px; color: rgba(201,211,192,.7); }

/* ---------- panels ---------- */
.overlay { z-index: 55; display: grid; place-items: center; background: rgba(4, 9, 6, .62); backdrop-filter: blur(10px); animation: fadein .35s ease both; }
.panel { width: min(460px, 92vw); text-align: center; padding: 36px 34px 30px; border-radius: 24px; background: linear-gradient(180deg, rgba(18, 32, 22, .92), rgba(9, 17, 12, .96)); border: 1px solid var(--hair); box-shadow: 0 40px 100px rgba(0,0,0,.55); }
.panel.wide { width: min(640px, 94vw); }
.panel h2 { margin: 4px 0 8px; font-family: var(--ar-display); font-size: 38px; font-weight: 700; color: var(--ivory); }
html[lang="en"] .panel h2 { font-family: var(--en-display); font-size: 24px; letter-spacing: 2px; }
.panel p { margin: 0 0 18px; color: var(--mist); line-height: 1.8; font-size: 16px; }
.panel .menu { align-items: center; animation: none; }
.eyebrow { color: var(--gold); font-size: 22px; }
.rows { display: grid; gap: 14px; margin: 18px 0 24px; text-align: start; }
.rows label { display: flex; align-items: center; justify-content: space-between; gap: 18px; font-size: 15px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 55%; height: 4px; border-radius: 4px; background: rgba(230,201,131,.25); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 10px rgba(230,201,131,.7); cursor: pointer; }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: var(--gold); }
.seg { display: inline-flex; border: 1px solid var(--hair); border-radius: 30px; overflow: hidden; }
.seg button { padding: 6px 14px; font-size: 13px; color: var(--mist); }
.seg button.on { background: var(--gold); color: var(--ink); font-weight: 700; }
.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; margin: 10px 0 16px; text-align: start; }
.keys span { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 10px; border-radius: 10px; background: rgba(255,255,255,.03); }
.keys b { font-weight: 400; color: var(--mist); font-size: 14px; }
.note { font-size: 13px !important; opacity: .8; }
.panel button.primary { margin-top: 6px; padding: 11px 30px; border-radius: 40px; background: linear-gradient(180deg, #f0d898, #c9a861); color: var(--ink); font-weight: 700; font-size: 16px; box-shadow: 0 10px 30px rgba(230,201,131,.25); }
.panel .menu button.primary { padding: 11px 30px; }
.panel .menu button.primary::before { display: none; }

/* ---------- ending ---------- */
#ending { z-index: 58; display: grid; place-items: center; background: #050a07; animation: fadein 2.5s ease both; }
.end-bg { position: absolute; inset: 0; background: url(./assets/img/end_far.webp) center/cover; opacity: .55; animation: kenburns 50s ease-out both; }
.end-bg::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(5,10,7,.2), rgba(5,10,7,.9) 78%); }
.end-body { position: relative; text-align: center; padding: 0 6vw; }
.end-body h2 { margin: 6px 0; font-family: var(--ar-display); font-size: clamp(54px, 8vw, 110px); background: linear-gradient(180deg, #fff9e6, #e6c983 60%, #a8874a); -webkit-background-clip: text; background-clip: text; color: transparent; animation: rise 2s .6s ease both; }
html[lang="en"] .end-body h2 { font-family: var(--en-display); font-size: clamp(36px, 5vw, 70px); letter-spacing: 3px; }
.end-body p { white-space: pre-line; font-family: var(--ar-sub); font-size: clamp(18px, 2vw, 26px); color: var(--ivory); line-height: 1.8; animation: rise 2s 1.2s ease both; }
.end-body .stats { font-family: var(--en-display); font-size: 14px; color: var(--gold); letter-spacing: 1px; }
html[lang="ar"] .end-body .stats { font-family: var(--ar-body); }
.end-body small { display: block; margin-top: 22px; color: var(--mist); opacity: .7; font-size: 12px; }
#btnReplay { padding: 12px 34px; border-radius: 40px; border: 1px solid var(--gold); color: var(--gold); font-size: 16px; letter-spacing: 1px; transition: .25s; animation: rise 2s 2s ease both; }
#btnReplay:hover { background: var(--gold); color: var(--ink); }

#fatal { z-index: 80; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
#dialog, #interact, #bossbar { animation-name: risex; }
@keyframes risex { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeout { from { opacity: 1; } to { opacity: 0; } }
@keyframes kenburns { from { transform: scale(1.12); } to { transform: scale(1); } }
@keyframes kenburnsflip { from { transform: scaleX(-1) scale(1.12); } to { transform: scaleX(-1) scale(1); } }
@keyframes breathe { 0%, 100% { opacity: .65; } 50% { opacity: 1; } }
@keyframes pop { 50% { transform: scale(1.18); border-color: #ffe39a; } }
@keyframes questflash { 0% { color: var(--emerald); text-shadow: 0 0 22px var(--emerald); } 100% { color: inherit; } }
@keyframes powerin { from { opacity: 0; transform: translate(-50%, -40%) scale(.85); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }

@media (max-width: 760px) {
  .quest { top: 16px; inset-inline-start: 16px; max-width: 60vw; }
  .quest h2 { font-size: 22px; }
  .quest p { font-size: 13px; }
  .topend { top: 14px; inset-inline-end: 14px; }
  .pw { width: 38px; height: 38px; } .pw svg { width: 22px; height: 22px; }
  .tt-main { inset-inline-start: 6vw; }
  .menu button { font-size: 18px; }
  #dialog { padding: 12px 14px; gap: 12px; } #dialog .portrait { flex-basis: 52px; height: 52px; }
  .keys { grid-template-columns: 1fr; }
}

/* animated title logo (keyed from the film's title animation) */
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.logo { position: relative; display: block; width: min(500px, 80vw); aspect-ratio: 16 / 9; margin: -44px 0 -10px; margin-inline-start: -52px; filter: drop-shadow(0 10px 30px rgba(0,0,0,.65)); }
.logo video, .logo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.logo img { opacity: 0; transition: opacity .6s ease; }
.logo.static video { display: none; }
.logo.static img { opacity: 1; animation: rise 1.6s .2s ease both; }
@media (max-width: 760px) { .logo { margin: -30px auto -40px; } }

/* ---------- phones ---------- */
@media (max-height: 520px) {
  .logo { width: min(300px, 42vw); margin: -26px 0 -6px; margin-inline-start: -30px; }
  h1 .en { font-size: 12px; letter-spacing: 4px; }
  .tt-main .orn { margin: 6px 0; }
  .tagline { display: none; }
  .menu { gap: 2px; }
  .menu button { font-size: 16px; padding: 5px 4px; } .menu button.primary { font-size: 20px; }
  .tt-foot { display: none; }
  .tt-top { top: 10px; }
  .quest { top: 10px; } .quest h2 { font-size: 18px; } .quest p { font-size: 12px; }
  #dialog { bottom: 12px; padding: 10px 12px; } #dialog p { font-size: 15px; }
  #subtitle p { font-size: 16px; }
  #chapter h2 { font-size: 40px; }
}
#rotate { display: none; position: fixed; inset: 0; z-index: 200; background: #070d09; color: var(--ivory); align-items: center; justify-content: center; flex-direction: column; gap: 18px; text-align: center; font-family: var(--ar-sub); font-size: 20px; padding: 24px; }
#rotate .ph { width: 54px; height: 88px; border: 3px solid var(--gold); border-radius: 10px; animation: rot 2.2s ease-in-out infinite; }
@keyframes rot { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) { body.touch.ingame #rotate { display: flex; } }

/* ---------- touch HUD: each control in its own corner, nothing overlaps ---------- */
body.touch .energy { top: auto; bottom: calc(14px + env(safe-area-inset-bottom)); left: 50%; right: auto; inset-inline-start: auto; transform: translateX(-50%); width: min(260px, 30vw); text-align: center; }
body.touch .energy .lbl { margin-bottom: 4px; font-size: 11px; }
body.touch #minimap { display: none; }
body.touch #joystick { left: calc(28px + env(safe-area-inset-left)); bottom: calc(24px + env(safe-area-inset-bottom)); }
body.touch .tbtns { right: calc(20px + env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom)); }
body.touch .topend { top: calc(12px + env(safe-area-inset-top)); }
html[dir="rtl"] body.touch .topend { left: calc(14px + env(safe-area-inset-left)); }
html[dir="ltr"] body.touch .topend { right: calc(14px + env(safe-area-inset-right)); }
body.touch #interact { bottom: 72px; }
@media (max-height: 520px) {
  body.touch .tbtns { grid-template-columns: repeat(2, 56px); gap: 10px; }
  body.touch .tbtns button { width: 56px; height: 56px; font-size: 19px; }
  body.touch #joystick { width: 112px; height: 112px; }
  body.touch .pw { width: 34px; height: 34px; } body.touch .pw svg { width: 20px; height: 20px; }
  body.touch .topend { gap: 8px; }
  body.touch .seedcount { padding: 3px 10px; }
  body.touch #tPause { top: 10px; width: 38px; height: 38px; margin-left: -19px; }
  body.touch .quest { max-width: 42vw; }
}

/* ---------- phone portrait title: one identical layout for Arabic and English ---------- */
@media (max-width: 760px) and (orientation: portrait) {
  html[dir] .tt-bg { inset: -3%; background-position: 50% 22%; animation-name: kenburns; -webkit-mask-image: none; mask-image: none; }
  html[dir] #title::before { display: none; }
  html[dir] .tt-bg::after { background: linear-gradient(0deg, rgba(5,11,7,.94) 0%, rgba(5,11,7,.75) 38%, rgba(5,11,7,.1) 68%, rgba(5,11,7,.35) 100%) !important; }
  html[dir] #title .tt-main::before { display: none; }
  .tt-main { top: auto; bottom: calc(4vh + env(safe-area-inset-bottom)); transform: none; inset-inline-start: 6vw; left: 6vw; right: 6vw; width: auto; text-align: center; }
  .logo { width: min(330px, 80vw); margin: 0 auto -6px !important; }
  h1 .en { font-size: 11px; letter-spacing: 3px; white-space: nowrap; }
  .tt-main .orn { justify-content: center; margin: 10px 0; }
  .tagline { margin-bottom: 14px; font-size: 16px; }
  .menu { align-items: center; gap: 0; }
  .menu button { font-size: 18px; padding: 7px 4px; }
  .menu button.primary { font-size: 22px; }
  .tt-foot { display: none; }
}

.ios-hint { position: absolute; z-index: 3; left: 50%; transform: translateX(-50%); top: calc(54px + env(safe-area-inset-top)); width: min(92vw, 520px); margin: 0; padding: 8px 14px; border-radius: 14px; background: rgba(6,14,9,.72); border: 1px solid var(--hair); color: var(--ivory); font-size: 13px; line-height: 1.5; text-align: center; font-family: var(--ar-sub); }
.ios-hint b { color: var(--gold); } .ios-hint span { font-family: var(--en-body); font-size: 11px; opacity: .75; }
@media (max-height: 520px) { .ios-hint { top: auto; bottom: 8px; font-size: 11px; padding: 5px 10px; } }
