/* =========================================================================
   Concours Maroc — practice app (QCM trainer), embedded in the site layout.
   Components come from the original offline app, adapted to page scrolling
   (no full-screen panes) so the site header, browser back button and
   bookmarks all keep working.
   ========================================================================= */

.cm-app { max-width: 820px; margin: 0 auto; padding: 0 var(--pad) 40px; min-height: 60vh; }
.cm-app .screen { display: none; }
.cm-app .screen.is-active { display: block; animation: cm-fade .18s ease; }
@keyframes cm-fade { from { opacity: .4; transform: translateY(4px); } }

.cm-app .appbar {
  position: sticky; top: var(--header-h); z-index: 20;
  display: flex; align-items: center; gap: 6px;
  padding: 10px 0; margin-bottom: 14px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.cm-app .appbar h2 { margin: 0; font-size: var(--fs-lg); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  flex: 0 0 auto; min-width: 44px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: 12px; color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }
html[dir="rtl"] .icon-btn.flip svg { transform: scaleX(-1); }

/* ---------- home: target concours banner ---------- */
.target {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  position: relative; overflow: hidden; isolation: isolate;
  background: var(--pattern-dark), linear-gradient(135deg, var(--navy-900), var(--majorelle-600)); color: #fff;
  border-radius: var(--r-lg); padding: 18px 20px; margin: 6px 0 16px; box-shadow: var(--shadow);
}
.target .tg-body { flex: 1 1 220px; min-width: 0; }
.target .tg-lab { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .1em; opacity: .85; font-weight: 700; }
html[dir="rtl"] .target .tg-lab { letter-spacing: 0; }
.target .tg-name { font-size: 1.25rem; font-weight: 800; line-height: 1.3; }
.target .tg-sub { font-size: var(--fs-sm); opacity: .9; }
.target::after { content: ""; position: absolute; z-index: -1; width: 130px; height: 130px; inset-inline-end: -36px; bottom: -48px; clip-path: var(--star); background: rgba(245, 165, 36, .22); }
.target .btn { background: var(--saffron); color: var(--navy-950); box-shadow: none; }
.target .btn:hover { background: #ffb84d; color: var(--navy-950); }
.target .btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.55); }
.target .btn.ghost:hover { background: rgba(255,255,255,.12); }

.home-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 560px) { .tiles { grid-template-columns: 1fr; } }
.tile {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: start;
  min-height: 72px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 14px 16px; color: inherit; font: inherit; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.tile:hover { border-color: var(--accent); box-shadow: var(--shadow-lift); }
.tile:active { transform: scale(.985); }
.tile .t-icon { flex: 0 0 42px; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.tile .t-icon svg { width: 22px; height: 22px; fill: currentColor; }
.tile .t-body { flex: 1 1 auto; min-width: 0; }
.tile .t-title { font-weight: 700; }
.tile .t-hint { color: var(--muted); font-size: var(--fs-sm); line-height: 1.4; }
.tile .t-chev { flex: 0 0 auto; color: var(--muted); }
.tile .t-chev svg { width: 18px; height: 18px; fill: currentColor; }
html[dir="rtl"] .tile .t-chev { transform: scaleX(-1); }
.tile.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tile.primary .t-icon { background: rgba(255,255,255,.18); color: inherit; }
.tile.primary .t-hint, .tile.primary .t-chev { color: rgba(255,255,255,.85); }
.tile.gold .t-icon { background: var(--gold-soft); color: var(--gold); }
.tile .t-count { font-weight: 800; color: var(--gold); }

/* ---------- concours picker (sheet) ---------- */
.picker-group { margin: 12px 0 4px; font-size: var(--fs-xs); font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
html[dir="rtl"] .picker-group { letter-spacing: 0; }
.picker-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 520px) { .picker-list { grid-template-columns: 1fr; } }
.picker-list button {
  text-align: start; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-size: var(--fs-sm); cursor: pointer; min-height: 44px;
}
.picker-list button:hover { border-color: var(--accent); }
.picker-list button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.picker-search { width: 100%; min-height: 44px; padding: 9px 12px; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 4px; }

/* ---------- setup ---------- */
.cm-app .field select, .cm-app .field input[type="text"], .cm-app textarea, .cm-app select {
  width: 100%; min-height: var(--tap); padding: 10px 12px; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
}
.cm-app textarea { min-height: 90px; resize: vertical; }
.cm-app input[type="range"] { width: 100%; accent-color: var(--accent); }
.subject-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.subject-grid button {
  padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; font-size: var(--fs-sm); cursor: pointer; min-height: 40px;
}
.subject-grid button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); padding: 6px 0; }
.switch-row .sr-label { flex: 1 1 auto; }
.switch-row .sr-label small { display: block; color: var(--muted); font-size: var(--fs-xs); }
.switch { flex: 0 0 auto; position: relative; width: 52px; height: 30px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-3); cursor: pointer; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: inset-inline-start .16s ease; }
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"]::after { inset-inline-start: 25px; }

