:root {
  --bg0: #0a1128;
  --bg1: #101c3f;
  --card: #14224a;
  --card2: #1a2c5c;
  --gold: #e8b64c;
  --gold2: #f6d47e;
  --text: #eef2ff;
  --muted: #9fb0d8;
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Tajawal', system-ui, sans-serif;
  background:
    radial-gradient(1200px 600px at 85% -10%, #1c2f63 0%, transparent 60%),
    radial-gradient(900px 500px at 10% 110%, #16244d 0%, transparent 55%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  color: var(--text);
  min-height: 100vh;
}

main { max-width: 720px; margin: 0 auto; padding: 0 14px 40px; }

/* ===== Header ===== */
.topbar { text-align: center; padding: 26px 14px 10px; }
.bism { font-family: 'Amiri', serif; color: var(--gold2); font-size: 17px; opacity: .9; }
.topbar h1 {
  margin: 8px 0 4px; font-size: 30px; font-weight: 800; letter-spacing: .3px;
  background: linear-gradient(90deg, var(--gold2), var(--gold) 45%, #fff2cf);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.subtitle { margin: 0; color: var(--muted); font-size: 14px; }

/* ===== 3D Stage ===== */
.stage {
  position: relative; margin-top: 14px; border-radius: 22px; overflow: hidden;
  background: linear-gradient(180deg, #0d1836, #0a1128);
  border: 1px solid rgba(232,182,76,.22);
  box-shadow: 0 18px 50px rgba(0,0,0,.45), inset 0 0 60px rgba(20,40,90,.5);
}
#canvas-wrap { width: 100%; height: 52vh; min-height: 340px; touch-action: none; }
#canvas-wrap canvas { display: block; width: 100% !important; height: 100% !important; }
.stage-hint {
  position: absolute; bottom: 10px; right: 0; left: 0; text-align: center;
  color: var(--muted); font-size: 12px; pointer-events: none; opacity: .8;
  transition: opacity .6s;
}
.stage-actions {
  position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 8px;
}
.sbtn {
  font-family: inherit; font-size: 13px; font-weight: 700; color: var(--text);
  background: rgba(20,34,74,.85); border: 1px solid rgba(232,182,76,.45);
  border-radius: 12px; padding: 8px 14px; cursor: pointer; backdrop-filter: blur(4px);
}
.sbtn:active { transform: scale(.96); }
.sbtn.active { background: var(--gold); color: #1a1205; border-color: var(--gold); }
.sbtn.ghost { border-color: rgba(159,176,216,.4); color: var(--muted); }

.marker-tag {
  position: absolute; pointer-events: none; transform: translate(-50%, -130%);
  background: rgba(10,17,40,.92); border: 1px solid var(--gold);
  color: var(--gold2); font-weight: 800; font-size: 15px;
  padding: 5px 12px; border-radius: 12px; white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0,0,0,.5);
}
.hidden { display: none !important; }

/* ===== تبديل المنظر ===== */
.view-toggle { display: flex; gap: 8px; justify-content: center; margin-top: 14px; }
.vbtn {
  font-family: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
  border-radius: 999px; padding: 9px 22px;
  background: var(--card); color: var(--muted); border: 1.5px solid rgba(159,176,216,.35);
}
.vbtn.active { background: linear-gradient(180deg, var(--gold2), var(--gold)); color: #201503; border-color: var(--gold); }

/* ===== المنظر الأمامي ===== */
.frontstage { padding: 0; }
.fv-wrap { position: relative; width: 100%; aspect-ratio: 4/5; overflow: hidden; }
.fv-mouth { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.fv-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.fv-guide {
  position: absolute; height: 52%; width: auto; pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.45));
  transition: left .55s cubic-bezier(.3,.9,.3,1), top .55s cubic-bezier(.3,.9,.3,1), transform .3s;
}
.fv-guide.flip { transform: scaleX(-1); }
.fv-tag { transform: translate(-50%, -140%); transition: left .55s, top .55s; z-index: 3; }
.fv-note {
  position: absolute; bottom: 8px; left: 0; right: 0; text-align: center;
  color: rgba(255,255,255,.75); font-size: 10.5px; text-shadow: 0 1px 3px rgba(0,0,0,.8);
  pointer-events: none;
}
.fv-ring { filter: drop-shadow(0 0 6px rgba(255,200,60,.9)); }
@keyframes fvPulse { 0%,100% { opacity: .85; } 50% { opacity: .35; } }
.fv-halo { animation: fvPulse 1.6s ease-in-out infinite; }

/* ===== Regions ===== */
.regions {
  display: flex; gap: 8px; overflow-x: auto; padding: 16px 2px 4px;
  scrollbar-width: none;
}
.regions::-webkit-scrollbar { display: none; }
.region-chip {
  flex: 0 0 auto; font-family: inherit; cursor: pointer;
  border-radius: 999px; padding: 9px 18px; font-size: 15px; font-weight: 700;
  background: var(--card); color: var(--text);
  border: 1.5px solid var(--rc, #3a4f8f);
  transition: transform .12s, background .2s;
}
.region-chip:active { transform: scale(.95); }
.region-chip.active { background: var(--rc); color: #0a1128; border-color: var(--rc); }
.region-chip .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--rc); margin-left: 6px; vertical-align: 1px; }
.region-chip.active .dot { background: #0a1128; }

/* ===== Letters grid ===== */
.letters-wrap { margin-top: 8px; }
.letters {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 8px;
}
.lchip {
  font-family: 'Amiri', serif; font-size: 26px; line-height: 1; cursor: pointer;
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  background: var(--card); color: var(--text); border-radius: 14px;
  border: 1.5px solid rgba(159,176,216,.25); border-bottom-width: 3px;
  transition: transform .12s, border-color .2s, background .2s;
}
.lchip:active { transform: scale(.92); }
.lchip.active {
  background: linear-gradient(180deg, var(--gold2), var(--gold)); color: #201503;
  border-color: var(--gold);
  box-shadow: 0 6px 18px rgba(232,182,76,.35);
}

/* ===== Explain card ===== */
.card {
  margin-top: 16px; background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid rgba(232,182,76,.25); border-radius: var(--radius);
  padding: 18px; box-shadow: 0 14px 36px rgba(0,0,0,.35);
}
.card-head { display: flex; align-items: center; gap: 14px; }
.card-letter {
  flex: 0 0 auto; width: 64px; height: 64px; border-radius: 16px;
  font-family: 'Amiri', serif; font-size: 36px; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--gold2), var(--gold)); color: #201503;
  box-shadow: inset 0 -4px 10px rgba(0,0,0,.15);
}
.card-letter.small { font-size: 22px; font-family: 'Tajawal', sans-serif; font-weight: 800; }
.card-titles { flex: 1; min-width: 0; }
.card-titles h2 { margin: 0 0 3px; font-size: 21px; }
.c-makhraj { color: var(--gold2); font-size: 13.5px; font-weight: 700; line-height: 1.5; }
.tts-btn {
  font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  background: rgba(232,182,76,.14); color: var(--gold2);
  border: 1px solid rgba(232,182,76,.5); border-radius: 12px; padding: 8px 12px;
}
.tts-btn:active { transform: scale(.95); }
.explain { color: var(--text); font-size: 15.5px; line-height: 1.9; margin: 14px 0 0; }

.sifaat { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.sifa {
  font-size: 12.5px; font-weight: 700; color: #cfe0ff;
  background: rgba(56,84,160,.35); border: 1px solid rgba(120,150,220,.4);
  padding: 5px 11px; border-radius: 999px;
}

.example-row { margin-top: 14px; padding: 12px 14px; background: rgba(10,17,40,.55); border-radius: 12px; border: 1px solid rgba(159,176,216,.2); }
.example-label { color: var(--muted); font-size: 13px; margin-left: 8px; }
.example-word { font-family: 'Amiri', serif; font-size: 22px; color: var(--gold2); }
.example-ref { color: var(--muted); font-size: 12px; margin-right: 8px; }

.tip {
  margin-top: 12px; padding: 12px 14px; border-radius: 12px;
  background: rgba(232,182,76,.09); border-right: 3px solid var(--gold);
  color: #ffe9b8; font-size: 14.5px; line-height: 1.8;
}
.tip::before { content: '💡 تدريب: '; font-weight: 800; color: var(--gold2); }

/* ===== Quiz ===== */
.quiz-head { display: flex; align-items: center; justify-content: space-between; }
.quiz h2, .jazariyya h2 { margin: 0 0 10px; font-size: 19px; color: var(--gold2); }
.quiz-score { color: var(--muted); font-size: 14px; font-weight: 700; }
.quiz-q { font-size: 15.5px; line-height: 1.8; margin: 6px 0 12px; }
.quiz-opts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.qopt {
  font-family: 'Amiri', serif; font-size: 24px; cursor: pointer;
  padding: 10px; border-radius: 12px; text-align: center;
  background: var(--card); color: var(--text); border: 1.5px solid rgba(159,176,216,.3);
}
.qopt.correct { background: #14532d; border-color: #22c55e; }
.qopt.wrong { background: #5b1a1a; border-color: #ef4444; }
.quiz-foot { display: flex; gap: 8px; margin-top: 12px; }

/* ===== Jazariyya ===== */
.jazariyya .bayt {
  font-family: 'Amiri', serif; font-size: 17.5px; line-height: 2.1; color: #dfe8ff;
  text-align: center; border-bottom: 1px dashed rgba(159,176,216,.18); padding: 4px 0;
}
.jazariyya .bayt:last-child { border-bottom: none; }

/* ===== Footer ===== */
.foot { text-align: center; margin-top: 26px; color: var(--muted); font-size: 13.5px; line-height: 2; }
.foot strong { color: var(--gold2); }
.foot-note { font-size: 12px; opacity: .75; }

@media (min-width: 640px) {
  #canvas-wrap { height: 56vh; }
  .topbar h1 { font-size: 36px; }
}
