/* ═══════════════ Modal dialog ═══════════════ */
.modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgb(2 6 15 / .55); backdrop-filter: blur(4px); opacity: 0; transition: opacity .25s; }
.modal.open .modal-backdrop { opacity: 1; }
.modal-box {
  position: relative; width: min(520px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; border-radius: 18px;
  background: var(--bg-2); border: 1px solid var(--line); box-shadow: var(--shadow); padding: 18px 20px 20px;
  transform: translateY(14px) scale(.98); opacity: 0; transition: transform .3s var(--ease), opacity .2s;
}
.modal-box.wide { width: min(760px, 100%); }
.modal.open .modal-box { transform: none; opacity: 1; }
.modal-box > header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-box > header h2 { font-size: 19px; }
.modal-body { display: grid; gap: 12px; }
.modal-body p { margin: 0; color: var(--ink-dim); }
.code { width: 100%; font-family: var(--font-mono); font-size: 12.5px; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); resize: vertical; }
.row.start { justify-content: flex-start; }

/* Share */
.share-url { display: flex; gap: 8px; }
.share-url input { flex: 1; min-width: 0; padding: 0 10px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
.share-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.share-link { display: grid; place-items: center; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px; }
.share-link:hover { border-color: var(--accent); text-decoration: none; }

/* Settings */
.set-sec { display: grid; gap: 10px; padding-bottom: 14px; border-bottom: 1px solid var(--line-soft); }
.set-sec:last-child { border-bottom: 0; padding-bottom: 0; }
.set-sec h3 { display: flex; align-items: center; gap: 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-dim); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.seg.wrap { flex-wrap: wrap; }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.shortcuts { display: grid; gap: 6px; margin: 0; }
.shortcuts div { display: flex; justify-content: space-between; gap: 16px; padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
.shortcuts dd { margin: 0; color: var(--ink-dim); text-align: end; }

/* Pronunciation */
.speak { display: none; vertical-align: middle; }
.can-speak .speak { display: inline-grid; }
.speak.speaking { color: var(--accent); animation: speak-pulse .8s ease-in-out infinite; }
@keyframes speak-pulse { 50% { transform: scale(1.12); } }
h1 .speak, h2 .speak { width: 34px; height: 34px; }
.pn-title .speak { margin-inline-start: 4px; }

/* Tour */
.tour { position: fixed; inset: 0; z-index: 75; }
.tour-spot {
  position: fixed; border-radius: 14px; box-shadow: 0 0 0 9999px rgb(2 6 15 / .62), 0 0 0 2px var(--accent), var(--glow);
  transition: all .45s var(--ease); pointer-events: none;
}
.tour-card {
  position: fixed; padding: 16px 18px; border-radius: 16px; background: var(--bg-2); border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: var(--shadow); transition: left .45s var(--ease), top .45s var(--ease); animation: rise .4s var(--ease) both;
}
.tour-card h3 { font-size: 17px; margin-bottom: 6px; }
.tour-card p { color: var(--ink-dim); font-size: 14px; margin-bottom: 12px; }
.tour-count { font-size: 12px; color: var(--accent); font-weight: 700; margin-bottom: 4px !important; }
.tour-btns { display: flex; gap: 8px; justify-content: flex-end; }

/* Nav dot (today's question unanswered) */
.nav a.dot::after { content: ''; position: absolute; top: 5px; inset-inline-end: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--sys-digestive); box-shadow: 0 0 8px var(--sys-digestive); }

/* ═══════════════ Explore additions ═══════════════ */
.stage-top { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; z-index: 3; }
.stage-top .seg { background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: blur(10px); }
.body-svg.flipping { animation: flip-in .5s var(--ease); }
@keyframes flip-in { from { opacity: .2; transform: scaleX(.7); } to { opacity: 1; transform: none; } }
@media (max-width: 900px) { .stage-top { top: 14px; left: auto; right: 12px; transform: none; } .stage-top .btn span { display: none; } }

/* ═══════════════ Diagram viewer additions ═══════════════ */
.dgv-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.dgv-prompt {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 4; display: flex; align-items: baseline; gap: 8px; padding: 10px 18px;
  border-radius: 999px; background: var(--bg-2); border: 1px solid var(--accent); box-shadow: var(--shadow), var(--glow); font-size: 16px; max-width: calc(100% - 24px);
}
.dgv-prompt.pop { animation: rise .35s var(--ease); }
.dgv-prompt span { color: var(--ink-dim); }
.dgv-prompt i { font-style: normal; color: var(--ink-faint); font-size: 13px; }
.dgv.quizzing .dgv-parts, .dgv.quizzing .dgv-steps, .dgv.quizzing .dgv-desc, .dgv.quizzing .dgv-info, .dgv.quizzing .dgv-tip { display: none !important; }
.dg [data-id].quiz-right { filter: drop-shadow(0 0 8px var(--ok)) brightness(1.3); animation: quiz-pop .6s var(--ease); }
.dg [data-id].quiz-wrong { filter: drop-shadow(0 0 8px var(--danger)) saturate(.4); animation: shake .4s; }
.dg [data-id].quiz-reveal { filter: drop-shadow(0 0 10px var(--accent)) brightness(1.4); animation: quiz-pop 1.1s var(--ease); }
@keyframes quiz-pop { 30% { opacity: .55; } 60% { opacity: 1; } }
.dgv-quiz .progress { margin: 10px 0; }
.quiz-score { font-weight: 650; }
.quiz-result { font-size: 22px; margin: 6px 0; }
.step-body:not(:has(h5:not(:empty)))::before { content: attr(data-empty); color: var(--ink-dim); font-size: 14px; }

/* Embed page */
.embed .topbar, .embed .nav, .embed #progress { display: none !important; }
.embed #app { top: 0; bottom: 0; }
.embed-view { height: 100%; display: flex; flex-direction: column; padding: 8px; gap: 6px; }
.embed-host { flex: 1; min-height: 0; }
.embed-brand { align-self: flex-end; font-size: 12.5px; color: var(--ink-dim); }

/* ═══════════════ Study additions ═══════════════ */
.daily { max-width: 1100px; margin: 0 auto 16px; border-color: color-mix(in srgb, var(--c, var(--accent)) 35%, var(--line-soft)); }
.daily-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.daily-head h3 { display: flex; align-items: center; gap: 8px; }
.daily-head h3 .ico { color: var(--sys-digestive); }
.streak { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--sys-digestive); background: color-mix(in srgb, var(--sys-digestive) 14%, transparent); }
.daily-q { font-size: 17px; font-weight: 600; margin: 12px 0; }
.daily .chip { --c: inherit; }
.mini-grid { max-width: 1100px; margin: 16px auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.mini-card { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 14px; border: 1px solid var(--line-soft); background: var(--surface); color: var(--ink); transition: border-color .2s, transform .2s var(--ease); }
.mini-card:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-2px); }
.mini-card > .ico { width: 24px; height: 24px; color: var(--accent); }
.mini-card span { display: flex; flex-direction: column; }
.mini-card small { color: var(--ink-dim); }
.progress-table { max-width: 1100px; margin: 0 auto; }
.ptable { display: grid; gap: 4px; margin-top: 10px; }
.prow { display: grid; grid-template-columns: minmax(150px, 1.2fr) 2fr 50px 80px; gap: 12px; align-items: center; padding: 6px 8px; border-radius: 8px; color: var(--ink); font-size: 14px; }
.prow:hover { background: var(--surface-2); text-decoration: none; }
.pname { display: flex; align-items: center; gap: 8px; }
.pname .ico { color: var(--c); }
.pbar { height: 7px; border-radius: 7px; background: var(--surface-2); overflow: hidden; }
.pbar i { display: block; height: 100%; background: var(--c); border-radius: 7px; transition: width .8s var(--ease); }
.pnum { font-variant-numeric: tabular-nums; text-align: end; font-size: 13px; }
@media (max-width: 640px) { .prow { grid-template-columns: 1fr 1fr 44px; } .prow .pnum.muted { display: none; } }
.setup-card { max-width: 640px; margin: 0 auto; display: grid; gap: 16px; }
.setup-card .btn.big { justify-self: start; }
.qc-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.timer { margin-inline-start: auto; display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.time-bar { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.time-bar span { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--danger), var(--sys-nervous), var(--ok)); }
.case-title { font-size: 15px; color: var(--ink-dim); margin-top: 12px; }
.case-stem { margin: 10px 0 0; padding: 14px 16px; border-radius: 12px; background: var(--surface-2); border-inline-start: 3px solid var(--c, var(--accent)); font-size: 15.5px; line-height: 1.65; }
.explain .chips { margin: 10px 0 0; }
.view.study-mode.wide { max-width: 1240px; }
.note-card h3 { font-size: 16px; margin-bottom: 6px; }
.note-card p { color: var(--ink-dim); margin: 0; }

