/* Mashq: paper, ink and a red pen. */
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/atkinson-hyperlegible-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 700; font-display: swap; src: url(fonts/atkinson-hyperlegible-latin-700-normal.woff2) format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: italic; font-weight: 400; font-display: swap; src: url(fonts/atkinson-hyperlegible-latin-400-italic.woff2) format("woff2"); }
@font-face { font-family: "Kalam"; font-style: normal; font-weight: 700; font-display: swap; src: url(fonts/kalam-latin-700-normal.woff2) format("woff2"); }

:root {
  --paper: #E9EEF0;
  --sheet: #FBFCFC;
  --ink: #1B2A3A;
  --ink-2: #4E5E6C;
  --ink-3: #75848F;
  --rule: #C8D2D7;
  --rule-soft: #DCE3E6;
  --pen: #C42634;
  --pen-soft: rgba(196, 38, 52, .09);
  --hi: #F7E37A;
  --ok: #2B7553;
  --ok-soft: rgba(43, 117, 83, .1);
  --onc: #6A4A9C;
  --cv: #1D6F82;
  --custom: #8A6A2E;
  --me: #1B2A3A;
  --me-text: #F3F6F8;
  --shadow: 0 1px 0 rgba(27, 42, 58, .06), 0 8px 24px -16px rgba(27, 42, 58, .35);
  --font: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --hand: "Kalam", "Segoe Print", "Bradley Hand", cursive;
  --r: 14px;
  --gutter: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #10171E;
    --sheet: #17212A;
    --ink: #E5ECF0;
    --ink-2: #A9B7C2;
    --ink-3: #7E8E9A;
    --rule: #2C3A46;
    --rule-soft: #22303B;
    --pen: #FF6F6F;
    --pen-soft: rgba(255, 111, 111, .12);
    --hi: rgba(247, 227, 122, .28);
    --ok: #63C493;
    --ok-soft: rgba(99, 196, 147, .12);
    --onc: #A98BE0;
    --cv: #5BBBD0;
    --custom: #D2AE6A;
    --me: #2C4258;
    --me-text: #F3F6F8;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 26px -18px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #10171E; --sheet: #17212A; --ink: #E5ECF0; --ink-2: #A9B7C2; --ink-3: #7E8E9A;
  --rule: #2C3A46; --rule-soft: #22303B; --pen: #FF6F6F; --pen-soft: rgba(255,111,111,.12);
  --hi: rgba(247,227,122,.28); --ok: #63C493; --ok-soft: rgba(99,196,147,.12);
  --onc: #A98BE0; --cv: #5BBBD0; --custom: #D2AE6A; --me: #2C4258; --me-text: #F3F6F8;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.5 var(--font);
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--cv); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.view { padding: 0 var(--gutter) calc(32px + env(safe-area-inset-bottom)); flex: 1; display: flex; flex-direction: column; }

/* Top bar */
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px;
  position: sticky; top: 0; z-index: 5; background: var(--paper);
}
.bar h1, .bar .title { font-size: 19px; font-weight: 700; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent; border-radius: 12px;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--ink);
}
.icon-btn:hover { background: var(--rule-soft); }
.icon-btn svg { width: 24px; height: 24px; }

