* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #0f0f16; --surface: #1a1a26; --surface2: #242436; --border: #2c2c42;
  --text: #e8e8f4; --text2: #9090b0; --accent: #4f7cff; --accent2: #3a5fd9;
  --green: #2ecc71; --red: #ff4d5e; --yellow: #ffcf40; --ai: #b06cff;
}
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Arabic', Tahoma, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100dvh;
}
.screen { display: none; min-height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }
.hidden { display: none !important; }
.muted { color: var(--text2); }
.small { font-size: .82rem; line-height: 1.5; }
a { color: var(--accent); }
b { font-weight: 700; }
code { background: var(--surface2); padding: 1px 5px; border-radius: 4px; font-size: .85em; }

/* ── buttons ── */
.btn {
  border: 1px solid var(--border); background: var(--surface2); color: var(--text);
  border-radius: 10px; cursor: pointer; font-size: .95rem; font-weight: 600;
  padding: 10px 14px; transition: filter .15s, transform .05s; touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn.primary  { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.secondary{ background: var(--surface2); }
.btn.danger   { background: #3a1a22; border-color: #5c2530; color: #ff8896; }
.btn.ghost    { background: transparent; }
.btn.ai       { background: linear-gradient(135deg, #7b3fe0, #b06cff); border: none; color: #fff; }
.btn.big      { width: 100%; padding: 15px; font-size: 1.05rem; margin-top: 10px; min-height: 52px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.chip     { padding: 6px 12px; font-size: .82rem; border-radius: 999px; }
.btn.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── home ── */
.home-wrap { max-width: 520px; margin: 0 auto; padding: 24px 18px calc(24px + env(safe-area-inset-bottom)); width: 100%; }
.brand { text-align: center; margin-bottom: 18px; }
.brand-logo { font-size: 44px; }
.brand h1 { font-size: 1.7rem; margin: 4px 0; }
.tagline { color: var(--text2); line-height: 1.6; font-size: .95rem; }
.tagline .en { font-size: .82rem; opacity: .8; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; margin-bottom: 14px;
}
.card.resume { border-color: var(--yellow); }
.field-label { display: block; font-size: .8rem; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; margin: 14px 0 6px; }
.field-label:first-child { margin-top: 0; }
select, input[type=text], input[type=password], input[type=tel] {
  width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); font-size: 1rem;
}
.pdf-status { margin-top: 10px; font-size: .9rem; min-height: 1.3em; }
.pdf-status.ok  { color: var(--green); }
.pdf-status.err { color: var(--red); }
.how ol { margin: 10px 0 0 22px; line-height: 1.9; font-size: .9rem; color: var(--text2); }
.foot { text-align: center; color: var(--text2); font-size: .82rem; margin-top: 6px; }

/* ── exam ── */
.exam-top {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.module-name { font-size: .82rem; font-weight: 700; color: var(--text2); max-width: 40%; }
.timer { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer.low { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.q-counter { font-size: .85rem; color: var(--text2); }
.q-grid {
  display: flex; gap: 6px; overflow-x: auto; padding: 8px 14px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.q-grid::-webkit-scrollbar { display: none; }
.q-cell {
  min-width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text2); font-weight: 700; font-size: .85rem;
  display: flex; align-items: center; justify-content: center; cursor: pointer; position: relative;
  flex-shrink: 0;
}
.q-cell.answered { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.q-cell.current  { outline: 2px solid #fff; }
.q-cell.flagged::after { content: ''; position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--yellow); }
.q-cell.good { background: #14432a; border-color: var(--green); color: var(--green); }
.q-cell.bad  { background: #431420; border-color: var(--red); color: var(--red); }
.q-cell.skip { opacity: .55; }

.q-area { flex: 1; overflow-y: auto; padding: 14px; -webkit-overflow-scrolling: touch; }
.q-area canvas.qcrop {
  display: block; width: 100%; max-width: 680px; height: auto;
  margin: 0 auto 8px; background: #fff; border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,.5);
}
.q-loading { color: var(--text2); text-align: center; padding: 40px 0; }

.exam-bottom {
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  position: sticky; bottom: 0; z-index: 10;
}
.answer-bar { display: flex; gap: 8px; margin-bottom: 10px; }
.ans-btn {
  flex: 1; min-height: 52px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); font-size: 1.15rem; font-weight: 800; cursor: pointer;
}
.ans-btn.sel { background: var(--accent); border-color: var(--accent); color: #fff; }
.grid-input { flex: 1; text-align: center; font-size: 1.15rem; font-weight: 700; min-height: 52px; }
.grid-hint { font-size: .75rem; color: var(--text2); text-align: center; width: 100%; margin-top: 4px; }
.nav-bar { display: flex; gap: 8px; }
.nav-bar .btn.nav { flex: 1; min-height: 46px; }
.nav-bar .btn.flag { flex: 0 0 54px; font-size: 1.1rem; }
.nav-bar .btn.flag.on { background: #4a3a10; border-color: var(--yellow); }

/* ── break / center ── */
.center-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; }
.card.center { text-align: center; max-width: 440px; width: 100%; }
.break-emoji { font-size: 52px; margin-bottom: 8px; }
.card.center h2 { margin-bottom: 8px; }

/* ── results ── */
.results-wrap { max-width: 560px; margin: 0 auto; padding: 26px 18px calc(26px + env(safe-area-inset-bottom)); width: 100%; }
.results-title { text-align: center; margin-bottom: 14px; }
.score-hero { text-align: center; margin-bottom: 16px; }
.total-score { font-size: 3rem; font-weight: 800; letter-spacing: 1px; color: var(--accent); }
.section-scores { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.card.sec { text-align: center; margin: 0; padding: 14px; }
.sec-label { font-size: .8rem; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; }
.sec-score { font-size: 1.5rem; font-weight: 800; margin: 4px 0; }
#results-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
#results-chips .q-cell { cursor: pointer; }
.chips-mod-label { width: 100%; font-size: .78rem; color: var(--text2); margin-top: 8px; text-transform: uppercase; letter-spacing: .5px; }
.results-actions { margin-top: 10px; }

/* ── review ── */
.review-filters { display: flex; gap: 6px; }
.review-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; font-size: .95rem; }
.pill { padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: .88rem; }
.pill.you-good { background: #14432a; color: var(--green); }
.pill.you-bad  { background: #431420; color: var(--red); }
.pill.correct  { background: var(--surface2); color: var(--green); }
.pill.skip     { background: var(--surface2); color: var(--text2); }
.explain-out {
  background: var(--surface); border: 1px solid var(--ai); border-radius: 12px;
  padding: 14px; margin-top: 12px; line-height: 1.8; white-space: pre-wrap; font-size: .95rem;
}
.explain-out.rtl { direction: rtl; text-align: right; }
.explain-out .thinking { color: var(--ai); }

/* ── modal / toast ── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 18px; }
.modal-card { max-width: 460px; width: 100%; margin: 0; }
.modal-card input, .modal-card select { margin-bottom: 4px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }
.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: 12px; z-index: 200; font-size: .92rem; max-width: 90vw;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}

@media (min-width: 720px) {
  .q-area { padding: 20px 10vw; }
  .answer-bar { max-width: 560px; margin: 0 auto 10px; }
  .nav-bar { max-width: 560px; margin: 0 auto; }
}

/* ═══════════ PDF AI Workbench ═══════════ */
.wb-body { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.wb-top {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.wb-title { font-size: .95rem; }
.wb-top-actions { display: flex; gap: 8px; }
.wb-empty { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; overflow-y: auto; }
.wb-main { flex: 1; display: flex; min-height: 0; }
.wb-left {
  flex: 1.15; display: flex; flex-direction: column; min-width: 0;
  border-right: 1px solid var(--border);
}
.wb-pagebar {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 8px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.wb-pagebar .btn.nav { min-width: 64px; }
.wb-pageno { color: var(--text2); font-size: .95rem; display: flex; align-items: center; gap: 6px; }
.wb-pageno input { width: 64px; text-align: center; padding: 8px 4px; }
.wb-canvas-wrap { flex: 1; overflow: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
/* block + max-content + auto margins: centered when narrower than the wrap,
   overflows right-only when zoomed (a centered inline-block would clip its
   left edge unreachably) */
.wb-canvas-stage { position: relative; display: block; width: max-content; margin: 0 auto; touch-action: pan-x pan-y; }
.wb-canvas-stage.selecting { cursor: crosshair; touch-action: none; }
.wb-zoom { display: flex; gap: 4px; align-items: center; }
.wb-zoom .btn { min-width: 42px; padding: 10px 8px; }
.zoom-pct { font-size: .78rem; min-width: 56px; color: var(--text2); font-variant-numeric: tabular-nums; }
#wb-canvas { display: block; background: #fff; border-radius: 8px; box-shadow: 0 2px 14px rgba(0,0,0,.55); }
.wb-selbox {
  position: absolute; border: 2px solid var(--accent); background: rgba(79,124,255,.16);
  border-radius: 4px; pointer-events: none;
}
.wb-badge {
  font-size: .74rem; color: var(--text2); background: var(--surface2);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 40%;
}
.wb-badge.sel { color: var(--accent); border-color: var(--accent); max-width: none; }
.wb-badge.sel .sel-x { cursor: pointer; padding: 0 2px; }
.wb-badge.keyline {
  display: block; max-width: none; white-space: normal; margin-bottom: 10px;
  color: var(--green); border-color: var(--green); font-size: .8rem;
}
.nb-count {
  background: var(--red); color: #fff; border-radius: 999px; font-size: .7rem;
  padding: 1px 6px; margin-inline-start: 3px;
}
.wb-nb-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.wb-right { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.wb-tabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 10px 12px 6px;
  background: var(--surface); scrollbar-width: none; flex-shrink: 0;
}
.wb-tabs::-webkit-scrollbar { display: none; }
.wb-tabs .tab-btn { flex-shrink: 0; }
.wb-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 12px 10px; background: var(--surface);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.wb-vision { font-size: .8rem; color: var(--text2); display: flex; align-items: center; gap: 6px; }
.wb-ask-row { padding: 10px 12px 0; flex-shrink: 0; }
.wb-out { flex: 1; overflow-y: auto; padding: 14px; -webkit-overflow-scrolling: touch; }
.wb-text { line-height: 1.85; font-size: .95rem; overflow-wrap: break-word; }
.wb-text.rtl ul, .wb-text.rtl ol { padding-right: 22px; padding-left: 0; }
.wb-text ul, .wb-text ol { padding-left: 22px; margin: 4px 0; }
.wb-text .md-h1, .wb-text .md-h2 { font-size: 1.15rem; font-weight: 800; margin: 10px 0 4px; }
.wb-text .md-h3, .wb-text .md-h4 { font-size: 1.02rem; font-weight: 700; margin: 8px 0 3px; color: var(--accent); }
.wb-text .md-gap { height: 8px; }
.wb-scorebar { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.wb-text.rtl, .wb-q.rtl { direction: rtl; text-align: right; }
.thinking { color: var(--ai); }
.center-text { text-align: center; padding: 30px 0; }
.wb-q { padding: 14px; }
.wb-q-title { font-weight: 700; margin-bottom: 10px; line-height: 1.6; }
.wb-choice { display: block; width: 100%; text-align: start; margin-bottom: 6px; font-weight: 500; line-height: 1.5; }
.wb-choice.good { background: #14432a; border-color: var(--green); color: var(--green); }
.wb-choice.bad  { background: #431420; border-color: var(--red); color: var(--red); }
.wb-why { margin-top: 8px; color: var(--text2); font-size: .88rem; line-height: 1.7; }
.wb-reveal { margin-top: 4px; font-size: .82rem; }
.wb-scorebar { text-align: center; font-size: 1.15rem; font-weight: 800; padding: 12px; }
/* Ask conversation bubbles */
.wb-msg { margin-bottom: 16px; }
.wb-msg.user { text-align: left; }
.wb-msg.assistant { text-align: left; }
.wb-msg-label { font-size: .75rem; font-weight: 700; color: var(--text2); margin-bottom: 4px; }
.wb-msg-body { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; line-height: 1.7; font-size: .9rem; }
.wb-msg-body.rtl { direction: rtl; text-align: right; }
.wb-msg.user .wb-msg-body { background: var(--surface2); white-space: pre-wrap; }
.wb-switch { display: none; }
@media (max-width: 860px) {
  .wb-switch {
    display: flex; gap: 8px; padding: 8px 12px; background: var(--surface);
    border-bottom: 1px solid var(--border); flex-shrink: 0;
  }
  .wb-main { flex-direction: column; }
  .wb-left { border-right: none; }
  body:not(.wb-show-ai) .wb-right { display: none; }
  body.wb-show-ai .wb-left { display: none; }
}
