:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #1d2327;
  --muted: #5d6870;
  --line: #e3ddd3;
  --doctor: #1f5f8b;      /* deep blue */
  --doctor-bg: #e8f1f8;
  --patient: #8a4b14;     /* warm amber-brown */
  --patient-bg: #fbefe2;
  --accent: #127a5a;      /* calm green */
  --warn: #b3261e;
  --remind: #fff4c2;
  --radius: 16px;
  --fs: 1.25rem;          /* caption size, adjustable */
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#14181b; --card:#1d2327; --ink:#eef2f4; --muted:#a3adb4; --line:#2e363c;
          --doctor:#8cc4ec; --doctor-bg:#16293a; --patient:#f1b47a; --patient-bg:#33240f;
          --accent:#5fd1a6; --remind:#3d3410; }
}
body.contrast { --bg:#000; --card:#000; --ink:#fff; --muted:#ddd; --line:#fff;
                --doctor:#7fd4ff; --doctor-bg:#000; --patient:#ffd27f; --patient-bg:#000; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.screen { display: none; min-height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }
#screen-setup, #screen-summary { padding: 20px 16px calc(24px + var(--safe-b)); gap: 16px; max-width: 640px; margin: 0 auto; width: 100%; }

.brand { display: flex; gap: 12px; align-items: center; }
.logo { width: 48px; height: 48px; border-radius: 14px; background: var(--accent); color: #fff;
        display: grid; place-items: center; font-size: 26px; }
h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.01em; }
.sub { margin: 2px 0 0; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .95rem; }
.hint { font-weight: 400; color: var(--muted); }
input, select, textarea { border: 1px solid var(--line); background: var(--bg); border-radius: 12px;
  padding: 12px; font-size: 1rem; font-weight: 400; width: 100%; }
textarea { resize: vertical; }
.consent { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 500; }
.consent input { width: 24px; height: 24px; flex: none; margin-top: 2px; accent-color: var(--accent); }
.fine { color: var(--muted); font-size: .8rem; margin: 0; }

button { cursor: pointer; border: 0; border-radius: 14px; min-height: 44px; }
.primary { background: var(--accent); color: #fff; font-weight: 700; padding: 12px 16px; }
.primary:disabled, .secondary:disabled { opacity: .45; }
.primary.big { font-size: 1.2rem; min-height: 60px; }
.secondary { background: transparent; border: 1.5px solid var(--line); padding: 12px 16px; font-weight: 600; }
.small { min-height: 38px; padding: 6px 12px; font-size: .9rem; }
.link { background: none; color: var(--accent); align-self: flex-start; padding: 0; min-height: 0; font-weight: 600; }
.icon { background: none; font-size: 1.1rem; width: 40px; }
.chip { background: var(--card); border: 1px solid var(--line); padding: 6px 12px; min-height: 36px; font-size: .85rem; font-weight: 600; }

/* ---------- live visit */
#screen-visit { height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
          border-bottom: 1px solid var(--line); background: var(--card); }
.live-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); }
.live-dot.on { background: #e5483b; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
#timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.status { flex: 1; color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.warn { color: var(--warn); }

.reminder { display: flex; align-items: center; gap: 10px; margin: 10px 12px 0; padding: 12px 12px 12px 14px;
            background: var(--remind); border-radius: var(--radius); border: 1px solid #e8d77a; animation: slidein .3s; }
.reminder { flex-wrap: wrap; }
.reminder-text { flex: 1 1 100%; display: flex; flex-direction: column; gap: 4px; font-size: 1.05rem; }
#reminder-show { flex: 1; }
@keyframes slidein { from { transform: translateY(-8px); opacity: 0; } }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 10px 12px 0; }
.tab { background: transparent; border: 1px solid var(--line); font-weight: 600; color: var(--muted); }
.tab.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--warn); color: #fff; font-size: .75rem; }
.badge:empty { display: none; }