/* Study page notes + review badge */
.sp-notes textarea { width: 100%; min-height: 96px; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); resize: vertical; font: inherit; font-size: 14px; }
.sp-notes textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow); }
.review-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ok); margin: 0 0 14px; }

/* ═══════════════ Tables, revision, mnemonics ═══════════════ */
.page-wrap.wide { max-width: 1240px; }
.table-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin-top: 20px; }
.table-tools { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin: 14px 0; }
.tbl-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--line-soft); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 760px; }
.tbl th, .tbl td { padding: 10px 12px; text-align: start; vertical-align: top; border-bottom: 1px solid var(--line-soft); }
.tbl thead th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-dim); z-index: 1; }
.tbl tbody th { font-weight: 650; min-width: 150px; }
.tbl tbody tr:hover { background: color-mix(in srgb, var(--sys, var(--accent)) 6%, transparent); }
.tbl td { color: var(--ink-dim); }
.rev-head h1 { font-size: clamp(26px, 3.5vw, 36px); }
.rev-facts { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 14px 0; font-size: 14px; color: var(--ink-dim); }
.rev-group h2 { font-size: 18px; margin: 22px 0 8px; padding-bottom: 6px; border-bottom: 2px solid var(--sys); }
.rev-group dl { margin: 0; columns: 2 420px; column-gap: 28px; }
.rev-item { break-inside: avoid; padding: 6px 0; border-bottom: 1px dashed var(--line-soft); }
.rev-item dt { font-weight: 700; }
.rev-item dt small { font-weight: 500; color: var(--ink-faint); }
.rev-item dd { margin: 2px 0 0; font-size: 14px; color: var(--ink-dim); }
.oian { display: grid; gap: 2px; margin-top: 4px; font-size: 13px; }
.oian i { font-style: normal; }
.oian b { display: inline-block; width: 16px; color: var(--sys); }
.mn-sec { margin-top: 10px; scroll-margin-top: 16px; }
.mn-sec .card.mnemonic h3 { display: flex; gap: 8px; align-items: center; font-size: 15.5px; margin-bottom: 6px; }

