/* ============================================================
   الكتاب التفاعلي v2 — shared styles
   Layout contract: exactly two bars (top + bottom). The printed
   page lives between them and is never overlapped by controls.
   ============================================================ */
*{margin:0;padding:0;box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{height:100%}
body{
  font-family:"Segoe UI",Tahoma,Arial,sans-serif;
  background:#fdf6ec; color:#3a2a10;
  height:100dvh; overflow:hidden;
  display:flex; flex-direction:column;
  user-select:none; -webkit-user-select:none;
}
button{font-family:inherit; cursor:pointer; border:none; background:none; color:inherit}
img{-webkit-user-drag:none; user-select:none}

/* ================= TOP BAR ================= */
#topbar{
  flex:0 0 auto; height:52px; z-index:40;
  display:flex; align-items:center; gap:8px;
  padding:6px 10px;
  background:linear-gradient(180deg,#fff8ea,#ffeecb);
  border-bottom:2px solid #f0c475;
}
#topbar .tb-btn{
  min-width:44px; height:40px; padding:0 10px;
  border-radius:12px; background:#fff; border:2px solid #f0c475;
  font-size:19px; display:flex; align-items:center; justify-content:center; gap:4px;
}
#topbar .tb-btn:active{background:#ffe1a1}
#tbTitle{
  flex:1 1 auto; text-align:center; font-weight:800; font-size:16px; color:#7c4a03;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
#tbPage{
  font-size:15px; font-weight:800; color:#7c4a03;
}
#tbPage .car{font-size:12px}

/* ================= STAGE ================= */
#stageWrap{
  flex:1 1 auto; position:relative; overflow:hidden;
  display:flex; align-items:center; justify-content:center;
  background:radial-gradient(120% 100% at 50% 0%, #fffdf7 0%, #fdf6ec 60%, #f7e8cd 100%);
  touch-action:none;
}
#stage{
  position:relative; overflow:hidden; background:#fff;
  border-radius:6px; box-shadow:0 4px 24px rgba(124,74,3,.25);
}
.pagelayer{position:absolute; inset:0; will-change:transform}
.pagelayer img.pageimg{position:absolute; inset:0; width:100%; height:100%; display:block; background:#fff}
.pagelayer .hits{position:absolute; inset:0}
.hit{
  position:absolute; border-radius:8px; background:transparent; padding:0;
  -webkit-tap-highlight-color:transparent;
}
.hit:active{background:rgba(255,183,3,.35)}
.hit.word.on{background:rgba(255,183,3,.45); box-shadow:inset 0 0 0 3px #ffb703}
.hit.found{box-shadow:inset 0 0 0 4px #39b54a; background:rgba(57,181,74,.18); border-radius:10px}
.hit.sel{box-shadow:inset 0 0 0 4px #ffb703; background:rgba(255,183,3,.25)}
.hit.wrong{animation:shake .35s}
@keyframes shake{0%,100%{transform:translateX(0)}25%{transform:translateX(-5px)}75%{transform:translateX(5px)}}
.mark{
  position:absolute; display:flex; align-items:center; justify-content:center;
  font-weight:900; pointer-events:none; z-index:6;
  text-shadow:0 1px 0 #fff, 0 0 6px #fff;
}
.mark.ok{color:#1d9e3f}
.mark.no{color:#e0483e}
.ring{
  position:absolute; border:4px solid #39b54a; border-radius:12px; pointer-events:none; z-index:5;
  animation:ringpop .3s ease;
}
@keyframes ringpop{from{transform:scale(1.25); opacity:.4} to{transform:scale(1); opacity:1}}
#karaoke{
  position:absolute; border:4px solid #ff8c1a; border-radius:10px; z-index:7; pointer-events:none;
  background:rgba(255,183,3,.22); display:none;
  animation:kpulse 1s ease-in-out infinite;
}
@keyframes kpulse{0%,100%{box-shadow:0 0 0 0 rgba(255,140,26,.45)}50%{box-shadow:0 0 0 9px rgba(255,140,26,0)}}
#traceCanvas{position:absolute; inset:0; z-index:8; touch-action:none}
.judgePick{
  position:absolute; z-index:12; display:flex; gap:8px;
  transform:translate(-50%,-115%);
}
.judgePick button{
  width:52px; height:52px; border-radius:50%; font-size:26px; font-weight:900;
  background:#fff; border:3px solid #f0c475; box-shadow:0 3px 10px rgba(0,0,0,.25);
}
.judgePick button:active{transform:scale(.92)}
#starPop{
  position:absolute; z-index:15; font-size:34px; pointer-events:none; display:none;
  transform:translate(-50%,-50%);
}
#numPad{
  position:absolute; left:50%; bottom:10px; transform:translateX(-50%); z-index:13;
  background:#fffdf6; border:3px solid #f0c475; border-radius:16px; padding:8px;
  display:none; gap:6px; box-shadow:0 6px 20px rgba(0,0,0,.25);
  grid-template-columns:repeat(5,52px);
}
#numPad.open{display:grid}
#numPad button{
  width:52px; height:52px; border-radius:12px; background:#ffeecb; font-size:22px; font-weight:900; color:#7c4a03;
  border:2px solid #f0c475;
}
#numPad button:active{background:#ffd166}

/* ================= BOTTOM BAR ================= */
#botbar{
  flex:0 0 auto; z-index:40;
  display:flex; align-items:stretch; gap:6px;
  padding:7px 8px calc(7px + env(safe-area-inset-bottom));
  background:linear-gradient(0deg,#fff8ea,#ffeecb);
  border-top:2px solid #f0c475;
}
#botbar button{
  flex:1 1 0; min-height:52px; border-radius:14px;
  background:#fff; border:2px solid #f0c475; color:#7c4a03;
  font-size:14px; font-weight:800; line-height:1.15;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:1px;
  padding:4px 2px;
}
#botbar button .ic{font-size:20px; line-height:1}
#botbar button:active{background:#ffe1a1}
#botbar button:disabled{opacity:.38}
#botbar button.nav{flex:0 0 52px; font-size:24px}
#botbar #bbStars{
  flex:0 0 auto; min-width:58px; border-radius:14px; background:#fff3d6; border:2px dashed #f0c475;
  display:flex; align-items:center; justify-content:center; font-weight:900; color:#b97e10; font-size:15px; padding:0 6px;
}

