:root {
  /* SHID core palette (from the logo) */
  --navy: #0a1330;
  --blue: #4b55f5;
  --purple: #5b45f8;
  --violet: #6f3ff8;
  --spark: #5445f7;
  --peach: #fcb798;
  --gradient: linear-gradient(135deg, var(--blue), var(--violet));

  /* UI roles */
  --primary: var(--purple);
  --primary-dark: #3f2fd1;
  --primary-soft: #eeecff;
  --ink: var(--navy);
  --muted: #646b85;
  --bg: #f6f5ff;
  --card: #ffffff;
  --line: #e4e2f5;
  --danger: #e5484d;

  /* Playful accents for the kids' UI */
  --yellow: #ffc93c;
  --green: #22b67e;
  --pink: #ff6b9a;
  --sky: #3db2ff;
  --orange: #ff8a3d;

  --radius: 20px;
  --shadow: 0 10px 30px rgba(10, 19, 48, .08);
  /* Latin glyphs use the first font, Arabic falls through to the second. */
  --font: "Nunito", "Tajawal", system-ui, sans-serif;
  --font-display: "Fredoka", "Baloo Bhaijaan 2", "Tajawal", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg);
}
img { max-width: 100%; display: block; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.3; margin: 0 0 .5em; }

.container { width: min(1120px, 100% - 32px); margin-inline: auto; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 26px; border-radius: 999px; border: 2px solid transparent;
  font: 700 17px var(--font); cursor: pointer; transition: transform .15s, box-shadow .15s, background .15s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--gradient); color: #fff; box-shadow: 0 6px 0 var(--primary-dark); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-yellow { background: var(--yellow); color: var(--ink); box-shadow: 0 6px 0 #e0a919; }