/* ---------- quiz ---------- */
.quiz-head {
  position: sticky; top: var(--header-h); z-index: 20; padding: 10px 0 10px; margin-bottom: 8px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.qh-top { display: flex; align-items: center; gap: 6px; }
.qh-meta { flex: 1 1 auto; min-width: 0; }
.qh-cat { font-size: var(--fs-xs); font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html[dir="rtl"] .qh-cat { letter-spacing: 0; }
.qh-count { font-size: var(--fs-sm); color: var(--muted); }
.qh-timer { flex: 0 0 auto; font-variant-numeric: tabular-nums; font-weight: 800; padding: 6px 10px; border-radius: 999px; background: var(--surface-2); font-size: var(--fs-sm); }
.qh-timer.low { background: var(--bad-bg); color: var(--bad-ink); }
.star-track { display: flex; gap: 3px; margin-top: 10px; }
.star-track i { flex: 1 1 0; height: 6px; border-radius: 2px; background: var(--surface-3); display: block; }
.star-track i.done { background: var(--accent); }
.star-track i.skip { background: var(--warn-line); }
.star-track i.now { background: var(--gold); }
.q-card { margin: 4px 0 0; }
.q-meta { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 4px; }
.q-text { font-size: clamp(1.12rem, 2.6vw, 1.42rem); font-weight: 650; line-height: 1.5; margin: 8px 0 18px; white-space: pre-line; }
.q-text[lang="ar"] { font-family: var(--font-ar); line-height: 1.85; }
.options { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; align-items: flex-start; gap: 12px; width: 100%; text-align: start; min-height: var(--tap);
  padding: 13px 15px; border: 2px solid var(--line); border-radius: var(--r-md); background: var(--surface); color: var(--ink);
  font: inherit; cursor: pointer; transition: border-color .12s ease, background .12s ease, transform .1s ease;
}
.opt:hover:not([disabled]) { border-color: var(--accent); }
.opt:active:not([disabled]) { transform: scale(.99); }
.opt .opt-key { flex: 0 0 28px; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-weight: 800; font-size: var(--fs-sm); }
.opt .opt-label { flex: 1 1 auto; min-width: 0; line-height: 1.5; }
.opt[data-state="selected"] { border-color: var(--accent); background: var(--accent-soft); }
.opt[data-state="selected"] .opt-key { background: var(--accent); color: var(--accent-ink); }
.opt[data-state="correct"] { border-color: var(--ok-line); background: var(--ok-bg); color: var(--ok-ink); }
.opt[data-state="correct"] .opt-key { background: var(--ok-line); color: #fff; }
.opt[data-state="wrong"] { border-color: var(--bad-line); background: var(--bad-bg); color: var(--bad-ink); }
.opt[data-state="wrong"] .opt-key { background: var(--bad-line); color: #fff; }
.opt[disabled] { cursor: default; }
.feedback { margin-top: 18px; border-radius: var(--r-md); padding: 14px 16px; border: 1px solid; }
.feedback.good { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-ink); }
.feedback.bad { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad-ink); }
.feedback .fb-head { font-weight: 800; margin-bottom: 6px; }
.feedback p { margin: 0 0 6px; }
.explain { margin-top: 12px; padding-top: 12px; border-top: 1px dashed currentColor; font-size: var(--fs-sm); line-height: 1.65; }
.explain .src { display: block; margin-top: 8px; opacity: .85; font-size: var(--fs-xs); }
.quiz-foot {
  position: sticky; bottom: 0; z-index: 15; padding: 12px 0 calc(env(safe-area-inset-bottom, 0px) + 12px); margin-top: 18px;
  background: color-mix(in srgb, var(--bg) 94%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); display: flex; gap: 10px;
}
.quiz-foot .btn { flex: 1 1 auto; }
.kbd-hint { font-size: var(--fs-xs); color: var(--muted); margin-top: 10px; }
@media (hover: none) { .kbd-hint { display: none; } }

/* exam-mode navigator */
.navgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; }
.navgrid button { min-height: 40px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--fs-sm); font-weight: 700; cursor: pointer; }
.navgrid button.answered { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.navgrid button.current { outline: 3px solid var(--gold); }

/* ---------- results & stats ---------- */
.score-hero { text-align: center; padding: 8px 0 4px; }
.score-ring { width: 150px; height: 150px; margin: 0 auto 14px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--surface-3) 0); position: relative; }
.score-ring::after { content: ""; position: absolute; inset: 12px; border-radius: 50%; background: var(--bg); }
.score-ring span { position: relative; z-index: 1; font-size: 2rem; font-weight: 850; font-variant-numeric: tabular-nums; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: var(--gap); }
@media (max-width: 620px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; }
.kpi .k-val { font-size: var(--fs-xl); font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .k-lab { font-size: var(--fs-xs); color: var(--muted); }
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row .b-top { display: flex; justify-content: space-between; gap: 10px; font-size: var(--fs-sm); margin-bottom: 5px; }
.bar-row .b-track { height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar-row .b-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.bar-row.weak .b-fill { background: var(--gold); }
.bar-row.elim .b-fill { background: var(--red); }
.review-item { border-inline-start: 4px solid var(--line); padding-inline-start: 12px; margin-bottom: 18px; }
.review-item.ok { border-color: var(--ok-line); }
.review-item.ko { border-color: var(--bad-line); }
.review-item.skip { border-color: var(--warn-line); }
.review-item .ri-q { font-weight: 650; margin-bottom: 6px; white-space: pre-line; }
.review-item .ri-a { font-size: var(--fs-sm); margin: 3px 0; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row .lr-main { flex: 1 1 auto; min-width: 0; }
.list-row .lr-sub { font-size: var(--fs-xs); color: var(--muted); }
.cm-app .card { margin-bottom: var(--gap); }
.cm-app .card h3 { margin: 0 0 10px; }

/* ---------- states ---------- */
.state { text-align: center; padding: 36px 16px; color: var(--muted); }
.state .st-star { width: 46px; height: 46px; margin: 0 auto 14px; background: var(--surface-3); clip-path: var(--star); }
.state.error .st-star { background: var(--bad-line); }
.spinner { width: 30px; height: 30px; margin: 0 auto 14px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--accent); animation: cm-spin .8s linear infinite; }
@keyframes cm-spin { to { transform: rotate(360deg); } }

/* ---------- sheet ---------- */
.sheet-back { position: fixed; inset: 0; z-index: 80; background: rgba(9, 15, 34, .58); display: none; align-items: flex-end; justify-content: center; }
.sheet-back.is-open { display: flex; }
@media (min-width: 700px) { .sheet-back { align-items: center; } .sheet { border-radius: var(--r-lg) !important; } }
.sheet { width: 100%; max-width: 620px; background: var(--surface); color: var(--ink); border-radius: var(--r-lg) var(--r-lg) 0 0; padding: 22px var(--pad) calc(env(safe-area-inset-bottom, 0px) + var(--pad)); box-shadow: var(--shadow-lift); animation: cm-rise .22s ease; max-height: 88vh; overflow-y: auto; }
.sheet h3 { margin-top: 0; }
@keyframes cm-rise { from { transform: translateY(18px); opacity: .6; } }

/* ---------- onboarding ---------- */
.ob-step { display: none; }
.ob-step.is-active { display: block; animation: cm-fade .25s ease; }
.ob-dots { display: flex; gap: 6px; justify-content: center; margin: 20px 0 4px; }
.ob-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--surface-3); }
.ob-dots i.on { background: var(--accent); width: 20px; border-radius: 999px; }
.brand-mark { width: 80px; height: 80px; margin: 8px auto 18px; display: block; color: var(--accent); }

.legal { font-size: var(--fs-sm); color: var(--muted); line-height: 1.6; }
.pre-wrap { white-space: pre-wrap; }

/* memory game */
.mem-board { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin: 12px 0; }
.mem-board div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; font-weight: 700; }
.mem-timer { font-size: 2rem; font-weight: 850; color: var(--accent); text-align: center; font-variant-numeric: tabular-nums; }

/* focus mode: outside the practice home, keep only the app on screen */
body[data-cm-route]:not([data-cm-route="home"]) .practice-extra { display: none; }
body[data-cm-route="quiz"] .practice-head,
body[data-cm-route="quiz"] .breadcrumb,
body[data-cm-route="memoire"] .practice-head { display: none; }
body[data-cm-route]:not([data-cm-route="home"]) .practice-head .lead { display: none; }
body[data-cm-route="quiz"] .cm-app { padding-top: 6px; }