/* ================= OVERLAYS (shared component) ================= */
.ovl-backdrop{
  position:fixed; inset:0; z-index:100; background:rgba(43,28,4,.55);
  display:flex; align-items:center; justify-content:center;
}
.ovl-panel{
  position:relative; width:100%; height:100%;
  background:#fffdf6; display:flex; flex-direction:column; overflow:hidden;
}
@media (min-width:560px){
  .ovl-panel{width:min(96vw,880px); height:min(94dvh,1100px); border-radius:20px; box-shadow:0 18px 60px rgba(0,0,0,.4)}
}
.ovl-head{
  flex:0 0 auto; display:flex; align-items:center; gap:10px;
  padding:10px 12px; background:linear-gradient(180deg,#fff8ea,#ffeecb);
  border-bottom:2px solid #f0c475; min-height:64px;
}
.ovl-title{flex:1; font-size:19px; font-weight:900; color:#7c4a03; text-align:center}
.ovl-x{
  flex:0 0 auto; width:52px; height:52px; border-radius:50%;
  background:#e0483e; color:#fff; font-size:26px; font-weight:900; line-height:1;
  display:flex; align-items:center; justify-content:center;
  box-shadow:0 3px 8px rgba(0,0,0,.3); z-index:30; position:relative;
}
.ovl-x:active{transform:scale(.9); background:#c93a31}
.ovl-body{flex:1 1 auto; position:relative; overflow:hidden; display:flex; flex-direction:column}

/* page picker */
.pick-grid{
  overflow-y:auto; padding:14px; display:grid; gap:10px;
  grid-template-columns:repeat(auto-fill,minmax(64px,1fr)); touch-action:pan-y;
}
.pick-grid button{
  height:60px; border-radius:14px; background:#fff; border:2px solid #f0c475;
  font-size:19px; font-weight:900; color:#7c4a03;
  display:flex; flex-direction:column; align-items:center; justify-content:center;
}
.pick-grid button.cur{background:#ffb703; border-color:#e09f00; color:#5b3400}
.pick-grid button small{font-size:10px; font-weight:700; color:#a97a20}

/* contents */
.contents-list{overflow-y:auto; padding:12px; touch-action:pan-y}
.contents-list a{
  display:flex; align-items:center; gap:10px; text-decoration:none; color:#7c4a03;
  background:#fff; border:2px solid #f0c475; border-radius:14px; padding:13px 14px; margin-bottom:9px;
  font-weight:800; font-size:16px;
}
.contents-list a.cur{background:#ffeecb}
.contents-list a .pg{margin-inline-start:auto; font-size:12px; color:#a97a20; font-weight:700}
.contents-list h3{color:#b97e10; margin:14px 4px 8px; font-size:15px}

/* games menu */
.menu-grid{flex:1; display:flex; flex-direction:column; gap:12px; padding:16px; justify-content:center}
.menu-grid button{
  flex:0 0 auto; padding:20px 14px; border-radius:18px; background:#fff; border:3px solid #f0c475;
  font-size:20px; font-weight:900; color:#7c4a03; display:flex; align-items:center; gap:12px; justify-content:center;
}
.menu-grid button .ic{font-size:30px}
.menu-grid button:active{background:#ffe1a1}
.menu-grid button:disabled{opacity:.4}

/* ================= PLAYER ================= */
#playerPanel{padding:14px; gap:12px; align-items:stretch; justify-content:flex-start}
#plText{
  background:#fff; border:2px solid #f0c475; border-radius:16px; padding:20px 14px;
  font-size:clamp(24px,6vw,38px); font-weight:900; color:#5b3400; text-align:center; min-height:110px;
  display:flex; align-items:center; justify-content:center;
}
#plText .ar{display:block; font-size:15px; color:#a97a20; font-weight:700; margin-top:6px}
#plProgWrap{height:16px; background:#f3e3c2; border-radius:99px; overflow:hidden}
#plProg{height:100%; width:0%; background:linear-gradient(90deg,#ffb703,#ff8c1a); border-radius:99px; transition:width .25s}
#plCount{text-align:center; font-weight:800; color:#a97a20}
#plBtns{display:flex; gap:10px; justify-content:center; margin-top:4px}
#plBtns button{
  width:72px; height:72px; border-radius:50%; background:#ffb703; border:3px solid #e09f00;
  font-size:30px; display:flex; align-items:center; justify-content:center; color:#5b3400;
}
#plBtns button.small{width:58px; height:58px; font-size:22px; background:#fff}
#plBtns button:active{transform:scale(.92)}
#plList{overflow-y:auto; touch-action:pan-y; border-top:2px dashed #f0c475; padding-top:8px}
#plList button{
  display:block; width:100%; text-align:start; padding:9px 10px; border-radius:10px; font-size:17px; font-weight:700; color:#5b3400;
}
#plList button.cur{background:#ffe1a1}
#plList button .n{color:#c08c1d; font-weight:900; margin-inline-end:8px}

/* ================= SCENE ================= */
.scenePanel .ovl-body{background:#000}
#scStage{position:absolute; inset:0; overflow:hidden; background:#123}
#scBg{position:absolute; inset:0; width:100%; height:100%; object-fit:cover; opacity:.95}
#scShade{position:absolute; inset:0; background:linear-gradient(180deg,rgba(0,0,0,.18),transparent 30%,transparent 70%,rgba(0,0,0,.25))}
.scBeat{
  position:absolute; bottom:0; height:88%; max-width:62%; object-fit:contain; object-position:bottom;
  opacity:0; pointer-events:none; filter:drop-shadow(0 6px 14px rgba(0,0,0,.35));
}
.scBeat.left{left:2%} .scBeat.right{right:2%}
.scBeat.show{opacity:1}
.scBeat .inner{}
#scArt{
  position:absolute; left:50%; top:44%; transform:translate(-50%,-50%) scale(.9);
  max-width:74%; max-height:56%; border-radius:18px; border:5px solid #fff;
  box-shadow:0 14px 40px rgba(0,0,0,.5); opacity:0; pointer-events:none; object-fit:cover;
}
#scArt.show{opacity:1; transform:translate(-50%,-50%) scale(1)}
#scCard{
  position:absolute; left:50%; top:44%; transform:translate(-50%,-50%) scale(.92);
  width:min(64%,340px); aspect-ratio:4/3; border-radius:18px; border:4px solid #fff;
  box-shadow:0 14px 40px rgba(0,0,0,.5); background:#f7efdb; background-repeat:no-repeat;
  opacity:0; pointer-events:none; transition:opacity .35s, transform .35s; z-index:3;
}
#scCard.show{opacity:1; transform:translate(-50%,-50%) scale(1)}
#scBubble{
  position:absolute; left:50%; bottom:5%; transform:translateX(-50%) translateY(16px);
  width:min(88%,560px); background:#fff; color:#17301f; border-radius:20px; padding:14px 18px;
  font-size:clamp(19px,4.6vw,27px); font-weight:800; text-align:center; opacity:0; z-index:5;
  box-shadow:0 10px 30px rgba(0,0,0,.4); transition:opacity .3s, transform .3s;
}
#scBubble.show{opacity:1; transform:translateX(-50%) translateY(0)}
#scBubble:after{
  content:""; position:absolute; top:-12px; left:50%; margin-left:-12px;
  border:12px solid transparent; border-top:0; border-bottom-color:#fff;
}
#scDots{position:absolute; top:10px; left:50%; transform:translateX(-50%); display:flex; gap:6px; z-index:6}
#scDots i{width:10px; height:10px; border-radius:50%; background:rgba(255,255,255,.45)}
#scDots i.on{background:#ffb703}
#scHearts{position:absolute; inset:0; pointer-events:none; overflow:hidden; z-index:4}
#scHearts span{position:absolute; bottom:12%; font-size:26px; animation:floatUp 2.4s ease-in forwards}
@keyframes floatUp{to{transform:translateY(-46vh) rotate(24deg); opacity:0}}
#scEnd{
  position:absolute; inset:0; display:none; flex-direction:column; align-items:center; justify-content:center; gap:14px;
  background:rgba(20,35,20,.55); z-index:8; text-align:center; padding:20px;
}
#scEnd.show{display:flex}
#scEnd .big{font-size:56px}
#scEnd h3{color:#fff; font-size:26px}
#scEnd button{
  padding:14px 28px; border-radius:99px; background:#ffb703; color:#5b3400; font-size:19px; font-weight:900; border:3px solid #e09f00;
}

/* ================= MINI GAMES / EASY (DOM) ================= */
.gm-body{padding:12px; gap:10px; align-items:stretch}
.gm-prompt{
  display:flex; align-items:center; gap:10px; justify-content:center;
  background:#fff; border:2px solid #f0c475; border-radius:14px; padding:10px; min-height:64px;
  font-size:20px; font-weight:900; color:#5b3400; text-align:center;
}
.gm-prompt .spk{
  flex:0 0 auto; width:52px; height:52px; border-radius:50%; background:#ffb703; font-size:24px;
  display:flex; align-items:center; justify-content:center; border:2px solid #e09f00;
}
.gm-score{text-align:center; font-weight:900; color:#b97e10; font-size:17px}
.gm-stage{flex:1; position:relative; overflow:hidden; border-radius:16px; background:linear-gradient(180deg,#fff8ea,#ffeecb); border:2px solid #f3e3c2}
.gm-cards{display:flex; flex-wrap:wrap; gap:12px; justify-content:center; align-content:center; padding:14px; height:100%; overflow-y:auto; touch-action:pan-y}
.gm-card{
  background:#fff; border:3px solid #f0c475; border-radius:16px; padding:8px;
  display:flex; flex-direction:column; align-items:center; gap:4px; width:118px;
  box-shadow:0 3px 8px rgba(124,74,3,.15);
}
.gm-card:active{transform:scale(.95)}
.gm-card .pic{border-radius:10px; background-color:#f7efdb; background-repeat:no-repeat}
.gm-card .wd{font-weight:900; color:#5b3400; font-size:16px; text-align:center; line-height:1.1}
.gm-card.good{border-color:#39b54a; background:#eaffef}
.gm-card.bad{border-color:#e0483e; animation:shake .35s}
.gm-card.flip{width:96px; height:128px; align-items:center; justify-content:center; font-size:44px; background:linear-gradient(160deg,#ffd166,#ffb703)}
.gm-card.flip.open{background:#fff; font-size:16px}
.gm-balloon{
  position:absolute; width:104px; padding:6px; border-radius:50% 50% 50% 50%/58% 58% 42% 42%;
  display:flex; flex-direction:column; align-items:center; justify-content:center; min-height:118px;
  border:3px solid rgba(0,0,0,.12); box-shadow:inset -8px -10px 0 rgba(0,0,0,.08);
}
.gm-balloon .wd{font-weight:900; color:#fff; text-shadow:0 1px 3px rgba(0,0,0,.4); font-size:15px; text-align:center}
.gm-end{
  position:absolute; inset:0; display:none; flex-direction:column; align-items:center; justify-content:center; gap:12px;
  background:rgba(255,253,246,.94); z-index:9; text-align:center; padding:16px;
}
.gm-end.show{display:flex}
.gm-end .big{font-size:54px}
.gm-end h3{font-size:24px; color:#5b3400}
.gm-end button{padding:13px 26px; border-radius:99px; background:#ffb703; border:3px solid #e09f00; font-size:18px; font-weight:900; color:#5b3400}

/* ================= ARCADE (canvas) ================= */
.arcPanel .ovl-body{background:#79c7ee}
#arcStage{position:absolute; inset:0; overflow:hidden}
#arcCanvas{position:absolute; inset:0; width:100%; height:100%; display:block; touch-action:none}
.arc-hud{
  position:absolute; top:8px; inset-inline:10px; z-index:5; display:flex; gap:8px; align-items:center; pointer-events:none;
}
.arc-hud .pill{
  background:rgba(255,255,255,.92); border-radius:99px; padding:5px 13px; font-weight:900; color:#5b3400; font-size:16px;
  border:2px solid #f0c475;
}
.arc-hud .pill.tgt{pointer-events:auto; display:flex; gap:7px; align-items:center}
.arc-hud .pill.tgt button{width:38px; height:38px; border-radius:50%; background:#ffb703; font-size:19px; border:2px solid #e09f00; display:flex; align-items:center; justify-content:center}
.arc-screen{
  position:absolute; inset:0; z-index:6; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:12px;
  text-align:center; padding:20px; background:rgba(23,42,20,.45);
}
.arc-screen img.hero{width:118px; height:118px; object-fit:cover; border-radius:50%; border:5px solid #fff; box-shadow:0 10px 30px rgba(0,0,0,.4)}
.arc-screen h2{color:#fff; font-size:clamp(23px,6vw,32px); text-shadow:0 2px 8px rgba(0,0,0,.5)}
.arc-screen p{color:#fff; font-size:17px; font-weight:700; max-width:440px; text-shadow:0 1px 5px rgba(0,0,0,.6)}
.arc-screen button{
  padding:15px 38px; border-radius:99px; background:#ffb703; border:3px solid #e09f00; color:#5b3400;
  font-size:21px; font-weight:900; box-shadow:0 8px 22px rgba(0,0,0,.35);
}
.arc-screen button:active{transform:scale(.94)}

/* ================= HOME (index) ================= */
.home{overflow-y:auto; height:100dvh; padding:18px 14px 30px; touch-action:pan-y}
.home h1{text-align:center; color:#7c4a03; font-size:27px; margin:8px 0 4px}
.home .sub{text-align:center; color:#a97a20; font-weight:700; margin-bottom:16px}
.home h2{color:#b97e10; margin:18px 4px 10px; font-size:18px}
.home .grid{display:grid; grid-template-columns:repeat(auto-fill,minmax(150px,1fr)); gap:11px}
.home a{
  text-decoration:none; background:#fff; border:2px solid #f0c475; border-radius:16px; padding:14px 12px;
  color:#5b3400; display:flex; flex-direction:column; gap:3px; box-shadow:0 2px 7px rgba(124,74,3,.1);
}
.home a b{font-size:16px}
.home a span{font-size:12.5px; color:#a97a20; font-weight:700}
.home a .n{
  align-self:flex-start; background:#ffb703; color:#5b3400; border-radius:99px; padding:1px 10px; font-size:12px; font-weight:900;
}

/* ================= TERM2: VIDEO ================= */
.vid-wrap{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;padding:14px;background:#14100a}
.vid-player{width:100%;max-height:78%;background:#000;border-radius:14px;box-shadow:0 10px 34px rgba(0,0,0,.5)}
.vid-hint{color:#ffeecb;font-weight:800;font-size:15px;text-align:center}
.videoPanel .ovl-body{background:#14100a}

/* ================= TERM2: GAMES HUB ================= */
.hub-grid{
  flex:1; overflow-y:auto; touch-action:pan-y; padding:14px;
  display:grid; gap:10px; grid-template-columns:repeat(auto-fill,minmax(150px,1fr)); align-content:start;
}
.hub-game{
  min-height:76px; padding:12px 10px; border-radius:16px; background:#fff; border:3px solid #f0c475;
  font-size:17px; font-weight:900; color:#7c4a03; display:flex; align-items:center; gap:9px; justify-content:center;
  flex-direction:column;
}
.hub-game .ic{font-size:28px}
.hub-game:active{background:#ffe1a1}
.hub-game.unavail{opacity:.55; border-style:dashed}
.hub-game small{font-size:11.5px; font-weight:800; color:#b3543f}
.menu-extra{display:flex; flex-wrap:wrap; gap:8px; padding:0 14px 14px}
.menu-extra button{
  flex:1 1 30%; min-height:52px; padding:10px 8px; border-radius:14px; background:#fff8ea; border:2px solid #f0c475;
  font-size:15px; font-weight:900; color:#7c4a03; display:flex; align-items:center; gap:7px; justify-content:center;
}
.menu-extra button:disabled{opacity:.38}
.hub-empty{
  flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:12px;
  text-align:center; padding:24px;
}
.hub-empty .big{font-size:56px}
.hub-empty h3{font-size:23px; color:#7c4a03}
.hub-empty p{font-size:16px; font-weight:700; color:#a97a20; max-width:420px}

/* hub DOM game extras */
.gm-card.sel{box-shadow:inset 0 0 0 4px #ffb703; background:#fff3d6}
.gm-col{display:flex; flex-direction:column; gap:10px; align-items:center}
.gm-tiles{display:flex; flex-direction:column; gap:12px; align-items:center; padding:10px}
.gm-answer{
  min-height:58px; min-width:180px; padding:8px 18px; border-radius:14px; background:#fff; border:3px dashed #e09f00;
  font-size:30px; font-weight:900; color:#5b3400; text-align:center; letter-spacing:3px;
}
.gm-bank{display:flex; flex-wrap:wrap; gap:9px; justify-content:center}
.gm-tile{
  min-width:52px; height:56px; padding:0 10px; border-radius:13px; background:#ffb703; border:3px solid #e09f00;
  font-size:25px; font-weight:900; color:#5b3400;
}
.gm-tile:disabled{opacity:.3}
.gm-tile.reset{background:#fff; font-size:16px; height:48px}
.gm-judge{display:flex; gap:16px; justify-content:center; padding:12px}
/* true-false only (sole user of .gm-judge): pin the ✔/✘ row to the bottom
   of the game stage so it never falls below the fold — the sibling
   .gm-cards is height:100%, which pushed this row out of the
   overflow:hidden stage at small viewports (e.g. 360x740). */
.gm-stage>.gm-judge{position:absolute; left:0; right:0; bottom:4px; z-index:6; padding:8px}
