:root {
  --teal: #0f766e;
  --teal-dark: #115e59;
  --teal-light: #ccfbf1;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f8fafc;
  --card: #ffffff;
  --good: #16a34a;
  --good-bg: #dcfce7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --amber: #d97706;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .06);
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "Heebo", "Arial Hebrew", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--teal);
  color: #fff;
  box-shadow: var(--shadow);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; color: #fff;
  font-size: 1.15rem; font-weight: 700; cursor: pointer; font-family: inherit;
}
.brand .logo { font-size: 1.4rem; }
.timer {
  font-variant-numeric: tabular-nums; font-weight: 700;
  background: rgba(255,255,255,.15); padding: 6px 12px; border-radius: 999px;
  font-size: 1rem;
}
.timer.warn { background: var(--amber); }
.hidden { display: none !important; }

.app { max-width: 760px; margin: 0 auto; padding: 20px 16px 60px; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px 40px; }

/* Cards & buttons */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 20px; border-radius: 12px; border: none; cursor: pointer;
  font-size: 1rem; font-weight: 600; font-family: inherit;
  background: var(--teal); color: #fff; transition: transform .05s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn:hover { background: var(--teal-dark); }
.btn.ghost { background: #fff; color: var(--teal); border: 1.5px solid var(--teal); }
.btn.ghost:hover { background: var(--teal-light); }
.btn.subtle { background: #f1f5f9; color: var(--ink); }
.btn.subtle:hover { background: #e2e8f0; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.25rem; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 20px; }

/* Home menu */
.menu { display: grid; gap: 14px; }
.menu-item {
  display: flex; align-items: center; gap: 16px; text-align: right;
  width: 100%; padding: 18px; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); font-family: inherit; transition: transform .08s, border-color .15s;
}
.menu-item:hover { transform: translateY(-2px); border-color: var(--teal); }
.menu-item .emoji { font-size: 2rem; flex-shrink: 0; }
.menu-item .mi-title { font-size: 1.15rem; font-weight: 700; color: var(--ink); }
.menu-item .mi-desc { font-size: .9rem; color: var(--muted); }

/* Grid of exams / topics */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile {
  position: relative; padding: 18px 14px; border-radius: 14px; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
  text-align: center; font-family: inherit; transition: transform .08s, border-color .15s;
}
.tile:hover { transform: translateY(-2px); border-color: var(--teal); }
.tile .tile-num { font-size: 1.5rem; font-weight: 800; color: var(--teal); }
.tile .tile-label { font-size: .9rem; font-weight: 600; }
.tile .tile-meta { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.tile .done-badge {
  position: absolute; top: 8px; left: 8px; background: var(--good-bg); color: var(--good);
  font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
}

/* Quiz */
.q-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.q-progress { font-size: .85rem; color: var(--muted); font-weight: 600; }
.q-type-badge {
  font-size: .75rem; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--teal-light); color: var(--teal-dark);
}
.progressbar { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; margin-bottom: 18px; }
.progressbar > span { display: block; height: 100%; background: var(--teal); transition: width .3s; }

.stem { font-size: 1.2rem; font-weight: 600; margin-bottom: 8px; white-space: pre-wrap; }
.diff-dots { margin-bottom: 16px; color: var(--amber); font-size: .8rem; letter-spacing: 2px; }

.fig-prompt { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 8px 0 20px; }
.fig-prompt .fig, .fig-prompt .arrowsep { width: 84px; height: 84px; }
.fig-prompt .arrowsep { display: flex; align-items: center; justify-content: center; font-size: 1.6rem; color: var(--muted); width: auto; }
.fig { width: 100%; height: auto; display: block; }

.passage {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; margin-bottom: 14px; line-height: 1.85; font-size: 1.02rem;
  text-align: justify; color: #1e293b;
}
.matrix-prompt { display: flex; justify-content: center; margin: 8px 0 20px; }
.matrix-prompt svg { width: min(280px, 82%); height: auto; }

.options { display: grid; gap: 12px; }
.option {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 16px; border-radius: 14px; cursor: pointer; text-align: right;
  background: var(--card); border: 2px solid var(--line); font-family: inherit;
  font-size: 1.05rem; transition: border-color .12s, background .12s;
}
.option:hover { border-color: var(--teal); }
.option.selected { border-color: var(--teal); background: var(--teal-light); }
.option .opt-label {
  flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  background: #f1f5f9; color: var(--ink);
}
.option.selected .opt-label { background: var(--teal); color: #fff; }
.option.correct { border-color: var(--good); background: var(--good-bg); }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.option .opt-fig { width: 90px; height: 90px; flex-shrink: 0; }
.option .opt-mark { margin-inline-start: auto; font-weight: 800; }
.option.correct .opt-mark { color: var(--good); }
.option.wrong .opt-mark { color: var(--bad); }

.nav-row { display: flex; gap: 10px; margin-top: 22px; }
.nav-row .btn { flex: 1; }

.explain {
  margin-top: 14px; padding: 14px 16px; border-radius: 12px;
  background: #f8fafc; border: 1px solid var(--line); font-size: .95rem;
}
.explain b { color: var(--teal-dark); }

/* Results */
.score-ring { text-align: center; margin: 10px 0 24px; }
.score-big { font-size: 4rem; font-weight: 800; color: var(--teal); line-height: 1; }
.score-cap { color: var(--muted); font-weight: 600; }
.score-msg { font-size: 1.05rem; margin-top: 10px; }
.breakdown { display: grid; gap: 10px; margin: 8px 0; }
.bd-row { }
.bd-top { display: flex; justify-content: space-between; font-size: .9rem; font-weight: 600; margin-bottom: 4px; }
.bd-bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bd-bar > span { display: block; height: 100%; background: var(--teal); }

/* History */
.hist-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.hist-item:last-child { border-bottom: none; }
.hist-score { font-weight: 800; color: var(--teal); font-size: 1.2rem; }
.hist-meta { font-size: .82rem; color: var(--muted); }

.callout { background: var(--teal-light); border: 1px solid #99f6e4; border-radius: 12px; padding: 14px 16px; font-size: .92rem; color: var(--teal-dark); margin-bottom: 16px; }

.personal-banner {
  background: linear-gradient(135deg, #0f766e 0%, #0ea5a4 60%, #f59e0b 140%);
  color: #fff; font-weight: 800; font-size: 1.15rem; text-align: center;
  padding: 18px 16px; border-radius: var(--radius); margin-bottom: 18px;
  box-shadow: var(--shadow); letter-spacing: .2px;
  animation: pop .4s ease;
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.center { text-align: center; }
.spacer { height: 8px; }
.review-q { border-top: 2px solid var(--line); padding-top: 18px; margin-top: 18px; }