.btn-ghost { background: #fff; color: var(--primary); border-color: var(--line); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: progress; transform: none; }

/* Header */
.site-header { position: sticky; top: 0; z-index: 10; background: rgba(247, 245, 255, .85); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.site-header .container { display: flex; align-items: center; justify-content: space-between; height: 72px; gap: 16px; }
.logo { display: inline-flex; align-items: center; color: var(--ink); line-height: 1; }
.wordmark { display: inline-flex; align-items: flex-end; font: 700 30px var(--font-display); letter-spacing: -.5px; direction: ltr; }
.wordmark .pencil { height: .98em; width: .33em; flex-shrink: 0; margin: 0 .05em .1em; position: relative; }
.wordmark .sparks { position: absolute; }
.logo:hover .pencil { animation: wiggle .5s ease; }
@keyframes wiggle { 30% { rotate: -10deg; } 60% { rotate: 6deg; } }
.lang-btn { min-width: 44px; padding: 9px 14px !important; font-family: var(--font-display) !important; }
.nav-actions { display: flex; gap: 10px; }
.nav-actions .btn { padding: 9px 20px; font-size: 16px; }

/* Hero */
.hero { padding: 64px 0 48px; overflow: hidden; }
.hero .container { display: grid; grid-template-columns: 1.1fr .9fr; gap: 40px; align-items: center; }
.badge { display: inline-block; padding: 6px 16px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 15px; margin-bottom: 18px; }
.hero h1 { font-size: clamp(36px, 5.5vw, 58px); }
.hero h1 .hl { background: var(--gradient); -webkit-background-clip: text; background-clip: text; color: transparent; position: relative; white-space: nowrap; }
.hero h1 .hl::after { content: ""; position: absolute; inset-inline: 0; bottom: 6px; height: 14px; background: var(--yellow); opacity: .55; z-index: -1; border-radius: 8px; }
.hero p { font-size: 20px; color: var(--muted); max-width: 520px; }
.hero-cta { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 28px; }
.hero-art { position: relative; aspect-ratio: 1; }
.bubble {
  position: absolute; display: grid; place-items: center; border-radius: 28px; color: #fff;
  box-shadow: var(--shadow); font-size: 54px; animation: float 5s ease-in-out infinite;
}
.bubble.b1 { inset: 4% auto auto 8%; width: 44%; aspect-ratio: 1; background: var(--gradient); transform: rotate(-8deg); }
.bubble.b2 { inset: 10% 6% auto auto; width: 34%; aspect-ratio: 1; background: var(--yellow); animation-delay: -1.5s; }
.bubble.b3 { inset: auto auto 6% 20%; width: 36%; aspect-ratio: 1; background: var(--green); animation-delay: -3s; }
.bubble.b4 { inset: auto 8% 14% auto; width: 30%; aspect-ratio: 1; background: var(--pink); animation-delay: -2s; }
@keyframes float { 50% { translate: 0 -12px; } }

/* Sections */
.section { padding: 64px 0; }
.section-head { text-align: center; max-width: 620px; margin: 0 auto 40px; }
.section-head h2 { font-size: clamp(28px, 4vw, 40px); }
.section-head p { color: var(--muted); margin: 0; }

.grid { display: grid; gap: 22px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-games { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

.card { background: var(--card); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.feature .icon { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; font-size: 32px; margin-bottom: 16px; }
.feature h3 { font-size: 22px; }
.feature p { color: var(--muted); margin: 0; }

.game-card { padding: 0; overflow: hidden; transition: transform .2s; display: flex; flex-direction: column; }
.game-card:hover { transform: translateY(-4px) rotate(-.5deg); }
.game-card .thumb { aspect-ratio: 16/10; display: grid; place-items: center; font-size: 56px; }
.game-card .body { padding: 16px 20px 20px; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.game-card h3 { font-size: 20px; margin: 0; }
.game-card p { color: var(--muted); font-size: 15px; margin: 0; flex: 1; }
.tag { display: inline-block; font-size: 13px; font-weight: 700; padding: 2px 12px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); }
.tag.fun { background: #ffeef4; color: #d63a6f; }
.game-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 14px; color: var(--muted); }

.safe { background: linear-gradient(135deg, var(--navy), #1c2470 60%, var(--violet)); color: #fff; border-radius: 32px; padding: 48px; display: grid; grid-template-columns: 1fr 1fr; gap: 32px; align-items: center; }
.safe h2 { font-size: clamp(26px, 3.5vw, 36px); }
.safe p { opacity: .9; }
.safe ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.safe li { background: rgba(255, 255, 255, .14); padding: 14px 18px; border-radius: 16px; display: flex; gap: 12px; align-items: center; font-weight: 500; }

.cta { text-align: center; }
.site-footer { padding: 32px 0; color: var(--muted); text-align: center; font-size: 15px; border-top: 1px solid var(--line); margin-top: 32px; }

/* Auth pages */
.auth-wrap { min-height: calc(100vh - 72px); display: grid; place-items: center; padding: 32px 0; }
.auth-card { width: min(440px, 100%); }
.auth-card h1 { font-size: 32px; text-align: center; }
.auth-card .sub { text-align: center; color: var(--muted); margin: -6px 0 24px; }
.field { margin-bottom: 18px; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 13px 16px; border-radius: 14px; border: 2px solid var(--line); background: #fff;
  font: 17px var(--font); color: var(--ink); transition: border-color .15s;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); }
.field .hint { font-size: 14px; color: var(--muted); margin-top: 4px; }
.field .err { font-size: 14px; color: var(--danger); margin-top: 4px; display: none; }
.field.invalid input, .field.invalid select { border-color: var(--danger); }
.field.invalid .err { display: block; }
.alert { padding: 12px 16px; border-radius: 14px; background: #fdecec; color: var(--danger); font-weight: 500; margin-bottom: 18px; display: none; }
.alert.show { display: block; }
.auth-switch { text-align: center; margin-top: 18px; color: var(--muted); }

/* Student home */
.welcome { display: flex; justify-content: space-between; align-items: center; gap: 24px; flex-wrap: wrap; padding: 36px 0 12px; }
.welcome h1 { font-size: clamp(28px, 4vw, 38px); margin: 0; }
.level-card { display: flex; align-items: center; gap: 18px; min-width: 300px; }
.level-badge { width: 64px; height: 64px; border-radius: 50%; background: var(--yellow); display: grid; place-items: center; font: 800 26px var(--font-display); box-shadow: 0 4px 0 #e0a919; flex-shrink: 0; }
.xp-bar { height: 12px; background: var(--primary-soft); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.xp-bar span { display: block; height: 100%; background: var(--gradient); border-radius: 999px; transition: width .6s; }
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin: 24px 0 8px; }
.quick .card { display: flex; align-items: center; gap: 14px; padding: 20px; color: var(--ink); }
.quick .card .icon { font-size: 30px; width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; flex-shrink: 0; }
.quick .card strong { display: block; font-size: 18px; }
.quick .card small { color: var(--muted); }
.soon { font-size: 12px; background: var(--line); color: var(--muted); padding: 1px 8px; border-radius: 999px; margin-inline-start: 6px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.chip { padding: 8px 18px; border-radius: 999px; border: 2px solid var(--line); background: #fff; font: 700 15px var(--font); color: var(--muted); cursor: pointer; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.loading { text-align: center; color: var(--muted); padding: 40px; }

.toast { position: fixed; bottom: 24px; inset-inline: 0; margin-inline: auto; width: max-content; max-width: calc(100% - 32px); background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 14px; box-shadow: var(--shadow); opacity: 0; translate: 0 20px; transition: .25s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; translate: 0 0; }

/* Thumbnail colors per subject */
.c-math { background: #e8e3ff; } .c-arabic { background: #dff6ec; } .c-english { background: #def1ff; }
.c-science { background: #fff4d6; } .c-fun { background: #ffe6ee; } .c-puzzle { background: #ffeadb; }

@media (max-width: 860px) {
  .hero .container, .safe { grid-template-columns: 1fr; }
  .hero { padding-top: 36px; }
  .hero-art { max-width: 360px; margin-inline: auto; width: 100%; }
  .grid-3, .quick { grid-template-columns: 1fr; }
  .safe { padding: 32px 24px; }
}
@media (max-width: 480px) {
  .nav-actions .btn-ghost:not(.lang-btn) { display: none; }
  .nav-actions .btn { padding: 8px 14px; font-size: 15px; }
  .wordmark { font-size: 26px; }
  .hero-cta .btn { flex: 1; }
  .level-card { min-width: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Admin panel */
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; padding: 32px 0 8px; }
.admin-head h1 { margin: 0; font-size: clamp(26px, 4vw, 34px); }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0 24px; border-bottom: 2px solid var(--line); }
.tab { padding: 10px 18px; border: 0; background: none; font: 700 16px var(--font); color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab .count { background: var(--danger); color: #fff; border-radius: 999px; font-size: 12px; padding: 0 7px; margin-inline-start: 4px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.stat { padding: 20px; }
.stat .label { color: var(--muted); font-size: 15px; }
.stat .value { font: 800 34px var(--font-display); line-height: 1.2; }
.stat .sub { color: var(--muted); font-size: 13px; }
.stat.alert-stat .value { color: var(--danger); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input, .toolbar select { padding: 10px 14px; border-radius: 12px; border: 2px solid var(--line); font: 16px var(--font); background: #fff; color: var(--ink); }
.toolbar input { flex: 1; min-width: 180px; }
.table-wrap { overflow-x: auto; background: #fff; border-radius: var(--radius); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 12px 14px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: var(--primary-soft); font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td .muted { color: var(--muted); font-size: 13px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.pill.ok { background: #dff6ec; color: #138a5e; }
.pill.bad { background: #fdecec; color: var(--danger); }
.pill.role-admin { background: #efeaff; color: var(--primary); }
.pill.role-teacher { background: #def1ff; color: #1a7cc4; }
.btn-sm { padding: 6px 14px; font-size: 14px; box-shadow: none; }
.btn-danger { background: #fdecec; color: var(--danger); }
.btn-success { background: #dff6ec; color: #138a5e; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 16px; color: var(--muted); }
.report { margin-bottom: 14px; padding: 20px; }
.report .top { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.report blockquote { margin: 12px 0; padding: 12px 16px; background: var(--bg); border-inline-start: 4px solid var(--danger); border-radius: 10px; white-space: pre-wrap; word-break: break-word; }
.report .actions { display: flex; gap: 8px; flex-wrap: wrap; }
dialog { border: 0; border-radius: var(--radius); padding: 28px; width: min(560px, calc(100% - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(36, 28, 77, .45); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.tagline { font: 600 13px var(--font-display); letter-spacing: 4px; color: var(--muted); text-transform: uppercase; }
.site-footer .wordmark { font-size: 22px; }
.site-footer .container { display: flex; flex-direction: column; align-items: center; gap: 6px; }
html[lang="en"] .hero h1 .hl { white-space: nowrap; }

/* App shell (signed-in pages) */
.app-nav { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 72px; z-index: 9; }
.app-nav .container { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.app-nav .container::-webkit-scrollbar { display: none; }
.app-nav a { padding: 12px 14px; color: var(--muted); font-weight: 700; white-space: nowrap; border-bottom: 3px solid transparent; display: flex; gap: 6px; align-items: center; }
.app-nav a.active { color: var(--primary); border-bottom-color: var(--primary); }
.app-nav .dot { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; }
.page-head { padding: 28px 0 8px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: clamp(26px, 4vw, 34px); }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 22px; align-items: start; }
.stack { display: grid; gap: 18px; }
.card h2 { font-size: 22px; margin-bottom: 14px; }
.card h3 { font-size: 18px; margin-bottom: 10px; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; }
.notice { background: var(--primary-soft); border-radius: 16px; padding: 14px 18px; color: var(--ink); }
.notice.warn { background: #fff4d6; }
.stage-tag { display: inline-block; font-size: 12px; font-weight: 800; background: #fff4d6; color: #9a6b00; padding: 2px 10px; border-radius: 999px; }

/* People rows */
.person { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person .av { width: 44px; height: 44px; border-radius: 14px; background: var(--primary-soft); display: grid; place-items: center; font-size: 24px; flex-shrink: 0; }
.person .who { flex: 1; min-width: 0; }
.person .who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .who small { color: var(--muted); }
.person .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* Pickers */
.avatar-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; }
.avatar-grid button { aspect-ratio: 1; border-radius: 16px; border: 2px solid var(--line); background: #fff; font-size: 26px; cursor: pointer; transition: transform .15s; }
.avatar-grid button:hover { transform: scale(1.06); }
.avatar-grid button.on { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px rgba(91, 69, 248, .18); }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.switch-row:last-child { border-bottom: 0; }
.switch-row small { display: block; color: var(--muted); }
.switch { position: relative; width: 50px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 22px; height: 22px; inset-block-start: 3px; inset-inline-start: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { translate: 22px 0; }
html[dir="rtl"] .switch input:checked + span::before { translate: -22px 0; }
.switch input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }

/* Codes */
.code-box { font: 800 28px/1 var(--font-display); letter-spacing: 4px; direction: ltr; background: var(--bg); border: 2px dashed var(--primary); border-radius: 14px; padding: 14px; text-align: center; color: var(--primary); }
.code-pill { font: 700 15px var(--font-display); letter-spacing: 2px; direction: ltr; background: var(--primary-soft); color: var(--primary); padding: 2px 10px; border-radius: 8px; }
.invite-preview { margin-top: 8px; padding: 10px 14px; border-radius: 12px; background: #dff6ec; color: #138a5e; font-weight: 700; display: none; }
.invite-preview.show { display: block; }

/* Group card */
.group-hero { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.group-hero .gav { width: 84px; height: 84px; border-radius: 24px; background: var(--gradient); display: grid; place-items: center; font-size: 44px; box-shadow: 0 6px 0 var(--primary-dark); }
.group-hero h2 { margin: 0; }
.group-stats { display: flex; gap: 22px; margin-top: 6px; color: var(--muted); }
.group-stats b { color: var(--ink); font: 800 20px var(--font-display); }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; margin: 18px 0; }
.dash-card { display: flex; flex-direction: column; gap: 8px; }
.dash-card .big { font: 800 22px var(--font-display); }
.dash-card .muted { color: var(--muted); }
.dash-card .btn { align-self: flex-start; margin-top: auto; }

html.reduce-motion *, html.reduce-motion *::before { animation: none !important; transition: none !important; }

@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .avatar-grid { grid-template-columns: repeat(4, 1fr); }
  .app-nav { top: 72px; }
}
