:root {
  --purple: #6d28d9;
  --purple-2: #8b5cf6;
  --purple-3: #4c1d95;
  --bg: #f4f5fb;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e9eaf3;
  --green: #0f9d58;
  --green-bg: #e6f6ee;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --radius: 18px;
  --shadow: 0 6px 20px rgba(31, 41, 55, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* app feel: no text selection on the UI, no zoom on double tap, no tap flash */
html, body { -webkit-user-select: none; user-select: none; }
input, textarea, select, [contenteditable="true"] { -webkit-user-select: text; user-select: text; }
button, a, .row, .tile, .tabbar button, .pill, .card, label { touch-action: manipulation; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Baloo Bhaijaan 2", "Segoe UI", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--purple); text-decoration: none; }
button { font-family: inherit; }

.wrap { max-width: 720px; margin: 0 auto; padding: 16px 16px 96px; }

.topbar {
  background: linear-gradient(135deg, var(--purple-2), var(--purple) 60%, var(--purple-3));
  color: #fff;
  padding: 18px 18px 26px;
  border-radius: 0 0 26px 26px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 700; }
.topbar .sub { font-size: 12.5px; opacity: .85; margin-top: 2px; }
.topbar .logo {
  width: 46px; height: 46px; border-radius: 14px; background: rgba(255,255,255,.18);
  display: grid; place-items: center; font-size: 22px; margin-inline-start: auto;
}
.topbar .spacer { margin-inline-start: auto; }

.btn {
  border: 0; border-radius: 14px; padding: 13px 18px; font-size: 15.5px; font-weight: 700;
  background: var(--purple); color: #fff; cursor: pointer; width: 100%;
}
.btn:active { transform: translateY(1px); }
.btn.ghost { background: #fff; color: var(--purple); border: 1.5px solid var(--purple); }
.btn.soft { background: #f0ebff; color: var(--purple-3); }
.btn.small { width: auto; padding: 8px 14px; font-size: 13.5px; border-radius: 11px; }
.btn.danger { background: var(--red-bg); color: var(--red); }
.btn:disabled { opacity: .6; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 16px; margin: 0 0 12px; }

.hero { text-align: center; padding: 34px 18px 8px; }
.hero .mark {
  width: 86px; height: 86px; border-radius: 24px; margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--purple-2), var(--purple-3));
  display: grid; place-items: center; color: #fff; font-size: 40px;
  box-shadow: 0 10px 26px rgba(109, 40, 217, .3);
}
.hero h1 { font-size: 23px; margin: 0 0 6px; }
.hero p { color: var(--muted); margin: 0 0 22px; font-size: 14.5px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { border-radius: var(--radius); padding: 14px 10px; text-align: center; color: #fff; box-shadow: var(--shadow); }
.stat .n { font-size: 24px; font-weight: 800; line-height: 1.1; }
.stat .l { font-size: 12.5px; opacity: .95; margin-top: 2px; }
.stat.p1 { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.stat.p2 { background: linear-gradient(135deg, #10b981, #059669); }
.stat.p3 { background: linear-gradient(135deg, #f59e0b, #d97706); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  background: #fff; border-radius: var(--radius); padding: 15px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px; cursor: pointer; border: 0; text-align: start; width: 100%;
}
.tile .ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 19px; }
.tile .t { font-weight: 700; font-size: 14.5px; }
.tile .s { font-size: 12px; color: var(--muted); }

.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 700; font-size: 15px; }
.row .meta { font-size: 12.5px; color: var(--muted); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: #f0ebff; color: var(--purple); font-weight: 800; flex: 0 0 auto;
}

.pill { font-size: 11.5px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pill.ok { background: var(--green-bg); color: var(--green); }
.pill.warn { background: var(--amber-bg); color: var(--amber); }
.pill.bad { background: var(--red-bg); color: var(--red); }
.pill.mut { background: #eef0f6; color: var(--muted); }

/* coloured group cards: purple, rose, gold, blue (same palette as the games site) */
.groups-cards { display: grid; gap: 12px; }
.gcard {
  border-bottom: 0; border-radius: 16px; padding: 14px 16px; color: #fff;
  box-shadow: 0 6px 16px rgba(31, 41, 55, .12); cursor: pointer;
}
.gcard .name { font-size: 15.5px; font-weight: 800; }
.gcard .meta { color: rgba(255, 255, 255, .88); }
.gcard .pill { background: rgba(255, 255, 255, .22); color: #fff; }
.gcard.g1 { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.gcard.g2 { background: linear-gradient(135deg, #ef5b66, #e63946); }
.gcard.g3 { background: linear-gradient(135deg, #ffd84a, #ffb703); color: #4a3200; }
.gcard.g3 .meta { color: rgba(74, 50, 0, .82); }
.gcard.g3 .pill { background: rgba(255, 255, 255, .6); color: #5a3d00; }
.gcard.g4 { background: linear-gradient(135deg, #2a5fa8, #1e4d8f); }

.section-title { font-size: 15px; font-weight: 800; margin: 18px 4px 10px; display: flex; align-items: center; }
.section-title a { margin-inline-start: auto; font-size: 12.5px; font-weight: 700; }

label { display: block; font-size: 13px; font-weight: 700; margin: 12px 0 6px; color: #374151; }
input, select, textarea {
  width: 100%; padding: 12px 13px; border-radius: 13px; border: 1.5px solid var(--line);
  background: #fbfbfe; font-family: inherit; font-size: 16px; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--purple-2); background: #fff; }
.field-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.error { color: var(--red); font-size: 13.5px; font-weight: 700; min-height: 20px; margin-top: 10px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line);
  display: flex; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 20;
}
.tabbar button {
  flex: 1; border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 700;
  padding: 6px 0; display: grid; gap: 2px; justify-items: center; cursor: pointer;
}
.tabbar button .i { font-size: 18px; line-height: 1; }
.tabbar button.active { color: var(--purple); }

.sheet-bg {
  position: fixed; inset: 0; background: rgba(17, 24, 39, .45); z-index: 40;
  display: none; align-items: flex-end; justify-content: center;
}
.sheet-bg.open { display: flex; }
.sheet {
  background: #fff; width: 100%; max-width: 720px; border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 88vh; overflow: auto;
}
.sheet h3 { margin: 0 0 4px; font-size: 18px; }
.sheet .close { float: left; border: 0; background: #f0ebff; color: var(--purple); border-radius: 10px; padding: 6px 12px; font-weight: 700; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); bottom: 84px;
  background: #111827; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 13.5px;
  opacity: 0; transition: all .2s; z-index: 60; pointer-events: none; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hide { display: none !important; }
.mt { margin-top: 14px; }
.gap { height: 10px; }

.tile .ic svg, .tabbar .i svg { width: 20px; height: 20px; display: block; }
.tile .ic svg { width: 21px; height: 21px; }
.topbar .logo svg, .hero .mark svg { display: block; }

.sess-row { display: grid; grid-template-columns: 1.25fr .9fr 12px .9fr 30px; gap: 6px; align-items: center; margin-top: 8px; }
.sess-row select, .sess-row input { padding: 9px 8px; font-size: 13.5px; border-radius: 11px; }
.sess-row .s-dash { text-align: center; color: var(--muted); font-size: 12px; }
.sess-row .s-del { border: 0; background: #fee2e2; color: #b91c1c; border-radius: 9px; width: 28px; height: 30px; font-size: 15px; font-weight: 800; cursor: pointer; }

/* offline banner */
.offline-bar {
  display: none; background: #fff4d6; color: #7a4b00; border-bottom: 1px solid #f0d79a;
  font-size: 12.5px; font-weight: 700; padding: 9px 14px; text-align: center; line-height: 1.6;
}
.offline-bar.show { display: block; }
.offline-bar b { font-weight: 800; }

/* attendance: coloured status buttons and the minutes-late field */
.btn.small.st-present { background: #0f9d58; color: #fff; }
.btn.small.st-late { background: #f59e0b; color: #fff; }
.btn.small.st-absent { background: #e11d48; color: #fff; }
.att-item { border-bottom: 1px solid var(--line); }
.att-item:last-child { border-bottom: 0; }
.att-item .row { border-bottom: 0; padding-bottom: 6px; }
.late-line { display: flex; align-items: center; gap: 8px; padding: 0 0 10px; }
.late-line label { margin: 0; font-size: 12.5px; color: var(--muted); }
.late-line input { max-width: 130px; padding: 8px 10px; font-size: 16px; }

/* lesson scoring screen: big tap targets, one card per student */
.lp-item { border-bottom: 1px solid var(--line); padding: 10px 0; }
.lp-item:last-child { border-bottom: 0; }
.lp-item.on-turn { background: #fffbeb; border-radius: 12px; padding: 10px; }
.lp-head { display: flex; align-items: center; gap: 10px; }
.lp-head .grow { flex: 1; min-width: 0; }
.lp-score { font-size: 24px; font-weight: 800; color: var(--purple); min-width: 54px; text-align: center; }
.lp-btns { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.lp-btns .btn.small { min-width: 58px; padding: 12px 8px; font-size: 15px; }
.lp-score-row .btn.small { flex: 1; }
.lp-fix-row { align-items: center; }
.lp-q { display: grid; place-items: center; min-width: 40px; font-weight: 800; }
.lp-time { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
@media print {
  .topbar, .tabbar, #offline-bar, .btn, .section-title a { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #e5e7eb; }
}

/* الدرجة العظمى: مفتاح واحد بتلات اختيارات */
.seg { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.seg button { flex: 1 1 30%; min-height: 44px; padding: 9px 10px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; color: var(--muted); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.seg button.on { background: var(--purple); border-color: var(--purple); color: #fff; }
.tied { font-size: 11.5px; font-weight: 700; color: var(--amber); }

/* ---------- المحافظ ---------- */
.total-card {
  background: linear-gradient(135deg, #8b5cf6, #6d28d9 60%, #4c1d95);
  color: #fff; border-radius: 22px; padding: 20px 18px; margin-bottom: 14px;
  box-shadow: 0 10px 26px rgba(109, 40, 217, .28); text-align: center;
}
.total-card .tl { font-size: 13px; opacity: .9; }
.total-card .tv { font-size: 32px; font-weight: 800; line-height: 1.2; margin: 4px 0 2px; direction: ltr; }
.total-card .tm { font-size: 12px; opacity: .85; }

.tx-row { cursor: pointer; }
.tx-amt { font-weight: 800; font-size: 15px; direction: ltr; white-space: nowrap; }
.tx-amt.in { color: var(--green); }
.tx-amt.out { color: var(--red); }
.tx-bal { font-size: 12px; color: var(--muted); direction: ltr; min-width: 78px; text-align: end; }
.w-bal { font-weight: 800; font-size: 16px; direction: ltr; white-space: nowrap; }
.amt-in { color: var(--green); }
.amt-out { color: var(--red); }

.kv { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-of-type { border-bottom: 0; }
.kv span { color: var(--muted); }
.kv b { margin-inline-start: auto; font-weight: 800; direction: ltr; }

.filter-foot { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.filter-foot .btn.small { margin-inline-start: auto; }

.log-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.log-item:last-child { border-bottom: 0; }
.log-item .grow { flex: 1; min-width: 0; }
.log-item .name { font-weight: 700; font-size: 13.5px; }
.log-item .meta { font-size: 12.5px; color: var(--muted); }
.log-item .when { font-size: 11.5px; color: var(--muted); white-space: nowrap; padding-top: 3px; }
.log-item .pill { flex: 0 0 auto; }
.list-head { display: grid; grid-template-columns: 1fr auto 78px; gap: 10px; font-size: 11.5px; font-weight: 700; color: var(--muted); padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.list-head span:nth-child(2) { text-align: end; }
.list-head span:nth-child(3) { text-align: end; }
a.btn { display: block; text-align: center; text-decoration: none; }

/* ---------- narrow phones (320–375): stack what does not fit ---------- */
input, select, textarea { min-width: 0; }
.field-2 > div { min-width: 0; }
.tx-row .grow { min-width: 0; }
.tx-row .name, .tx-row .meta { overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 375px) {
  .field-2 input, .field-2 select { font-size: 14px; padding: 10px 9px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stats .stat:nth-child(3) { grid-column: 1 / -1; }
  .stat .n { font-size: 20px; }
  .total-card { padding: 16px 14px; }
  .total-card .tv { font-size: 26px; }
  .topbar { padding: 14px 14px 22px; gap: 8px; }
  .topbar h1 { font-size: 17px; }
  .topbar .sub { font-size: 11.5px; }
  .btn.small { padding: 7px 9px; font-size: 12.5px; }
  .tx-amt { font-size: 14px; }
  .tx-bal { min-width: 64px; font-size: 11.5px; }
  .list-head { grid-template-columns: 1fr auto 64px; }
  .seg button { font-size: 12px; padding: 8px 6px; }
}

/* landscape phones: the header and tiles must not eat the screen */
@media (max-height: 430px) and (orientation: landscape) {
  .topbar { padding: 10px 14px 14px; }
  .total-card { padding: 14px; }
  .total-card .tv { font-size: 26px; }
  .wrap { padding-bottom: 84px; }
}
.foot-stats { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.foot-stats b { font-weight: 800; }
