:root {
  --blue: #1E88E5;
  --blue-d: #0D47A1;
  --blue-s: #E3F2FD;
  --gold: #F9A825;
  --ink: #12324D;
  --muted: #5A7190;
  --bg1: #B3E5FC;
  --bg2: #E1F5FE;
  --bg3: #FFF8E1;
  --card: #ffffff;
  --ok: #2E7D32;
  --ok-bg: #E8F5E9;
  --bad: #C62828;
  --bad-bg: #FFEBEE;
  --line: #D7E6F2;
  --shadow: 0 10px 28px rgba(13, 71, 161, .14);
  --radius: 20px;
  --font: "Tajawal", "Noto Kufi Arabic", "Segoe UI", Tahoma, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg1) 0%, var(--bg2) 42%, var(--bg3) 100%);
  background-attachment: fixed;
}
body { padding: 0; }
button, input, select { font-family: inherit; }
a { color: inherit; }

.app {
  width: min(520px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-bottom: 16px;
}
.app.wide { width: min(920px, 100%); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 12px 14px 8px; position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, rgba(179,229,252,.96), rgba(225,245,254,.88));
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 17px; color: var(--blue-d); text-decoration: none; }
.brand img { width: 42px; height: 42px; border-radius: 14px; object-fit: cover; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: #fff; border-radius: 999px; padding: 5px 10px;
  font-weight: 800; font-size: 13px; box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.chip .star { color: var(--gold); }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 12px;
  background: #fff; color: var(--blue-d); font-size: 18px; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

.hero { padding: 6px 16px 18px; text-align: center; }
.hero-art {
  display: flex; justify-content: center; align-items: flex-end; gap: 4px;
  height: 180px; margin-bottom: 8px; overflow: visible; padding: 0 8px;
}
.hero-art img { height: 130px; width: 110px; object-fit: cover; border-radius: 24px;
  filter: drop-shadow(0 8px 12px rgba(0,0,0,.15)); background: #fff; }
.hero-art img.main { height: 170px; width: 150px; }
.hero h1 { margin: 0 0 6px; font-size: 26px; color: var(--blue-d); }
.hero p { margin: 0 auto; max-width: 420px; color: var(--muted); line-height: 1.7; font-size: 15px; }

.grid { display: grid; gap: 12px; padding: 0 16px 20px; }
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; border: 1px solid rgba(255,255,255,.8);
}
.grade-card { text-decoration: none; color: inherit; display: flex; gap: 12px; align-items: center; transition: transform .2s; }
.grade-card:hover, .grade-card:focus { transform: translateY(-2px); }
.grade-card img { width: 86px; height: 86px; object-fit: cover; border-radius: 18px; background: var(--blue-s); }
.grade-card h2 { margin: 0 0 4px; font-size: 18px; }
.grade-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.tag { display: inline-block; background: var(--blue-s); color: var(--blue-d); font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; margin-left: 4px; }

.note { font-size: 12px; color: var(--muted); text-align: center; padding: 4px 18px 20px; line-height: 1.7; }

/* screens */
.screen { display: none; padding: 8px 16px 24px; animation: fade .25s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.field { margin: 10px 0; }
.field label { display: block; font-weight: 800; font-size: 13px; margin-bottom: 6px; }
.field input, .field select {
  width: 100%; border: 2px solid var(--line); border-radius: 14px;
  padding: 12px 14px; font-size: 16px; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus { outline: 0; border-color: var(--blue); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; border: 0; border-radius: 16px; padding: 13px 16px;
  font-weight: 800; font-size: 16px; cursor: pointer;
  background: var(--blue); color: #fff; box-shadow: 0 6px 16px rgba(30,136,229,.35);
  transition: transform .15s, filter .15s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: scale(.98); }
.btn.secondary { background: #fff; color: var(--blue-d); border: 2px solid var(--line); box-shadow: none; }
.btn.gold { background: linear-gradient(90deg, #F9A825, #FF8F00); color: #3E2723; }
.btn.ok { background: var(--ok); box-shadow: 0 6px 16px rgba(46,125,50,.3); }
.btn.ghost { background: transparent; color: var(--blue-d); box-shadow: none; width: auto; padding: 8px 10px; }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.subj-grid { display: grid; gap: 10px; }
.subj-btn {
  display: flex; align-items: center; gap: 12px; text-align: right;
  background: #fff; border: 2px solid var(--line); border-radius: 18px;
  padding: 12px; cursor: pointer; width: 100%; color: inherit;
}
.subj-btn img { width: 64px; height: 64px; border-radius: 16px; object-fit: cover; }
.subj-btn strong { display: block; font-size: 16px; }
.subj-btn span { color: var(--muted); font-size: 12px; }

.progress-wrap { flex: 1; margin: 0 10px; }
.bar { height: 8px; background: rgba(255,255,255,.7); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg,#42A5F5,#1565C0); transition: width .35s; }
.meta { display: flex; justify-content: space-between; font-size: 12px; font-weight: 800; color: var(--blue-d); margin-bottom: 3px; }
.timer.warn { color: #E65100; }
.timer.danger { color: var(--bad); animation: pulse .8s infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.stage { background: #fff; border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; }
.char-row { display: flex; gap: 10px; align-items: flex-end; padding: 12px 12px 0; }
.char-row img {
  width: 96px; height: 96px; object-fit: cover; border-radius: 20px;
  background: var(--blue-s); flex-shrink: 0;
  animation: pop .35s ease;
}
.char-row img.talk { animation: bounce .7s ease infinite; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.bubble {
  flex: 1; background: var(--blue-s); border-radius: 18px 18px 18px 6px;
  padding: 10px 12px; position: relative; min-height: 72px;
}
.bubble .who { font-size: 11px; font-weight: 800; color: var(--blue-d); margin-bottom: 2px; }
.bubble .hook { font-size: 14px; line-height: 1.7; margin: 0; }
.qbox { padding: 12px 14px 16px; }
.passage {
  background: #F7FBFF; border: 1px dashed #90CAF9; border-radius: 14px;
  padding: 10px 12px; margin-bottom: 10px; font-size: 14px; line-height: 1.85;
}
.stem { font-size: 17px; font-weight: 800; line-height: 1.7; margin: 0 0 12px; }
.skill-pill { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.choices { display: grid; gap: 8px; }
.choice {
  width: 100%; text-align: right; background: #fff; border: 2px solid var(--line);
  border-radius: 14px; padding: 12px 14px; font-size: 16px; font-weight: 700;
  cursor: pointer; color: var(--ink); transition: transform .12s, background .2s, border-color .2s;
}
.choice:hover { border-color: var(--blue); }
.choice:active { transform: scale(.98); }
.choice.correct { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); animation: okflash .4s ease; }
.choice.wrong { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); animation: shake .35s ease; }
.choice.dim { opacity: .55; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes okflash { 50% { transform: scale(1.03); } }

.feedback {
  display: none; margin-top: 12px; border-radius: 14px; padding: 12px;
  font-size: 14px; line-height: 1.75;
}
.feedback.show { display: block; animation: fade .25s ease; }
.feedback.ok { background: var(--ok-bg); color: #1B5E20; }
.feedback.bad { background: var(--bad-bg); color: #7F1D1D; }
.feedback strong { display: block; margin-bottom: 4px; }

/* results + gamification */
.stars-row { font-size: 36px; letter-spacing: 4px; text-align: center; margin: 8px 0; }
.stars-row span { display: inline-block; animation: pop .4s ease backwards; }
.stars-row span:nth-child(2) { animation-delay: .1s; }
.stars-row span:nth-child(3) { animation-delay: .2s; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat { background: var(--blue-s); border-radius: 14px; padding: 10px 6px; text-align: center; }
.stat b { display: block; font-size: 22px; color: var(--blue-d); }
.stat span { font-size: 11px; color: var(--muted); font-weight: 700; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0 14px; }
.badge { background: #FFF8E1; border: 1px solid #FFE082; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 800; }
.streak { display: inline-flex; align-items: center; gap: 4px; background: #FFF3E0; color: #E65100; border-radius: 999px; padding: 4px 8px; font-weight: 800; font-size: 13px; }
.streak.on { animation: pop .3s ease; }

/* confetti */
.confetti { pointer-events: none; position: fixed; inset: 0; overflow: hidden; z-index: 50; }
.confetti i {
  position: absolute; top: -10px; width: 8px; height: 14px; border-radius: 2px;
  animation: fall 1.1s ease-in forwards;
}
@keyframes fall {
  to { transform: translateY(110dvh) rotate(480deg); opacity: 0; }
}

/* grade 9 competitive */
body.g9 {
  background: linear-gradient(180deg, #0B1F36 0%, #12324D 50%, #1A3A5C 100%);
  color: #E8F1FA;
}
body.g9 .topbar { background: rgba(11,31,54,.92); }
body.g9 .brand, body.g9 .meta, body.g9 .timer { color: #E3F2FD; }
body.g9 .chip, body.g9 .icon-btn { background: #173554; color: #E3F2FD; }
body.g9 .card, body.g9 .stage, body.g9 .subj-btn, body.g9 .choice, body.g9 .field input, body.g9 .field select {
  background: #173554; color: #E8F1FA; border-color: #2A4A6A;
}
body.g9 .bubble { background: #1E4A73; }
body.g9 .bubble .who { color: #90CAF9; }
body.g9 .hero p, body.g9 .grade-card p, body.g9 .subj-btn span, body.g9 .note, body.g9 .muted, body.g9 .skill-pill { color: #A9C2D8; }
body.g9 .hero h1, body.g9 h2 { color: #fff; }
body.g9 .bar { background: #234260; }
body.g9 .passage { background: #10263C; border-color: #2A4A6A; }
body.g9 .stat { background: #1E4A73; }
body.g9 .stat b { color: #fff; }
body.g9 .btn.secondary { background: #173554; color: #E3F2FD; border-color: #2A4A6A; }

.lb { width: 100%; border-collapse: collapse; font-size: 14px; }
.lb th, .lb td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--line); }
body.g9 .lb th, body.g9 .lb td { border-color: #2A4A6A; }
.lb tr:first-child td { font-weight: 800; color: var(--gold); }

.mode-grid { display: grid; gap: 10px; }
.mode-card {
  display: block; width: 100%; text-align: right; background: #fff;
  border: 2px solid var(--line); border-radius: 18px; padding: 14px; cursor: pointer;
}
body.g9 .mode-card { background: #173554; border-color: #2A4A6A; color: #E8F1FA; }
.mode-card h3 { margin: 0 0 4px; font-size: 16px; }
.mode-card p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.6; }

.section-banner {
  background: linear-gradient(90deg, #1565C0, #1E88E5); color: #fff;
  border-radius: 16px; padding: 14px; margin-bottom: 12px; text-align: center;
}
.break-box { text-align: center; padding: 28px 10px; }
.break-box h2 { margin: 0 0 8px; }

.hidden { display: none !important; }
.center { text-align: center; }
small.muted { color: var(--muted); }

@media (min-width: 720px) {
  .app:not(.wide) { width: 520px; box-shadow: 0 0 80px rgba(13,71,161,.12); background: transparent; }
}

#resSkills { list-style: none; padding: 0; margin: 0 0 12px; }
#resSkills li { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; line-height: 1.6; text-align: right; }
#resSkills li span.sc { flex-shrink: 0; font-weight: 800; color: var(--blue-d); }
body.g9 #resSkills li { border-color: #2A4A6A; }
body.g9 #resSkills li span.sc { color: #90CAF9; }
.meta { flex-wrap: wrap; gap: 4px 10px; }
#playTitle { font-weight: 800; }

/* weekly challenge */
.feature {
  margin: 0 16px 16px;
  background: linear-gradient(160deg, #0D47A1 0%, #1565C0 45%, #F9A825 160%);
  color: #fff;
  border: 0;
  overflow: hidden;
  position: relative;
  text-decoration: none;
  display: block;
  padding: 18px 16px 16px;
}
.feature h2 { margin: 0 0 6px; font-size: 22px; color: #fff; }
.feature p { margin: 0 0 12px; font-size: 14px; line-height: 1.75; color: #E3F2FD; }
.feature .feat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 14px; }
.feature .feat-item {
  background: rgba(255,255,255,.12);
  border-radius: 14px; padding: 8px 10px; font-size: 12px; font-weight: 800;
  line-height: 1.5;
}
.feature .badge-new {
  display: inline-block; background: #F9A825; color: #3E2723;
  font-size: 11px; font-weight: 800; border-radius: 999px; padding: 3px 10px; margin-bottom: 8px;
}
.feature-top { display: flex; gap: 10px; align-items: center; }
.feature-top img { width: 92px; height: 92px; border-radius: 22px; object-fit: cover; background: #fff; flex-shrink: 0; }
.linkbox {
  display: flex; gap: 8px; align-items: stretch; margin-top: 8px;
}
.linkbox input {
  flex: 1; border: 2px solid var(--line); border-radius: 14px;
  padding: 10px 12px; font-size: 13px; direction: ltr; text-align: left;
}
.honor h3 { margin: 0 0 8px; font-size: 16px; }
.honor .me { background: #FFF8E1; }
body.g9 .honor .me, .weekly-dark .honor .me { background: #3E2E0A; }
.tick-big { font-size: 28px; font-weight: 900; letter-spacing: 1px; font-variant-numeric: tabular-nums; }

/* dashboards */
.app.dash { width: min(1120px, 100%); padding-bottom: 40px; }
.demo-banner {
  margin: 0 16px 12px; background: #FFF8E1; border: 1px solid #FFE082; color: #7A5A00;
  border-radius: 14px; padding: 10px 14px; font-size: 13px; font-weight: 700; line-height: 1.7;
}
.nav-links { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }
.nav-links a {
  background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 800;
  text-decoration: none; color: var(--blue-d); box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.nav-links a.on { background: var(--blue); color: #fff; }
.kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; padding: 0 16px 12px; }
.lvl {
  display: inline-block; border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 800;
}
.lvl-high { background: #E8F5E9; color: #1B5E20; }
.lvl-medium { background: #FFF8E1; color: #F57F17; }
.lvl-low { background: #FFF3E0; color: #E65100; }
.lvl-vlow { background: #FFEBEE; color: #B71C1C; }
.lvl-none { background: #ECEFF1; color: #546E7A; }
.hint { font-size: 10px; font-weight: 700; color: var(--muted); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover { background: var(--blue-s); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }
.filters .field { margin: 0; flex: 1; min-width: 140px; }
.split { display: grid; gap: 12px; padding: 0 16px 16px; }
@media (min-width: 860px) {
  .split-2 { grid-template-columns: 1.2fr .8fr; }
  .split-detail { grid-template-columns: 1fr 1.1fr; }
}
.skill-bar { height: 8px; background: #E3EAF1; border-radius: 99px; overflow: hidden; margin-top: 4px; }
.skill-bar > i { display: block; height: 100%; background: #1E88E5; }
.panel { display: none; }
.panel.on { display: block; }
.muted-box { color: var(--muted); font-size: 13px; line-height: 1.7; }

/* map / journey */
.lands { display: grid; gap: 12px; padding: 0 16px 16px; }
@media (min-width: 640px) { .lands { grid-template-columns: 1fr 1fr; } }
.land {
  text-align: right; background: #fff; border: 2px solid var(--line); border-radius: 20px;
  padding: 12px; cursor: pointer; width: 100%; color: inherit; position: relative;
}
.land.lock { opacity: .55; }
.land .who { display: flex; gap: 10px; align-items: center; }
.land img { width: 72px; height: 72px; border-radius: 16px; object-fit: cover; }
.land h3 { margin: 0 0 4px; font-size: 16px; }
.ring { font-size: 12px; font-weight: 800; color: var(--blue-d); }
.boss-btn { margin-top: 8px; }
.cards-row, .badge-row { display: flex; flex-wrap: wrap; gap: 8px; }
.char-card {
  width: 86px; text-align: center; background: #fff; border-radius: 16px; padding: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,.08); font-size: 11px; font-weight: 800;
}
.char-card img { width: 64px; height: 64px; border-radius: 14px; object-fit: cover; }
.char-card.off { filter: grayscale(1); opacity: .45; }
.mission {
  margin: 0 16px 14px; background: linear-gradient(90deg, #1565C0, #26C6DA); color: #fff;
  border-radius: 18px; padding: 14px; display: flex; gap: 10px; align-items: center;
}
.mission img { width: 64px; height: 64px; border-radius: 16px; object-fit: cover; background: #fff; }
.mission p { margin: 0; font-size: 13px; line-height: 1.6; }
body.g9 .land, body.g9 .char-card { background: #173554; border-color: #2A4A6A; color: #E8F1FA; }

.badge-row .chip, .chip { white-space: nowrap; }
.badge-row { gap: 8px; }
