:root {
  color-scheme: light dark;
  --scale: 1;
  --bg: #f4f6f2;
  --card: #ffffff;
  --text: #17201b;
  --muted: #5d6a62;
  --line: #dfe5df;
  --primary: #1e9e5a;
  --primary-ink: #ffffff;
  --primary-soft: #e3f4ea;
  --warn: #b56a00;
  --warn-soft: #fff1d9;
  --danger: #c93b3b;
  --danger-soft: #fde6e6;
  --info-soft: #e7eefb;
  --radius: 18px;
  --tabbar: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1310;
    --card: #182019;
    --text: #edf2ee;
    --muted: #a1aea5;
    --line: #2a352d;
    --primary: #36c07a;
    --primary-ink: #04150b;
    --primary-soft: #143322;
    --warn: #f0b04a;
    --warn-soft: #3a2a0d;
    --danger: #ff7a7a;
    --danger-soft: #3d1717;
    --info-soft: #18243a;
  }
}

* { box-sizing: border-box; }

/* -apple-system-body follows the iPhone's own text size setting (Settings › Display › Text Size). */
html { font: -apple-system-body; font-family: -apple-system, system-ui, 'Segoe UI', Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
@supports not (font: -apple-system-body) { html { font-size: 17px; } }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-size: calc(1rem * var(--scale));
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  padding-top: env(safe-area-inset-top);
}
body.busy { cursor: progress; }
body.busy button[type='submit'], body.busy .btn { opacity: 0.7; }

h1 { font-size: 1.75em; line-height: 1.2; margin: 0.4em 0; }
h2 { font-size: 1.3em; line-height: 1.25; margin: 0.2em 0 0.4em; }
h3 { font-size: 1.05em; margin: 1em 0 0.4em; }
h3:first-child { margin-top: 0; }
p { margin: 0.4em 0; }
a { color: var(--primary); }

.page { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(var(--tabbar) + 32px + env(safe-area-inset-bottom)); }
.page.narrow { max-width: 480px; padding-top: 24px; }
.page.center { text-align: center; }
.title { margin: 8px 4px 12px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.88em; margin: 0.3em 0 0.8em; }
.small { font-size: 0.85em; }
.version { color: var(--muted); text-align: center; font-size: 0.8em; }
.legal { text-align: center; font-size: 0.85em; color: var(--muted); }

.ico { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.25em; flex: none; }