/* ═══════════════ Text size (reading areas scale; the body map does not) ═══════════════ */
:root { --fs: 1; }
.prose, .pn-body, .sp-main, .page-wrap, .quiz-card, .flash .face, .dgv-side, .s-card p, .lead { zoom: var(--fs); }
.page-wrap .prose, .sp-main .prose, .sp-main .lead, .pn-body .prose, .pn-body .lead, .dgv-side .prose, .quiz-card .prose { zoom: 1; }

/* ═══════════════ Right-to-left languages (Arabic, Urdu) ═══════════════ */
[dir="rtl"] body { font-family: "Noto Naskh Arabic", "Segoe UI", Tahoma, var(--font); }
[dir="rtl"] .rail { border-right: 0; border-left: 1px solid var(--line-soft); }
[dir="rtl"] .atlas-side { border-right: 0; border-left: 1px solid var(--line-soft); }
[dir="rtl"] #panel { right: auto; left: 12px; transform: translateX(calc(-100% - 24px)); }
[dir="rtl"] #panel.open { transform: none; }
[dir="rtl"] .ticks li { padding-left: 0; padding-right: 22px; }
[dir="rtl"] .ticks li::before { left: auto; right: 2px; }
[dir="rtl"] .parts li { padding: 10px 42px 10px 12px; }
[dir="rtl"] .parts li::before { left: auto; right: 12px; }
[dir="rtl"] .kv, [dir="rtl"] .card.clinical, [dir="rtl"] .card.mnemonic { border-left: 0; border-right: 3px solid var(--sys, var(--accent)); }
[dir="rtl"] .ico[aria-hidden] { transform: none; }
[dir="rtl"] .icon-btn .ico, [dir="rtl"] .btn .ico { }
/* Anatomy is never mirrored: the body map and diagrams keep their orientation. */
[dir="rtl"] .stage, [dir="rtl"] .dgv-stage, [dir="rtl"] .ident-stage, [dir="rtl"] .sp-map-svg { direction: ltr; }
@media (min-width: 901px) { [dir="rtl"] .zoom-ctrls { left: auto; right: 16px; } }

/* ═══════════════ Print (study pages, tables, revision sheets) ═══════════════ */
@media print {
  :root, :root[data-theme] { --bg: #fff; --bg-2: #fff; --surface: #fff; --surface-2: #f4f4f4; --ink: #000; --ink-dim: #333; --ink-faint: #666; --line: #bbb; --line-soft: #ddd; }
  body { background: #fff !important; overflow: visible !important; }
  .topbar, .nav, #panel, #palette, #progress, .ad, .site-foot, .sp-side, .sp-actions, .no-print, .table-tools, .crumbs, .tour, .modal, .sp-sib { display: none !important; }
  #app { position: static !important; overflow: visible !important; }
  #app > .view { height: auto !important; overflow: visible !important; padding: 0 !important; }
  .sp-grid { display: block !important; }
  .card, .kv, .qa, .fact { break-inside: avoid; box-shadow: none !important; background: #fff !important; }
  .qa:not([open]) > *:not(summary) { display: block !important; }
  a { color: #000 !important; text-decoration: none !important; }
  .tbl { font-size: 10.5px; min-width: 0; }
  .tbl-wrap { overflow: visible; border: 0; }
  .tbl thead th { position: static; }
  .rev-group dl { columns: 2; }
  * { animation: none !important; transition: none !important; }
}
.hero-links { max-width: 1100px; margin: -6px auto 18px; display: flex; flex-wrap: wrap; gap: 8px; }
.sys-prog { position: absolute; left: 20px; right: 20px; bottom: 10px; height: 3px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.sys-prog i { display: block; height: 100%; width: 0; background: var(--c); transition: width 1s var(--ease); }