/* Home */
.masthead { padding: 8px 0 18px; }
.masthead .word { font-size: 44px; line-height: 1; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.masthead .urdu { font-size: 30px; color: var(--ink-3); margin-left: 8px; font-weight: 400; }
.masthead p { margin: 10px 0 0; color: var(--ink-2); max-width: 34ch; }

.seg { display: flex; background: var(--rule-soft); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button {
  flex: 1; min-height: 44px; border: 0; border-radius: 9px; background: transparent; cursor: pointer;
  font-weight: 700; color: var(--ink-2); padding: 6px 8px; line-height: 1.2;
}
.seg button[aria-pressed="true"] { background: var(--sheet); color: var(--ink); box-shadow: var(--shadow); }
.seg small { display: block; font-weight: 400; font-size: 13px; color: var(--ink-3); }
.field-label { font-weight: 700; margin: 18px 0 8px; display: block; font-size: 15px; }

.scn-list { list-style: none; margin: 18px 0 0; padding: 0; border-top: 1px solid var(--rule); }
.scn {
  display: block; width: 100%; text-align: left; border: 0; background: transparent; cursor: pointer;
  padding: 16px 4px 16px 16px; border-bottom: 1px solid var(--rule); position: relative;
}
.scn::before { content: ""; position: absolute; left: 0; top: 16px; bottom: 16px; width: 4px; border-radius: 2px; background: var(--fam, var(--ink-3)); }
.scn:hover { background: var(--rule-soft); }
.scn .prod { font-weight: 700; color: var(--fam); font-size: 15px; }
.scn .prod .area { font-weight: 400; color: var(--ink-2); margin-left: 10px; }
.scn .who { margin-top: 2px; font-size: 15px; color: var(--ink-2); }
.scn .hook { margin: 8px 0 0; font-size: 18px; line-height: 1.4; }
.scn .hook::before { content: "\201C"; }
.scn .hook::after { content: "\201D"; }
.scn .last { margin-top: 8px; font-size: 14px; color: var(--ink-3); }
.scn .last b { font-family: var(--hand); color: var(--pen); font-size: 18px; font-weight: 700; }
.fam-onc { --fam: var(--onc); }
.fam-cv { --fam: var(--cv); }
.fam-custom { --fam: var(--custom); }
.add-row { margin-top: 6px; padding: 14px 4px; font-weight: 700; color: var(--ink-2); background: transparent; border: 0; cursor: pointer; text-align: left; min-height: 44px; }
.add-row:hover { color: var(--ink); }

.notice {
  margin: 4px 0 14px; padding: 12px 14px; border-radius: 12px; background: var(--pen-soft); color: var(--ink);
  border-left: 4px solid var(--pen); font-size: 15px;
}
.notice.info { background: var(--rule-soft); border-left-color: var(--ink-3); }
.notice b { display: block; margin-bottom: 2px; }
.notice button { margin-top: 8px; }
.fine { color: var(--ink-3); font-size: 14px; margin: 22px 0 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 20px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--ink); color: var(--paper); font-weight: 700;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--rule); }
.btn.ghost:hover { background: var(--rule-soft); }
.btn.danger { background: transparent; color: var(--pen); box-shadow: inset 0 0 0 1.5px currentColor; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.btn-row .btn { flex: 1 1 140px; }
.link { background: none; border: 0; padding: 0; color: var(--cv); font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; min-height: 32px; }

/* Briefing */
.doctor { display: flex; gap: 14px; align-items: flex-start; padding: 8px 0 16px; border-bottom: 1px solid var(--rule); }
.avatar {
  flex: none; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: var(--fam, var(--ink-3)); color: #fff; font-weight: 700; font-size: 20px; letter-spacing: .02em;
}
.doctor h2 { margin: 0; font-size: 22px; line-height: 1.25; }
.doctor .role { color: var(--ink-2); margin-top: 2px; }
.doctor .prod { font-weight: 700; color: var(--fam); font-size: 15px; margin-bottom: 4px; }
.brief-block { padding: 14px 0; border-bottom: 1px solid var(--rule); }
.brief-block h3 { margin: 0 0 6px; font-size: 16px; }
.brief-block p { margin: 0; color: var(--ink-2); }
.brief-block p + p { margin-top: 8px; }
details.facts { padding: 14px 0; border-bottom: 1px solid var(--rule); }
details.facts summary { cursor: pointer; font-weight: 700; min-height: 32px; list-style: none; position: relative; padding-left: 22px; }
details.facts summary::-webkit-details-marker { display: none; }
details.facts summary::before { content: ""; position: absolute; left: 3px; top: .5em; width: 8px; height: 8px; border-right: 2.5px solid currentColor; border-bottom: 2.5px solid currentColor; transform: rotate(-45deg); transition: transform .15s; }
details.facts[open] summary::before { transform: rotate(45deg); top: .4em; }
details.facts ol { margin: 10px 0 0; padding-left: 22px; color: var(--ink-2); font-size: 15.5px; }
details.facts li { margin-bottom: 8px; }
details.facts .draft { font-size: 14px; color: var(--pen); margin: 10px 0 0; }
.opts { padding-top: 4px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; border-bottom: 1px solid var(--rule-soft); }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row span { flex: 1; }
.toggle-row small { display: block; color: var(--ink-3); font-size: 14px; }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 16px; background: var(--rule); transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 3px solid var(--cv); outline-offset: 2px; }
.start-dock { position: sticky; bottom: 0; padding: 14px 0 calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--paper) 70%, transparent); margin-top: auto; }