.card { background: var(--card); border-radius: var(--radius); padding: 18px; margin: 0 0 14px; box-shadow: 0 1px 2px rgb(0 0 0 / 0.05); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.btn-col { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

/* ----- controls */
button { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border: 0; border-radius: 14px;
  background: var(--primary); color: var(--primary-ink); font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.big { width: 100%; min-height: 56px; font-size: 1.05em; margin-top: 6px; }
.btn.huge { width: 100%; min-height: 72px; font-size: 1.3em; border-radius: 20px; }
.btn.ghost { background: transparent; color: var(--primary); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger.ghost { background: transparent; color: var(--danger); }
.btn.locked { background: var(--primary-soft); color: var(--primary); }
.btn:disabled, .btn[disabled] { opacity: 0.45; cursor: default; }
.card .btn.ghost { width: 100%; margin-top: 8px; }
.link { background: none; border: 0; color: var(--primary); padding: 10px 4px; cursor: pointer; font-weight: 600; }
.link.back { padding-left: 0; align-self: flex-start; }
.icon-btn { background: none; border: 0; width: 40px; height: 40px; border-radius: 10px; color: var(--muted); cursor: pointer; }
.icon-btn:disabled { opacity: 0.3; }

label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.95em; }
label.row { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0; }
label.row.lang { justify-content: center; }
input, select {
  font: inherit; font-weight: 400; color: var(--text); background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 12px; min-height: 50px; padding: 10px 14px; width: 100%;
}
label.row input, label.row select { width: auto; min-width: 9em; }
input:focus, select:focus { outline: none; border-color: var(--primary); }
.code-input { font-size: 1.5em; letter-spacing: 0.25em; text-align: center; font-family: ui-monospace, Menlo, monospace; }
.code-input.xl { font-size: 2em; min-height: 76px; text-transform: uppercase; }

.switch { flex-direction: row; align-items: center; gap: 12px; font-weight: 500; margin: 14px 0 0; }
.switch input { appearance: none; -webkit-appearance: none; width: 52px; min-width: 52px; height: 32px; min-height: 32px; padding: 0; border-radius: 16px; background: var(--line); border: 0; position: relative; cursor: pointer; transition: background 0.2s; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); transition: transform 0.2s; }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { transform: translateX(20px); }
.switch input:disabled { opacity: 0.4; }
.switch.small { margin: 0; gap: 6px; font-size: 0.8em; color: var(--muted); }
.switch.small input { width: 44px; min-width: 44px; height: 26px; min-height: 26px; }
.switch.small input::after { width: 20px; height: 20px; }
.switch.small input:checked::after { transform: translateX(18px); }

.seg { display: flex; background: var(--bg); border-radius: 14px; padding: 4px; gap: 4px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 10px; min-height: 44px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 4px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }
.seg button.locked { color: var(--muted); opacity: 0.75; }
.picker { flex-direction: row; align-items: center; gap: 8px; margin: 0 4px 12px; color: var(--muted); }
.picker select { min-height: 42px; font-weight: 600; }
form.card label.row { font-weight: 500; }

/* ----- notices */
.notice { background: var(--info-soft); border-radius: 14px; padding: 12px 14px; margin: 0 0 14px; font-size: 0.92em; display: block; border: 0; width: 100%; text-align: start; }
.notice.warn { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.notice.small { font-size: 0.8em; }
.tag { display: inline-block; font-size: 0.72em; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--primary-soft); color: var(--primary); vertical-align: 0.1em; }

/* ----- family home */
.status { text-align: center; padding: 24px 18px; }
.status .status-icon { width: 64px; height: 64px; margin: 0 auto 8px; border-radius: 50%; display: grid; place-items: center; }
.status .status-icon .ico { width: 36px; height: 36px; }
.status.ok .status-icon { background: var(--primary-soft); color: var(--primary); }
.status.waiting .status-icon, .status.idle .status-icon { background: var(--info-soft); color: var(--muted); }
.status.handled .status-icon { background: var(--warn-soft); color: var(--warn); }
.status.alarm { background: var(--danger-soft); }
.status.alarm .status-icon { background: var(--danger); color: #fff; }
.status.alarm h2 { color: var(--danger); }
.status.pending { background: var(--warn-soft); }
.status .btn-row { justify-content: center; }

.history { list-style: none; margin: 0; padding: 0; }
.history li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 0.95em; }
.history li:last-child { border-bottom: 0; }
.history .ico { margin-top: 2px; }
.h-ok .ico, .h-late .ico { color: var(--primary); }
.h-alarm .ico { color: var(--danger); }
.h-handled .ico, .h-waiting .ico { color: var(--warn); }

.members { list-style: none; margin: 0; padding: 0; }
.member { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.member .m-main { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.member .m-actions { display: flex; align-items: center; gap: 2px; }

/* ----- tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.tabbar button { flex: 1; min-width: 0; border: 0; background: none; height: var(--tabbar); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 0.68em; color: var(--muted); cursor: pointer; }
.tabbar button span { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; padding: 0 2px; }
.tabbar button .ico { width: 26px; height: 26px; }
.tabbar button.on { color: var(--primary); font-weight: 700; }
.tabbar button:disabled { opacity: 0.35; }

/* ----- welcome */
.welcome .logo { width: 96px; height: 96px; margin-top: 24px; }
.welcome h1 { font-size: 2.4em; margin: 0.2em 0 0; }
.tagline { color: var(--primary); font-weight: 700; font-size: 1.15em; margin-top: 0; }
.choice { display: flex; flex-direction: column; gap: 4px; width: 100%; text-align: start; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 12px 0; cursor: pointer; }
.choice b { font-size: 1.1em; }
.choice span { color: var(--muted); font-size: 0.92em; }
.choice:active { border-color: var(--primary); }

/* ----- the person's phone: few things, very large */
body[data-mode='senior'] { font-size: calc(1.15rem * var(--scale)); }
.senior-page { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 92vh; padding-bottom: 32px; }
.senior-page.narrow { align-items: stretch; justify-content: flex-start; }
.big-text { font-size: 1.15em; }
.family-line { color: var(--muted); min-height: 1.4em; }
.ok-button {
  width: min(78vw, 340px); aspect-ratio: 1; border-radius: 50%; border: 0; margin: 24px auto;
  background: var(--primary); color: var(--primary-ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  font-size: 1.9em; font-weight: 800; box-shadow: 0 12px 30px rgb(30 158 90 / 0.35); cursor: pointer; transition: transform 0.12s;
}
.ok-button .ico { width: 34%; height: 34%; stroke-width: 2.6; }
.ok-button:active, .ok-button.pressed { transform: scale(0.96); }
.ok-button.pulse { animation: pulse 1.6s ease-in-out infinite; }
.ok-button.done { background: var(--primary-soft); color: var(--primary); box-shadow: none; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgb(30 158 90 / 0.5); } 50% { box-shadow: 0 0 0 26px rgb(30 158 90 / 0); } }
@media (prefers-reduced-motion: reduce) { .ok-button.pulse { animation: none; outline: 6px solid var(--warn); } }
.status-line { font-size: 1.2em; font-weight: 600; max-width: 22em; }
.status-line.urgent { color: var(--warn); }
.bell { width: 96px; height: 96px; margin: 0 auto; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; }
.bell .ico { width: 52px; height: 52px; }

/* ----- sheets and dialogs */
dialog { border: 0; padding: 0; background: var(--card); color: var(--text); border-radius: 22px; max-width: min(560px, calc(100vw - 24px)); width: 100%; }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
#sheet { max-height: 90vh; }
.sheet-body { padding: 22px 18px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.sheet-body .btn { width: 100%; }
#ask form { padding: 22px 18px 18px; }
#ask p { font-size: 1.05em; margin-bottom: 8px; }
#ask .btn-row { justify-content: flex-end; }

.qr { width: min(64vw, 260px); height: auto; margin: 6px auto; display: block; border-radius: 12px; }
.code-big { text-align: center; font-size: 2em; font-weight: 800; letter-spacing: 0.12em; font-family: ui-monospace, Menlo, monospace; margin: 0; }

.features { list-style: none; padding: 0; margin: 4px 0 8px; }
.features li { display: flex; gap: 10px; padding: 6px 0; }
.features .ico { color: var(--primary); }
.plan-btn { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; padding: 14px 16px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--bg); cursor: pointer; text-align: start; }
.plan-btn.best { border-color: var(--primary); background: var(--primary-soft); }
.plan-btn em { position: absolute; top: 12px; right: 14px; font-style: normal; font-weight: 800; font-size: 0.8em; background: var(--primary); color: var(--primary-ink); padding: 3px 9px; border-radius: 99px; }
.plan-btn .trial { color: var(--primary); font-weight: 600; font-size: 0.9em; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + 20px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; max-width: calc(100vw - 32px);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 20; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

[dir='rtl'] .link.back { padding-right: 0; }

/* ----- trips, children's location and SOS */
.center { text-align: center; }
.btn-row.center { justify-content: center; }
.btn.sos { background: var(--danger); color: #fff; width: 100%; margin: 4px 0 14px; letter-spacing: 0.04em; }
.btn.sos.huge { margin-top: 14px; }
.senior-page .btn.huge + .btn.huge { margin-top: 12px; }
.label { font-weight: 600; margin: 8px 0 2px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid var(--line); background: var(--bg); border-radius: 99px; padding: 8px 14px; min-height: 40px; cursor: pointer; font-weight: 600; }
.chip.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.search { display: flex; gap: 8px; align-items: center; }
.search input { flex: 1; }
.result { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: start; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 10px 4px; cursor: pointer; }
.result.on { background: var(--primary-soft); border-radius: 10px; }
.result .muted { font-size: 0.85em; }
.radio { flex-direction: row; align-items: flex-start; gap: 12px; font-weight: 500; margin: 10px 0; cursor: pointer; }
.radio input { width: 24px; min-width: 24px; height: 24px; min-height: 24px; margin-top: 2px; accent-color: var(--primary); }
.radio.locked { opacity: 0.7; }
.card.trip h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.card.trip.alarm { background: var(--danger-soft); }
.card.trip.alarm h3 { color: var(--danger); }
.card.trip.handled { background: var(--warn-soft); }
.card.trip.active h3 .ico, .card.trip.arrived h3 .ico { color: var(--primary); }
.trip-big { text-align: center; width: 100%; }
.trip-big h2 { font-size: 1.5em; }
.sheet-body .seg button { flex-direction: column; gap: 2px; min-height: 58px; font-size: 0.85em; }
.link.danger-link { color: var(--danger); }
