:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --ink: #121417;
  --muted: #6b7280;
  --line: #e7e8ea;
  --accent: #0f6e62;
  --accent-soft: #e8f3f1;
  --warn: #9a5b00;
  --warn-soft: #fdf3e3;
  --radius: 14px;
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --font: "Segoe UI", Tahoma, system-ui, -apple-system, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font); background: var(--bg); color: var(--ink);
  line-height: 1.6; font-size: 16px; min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#app { max-width: 480px; margin-inline: auto; padding: 0 20px 40px; min-height: 100dvh; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.brand { font-weight: 700; letter-spacing: 0.01em; }
.chip-btn { font-size: 14px; color: var(--muted); padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; transition: transform 160ms var(--ease); }
.chip-btn:active { transform: scale(0.97); }

.screen { flex: 1; display: flex; flex-direction: column; }
.enter { animation: rise 280ms var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* intro */
.intro { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 20px; padding-bottom: 12vh; }
h1 { font-size: clamp(30px, 8vw, 40px); line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
.lead { color: var(--muted); font-size: 17px; max-width: 34ch; }
.fine { color: var(--muted); font-size: 13.5px; }
.fine.tight { margin: 6px 0 12px; }

.btn { display: block; width: 100%; padding: 15px 20px; border-radius: 12px; font-weight: 600; text-align: center; transition: transform 160ms var(--ease), opacity 160ms; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: #fff; }

.btn.primary:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.quiet { color: var(--muted); font-weight: 500; margin-top: 4px; }
.btn.sticky { position: sticky; bottom: calc(16px + env(safe-area-inset-bottom)); margin-top: 24px; }

/* quiz */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 44px; }
.link { color: var(--muted); font-size: 15px; padding: 8px 0; }
.step { color: var(--muted); font-size: 14px; }
.track { height: 3px; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: 28px; }
.track i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width 320ms var(--ease); }
.cat { color: var(--accent); font-size: 14px; font-weight: 600; margin-bottom: 6px; }
h2 { font-size: 24px; line-height: 1.35; font-weight: 700; }
.hint { color: var(--muted); font-size: 14.5px; margin-top: 6px; }
.opts { display: grid; gap: 10px; margin-top: 22px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 14px; text-align: start; width: 100%; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); transition: border-color 160ms, background 160ms, transform 160ms var(--ease); }
.opt:active { transform: scale(0.98); }
.opt b { display: block; font-weight: 600; }
.opt small { display: block; color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.tick { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--line); position: relative; transition: all 160ms; }
.opt.on { border-color: var(--accent); background: var(--accent-soft); }
.opt.on .tick { background: var(--accent); border-color: var(--accent); }
.opt.on .tick::after { content: ""; position: absolute; inset: 5px 6px 7px 6px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }

