:root {
  color-scheme: light;
  --ink: #183b38;
  --muted: #6a807b;
  --green: #0c675e;
  --green-dark: #084b45;
  --mint: #e9f5ef;
  --gold: #d8a943;
  --paper: #f5f8f5;
  --card: #ffffff;
  --line: #e2ebe6;
  --danger: #a94238;
  --tg-bg: var(--tg-theme-bg-color, #f5f8f5);
  --tg-text: var(--tg-theme-text-color, #183b38);
  font-family: Tahoma, "Noto Naskh Arabic", Arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--tg-bg);
  color: var(--tg-text);
}
button { font: inherit; }
.app-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: auto;
  padding: max(14px, env(safe-area-inset-top)) 18px calc(94px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}
.topbar { display: flex; align-items: center; gap: 12px; padding: 4px 2px 20px; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center;
  background: linear-gradient(145deg, #0c756b, #084b45); color: #fff; font: 800 14px Arial, sans-serif;
  box-shadow: 0 8px 20px #0c675e2b; letter-spacing: .5px;
}
.brand-title { font-weight: 800; font-size: 18px; color: var(--ink); }
.brand-caption { margin-top: 3px; color: var(--muted); font-size: 11px; }
.lang-chip { margin-inline-start: auto; padding: 7px 10px; background: var(--mint); color: var(--green-dark); border-radius: 999px; font-size: 11px; font-weight: 700; }
#app { flex: 1; }
.loading-card, .card, .exam-card, .result-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: 0 10px 32px #193b3810;
}
.loading-card { min-height: 180px; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.welcome { padding: 20px; border-radius: 24px; color: white; background: radial-gradient(circle at 90% 0%, #2a9785 0, transparent 40%), linear-gradient(140deg, #0c675e, #084b45); position: relative; overflow: hidden; }
.welcome:after { content: ""; position: absolute; width: 140px; height: 140px; border: 1px solid #ffffff2b; border-radius: 50%; inset: auto -45px -72px auto; }
.welcome-kicker { opacity: .78; font-size: 12px; }
.welcome h1 { font-size: 22px; margin: 8px 0 6px; }
.welcome p { font-size: 12px; line-height: 1.8; opacity: .85; margin: 0; }
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0 20px; }
.stat { padding: 13px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 17px; }
.stat-label { color: var(--muted); font-size: 11px; }
.stat-value { color: var(--ink); font-size: 15px; font-weight: 800; margin-top: 7px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin: 21px 2px 10px; }
.section-heading h2 { margin: 0; color: var(--ink); font-size: 15px; }
.section-heading span { color: var(--muted); font-size: 11px; }
.action-card { display: flex; align-items: center; gap: 13px; padding: 15px; margin-bottom: 10px; cursor: pointer; text-align: start; width: 100%; }
.action-card:active, .option:active, .small-button:active { transform: scale(.985); }
.action-icon { flex: 0 0 42px; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px; background: var(--mint); color: var(--green); font-size: 20px; }
.action-copy { flex: 1; }
.action-copy strong { display: block; color: var(--ink); font-size: 14px; }
.action-copy small { display: block; color: var(--muted); font-size: 11px; margin-top: 5px; }
.chevron { color: var(--muted); font-size: 20px; }
.subject-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.subject-button { padding: 13px 10px; display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 700; font-size: 12px; cursor: pointer; }
.subject-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.report-list { display: grid; gap: 8px; }
.report-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; }
.report-row strong { display: block; font-size: 12px; color: var(--ink); }
.report-row small { display: block; color: var(--muted); font-size: 10px; margin-top: 4px; }
.score-pill { padding: 7px 9px; border-radius: 11px; background: var(--mint); color: var(--green-dark); font-size: 12px; font-weight: 800; white-space: nowrap; }
.exam-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 2px 1px 13px; }
.exam-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.small-button { border: 0; background: transparent; color: var(--muted); padding: 9px 4px; cursor: pointer; font-size: 12px; }
.cancel-button { color: var(--danger); }
.timer { color: var(--green-dark); background: var(--mint); padding: 8px 11px; border-radius: 12px; font: 700 13px Arial, sans-serif; direction: ltr; }
.progress-track { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-bottom: 14px; }
.progress-bar { height: 100%; background: linear-gradient(90deg, #d8a943, #0c756b); border-radius: inherit; transition: width .25s ease; }
.exam-card { padding: 19px 17px; }
.question-meta { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 11px; margin-bottom: 13px; }
.question-text { color: var(--ink); font-size: 17px; line-height: 1.9; margin: 0 0 18px; font-weight: 700; }
.options { display: grid; gap: 9px; }
.option { border: 1px solid var(--line); background: #fbfdfb; color: var(--ink); border-radius: 14px; min-height: 49px; text-align: start; padding: 12px 13px; cursor: pointer; line-height: 1.6; transition: transform .12s, border-color .12s, background .12s; }
.option:before { content: attr(data-letter); display: inline-grid; place-items: center; width: 23px; height: 23px; margin-inline-end: 9px; border-radius: 8px; background: var(--mint); color: var(--green-dark); font: 700 11px Arial, sans-serif; }
.option:disabled { opacity: .65; cursor: wait; }
.result-card { padding: 27px 20px; text-align: center; }
.result-mark { width: 66px; height: 66px; margin: auto; border-radius: 22px; display: grid; place-items: center; color: var(--green); background: var(--mint); font-size: 28px; }
.result-card h1 { color: var(--ink); font-size: 21px; margin: 17px 0 6px; }
.result-card p { color: var(--muted); font-size: 13px; line-height: 1.8; }
.result-score { color: var(--green-dark); font-size: 35px; font-weight: 800; margin: 15px 0; direction: ltr; }
.primary-button { width: 100%; border: 0; border-radius: 15px; padding: 14px 16px; background: var(--green); color: #fff; font-weight: 800; cursor: pointer; margin-top: 13px; box-shadow: 0 7px 18px #0c675e2b; }
.primary-button:disabled { opacity: .55; cursor: wait; }
.secondary-button { border: 1px solid var(--line); border-radius: 13px; padding: 11px 13px; background: var(--mint); color: var(--green-dark); font-weight: 700; cursor: pointer; }
.secondary-button:disabled { opacity: .5; cursor: not-allowed; }
.compact-button { flex: 1; margin-top: 0; padding: 11px 12px; }
.text-button { border: 0; background: transparent; color: var(--green); font-weight: 700; padding: 11px 4px; cursor: pointer; }
.button-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.content-card { padding: 16px; margin-bottom: 10px; }
.content-title { display: block; color: var(--ink); font-size: 14px; line-height: 1.7; }
.content-copy { color: var(--muted); font-size: 12px; line-height: 1.8; margin: 6px 0 0; overflow-wrap: anywhere; }
.content-card > .secondary-button, .content-card > .primary-button { width: 100%; margin-top: 11px; }
.profile-card { display: flex; align-items: center; gap: 12px; }
.profile-avatar { flex: 0 0 44px; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 15px; background: var(--mint); color: var(--green); font-size: 20px; font-weight: 800; }
.profile-copy { min-width: 0; }
.report-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.report-stats .stat { padding: 12px 9px; }
.report-stats .stat-label { min-height: 30px; line-height: 1.5; }
.ranking-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.ranking-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.rank-number { width: 25px; color: var(--muted); font-weight: 800; }
.rank-alias { flex: 1; color: var(--ink); font-size: 12px; }
.ranking-row strong { color: var(--green); font-size: 13px; }
.bottom-nav { position: fixed; z-index: 10; bottom: 0; left: 50%; transform: translateX(-50%); width: min(100%, 560px); display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--tg-bg); box-shadow: 0 -8px 24px #183b3810; }
.nav-item { display: grid; justify-items: center; gap: 3px; border: 0; border-radius: 13px; padding: 7px 3px; background: transparent; color: var(--muted); cursor: pointer; }
.nav-item.is-active { background: var(--mint); color: var(--green-dark); }
.nav-icon { font-size: 18px; line-height: 1; }
.nav-label { font-size: 10px; font-weight: 700; }
.empty-card { padding: 17px; color: var(--muted); font-size: 12px; line-height: 1.8; }
.notice { padding: 15px; margin-top: 12px; background: #fff8e8; border: 1px solid #f0dfb4; border-radius: 15px; color: #725a24; font-size: 12px; line-height: 1.8; }
.error-card { padding: 22px; text-align: center; border-color: #f0d4d1; color: var(--danger); font-size: 13px; line-height: 1.8; }
#app-footer { text-align: center; padding: 22px 0 2px; color: #81918c; font-size: 10px; }
@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; --ink: #e7f3ed; --muted: #a3b6b0; --paper: #101a18; --card: #162421; --line: #2a3b37; --mint: #203b35; --tg-bg: var(--tg-theme-bg-color, #101a18); --tg-text: var(--tg-theme-text-color, #e7f3ed); }
  .brand-title, .stat-value, .section-heading h2, .action-copy strong, .subject-button, .report-row strong, .question-text, .content-title, .rank-alias { color: var(--ink); }
  .option { background: #1b2a26; color: var(--ink); }
}