.panes { flex: 1; overflow: hidden; position: relative; }
.pane { display: none; height: 100%; overflow-y: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
.pane.active { display: block; }

.captions { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.cap { border-radius: var(--radius); padding: 12px 14px; max-width: 92%; }
.cap.doctor { background: var(--doctor-bg); border-left: 5px solid var(--doctor); align-self: flex-start; }
.cap.patient { background: var(--patient-bg); border-right: 5px solid var(--patient); align-self: flex-end; }
.cap .who { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.cap.doctor .who { color: var(--doctor); }
.cap.patient .who { color: var(--patient); }
.cap .big { font-size: var(--fs); line-height: 1.4; margin: 4px 0 0; }
.cap .small { font-size: calc(var(--fs) * .72); color: var(--muted); margin: 6px 0 0; line-height: 1.35; }
.cap.partial .big::after { content: " ▍"; animation: pulse 1s infinite; }
.num { background: rgba(18,122,90,.14); border-radius: 6px; padding: 0 4px; font-weight: 700; }
.empty { color: var(--muted); text-align: center; margin-top: 30px; }

.qlist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.q { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line);
     border-radius: var(--radius); padding: 12px; }
.q .qtext { flex: 1; font-size: 1.05rem; }
.q .qtext small { display: block; color: var(--muted); font-size: .85rem; margin-top: 3px; }
.pill { font-size: .75rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.pill.open { background: var(--remind); }
.pill.asked { background: var(--doctor-bg); color: var(--doctor); }
.pill.answered { background: rgba(18,122,90,.15); color: var(--accent); }
.q.answered .qtext { color: var(--muted); }
.addq { display: flex; gap: 8px; margin-top: 12px; }

.nsec { margin-bottom: 16px; }
.nsec h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }
.nitem { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }
.nitem .t { font-weight: 700; font-size: 1.05rem; }
.nitem .d { color: var(--muted); margin-top: 4px; }
.nitem.warning_sign { border-color: var(--warn); }
.nitem.warning_sign .t::before { content: "⚠️ "; }
.tag { font-size: .7rem; font-weight: 700; border-radius: 6px; padding: 1px 6px; background: var(--line); margin-left: 6px; vertical-align: middle; }

.bottombar { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); background: var(--card);
             padding: 6px 6px calc(6px + var(--safe-b)); }
.tool { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: none;
        font-size: 1.3rem; min-height: 56px; border-radius: 12px; cursor: pointer; }
.tool small { font-size: .7rem; font-weight: 600; color: var(--muted); }
.tool[aria-pressed="true"] { background: var(--doctor-bg); }
.tool.end small { color: var(--warn); }

dialog { border: 0; border-radius: 24px; padding: 24px; width: min(92vw, 560px); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.55); }
.show-label { color: var(--muted); margin: 0; font-weight: 600; }
.show-big { font-size: 2rem; line-height: 1.3; font-weight: 700; margin: 12px 0; }
.show-small { color: var(--muted); font-size: 1.05rem; margin: 0 0 20px; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); background: var(--ink);
         color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; max-width: 90vw; z-index: 10; }

/* summary */
.keypoints { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 1.1rem; }
.saved { color: var(--accent); font-weight: 600; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

.pending { display: flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 600; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent);
           animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.backlink { display: flex; align-items: center; justify-content: center; text-decoration: none; border-radius: 14px; }

.demo-row { display: grid; grid-template-columns: 1fr; gap: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.nitem.ex .dose { font-size: 1.15rem; font-weight: 700; margin-top: 4px; }
.limit { color: var(--warn); font-weight: 700; margin-top: 4px; }
.cues { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: .92rem; }
.plan-note { color: var(--accent); font-weight: 600; margin: 4px 2px 0; font-size: .9rem; }

.backtop { align-self: flex-start; color: var(--accent); font-weight: 700; text-decoration: none; padding: 8px 4px; min-height: 44px; display: inline-flex; align-items: center; }
