/* Nyanda Ready. Brand: teal #1F6378, stage #0C2229, cream #FBEFD9, orange #E89B3C */
:root {
  --teal: #1F6378; --stage: #0C2229; --cream: #FBEFD9; --orange: #E89B3C;
  --fs: 17px;
  --radius: 14px;
  --bar-h: 56px; --tabs-h: 64px;
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
html[data-size="1"] { --fs: 16px; }
html[data-size="2"] { --fs: 17px; }
html[data-size="3"] { --fs: 19px; }
html[data-size="4"] { --fs: 21px; }
html[data-size="5"] { --fs: 24px; }

html[data-theme="dark"] {
  --bg: #0C2229; --surface: #133540; --surface2: #1a4350; --line: #2a5563;
  --text: #FBEFD9; --muted: #b5c9c9; --link: #f3b866; --accent: #E89B3C; --accent-text: #0C2229;
  --danger: #ff6b5e; --danger-bg: #3a1714; --warn-bg: #3a2a10; --tip-bg: #12392f; --note-bg: #183a46;
  --bar: #0C2229; --bar-text: #FBEFD9;
  color-scheme: dark;
}
html[data-theme="light"] {
  --bg: #FBF6EC; --surface: #ffffff; --surface2: #f3ead8; --line: #e2d5bd;
  --text: #0C2229; --muted: #4c6168; --link: #1F6378; --accent: #E89B3C; --accent-text: #0C2229;
  --danger: #b3261e; --danger-bg: #fbe5e2; --warn-bg: #fdf0d8; --tip-bg: #e2f1ec; --note-bg: #e6f0f2;
  --bar: #1F6378; --bar-text: #FBEFD9;
  color-scheme: light;
}
/* Night: dim amber, low brightness for reading by torchlight without wrecking night vision */
html[data-theme="night"] {
  --bg: #000; --surface: #120a06; --surface2: #1b0f08; --line: #3a2414;
  --text: #e8a46a; --muted: #a8764c; --link: #ffb27a; --accent: #b8692e; --accent-text: #000;
  --danger: #ff7a59; --danger-bg: #2a0d06; --warn-bg: #1f1306; --tip-bg: #140d06; --note-bg: #140d06;
  --bar: #000; --bar-text: #e8a46a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 400 var(--fs)/1.55 var(--sans);
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
  padding-top: calc(var(--bar-h) + env(safe-area-inset-top));
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
a { color: var(--link); }
h1, h2, h3, h4 { font-family: var(--serif); line-height: 1.25; margin: 1.2em 0 .45em; }
h2 { font-size: 1.35em; }
h3 { font-size: 1.15em; }
h4 { font-size: 1.02em; }
p { margin: .55em 0; }
ul, ol { padding-left: 1.3em; margin: .5em 0; }
li { margin: .3em 0; }
strong { font-weight: 700; }
button { font: inherit; color: inherit; }
svg { display: block; }

/* top bar */
#bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--bar-h) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top);
  background: var(--bar); color: var(--bar-text);
  display: flex; align-items: center; gap: 4px; padding-left: 6px; padding-right: 6px;
  border-bottom: 1px solid var(--line);
}
#bar-title { flex: 1; margin: 0 6px; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 48px; height: 48px; border: 0; background: none; border-radius: 12px; display: grid; place-items: center; cursor: pointer; color: inherit; }
.icon-btn svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active { background: rgba(255,255,255,.12); }

/* bottom tabs */
#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex;
}
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 12.5px; }
#tabs a svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#tabs a.on { color: var(--accent); }
#tabs a.on svg { stroke-width: 2.4; }

#view { padding: 12px 14px 28px; max-width: 760px; margin: 0 auto; outline: none; }

/* search box */
.search-box { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 12px; height: 54px; }
.search-box svg { width: 22px; height: 22px; fill: none; stroke: var(--muted); stroke-width: 2.2; stroke-linecap: round; flex: none; }
.search-box input { flex: 1; border: 0; background: none; color: var(--text); font: inherit; height: 100%; outline: none; min-width: 0; }
.search-box input::placeholder { color: var(--muted); }
.search-box .clear { border: 0; background: none; color: var(--muted); font-size: 1.4em; width: 40px; height: 40px; }

