/* Layout: one journey column. A timeline strip of dated stations on top, an atmospheric scene for the current
   station (sky + landscape tinted by the Muslims' situation), then the station's questions on parchment cards.
   The page deliberately commits to one look per era (set by JS on :root), so it is single-theme by design. */
:root {
  color-scheme: dark;
  /* era tokens — overwritten per station by JS */
  --bg: #1F2A2E; --ink: #EDE6D6; --ink-soft: color-mix(in srgb, var(--ink) 70%, transparent);
  --sky1: #1B2B3A; --sky2: #3E5468; --far: #2E3F4D; --near: #3B342B; --accent: #C9A45C;
  /* constant tokens */
  --paper: #FBF6EA; --paper-ink: #2A2118; --paper-muted: #6B5B45; --paper-line: #E5D9C0; --paper-sunk: #F3EBD9;
  --right: #2F7D4F; --right-bg: #E3F1E6; --wrong: #A8402B; --wrong-bg: #F7E3DC; --gold: #B08A4A;
  --f-display: "Amiri", "Traditional Arabic", serif;
  --f-body: "Noto Naskh Arabic", "Traditional Arabic", "Amiri", serif;
  --f-ui: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --r: 14px;
}
* { box-sizing: border-box; }
html, body { background: var(--bg); }
body {
  color: var(--ink); font-family: var(--f-body); font-size: 17px; line-height: 1.85;
  direction: rtl; transition: background-color .8s ease, color .8s ease;
  padding-inline: 16px; padding-block: 0 48px;
}
.wrap { max-width: 860px; margin-inline: auto; display: grid; gap: 20px; }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding-block: 10px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px); border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  transition: background-color .8s ease;
}
.brand { font-family: var(--f-display); font-size: 1.45rem; font-weight: 700; color: var(--accent); margin-inline-end: auto; display: flex; align-items: center; gap: 8px; }
.brand img { height: 34px; width: auto; flex: none; }
.brand .bt { display: grid; line-height: 1.15; }
.brand .bt small { font-family: var(--f-ui); font-size: .72rem; font-weight: 500; color: var(--ink-soft); }
.score-pill {
  font-family: var(--f-ui); font-size: .85rem; padding: 4px 12px; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 60%, transparent); color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.ghost {
  font-family: var(--f-ui); font-size: .85rem; background: none; color: var(--ink-soft);
  border: 1px solid color-mix(in srgb, var(--ink) 25%, transparent); border-radius: 999px; padding: 4px 12px;
}
.ghost:hover { color: var(--ink); border-color: var(--ink); }
.confirm {
  width: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  font-family: var(--f-ui); font-size: .9rem; padding: 10px 12px; border-radius: 10px;
  background: color-mix(in srgb, #A8402B 25%, var(--bg)); color: var(--ink);
}
.confirm span { margin-inline-end: auto; }
.danger { background: #A8402B; color: #fff; border: 0; border-radius: 999px; padding: 4px 14px; font-family: var(--f-ui); }

/* ---------- timeline ---------- */
.timeline { overflow-x: auto; scrollbar-width: thin; padding-block: 6px 4px; }
.timeline ol { list-style: none; margin: 0; padding: 0 2px; display: flex; gap: 0; min-width: max-content; }
.stop { position: relative; width: 104px; flex: none; }
.stop::before { /* the track between stations */
  content: ""; position: absolute; top: 15px; right: 50%; width: 100%; height: 2px;
  background: color-mix(in srgb, var(--ink) 22%, transparent);
}
.stop:first-child::before { display: none; }
.stop.done::before, .stop.current::before { background: var(--accent); }
.stop button {
  position: relative; width: 100%; background: none; border: 0; color: var(--ink-soft);
  display: grid; justify-items: center; gap: 4px; padding: 0 4px; text-align: center;
}
.dot {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--bg); border: 2px solid color-mix(in srgb, var(--ink) 30%, transparent);
  font-family: var(--f-ui); font-size: .78rem; font-variant-numeric: tabular-nums; transition: all .4s;
}
.stop.done .dot { border-color: var(--accent); color: var(--accent); }
.stop.current .dot { background: var(--accent); border-color: var(--accent); color: var(--bg); transform: scale(1.12); }
.stop .when { font-family: var(--f-ui); font-size: .72rem; line-height: 1.35; }
.stop .what { font-family: var(--f-body); font-size: .78rem; line-height: 1.4; color: var(--ink); }
.stop.current .when { color: var(--accent); font-weight: 600; }

/* ---------- scene ---------- */
.scene {
  position: relative; border-radius: var(--r); overflow: hidden; min-height: 250px;
  display: grid; align-items: end; isolation: isolate;
  box-shadow: 0 10px 30px -18px rgba(0,0,0,.7);
}
.scene svg.land { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; }
.scene .caption {
  padding: 22px 22px 18px; display: grid; gap: 6px;
  background: linear-gradient(to top, rgba(0,0,0,.62), rgba(0,0,0,.18) 70%, transparent);
  color: #FFF8EC;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: var(--f-ui); font-size: .75rem; padding: 2px 10px; border-radius: 999px;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.28);
}
.chip.date { background: var(--accent); color: #1a140c; border-color: transparent; font-weight: 600; }
.scene h1 { font-family: var(--f-display); font-size: clamp(1.7rem, 4.6vw, 2.5rem); line-height: 1.25; margin: 0; text-wrap: balance; }
.state { margin: 0; font-size: 1rem; max-width: 60ch; color: #F4EBDC; }
.state b { color: var(--accent); font-weight: 600; }

/* ---------- progress for the station ---------- */
.era-progress { display: flex; align-items: center; gap: 12px; font-family: var(--f-ui); font-size: .85rem; color: var(--ink-soft); }
.meter { flex: 1; height: 6px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 15%, transparent); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .5s; }

/* ---------- questions ---------- */
.qs { display: grid; gap: 16px; }
.q {
  background: var(--paper); color: var(--paper-ink); border-radius: var(--r); padding: 18px 20px 20px;
  display: grid; gap: 12px; border-top: 4px solid var(--accent);
}
.q-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-family: var(--f-ui); font-size: .78rem; color: var(--paper-muted); }
.q-head .n { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--paper-ink); }
.type { padding: 1px 9px; border-radius: 999px; background: var(--paper-sunk); border: 1px solid var(--paper-line); }
.q-head .mark { margin-inline-start: auto; font-weight: 600; }
.mark.ok { color: var(--right); } .mark.no { color: var(--wrong); } .mark.half { color: var(--gold); }
.q-text { font-size: 1.12rem; font-weight: 600; margin: 0; line-height: 1.8; }
.quran { font-family: var(--f-display); color: #1E5631; font-weight: 700; }

.opts { display: grid; gap: 8px; }
.opt {
  text-align: right; background: #fff; color: var(--paper-ink); border: 1.5px solid var(--paper-line);
  border-radius: 10px; padding: 9px 14px; display: flex; gap: 10px; align-items: baseline; line-height: 1.7;
  transition: border-color .2s, background-color .2s;
}
.opt:hover:not(:disabled) { border-color: var(--gold); background: #FFFDF7; }
.opt .k { font-family: var(--f-ui); font-size: .8rem; color: var(--paper-muted); min-width: 1.2em; }
.opt:disabled { cursor: default; }
.opt.right { border-color: var(--right); background: var(--right-bg); }
.opt.wrong { border-color: var(--wrong); background: var(--wrong-bg); }
.opt.dim { background: #FAF6EE; color: #5A4C3A; }
.opt .box { flex: none; width: 18px; height: 18px; margin-top: 4px; border: 2px solid var(--paper-line); border-radius: 5px; background: #fff; }
.opt.sel { border-color: var(--gold); background: #FFF8EA; }
.opt.sel .box, .opt.right:not(.missed) .box { background: var(--gold); border-color: var(--gold); box-shadow: inset 0 0 0 3px #fff; }
.opt.wrong .box { background: var(--wrong); border-color: var(--wrong); box-shadow: inset 0 0 0 3px #fff; }
.opt.missed { border-style: dashed; }
.btn:disabled { opacity: .4; cursor: default; }
.opt .ot { display: grid; gap: 2px; min-width: 0; }
.xw { font-family: var(--f-ui); font-size: .8rem; line-height: 1.6; color: var(--wrong); }
.xw.ok { color: var(--right); font-weight: 600; }
.stop button:disabled { cursor: not-allowed; opacity: .5; }
.mode { display: flex; border: 1px solid color-mix(in srgb, var(--accent) 60%, transparent); border-radius: 999px; overflow: hidden; }
.mode button { font-family: var(--f-ui); font-size: .85rem; padding: 4px 14px; border: 0; background: none; color: var(--ink-soft); }
.mode button[aria-pressed="true"] { background: var(--accent); color: var(--bg); font-weight: 600; }
.mode button#modeHard[aria-pressed="true"] { background: #B3261E; color: #fff; }
.chip.hard { background: #B3261E; border-color: transparent; color: #fff; font-weight: 600; }
.is-hard .scene { box-shadow: 0 0 0 2px #B3261E, 0 10px 30px -18px rgba(0,0,0,.7); }
.is-hard .q { border-top-color: #B3261E; }
.lock-note { font-family: var(--f-ui); font-size: .85rem; color: var(--ink-soft); text-align: center; margin: 0; }

.order { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; counter-reset: o; }
.order li {
  display: flex; align-items: center; gap: 10px; background: #fff; border: 1.5px solid var(--paper-line);
  border-radius: 10px; padding: 6px 10px; counter-increment: o;
}
.order li::before { content: counter(o, arabic-indic); font-family: var(--f-ui); font-weight: 600; color: var(--gold); min-width: 1.2em; }
.order li .t { flex: 1; min-width: 0; line-height: 1.6; }
.order li.right { border-color: var(--right); background: var(--right-bg); }
.order li.wrong { border-color: var(--wrong); background: var(--wrong-bg); }
/* drag to reorder (shared/sortable.js): a grip per row; the dragged row lifts, the others slide out of its way */
.order .drag {
  flex: none; width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--paper-line); background: var(--paper-sunk);
  color: var(--paper-muted); font-family: var(--f-ui); font-size: 1.1rem; font-weight: 700; letter-spacing: -2px; line-height: 1;
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
.order .drag:hover { color: var(--paper-ink); border-color: var(--gold); }
.order.sorting li { transition: transform .15s ease; }
.order.sorting, .order.sorting * { cursor: grabbing; user-select: none; -webkit-user-select: none; }
.order li.dragging { position: relative; z-index: 2; transition: none; border-color: var(--gold); box-shadow: 0 10px 24px -10px rgba(0,0,0,.45); }
@media (prefers-reduced-motion: reduce) { .order.sorting li { transition: none; } }

textarea {
  width: 100%; min-height: 96px; resize: vertical; font: inherit; font-size: 1rem; color: var(--paper-ink);
  background: #fff; border: 1.5px solid var(--paper-line); border-radius: 10px; padding: 10px 12px; line-height: 1.8;
}
.act { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn {
  font-family: var(--f-ui); font-size: .9rem; border-radius: 999px; padding: 6px 18px;
  background: var(--paper-ink); color: var(--paper); border: 0;
}
.btn.soft { background: var(--paper-sunk); color: var(--paper-ink); border: 1px solid var(--paper-line); }
.btn.ok { background: var(--right); color: #fff; } .btn.half { background: var(--gold); color: #fff; } .btn.no { background: var(--wrong); color: #fff; }
.self { font-family: var(--f-ui); font-size: .85rem; color: var(--paper-muted); }

.explain {
  background: var(--paper-sunk); border-inline-start: 4px solid var(--gold); border-radius: 8px;
  padding: 10px 14px; font-size: .98rem; line-height: 1.85;
}
.explain b { color: #7B1E1E; }
.explain .lbl { display: block; font-family: var(--f-ui); font-size: .78rem; color: var(--paper-muted); margin-bottom: 2px; }

/* ---------- footer nav ---------- */
.nav { display: flex; gap: 10px; justify-content: space-between; flex-wrap: wrap; }
.nav button {
  font-family: var(--f-ui); font-size: .95rem; border-radius: 999px; padding: 8px 20px;
  border: 1px solid color-mix(in srgb, var(--accent) 70%, transparent); background: none; color: var(--ink);
}
.nav button.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
.nav button:disabled { opacity: .35; cursor: default; }

/* ---------- results ---------- */
.results { background: var(--paper); color: var(--paper-ink); border-radius: var(--r); padding: 22px; display: grid; gap: 18px; }
.big { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.big strong { font-family: var(--f-display); font-size: 3rem; line-height: 1; color: #7B1E1E; font-variant-numeric: tabular-nums; }
.big span { color: var(--paper-muted); font-family: var(--f-ui); }
.verdict { font-family: var(--f-display); font-size: 1.35rem; margin: 0; }
.rows { display: grid; gap: 8px; }
.row { display: grid; grid-template-columns: minmax(0, 11rem) 1fr auto; gap: 10px; align-items: center; font-size: .92rem; }
.row .bar2 { height: 8px; border-radius: 999px; background: var(--paper-sunk); overflow: hidden; }
.row .bar2 i { display: block; height: 100%; background: var(--gold); }
.row .v { font-family: var(--f-ui); font-variant-numeric: tabular-nums; color: var(--paper-muted); font-size: .82rem; }
details { border: 1px solid var(--paper-line); border-radius: 10px; padding: 8px 14px; background: #fff; }
details + details { margin-top: 8px; }
summary { cursor: pointer; font-weight: 600; }
.key { display: grid; gap: 10px; margin-top: 10px; }
.key div { border-top: 1px dashed var(--paper-line); padding-top: 8px; font-size: .95rem; }
.key .qq { font-weight: 600; }
.key .aa { color: var(--right); font-weight: 600; }
.hint { font-family: var(--f-ui); font-size: .82rem; color: var(--ink-soft); text-align: center; margin: 0; }

@media (max-width: 520px) {
  body { font-size: 16px; }
  .scene { min-height: 230px; }
  .row { grid-template-columns: 1fr auto; }
  .row .bar2 { grid-column: 1 / -1; grid-row: 2; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.twinkle { animation: tw 3.5s ease-in-out infinite; }
@keyframes tw { 50% { opacity: .25; } }

/* ---------- exam mode ---------- */
.view-exam .p-only, body:not(.view-exam) .e-only { display: none !important; }
.exam-btn { font-family: var(--f-ui); font-size: .85rem; border-radius: 999px; padding: 4px 16px; border: 0; background: var(--accent); color: var(--bg); font-weight: 600; }
.panel { background: var(--paper); color: var(--paper-ink); border-radius: var(--r); padding: 20px 22px; display: grid; gap: 14px; }
.panel h2 { font-family: var(--f-display); margin: 0; font-size: 1.5rem; line-height: 1.3; }
.panel p { margin: 0; }
.field { display: grid; gap: 4px; font-family: var(--f-ui); font-size: .9rem; color: var(--paper-muted); }
.field select, .field input {
  font: inherit; font-family: var(--f-body); font-size: 1.05rem; padding: 8px 12px; color: var(--paper-ink);
  border: 1.5px solid var(--paper-line); border-radius: 10px; background: #fff; width: 100%;
}
.field input[dir="ltr"] { text-align: right; }
.err { color: var(--wrong); font-family: var(--f-ui); font-size: .9rem; }
.exam-list { display: grid; gap: 10px; }
.exam-item { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; border: 1px solid var(--paper-line); border-radius: 12px; padding: 12px 14px; background: #fff; }
.exam-item .t { font-weight: 700; margin-inline-end: auto; }
.exam-item small { font-family: var(--f-ui); color: var(--paper-muted); }
.era-head { font-family: var(--f-display); font-size: 1.35rem; color: var(--accent); margin: 10px 0 -4px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.era-head small { font-family: var(--f-ui); font-size: .8rem; color: var(--ink-soft); }
.submit-bar {
  position: sticky; bottom: 0; z-index: 4; display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px)); border-radius: 14px 14px 0 0;
  background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(6px);
  border-top: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); font-family: var(--f-ui); font-size: .88rem;
}
.submit-bar .info { margin-inline-end: auto; color: var(--ink-soft); }
.submit-bar .btn { background: var(--accent); color: var(--bg); font-weight: 600; }
.mark.wait { color: var(--paper-muted); font-weight: 500; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-family: var(--f-ui); font-size: .88rem; color: var(--ink-soft); }
.crumbs button { background: none; border: 0; padding: 2px 0; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; font-family: var(--f-ui); }
.crumbs b { color: var(--ink); font-weight: 600; }
.crumbs .note { margin-inline-start: auto; font-size: .8rem; }
.board { display: grid; gap: 8px; }
.board h3 { margin: 0; font-family: var(--f-display); font-size: 1.3rem; }
.board ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.board li { display: grid; grid-template-columns: 2.2em 1fr auto; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 10px; background: #fff; border: 1px solid var(--paper-line); }
.board li.me { border-color: var(--gold); background: #FFF8EA; }
.board .rk { width: 2em; height: 2em; border-radius: 50%; display: grid; place-items: center; font-family: var(--f-ui); font-weight: 700; background: var(--paper-sunk); color: var(--paper-ink); }
.board li[data-r="1"] .rk { background: #D9B565; color: #2a1d08; } .board li[data-r="2"] .rk { background: #C9CDD3; } .board li[data-r="3"] .rk { background: #D9A273; }
.board .sc { font-family: var(--f-ui); font-variant-numeric: tabular-nums; color: var(--paper-muted); }
.board small { color: var(--paper-muted); font-family: var(--f-ui); }
.tf { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tf .opt { justify-content: center; font-family: var(--f-ui); font-weight: 600; font-size: 1rem; }
.timer { font-family: var(--f-ui); font-variant-numeric: tabular-nums; font-weight: 700; padding: 3px 12px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--ink); min-width: 5.5em; text-align: center; }
.timer.warn { background: #B3261E; color: #fff; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .7; } }
.time-up { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(10,12,18,.72); }
.time-up .panel { max-width: 420px; text-align: center; }
.q.answered { border-top-color: var(--right); }

/* ---------- subjects: the home page with all subjects, and closed practice before signing in ---------- */
body.home .p-only:not(#qs), body.gated .bar .p-only, body.gated .hint { display: none !important; }
a.subject-card { text-decoration: none; color: inherit; }
a.subject-card:hover { border-color: var(--gold); }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--gold); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ---------- files view ---------- */
.view-files .p-only, .view-files .e-only, body:not(.view-files) .f-only { display: none !important; }
.exam-item .fnote { flex-basis: 100%; order: 3; color: var(--paper-muted); font-family: var(--f-ui); }
a.btn { text-decoration: none; display: inline-block; }
.ok-msg { color: var(--right); font-family: var(--f-ui); font-weight: 600; }