/* Call */
.call { display: flex; flex-direction: column; height: 100dvh; }
.call .bar { border-bottom: 1px solid var(--rule); }
.call .bar .avatar { width: 36px; height: 36px; font-size: 14px; }
.call .bar .meta { flex: 1; min-width: 0; }
.call .bar .meta .title { display: block; font-size: 16px; }
.call .bar .meta small { color: var(--ink-3); font-size: 13px; display: block; }
.end-btn { min-height: 40px; padding: 6px 14px; border-radius: 20px; border: 0; background: var(--pen); color: #fff; font-weight: 700; cursor: pointer; }
.thread { flex: 1; overflow-y: auto; padding: 18px var(--gutter) 12px; display: flex; flex-direction: column; gap: 14px; overscroll-behavior: contain; }
.turn { max-width: 88%; }
.turn.hcp { align-self: flex-start; }
.turn.hcp .who { font-size: 13px; color: var(--ink-3); margin-bottom: 2px; font-weight: 700; }
.turn.hcp .text { font-size: 18px; line-height: 1.45; }
.turn.me { align-self: flex-end; background: var(--me); color: var(--me-text); padding: 10px 14px; border-radius: 18px 18px 4px 18px; }
.turn.stage { align-self: center; max-width: 100%; font-size: 14px; color: var(--ink-3); text-align: center; }
.turn .replay { border: 0; background: transparent; color: var(--ink-3); padding: 4px 0; cursor: pointer; font-size: 14px; display: inline-flex; gap: 6px; align-items: center; min-height: 32px; }
.turn .replay svg { width: 16px; height: 16px; }
.typing { align-self: flex-start; color: var(--ink-3); font-size: 15px; display: flex; gap: 6px; align-items: center; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
.err { align-self: stretch; }
.dock {
  border-top: 1px solid var(--rule); background: var(--sheet);
  padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 8px; align-items: flex-end;
}
.dock textarea {
  flex: 1; resize: none; min-height: 48px; max-height: 140px; border-radius: 14px; border: 1.5px solid var(--rule);
  background: var(--paper); padding: 11px 14px; line-height: 1.4;
}
.dock textarea:focus { outline: none; border-color: var(--ink-3); }
.mic, .send {
  flex: none; width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center;
}
.mic { background: var(--ink); color: var(--paper); }
.mic svg, .send svg { width: 24px; height: 24px; }
.mic.on { background: var(--pen); color: #fff; box-shadow: 0 0 0 0 var(--pen); animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(196,38,52,.45); } 100% { box-shadow: 0 0 0 16px rgba(196,38,52,0); } }
.send { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--rule); }
.send:disabled, .mic:disabled { opacity: .4; cursor: not-allowed; animation: none; }
.ended { padding: 14px var(--gutter) calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--rule); background: var(--sheet); }
.ended p { margin: 0 0 10px; color: var(--ink-2); }

/* Scorecard: the marked script */
.sheet {
  background: var(--sheet); border-radius: 4px; box-shadow: var(--shadow); padding: 22px 18px 26px; margin-top: 4px;
  position: relative;
  background-image: linear-gradient(to right, transparent 34px, var(--pen-soft) 34px, var(--pen-soft) 35.5px, transparent 35.5px);
}
.sheet-head { padding-left: 26px; padding-right: 96px; min-height: 92px; }
.sheet-head .prod { font-weight: 700; font-size: 15px; color: var(--fam); }
.sheet-head h2 { margin: 2px 0 4px; font-size: 21px; line-height: 1.3; }
.sheet-head .sub { color: var(--ink-3); font-size: 14px; }
.mark {
  position: absolute; top: 14px; right: 14px; width: 88px; height: 88px; display: grid; place-items: center;
  font-family: var(--hand); font-weight: 700; color: var(--pen); font-size: 44px; line-height: 1;
  transform: rotate(-7deg);
}
.mark svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.mark span { position: relative; }
.mark.reveal svg path { stroke-dasharray: 300; stroke-dashoffset: 300; animation: draw .7s .15s ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.band { padding-left: 26px; margin: 12px 0 0; font-weight: 700; }
.band.pass { color: var(--ok); }
.band.fail { color: var(--pen); }
.verdict { padding-left: 26px; margin: 4px 0 0; font-size: 18px; line-height: 1.45; }
.sheet h3 { margin: 26px 0 8px; padding-left: 26px; font-size: 16px; }
.marks { list-style: none; margin: 0; padding: 0; }
.marks li { display: grid; grid-template-columns: 26px 1fr auto; gap: 4px 0; padding: 10px 0; border-top: 1px solid var(--rule-soft); align-items: baseline; }
.marks li:first-child { border-top: 0; }
.marks .lbl { grid-column: 2; font-weight: 700; }
.marks .pips { grid-column: 3; font-family: var(--hand); color: var(--pen); font-size: 20px; white-space: nowrap; }
.marks .note { grid-column: 2 / 4; color: var(--ink-2); font-size: 15.5px; }
.tests { list-style: none; margin: 0; padding: 0 0 0 26px; }
.tests li { padding: 8px 0; border-top: 1px solid var(--rule-soft); }
.tests li:first-child { border-top: 0; }
.tests .state { font-family: var(--hand); font-size: 18px; margin-right: 6px; }
.tests .state.yes { color: var(--ok); }
.tests .state.no { color: var(--pen); }
.tests .state.na { color: var(--ink-3); }
.tests small { display: block; color: var(--ink-2); font-size: 15px; }
.fixes { margin: 0; padding: 0 0 0 26px; list-style: none; counter-reset: fix; }
.fixes li { padding: 10px 0; border-top: 1px solid var(--rule-soft); counter-increment: fix; position: relative; }
.fixes li:first-child { border-top: 0; }
.fixes li::before { content: counter(fix); position: absolute; left: -26px; top: 9px; font-family: var(--hand); color: var(--pen); font-size: 18px; width: 22px; text-align: center; }
.fixes .sev { font-size: 13px; font-weight: 700; color: var(--pen); }
.fixes .sev.minor { color: var(--ink-3); }
.fixes q { display: block; font-style: italic; color: var(--ink-2); margin: 2px 0 4px; }
.fixes .fix { color: var(--ok); }
.plain { margin: 0; padding: 0 0 0 26px; list-style: none; }
.plain li { padding: 6px 0; }
.plain li::before { content: "\2014"; color: var(--ink-3); margin-right: 8px; }
.model { margin: 0 0 0 26px; padding: 12px 14px; border-left: 3px solid var(--ok); background: var(--ok-soft); border-radius: 0 10px 10px 0; }
.model .q { font-style: italic; color: var(--ink-2); margin: 0 0 8px; }
.model p { margin: 0; }

.script { padding-left: 26px; }
.line { padding: 8px 0; }
.line .who { font-size: 13px; font-weight: 700; color: var(--ink-3); }
.line.me .who { color: var(--ink); }
.line .said { margin: 2px 0 0; }
.line.hcp .said { color: var(--ink-2); }
mark.flag { background: linear-gradient(transparent 55%, var(--hi) 55%); color: inherit; text-decoration: underline wavy var(--pen); text-decoration-thickness: 1.5px; text-underline-offset: 4px; }
mark.good { background: none; color: inherit; text-decoration: underline var(--ok); text-decoration-thickness: 2px; text-underline-offset: 4px; }
sup.ref { font-family: var(--hand); color: var(--pen); font-size: 15px; margin-left: 2px; }
.margin-note { font-family: var(--hand); color: var(--pen); font-size: 17px; line-height: 1.3; margin: 4px 0 0; }
.margin-note.good { color: var(--ok); }

/* History & settings */
.hist { list-style: none; margin: 8px 0 0; padding: 0; border-top: 1px solid var(--rule); }
.hist button { width: 100%; text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--rule); padding: 14px 4px; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; cursor: pointer; }
.hist button:hover { background: var(--rule-soft); }
.hist .t { font-weight: 700; }
.hist .d { color: var(--ink-3); font-size: 14px; grid-column: 1; }
.hist .s { grid-row: 1 / 3; grid-column: 2; align-self: center; font-family: var(--hand); color: var(--pen); font-size: 26px; font-weight: 700; }
.hist .s.pend { font-family: var(--font); font-size: 14px; color: var(--ink-3); font-weight: 400; }
.empty { color: var(--ink-2); padding: 24px 0; }

.form section { padding: 8px 0 18px; border-bottom: 1px solid var(--rule); }
.form h2 { font-size: 18px; margin: 16px 0 4px; }
.form .hint { color: var(--ink-3); font-size: 14px; margin: 0 0 6px; }
.form label.f { display: block; margin-top: 12px; font-weight: 700; font-size: 15px; }
.form label.f small { font-weight: 400; color: var(--ink-3); display: block; }
.form input[type=text], .form input[type=password], .form input[type=url], .form select, .form textarea {
  width: 100%; margin-top: 6px; min-height: 48px; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--rule); background: var(--sheet);
}
.form textarea { min-height: 96px; line-height: 1.45; }
.form input:focus, .form select:focus, .form textarea:focus { outline: none; border-color: var(--ink-3); }
.form input[type=range] { width: 100%; margin-top: 10px; accent-color: var(--ink); }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; cursor: pointer; }
.radio input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--ink); flex: none; }
.radio small { display: block; color: var(--ink-3); font-size: 14px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--ink); flex: none; margin-top: 2px; }
.test-result { margin-top: 10px; font-size: 15px; }
.test-result.ok { color: var(--ok); }
.test-result.bad { color: var(--pen); }

/* Toast & update banner */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 12px; max-width: calc(100% - 32px);
  z-index: 50; box-shadow: var(--shadow); font-size: 15px;
}
#update {
  position: fixed; left: 12px; right: 12px; top: calc(10px + env(safe-area-inset-top)); z-index: 60; max-width: 536px; margin: 0 auto;
  background: var(--ink); color: var(--paper); border-radius: 12px; padding: 10px 10px 10px 16px; display: flex; align-items: center; gap: 12px; justify-content: space-between;
}
#update button { background: var(--paper); color: var(--ink); border: 0; border-radius: 9px; min-height: 40px; padding: 6px 14px; font-weight: 700; cursor: pointer; }

.spinner { width: 28px; height: 28px; border: 3px solid var(--rule); border-top-color: var(--pen); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.marking { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 60px 0; color: var(--ink-2); text-align: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .mark.reveal svg path { stroke-dashoffset: 0; }
}
@media (min-width: 600px) {
  .masthead .word { font-size: 52px; }
}

/* small utilities (no inline styles, so a strict CSP can stay on) */
.mt-s { margin-top: 12px; }
.form textarea.tall { min-height: 180px; }