.section-title { font-family: var(--serif); font-size: 1.12em; margin: 1.3em 0 .5em; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.section-title small { font-family: var(--sans); font-size: .78em; color: var(--muted); font-weight: 400; }

/* quick critical cards */
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quick a {
  display: flex; align-items: center; min-height: 62px; padding: 10px 12px; border-radius: 12px;
  background: var(--danger-bg); border: 1.5px solid var(--danger); color: var(--text); text-decoration: none; font-weight: 700; line-height: 1.2;
}
.quick a:active { filter: brightness(1.2); }

/* lists of cards */
.list { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list li { margin: 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list a { display: flex; align-items: center; gap: 10px; padding: 13px 14px; min-height: 56px; color: var(--text); text-decoration: none; }
.list a:active { background: var(--surface2); }
.list .t { font-weight: 600; display: block; }
.list .s { color: var(--muted); font-size: .86em; display: block; line-height: 1.35; margin-top: 2px; }
.list .grow { flex: 1; min-width: 0; }
.list .chev { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2.4; }
.list .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); flex: none; }
.list mark { background: none; color: var(--accent); font-weight: 700; }

/* section tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { display: flex; flex-direction: column; gap: 6px; padding: 12px; min-height: 96px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); text-decoration: none; }
.tile svg { width: 28px; height: 28px; fill: none; stroke: var(--accent); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tile b { font-family: var(--serif); font-size: 1.02em; line-height: 1.2; }
.tile small { color: var(--muted); font-size: .8em; }
.tile.soon { opacity: .55; }
.tile:active { background: var(--surface2); }

.group-head { font-size: .82em; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.4em 0 .5em 4px; font-weight: 700; }

/* card reader */
.card-head h2 { margin: .3em 0 .3em; font-size: 1.5em; }
.card-head .sum { color: var(--muted); margin: 0 0 .8em; }
.card-tools { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 6px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 0 16px;
  border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.on svg { fill: var(--accent); stroke: var(--accent); }
.btn:active { filter: brightness(1.15); }
.btn.small { min-height: 40px; padding: 0 12px; font-size: .9em; }

.body { overflow-wrap: anywhere; }
.body h2 { font-size: 1.25em; border-top: 1px solid var(--line); padding-top: .8em; }
.body h2:first-child { border-top: 0; padding-top: 0; }
.body table { border-collapse: collapse; width: 100%; font-size: .92em; }
.body th, .body td { border: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: top; }
.body th { background: var(--surface2); }
.table-wrap { overflow-x: auto; margin: .8em 0; -webkit-overflow-scrolling: touch; }

.box { border-radius: 12px; padding: 10px 14px; margin: 1em 0; border-left: 6px solid; }
.box > :last-child { margin-bottom: .2em; }
.box > p:first-of-type { margin-top: .2em; }
.box-label { font-weight: 800; font-size: .82em; text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }
.box-beyond { background: var(--danger-bg); border-color: var(--danger); }
.box-beyond .box-label { color: var(--danger); }
.box-dont { background: var(--danger-bg); border-color: var(--danger); }
.box-dont .box-label { color: var(--danger); }
.box-warn { background: var(--warn-bg); border-color: var(--accent); }
.box-warn .box-label { color: var(--accent); }
.box-tip { background: var(--tip-bg); border-color: #3fa587; }
.box-tip .box-label { color: #4cc19d; }
html[data-theme="light"] .box-tip .box-label { color: #1d7a5e; }
.box-nyanda, .box-note { background: var(--note-bg); border-color: var(--teal); }
.box-nyanda .box-label, .box-note .box-label { color: var(--link); }

.steps { background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 6px 14px 10px; margin: 1em 0; }
.steps-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.steps-head h3 { margin: .5em 0; }
.steps-go { min-height: 44px; background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.steps ol { padding-left: 1.5em; }
.steps li { margin: .5em 0; padding-left: .2em; }
.steps li::marker { font-weight: 800; color: var(--accent); }

figure.diagram { margin: 1em 0; background: #FBF6EC; border-radius: 12px; padding: 8px; border: 1px solid var(--line); }
html[data-theme="night"] figure.diagram { filter: sepia(1) saturate(2) hue-rotate(-20deg) brightness(.6); }
figure.diagram svg { width: 100%; height: auto; max-height: 420px; }
figure.diagram figcaption { color: #4c6168; font-size: .85em; text-align: center; padding: 4px 4px 2px; }

.meta { margin-top: 2em; padding-top: 1em; border-top: 1px solid var(--line); color: var(--muted); font-size: .86em; }
.meta ul { padding-left: 1.1em; }
.related { display: flex; flex-wrap: wrap; gap: 8px; margin: .6em 0 0; }
.chip { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: 22px; background: var(--surface); border: 1px solid var(--line); color: var(--text); text-decoration: none; font-weight: 600; font-size: .92em; }

.empty { color: var(--muted); padding: 1.2em .4em; }
.note-line { color: var(--muted); font-size: .9em; }

/* step-by-step overlay */
#steps-overlay { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
#steps-overlay[hidden] { display: none; }
.so-top { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.so-top .t { flex: 1; font-family: var(--serif); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.so-count { color: var(--accent); font-weight: 800; font-size: 1.05em; padding: 14px 18px 0; }
.so-bar { height: 6px; background: var(--surface2); margin: 8px 18px 0; border-radius: 3px; overflow: hidden; }
.so-bar i { display: block; height: 100%; background: var(--accent); }
.so-text { flex: 1; overflow-y: auto; padding: 18px 20px; font-size: 1.45em; line-height: 1.45; font-weight: 600; }
.so-text strong { color: var(--accent); }
.so-nav { display: flex; gap: 10px; padding: 10px 14px 14px; }
.so-nav .btn { flex: 1; min-height: 64px; font-size: 1.1em; }

/* toast */
#toast { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 10px); z-index: 40; background: var(--surface2); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.35); max-width: 640px; margin: 0 auto; }
#toast[hidden] { display: none; }
#toast span { flex: 1; }

/* settings */
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; min-width: 48px; min-height: 48px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: .6em 0; }
.panel h3 { margin: .2em 0 .5em; font-size: 1.02em; }
.ok { color: #4cc19d; font-weight: 700; }
html[data-theme="light"] .ok { color: #1d7a5e; }
.bad { color: var(--danger); font-weight: 700; }

@media (min-width: 700px) {
  .tiles { grid-template-columns: 1fr 1fr 1fr; }
  .quick { grid-template-columns: 1fr 1fr 1fr; }
}
@media print {
  #bar, #tabs, .card-tools, .steps-go, #toast { display: none !important; }
  body { padding: 0; background: #fff; color: #000; }
}

/* medicine chest */
.box-doctor { background: var(--danger-bg); border-color: var(--danger); }
.box-doctor .box-label { color: var(--danger); }
.chest-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin: .8em 0; }
.chest-panel .box-label { color: var(--accent); }
.chest-item { padding: 8px 0; border-top: 1px solid var(--line); }
.chest-item:first-of-type { border-top: 0; }
.ci-top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.ci-n { display: inline-block; min-width: 2.6em; padding: 1px 6px; border-radius: 6px; background: var(--surface2); color: var(--accent); font-weight: 800; text-align: center; flex: none; }
.ci-name { flex: 1; min-width: 0; }
.ci-meta { color: var(--muted); font-size: .88em; margin: 2px 0 4px; }
.ci-exp { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .9em; }
.ci-exp input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; min-height: 40px; }
.flag { display: inline-block; font-size: .72em; font-weight: 800; padding: 0 5px; border-radius: 4px; color: #fff; vertical-align: middle; margin-left: 2px; }
.flag-d { background: #b3261e; }
.flag-r { background: #2f6fb3; }
.exp { font-weight: 700; }
.exp-expired { color: var(--danger); }
.exp-soon { color: var(--accent); }
.exp-ok { color: #4cc19d; }
html[data-theme="light"] .exp-ok { color: #1d7a5e; }
.exp-none { color: var(--muted); font-weight: 400; }
.chest-list .ci-n { margin-right: 2px; }
.alert-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 12px 14px; border-radius: 12px; background: var(--warn-bg); border: 1.5px solid var(--accent); color: var(--text); text-decoration: none; }
.alert-row span { flex: 1; }
.alert-row .chev { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2.4; }
.btn.wide { width: 100%; margin: 6px 0 4px; }
.dose { background: var(--tip-bg); border-left: 6px solid #3fa587; border-radius: 12px; padding: 10px 14px; margin: 1em 0; }
.dose .box-label { color: #4cc19d; }
html[data-theme="light"] .dose .box-label { color: #1d7a5e; }
.dose-rule { margin: .3em 0; }
.dose-ui label { font-weight: 700; font-size: .9em; display: block; margin-top: 6px; }
.dose-row { display: flex; align-items: center; gap: 8px; margin: 4px 0 6px; }
.dose-row input { font: inherit; font-size: 1.15em; width: 7em; color: var(--text); background: var(--bg); border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 10px; min-height: 48px; }
.dose-out { font-size: 1.05em; }
.dose-out b { color: var(--accent); }

/* tools */
.fld { display: block; margin: 8px 0; }
.fld span { display: block; font-weight: 700; font-size: .88em; margin-bottom: 3px; }
.fld input, .fld select, .fld textarea, .panel textarea, select.btn { font: inherit; color: var(--text); background: var(--bg); border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 10px; min-height: 46px; width: 100%; }
.panel textarea { min-height: 80px; resize: vertical; }
select.btn { width: auto; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; align-items: end; }
.li-row { display: flex; align-items: center; gap: 10px; padding: 8px 2px; }
.list .li-row { padding: 10px 14px; min-height: 52px; }
.grow { flex: 1; min-width: 0; }
.big-read { font-size: 1.35em; font-weight: 800; color: var(--accent); margin: .2em 0; overflow-wrap: anywhere; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: .08em; }
#mcode { font-size: 1.3em; margin-top: 8px; color: var(--accent); overflow-wrap: anywhere; }
.morse td { white-space: nowrap; }
.small-num { width: 6em; font: inherit; color: var(--text); background: var(--bg); border: 1.5px solid var(--line); border-radius: 10px; padding: 6px 8px; min-height: 42px; }
details { margin: .6em 0; }
details summary { cursor: pointer; font-weight: 700; color: var(--link); min-height: 40px; display: flex; align-items: center; }
.cpr-big { display: flex; flex-direction: column; align-items: center; justify-content: center; width: min(78vw, 320px); height: min(78vw, 320px); margin: 18px auto 10px; border-radius: 50%; border: 6px solid var(--danger); background: var(--danger-bg); color: var(--text); cursor: pointer; }
.cpr-big span { font-size: 4.2em; font-weight: 800; line-height: 1; }
.cpr-big small { font-size: 1em; color: var(--muted); margin-top: 8px; text-align: center; padding: 0 16px; }
.cpr-big.pulse { animation: cprp .25s ease-out; }
.cpr-big.breath { border-color: #2f8fd8; background: #10304a; }
.cpr-big.breath span { font-size: 2.6em; }
@keyframes cprp { from { transform: scale(.92); } to { transform: scale(1); } }
.cpr-stats { display: flex; justify-content: center; gap: 24px; font-size: 1.1em; }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.preset-grid .btn { min-height: 52px; line-height: 1.2; text-align: left; justify-content: flex-start; }
.timer-row { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.timer-row .t { font-weight: 700; }
.timer-row .s { color: var(--muted); font-size: .85em; }
.tm { font-size: 1.5em; font-weight: 800; font-variant-numeric: tabular-nums; }
.tm-run { color: var(--text); }
.tm-done, .tm-due { color: var(--danger); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.timer-chips { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.tchip { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-radius: 12px; background: var(--surface); border: 1.5px solid var(--accent); color: var(--text); text-decoration: none; }
.tchip .tm { font-size: 1.2em; }
.tool-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 10px; }
.tool-btn { display: flex; align-items: center; justify-content: center; text-align: center; min-height: 54px; padding: 6px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); color: var(--text); text-decoration: none; line-height: 1.2; font-size: .95em; }
.tool-btn:active { background: var(--surface2); }
.prob { display: flex; flex-direction: column; gap: 8px; }
.prob-item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px 10px; }
.prob-item .t { font-weight: 700; }
.prob-item .related { margin-top: 4px; }
.chip-crit { border-color: var(--danger); }
.flash { position: fixed; inset: 0; z-index: 90; background: #000; }
.flash.on { background: #fff; }
.moon-now { display: flex; align-items: center; gap: 12px; }
.moon-disc { width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(90deg, #f3e7c4 var(--lit), #2a3a40 var(--lit)); border: 1px solid var(--line); flex: none; }
.alm { font-size: .82em; }
.alm td, .alm th { white-space: nowrap; padding: 5px 6px; }
.lib-img { max-width: 100%; border-radius: 8px; margin: 8px 0; }
.lib-txt { white-space: pre-wrap; background: var(--bg); padding: 10px; border-radius: 8px; max-height: 60vh; overflow: auto; font-size: .9em; }
.mynote textarea { width: 100%; }