/* result */
.result { display: grid; gap: 14px; padding-top: 8px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.pair small { display: block; color: var(--muted); font-size: 13px; }
.pair b { font-weight: 600; font-size: 15px; }
.note { display: grid; gap: 4px; padding: 14px 16px; border-radius: var(--radius); font-size: 14.5px; }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.zones { display: grid; gap: 10px; }
.zone { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: grid; gap: 8px; }
.zone-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.zone h3 { font-size: 17px; }
.zone p { color: var(--muted); font-size: 15px; }
.zone dl { display: flex; gap: 24px; padding-top: 4px; }
.zone dt { color: var(--muted); font-size: 12.5px; }
.zone dd { font-weight: 600; font-size: 15px; }
.status { font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.s-fits { background: var(--accent-soft); color: var(--accent); }
.s-tight, .s-discuss { background: var(--warn-soft); color: var(--warn); }
.s-after { background: var(--line); color: var(--muted); }

/* chat */
.chat { display: flex; flex-direction: column; gap: 4px; }
.pill { font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 2px 10px; border-radius: 999px; }
.feed { display: flex; flex-direction: column; gap: 10px; padding: 8px 0 12px; }
.msg { max-width: 86%; padding: 11px 14px; border-radius: 16px; font-size: 15.5px; white-space: pre-wrap; animation: rise 240ms var(--ease) both; }
.msg.me { align-self: flex-start; background: var(--accent); color: #fff; border-end-start-radius: 4px; }
.msg.brain { align-self: flex-end; background: var(--surface); border: 1px solid var(--line); border-end-end-radius: 4px; }

.typing { display: flex; gap: 5px; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: 0.5; animation: dot 1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 100% { opacity: 0.3; } 50% { opacity: 0.9; } }
.replies { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 8px; }
.reply { padding: 10px 16px; border: 1px solid var(--accent); color: var(--accent); border-radius: 999px; font-size: 15px; font-weight: 600; transition: transform 160ms var(--ease); }
.reply:active { transform: scale(0.97); }
.reply.alt { border-color: var(--line); color: var(--muted); }

.doctor { margin-top: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; animation: rise 320ms var(--ease) both; }
.doctor h3 { font-size: 16px; margin-bottom: 12px; }
.doctor dl { display: grid; gap: 10px; }
.doctor dt { color: var(--muted); font-size: 12.5px; }
.doctor dd { font-size: 15px; font-weight: 500; }

@media (prefers-reduced-motion: reduce) {
  .enter, .msg, .doctor { animation: none; }
  .typing i { animation: none; opacity: 0.6; }
  * { transition-duration: 0.01ms !important; }
}
@media (min-width: 600px) { #app { padding-top: 12px; } }

/* v2 additions */
.why { display: flex; gap: 10px; align-items: flex-start; margin-top: 22px; padding: 12px 14px; background: var(--accent-soft); color: var(--accent); border-radius: 12px; font-size: 14px; line-height: 1.55; }
.why span { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-top: 8px; }
.field { width: 100%; margin-top: 22px; padding: 15px 16px; font: inherit; font-size: 16px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.field:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; gap: 12px; align-items: flex-start; margin-top: 16px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; font-size: 15px; }
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check .box { flex: none; width: 22px; height: 22px; margin-top: 2px; border-radius: 6px; border: 1.5px solid var(--line); position: relative; transition: all 160ms; }
.check.on { border-color: var(--accent); background: var(--accent-soft); }
.check.on .box { background: var(--accent); border-color: var(--accent); }
.check.on .box::after { content: ""; position: absolute; inset: 3px 6px 6px 6px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.check:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.fine { margin-top: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: grid; gap: 8px; font-size: 15px; }
.card h3 { font-size: 16px; }
.list { margin: 4px 0 0; padding-inline-start: 20px; display: grid; gap: 6px; font-size: 15px; }
.note.warn .list { color: var(--warn); }
.tl { position: relative; height: 8px; border-radius: 8px; background: var(--line); margin-top: 4px; overflow: visible; }
.tl i { position: absolute; top: 0; bottom: 0; inset-inline-start: 0; border-radius: 8px; }
.tl-settle { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); opacity: 0.55; }
.tl-dt { background: var(--warn); }
.tl .tl-ev { top: -4px; bottom: -4px; width: 3px; border-radius: 2px; background: var(--ink); inset-inline-start: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); font-size: 12.5px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 6px; border-radius: 3px; display: inline-block; }
.legend .k1 { background: var(--warn); } .legend .k2 { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); } .legend .k3 { width: 3px; height: 12px; background: var(--ink); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.tag { font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--line); color: var(--muted); }
.tag.red { background: #fde8e8; color: #a4231f; } .tag.g { background: var(--accent-soft); color: var(--accent); } .tag.amber { background: var(--warn-soft); color: var(--warn); }

.doctor .red { color: #a4231f; } .doctor .soft { color: var(--muted); font-size: 13.5px; }


/* v3: images + background */
body { position: relative; }
body::before { content: ""; position: absolute; inset: 0 0 auto 0; height: max(100svh, 760px); pointer-events: none; z-index: -1;
  background: var(--bgimg) center top / cover no-repeat;
  -webkit-mask-image: linear-gradient(#000 55%, transparent); mask-image: linear-gradient(#000 55%, transparent); opacity: 0.9; }
body[data-screen="intro"] { --bgimg: url("../img/bg_intro.webp?v=21"); }
body[data-screen="quiz"] { --bgimg: url("../img/bg_quiz.webp?v=21"); }
body[data-screen="result"] { --bgimg: url("../img/bg_result.webp?v=21"); }
body[data-screen="chat"] { --bgimg: url("../img/bg_chat.webp?v=21"); }

.opts.imgs { grid-template-columns: 1fr 1fr; }
.opt.has-img { flex-direction: column; align-items: stretch; padding: 0; overflow: hidden; position: relative; gap: 0; }
.opt.has-img img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block; background: var(--line); }
.opt.has-img .opt-text { padding: 10px 12px 12px; }
.opt.has-img b { font-size: 14.5px; line-height: 1.35; }
.opt.has-img .tick { position: absolute; top: 10px; inset-inline-end: 10px; background: rgba(255, 255, 255, 0.85); }
.opts.imgs .opt.wide { grid-column: 1 / -1; }
.opts.imgs .opt.wide img { aspect-ratio: 16 / 9; }
.opts.imgs .opt:not(.has-img) { grid-column: 1 / -1; }
.zone { grid-template-columns: auto 1fr; align-items: start; column-gap: 14px; }
.zthumb { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; }
.zone:not(:has(.zthumb)) { grid-template-columns: 1fr; }
.zbody { display: grid; gap: 8px; min-width: 0; }

/* v13: language switch */
.langs { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.lg { min-width: 36px; padding: 4px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 700; letter-spacing: 0.04em; color: var(--muted); transition: background 160ms, color 160ms, transform 160ms var(--ease); }
.lg:active { transform: scale(0.96); }
.lg.on { background: var(--accent); color: #fff; }


/* v14: long translations must wrap, never widen the page */
.zone-head { flex-wrap: wrap; row-gap: 6px; }
.zone-head h3 { min-width: 0; overflow-wrap: anywhere; }
.status { white-space: normal; text-align: center; }
.zbody, .card, .note, .opt-text, .msg, .doctor dd { overflow-wrap: anywhere; }
html, body { overflow-x: hidden; }

/* v20: clinic branding (--brand from clinics.js), a calmer premium skin, doctor preview */
:root {
  --brand: #0f6e62;
  --bg: #fbfaf7; --surface: #ffffff; --line: #ebe8e2; --muted: #6f6a63; --ink: #1a1816;
  --accent: var(--brand);
  --accent-soft: color-mix(in srgb, var(--brand) 9%, #fff);
  --accent-ink: color-mix(in srgb, var(--brand) 78%, #000);
  --shadow: 0 1px 2px rgba(26, 24, 22, 0.04), 0 8px 24px -12px rgba(26, 24, 22, 0.12);
  --font: "Tajawal", "Segoe UI", Tahoma, system-ui, -apple-system, Arial, sans-serif;
}

body { font-feature-settings: "kern"; }
h1, h2 { letter-spacing: -0.015em; }
.opt, .zone, .card, .pair > div, .doctor, .check, .field { box-shadow: var(--shadow); }
.opt:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary { box-shadow: 0 10px 24px -12px color-mix(in srgb, var(--brand) 70%, transparent); }

.top { height: 72px; }
.brand { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
.brand > span { display: grid; line-height: 1.25; min-width: 0; }
.brand b { font-weight: 700; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }
.brand small { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.mono { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-weight: 700; font-size: 16px;
  color: #fff; background: var(--brand); box-shadow: inset 0 0 0 2px color-mix(in srgb, #fff 25%, transparent); }

.intro { justify-content: flex-start; gap: 18px; padding: 6vh 0 32px; }
.kicker { align-self: flex-start; font-size: 13px; font-weight: 600; color: var(--accent-ink); background: var(--accent-soft); padding: 5px 12px; border-radius: 999px; }
.intro h1 { font-size: clamp(31px, 8.4vw, 42px); line-height: 1.2; }
.gets { list-style: none; display: grid; gap: 10px; margin: 4px 0 6px; }
.gets li { display: flex; align-items: center; gap: 12px; font-size: 15.5px; font-weight: 500; }
.gets .num { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700;
  color: var(--accent-ink); background: var(--accent-soft); }
.cta { display: grid; gap: 8px; margin-top: 6px; }
.cta .btn { padding: 17px 20px; font-size: 16.5px; border-radius: 14px; }
.meta { text-align: center; color: var(--muted); font-size: 13px; }
.doclink { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 14px 16px; text-align: start;
  border: 1px dashed color-mix(in srgb, var(--accent) 40%, var(--line)); border-radius: 14px; color: var(--accent-ink); font-weight: 600; font-size: 14.5px;
  background: color-mix(in srgb, var(--surface) 70%, transparent); transition: transform 160ms var(--ease), background 160ms; }
.doclink:active { transform: scale(0.98); }
.doclink:hover { background: var(--accent-soft); }
.doclink i { font-style: normal; }

.stepper { list-style: none; display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin: 2px 0 10px; }
.stepper li { display: grid; gap: 5px; }
.stepper i { height: 4px; border-radius: 4px; background: var(--line); transition: background 240ms var(--ease); }
.stepper li.done i { background: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.stepper li.now i { background: var(--accent); }
.stepper span { font-size: 10.5px; color: var(--muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stepper li.now span { color: var(--accent-ink); font-weight: 700; }
.stepper + .track { display: none; }
.step { font-weight: 600; color: var(--accent-ink); }
.quiz h2 { font-size: 25px; }

.sample { display: grid; gap: 4px; margin: 6px 0 10px; padding: 14px 16px; border-radius: 14px; background: var(--accent-soft); color: var(--accent-ink); font-size: 14.5px; }
.sample b { font-size: 15.5px; }
.chat > .btn.primary { margin-top: 18px; }
.doctor { border-top: 3px solid var(--accent); }
.msg.me { background: var(--brand); }

@media (max-width: 360px) { .stepper span { display: none; } }

/* v21: light only, display font for headings */
:root { color-scheme: light; --display: "El Messiri", "Tajawal", serif; }
h1, h2, h3, .brand b, .kicker, .doctor h3, .sample b { font-family: var(--display); }
h1 { font-weight: 700; letter-spacing: 0; line-height: 1.25; }
h2 { font-weight: 600; letter-spacing: 0; }
.opt b, .gets li, .btn { font-weight: 500; }
.btn.primary { font-weight: 700; letter-spacing: 0.01em; }
/* v21 backgrounds (Gemini, imgwork/bg_v21): show more of the photo, keep text readable with a soft wash */
body::before { opacity: 1; -webkit-mask-image: linear-gradient(#000 62%, transparent); mask-image: linear-gradient(#000 62%, transparent); }
body::after { content: ""; position: absolute; inset: 0 0 auto 0; height: max(100svh, 760px); pointer-events: none; z-index: -1;
  background: linear-gradient(180deg, rgba(251, 250, 247, 0.1) 0%, rgba(251, 250, 247, 0.4) 45%, rgba(251, 250, 247, 0.8) 75%, var(--bg) 100%); }
body[data-screen="quiz"]::after, body[data-screen="result"]::after, body[data-screen="chat"]::after { background: linear-gradient(180deg, rgba(251, 250, 247, 0.55) 0%, rgba(251, 250, 247, 0.8) 40%, var(--bg) 90%); }
