/* MedStudy AI — premium design system. Tokens first; light / dark / auto; RTL-safe (logical properties only). */
@font-face { font-family: 'Cairo'; font-style: normal; font-weight: 200 1000; font-display: swap; src: url('vendor/fonts/cairo-arabic-wght-normal.woff2') format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: 'Cairo'; font-style: normal; font-weight: 200 1000; font-display: swap; src: url('vendor/fonts/cairo-latin-wght-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 100 900; font-display: swap; src: url('vendor/fonts/inter-latin-wght-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --bg: #fbf9f4; --bg-2: #f3f0e8; --surface: #ffffff; --surface-2: #f7f5ef; --line: #e7e3d8;
  --text: #17302f; --text-2: #4b6462; --text-3: #7d918f;
  --primary: #0f766e; --primary-2: #0d9488; --primary-ink: #ffffff; --primary-soft: #dff1ee;
  --emerald: #10a37f; --sky: #7cc4e8; --sky-soft: #e3f3fb; --lavender: #b8a9ef; --lav-soft: #eeeafc;
  --coral: #ef8a80; --coral-soft: #fdeceb; --yellow: #f2c75c; --yellow-soft: #fdf5dc; --green-soft: #e1f5ec;
  --danger: #c2410c; --ok: #0f8a5f; --warn: #a16207;
  --shadow: 0 1px 2px rgba(23,48,47,.05), 0 6px 20px rgba(23,48,47,.07);
  --shadow-lg: 0 10px 40px rgba(23,48,47,.14);
  --radius: 18px; --radius-sm: 12px;
  --hero: linear-gradient(135deg, #0f766e 0%, #14958a 55%, #3aaecb 100%);
  --font: 'Cairo', 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --nav-h: 66px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0e1a1b; --bg-2: #132224; --surface: #172a2c; --surface-2: #1c3235; --line: #28403f;
  --text: #e8f1ef; --text-2: #a9c1be; --text-3: #7a9794;
  --primary: #2dd4bf; --primary-2: #5eead4; --primary-ink: #062a27; --primary-soft: #14403d;
  --sky: #5bb4dc; --sky-soft: #15343f; --lavender: #a99be8; --lav-soft: #2a2748; --coral: #f08f86; --coral-soft: #3d2423;
  --yellow: #e8c157; --yellow-soft: #3a3318; --green-soft: #153a2e; --danger: #fb9561; --ok: #4ade80; --warn: #facc15;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
  --hero: linear-gradient(135deg, #0f4f4b 0%, #14766f 55%, #23708e 100%);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.6; min-height: 100vh; transition: background .25s, color .25s; }
html[lang="en"] body { font-family: 'Inter', 'Cairo', system-ui, sans-serif; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.3; font-weight: 700; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.02rem; }
p { margin: 0 0 .7em; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }
.muted { color: var(--text-2); } .small { font-size: .85rem; } .tiny { font-size: .75rem; color: var(--text-3); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; } .row.between { justify-content: space-between; } .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-block-start: .8rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: isolate; text-align: start; }
html[dir="rtl"] .ltr { text-align: left; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: minmax(0, 1fr); min-height: 100vh; }
.sidebar { display: none; }
.main { min-width: 0; padding: 1rem 1rem calc(var(--nav-h) + 1.5rem); max-width: 980px; width: 100%; margin-inline: auto; }
.topbar { display: flex; align-items: center; gap: .6rem; margin-block-end: 1rem; }
.topbar .brand { font-weight: 800; color: var(--primary); letter-spacing: .2px; display: flex; align-items: center; gap: .5rem; }
.logo { width: 30px; height: 30px; border-radius: 10px; background: var(--hero); display: inline-grid; place-items: center; color: #fff; font-size: 1rem; }
.bottom-nav { position: fixed; inset-inline: 0; bottom: 0; height: var(--nav-h); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); border-block-start: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
.nav-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: none; border: 0; color: var(--text-3); font-size: .72rem; cursor: pointer; min-height: 48px; text-decoration: none; position: relative; }
.nav-item .ic { font-size: 1.35rem; line-height: 1; transition: transform .2s; }
.nav-item[aria-current="page"] { color: var(--primary); font-weight: 700; }
.nav-item[aria-current="page"] .ic { transform: translateY(-2px) scale(1.1); }
.nav-item[aria-current="page"]::before { content: ''; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 4px 4px; background: var(--primary); }
@media (min-width: 900px) {
  .app { grid-template-columns: 250px 1fr; }
  .sidebar { display: flex; flex-direction: column; gap: .3rem; padding: 1.2rem .9rem; position: sticky; top: 0; height: 100vh; border-inline-end: 1px solid var(--line); background: var(--surface); }
  .sidebar .nav-item { flex-direction: row; justify-content: flex-start; gap: .7rem; font-size: .95rem; padding: .6rem .8rem; border-radius: 12px; }
  .sidebar .nav-item[aria-current="page"] { background: var(--primary-soft); } .sidebar .nav-item[aria-current="page"]::before { display: none; }
  .bottom-nav { display: none; }
  .main { padding: 1.6rem 2rem 3rem; }
}

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; background: var(--surface-2); }
.card.tint-sky { background: var(--sky-soft); border-color: transparent; } .card.tint-lav { background: var(--lav-soft); border-color: transparent; }
.card.tint-coral { background: var(--coral-soft); border-color: transparent; } .card.tint-yellow { background: var(--yellow-soft); border-color: transparent; } .card.tint-green { background: var(--green-soft); border-color: transparent; }
.hero { background: var(--hero); color: #fff; border-radius: 24px; padding: 1.2rem; box-shadow: var(--shadow-lg); position: relative; overflow: hidden; }
.hero::after { content: ''; position: absolute; inset-inline-end: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; background: rgba(255,255,255,.1); }
.hero h2, .hero h3 { color: #fff; } .hero .muted { color: rgba(255,255,255,.85); }
.grid { display: grid; gap: .8rem; } .grid.two { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); } .grid.three { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 1.3rem 0 .6rem; }
.section-title h2 { margin: 0; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 46px; padding: .55rem 1.1rem; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 600; text-decoration: none; transition: transform .1s, box-shadow .2s, background .2s; }
.btn:active { transform: scale(.97); }
.btn:hover { box-shadow: var(--shadow); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.soft { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { background: var(--coral-soft); color: var(--danger); border-color: transparent; }
.btn.big { min-height: 58px; font-size: 1.15rem; border-radius: 18px; width: 100%; }
.btn.on-hero { background: #fff; color: #0b5a54; border: 0; }
.btn.sm { min-height: 38px; padding: .3rem .8rem; font-size: .88rem; border-radius: 11px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 1.15rem; display: inline-grid; place-items: center; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=password], select, textarea { width: 100%; min-height: 46px; padding: .55rem .8rem; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
textarea { min-height: 90px; resize: vertical; }
label.field { display: block; font-size: .88rem; color: var(--text-2); } label.field > :not(span) { margin-block-start: .25rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .7rem; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); font-size: .8rem; cursor: default; }
button.chip { cursor: pointer; min-height: 36px; } button.chip[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 700; }
.chip.warn { background: var(--yellow-soft); border-color: transparent; color: var(--warn); } .chip.bad { background: var(--coral-soft); border-color: transparent; color: var(--danger); } .chip.ok { background: var(--green-soft); border-color: transparent; color: var(--ok); }
.tabs { display: flex; gap: .3rem; overflow-x: auto; padding-block-end: .3rem; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { white-space: nowrap; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: .45rem .9rem; min-height: 42px; cursor: pointer; font-weight: 600; font-size: .9rem; }
.tab[aria-selected="true"] { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.notice { padding: .7rem .9rem; border-radius: var(--radius-sm); background: var(--yellow-soft); color: var(--text); font-size: .9rem; border-inline-start: 4px solid var(--yellow); }
.notice.bad { background: var(--coral-soft); border-inline-start-color: var(--coral); } .notice.info { background: var(--sky-soft); border-inline-start-color: var(--sky); } .notice.ok { background: var(--green-soft); border-inline-start-color: var(--emerald); }

/* ---------- progress ---------- */
.bar { height: 10px; border-radius: 99px; background: color-mix(in srgb, var(--text) 10%, transparent); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--primary), var(--sky)); transition: width .9s cubic-bezier(.2,.8,.2,1); }
.hero .bar { background: rgba(255,255,255,.25); } .hero .bar > i { background: #fff; }
.bar.coral > i { background: linear-gradient(90deg, var(--coral), var(--yellow)); } .bar.lav > i { background: linear-gradient(90deg, var(--lavender), var(--sky)); }
.ring { --p: 0; width: 92px; height: 92px; border-radius: 50%; background: conic-gradient(var(--ring-c, var(--primary)) calc(var(--p) * 1%), color-mix(in srgb, var(--text) 10%, transparent) 0); display: grid; place-items: center; position: relative; flex: none; transition: --p .8s; }
.ring::before { content: ''; position: absolute; inset: 9px; border-radius: 50%; background: var(--ring-bg, var(--surface)); }
.ring > b { position: relative; font-size: 1.15rem; }
.hero .ring { --ring-c: #fff; --ring-bg: #12857c; } .hero .ring::before { background: color-mix(in srgb, #0f766e 85%, #fff 0%); }
.stat { text-align: center; } .stat b { display: block; font-size: 1.5rem; line-height: 1.2; } .stat span { font-size: .8rem; color: var(--text-2); }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--bg-2) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s infinite; border-radius: 12px; min-height: 18px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.empty { text-align: center; padding: 2rem 1rem; color: var(--text-2); } .empty .big { font-size: 2.6rem; display: block; margin-block-end: .3rem; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: .35rem; }
.day { border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: .4rem .1rem; min-height: 64px; text-align: center; cursor: pointer; font-size: .8rem; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.day.today { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); } .day.active { background: var(--primary-soft); } .day[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }
.day .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--emerald); } .day .dot.none { background: transparent; border: 1px solid var(--line); }
.quote { font-size: .95rem; font-style: italic; } 

/* ---------- list items ---------- */
.item { display: flex; gap: .7rem; align-items: center; padding: .8rem; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: inherit; cursor: pointer; min-height: 60px; }
.item:hover { border-color: var(--primary); }
.item .thumb { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 1.3rem; background: var(--primary-soft); flex: none; }
.list { display: grid; gap: .55rem; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 1.4rem; text-align: center; background: var(--surface-2); transition: .2s; }
.drop.over { border-color: var(--primary); background: var(--primary-soft); }
.badge-tile { text-align: center; padding: .8rem .4rem; } .badge-tile .ic { font-size: 2rem; display: block; } .badge-tile.locked .ic { filter: grayscale(1); opacity: .35; }

/* ---------- reader ---------- */
.reader { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; font-size: var(--rf, 1.05rem); line-height: var(--rl, 1.9); }
.reader.en { direction: ltr; text-align: left; font-family: 'Inter', 'Cairo', sans-serif; }
.reader p.para { margin: 0 0 .9em; position: relative; padding-inline-end: 34px; }
.para .bm { position: absolute; inset-inline-end: 0; top: 0; background: none; border: 0; cursor: pointer; font-size: 1.1rem; opacity: .35; min-width: 32px; min-height: 32px; }
.para .bm[aria-pressed="true"] { opacity: 1; }
mark.hl { border-radius: 4px; padding: 0 2px; color: inherit; } mark.hl-yellow { background: #fde68a88; } mark.hl-green { background: #86efac88; } mark.hl-blue { background: #93c5fd88; } mark.hl-pink { background: #f9a8d488; }
mark.found { background: var(--yellow); color: #3b2f05; border-radius: 3px; }
.k-num { font-weight: 700; color: var(--primary); } .k-abbr { font-weight: 700; color: var(--lavender); }
.selbar { position: sticky; bottom: calc(var(--nav-h) + 8px); z-index: 10; display: flex; gap: .4rem; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; align-items: center; padding: .5rem; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg); }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.swatch.yellow { background: #fde68a; } .swatch.green { background: #86efac; } .swatch.blue { background: #93c5fd; } .swatch.pink { background: #f9a8d4; }

/* ---------- quiz / cards / chat ---------- */
.choice { display: block; width: 100%; text-align: start; padding: .8rem 1rem; margin-block: .4rem; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); cursor: pointer; min-height: 52px; }
.choice[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); }
.choice.right { border-color: var(--ok); background: var(--green-soft); } .choice.wrong { border-color: var(--danger); background: var(--coral-soft); }
.flip { perspective: 1000px; min-height: 240px; cursor: pointer; }
.flip-in { position: relative; min-height: 240px; transition: transform .5s; transform-style: preserve-3d; }
.flip.on .flip-in { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 1.2rem; border-radius: 22px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 1.15rem; overflow: auto; }
.face.back { transform: rotateY(180deg); background: var(--primary-soft); }
.rate { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.chat { display: flex; flex-direction: column; gap: .7rem; }
.msg { max-width: 92%; padding: .7rem .9rem; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--primary); color: var(--primary-ink); border-end-end-radius: 6px; }
.msg.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-end-start-radius: 6px; }
.src-block { margin-block-start: .5rem; padding: .5rem .7rem; border-radius: 12px; font-size: .92rem; } .src-block.lec { background: var(--green-soft); } .src-block.ext { background: var(--lav-soft); }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; padding: .2rem .7rem; border-radius: 99px; background: var(--primary-soft); }
.timer.low { background: var(--coral-soft); color: var(--danger); }
.celebrate { position: fixed; inset: 0; pointer-events: none; display: grid; place-items: center; z-index: 60; }
.celebrate span { font-size: 4rem; animation: pop 1.6s ease-out forwards; }
@keyframes pop { 0% { transform: scale(.2); opacity: 0; } 25% { transform: scale(1.2); opacity: 1; } 100% { transform: translateY(-80px) scale(1); opacity: 0; } }

/* ---------- overlays ---------- */
#toast { position: fixed; inset-inline: 1rem; bottom: calc(var(--nav-h) + 14px); margin-inline: auto; max-width: 460px; z-index: 80; background: var(--text); color: var(--bg); padding: .75rem 1rem; border-radius: 14px; box-shadow: var(--shadow-lg); text-align: center; }
#toast[data-kind="error"] { background: var(--danger); color: #fff; }
dialog.modal { border: 0; border-radius: 22px; padding: 1.2rem; max-width: min(520px, 94vw); width: 100%; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog.modal::backdrop { background: rgba(5, 20, 20, .5); }
dialog.sheet { margin-block-end: 0; border-end-start-radius: 0; border-end-end-radius: 0; }
.more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; } .more-grid .btn { flex-direction: column; min-height: 84px; font-size: .85rem; }
.more-grid .btn .ic { font-size: 1.6rem; }
.fade-in { animation: fade .35s ease both; } @keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
.selbar .btn { white-space: nowrap; flex: none; }
@media print { .bottom-nav, .sidebar, .topbar, .selbar { display: none !important; } }
