:root {
  --navy: #0b2a6b;
  --navy-2: #123a8c;
  --blue: #12a4f5;
  --cyan: #29d3ff;
  --yellow: #ffd23f;
  --pink: #e91e8c;
  --ink: #12224a;
  --muted: #5b6a8c;
  --bg: #f2f6fc;
  --surface: #ffffff;
  --line: #d8e2f2;
  --ring: #1b6fe0;
  --radius: 18px;
  --tabs-h: 64px;
  --top-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1530;
    --surface: #16224a;
    --ink: #eef3ff;
    --muted: #a9b8dd;
    --line: #27386d;
    --ring: #6fb0ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #0c1530;
    --surface: #16224a;
    --ink: #eef3ff;
    --muted: #a9b8dd;
    --line: #27386d;
    --ring: #6fb0ff;
    color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
img { -webkit-user-drag: none; user-select: none; -webkit-touch-callout: none; }
[hidden] { display: none !important; }

/* ---------- Header ---------- */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0 18px;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(135deg, var(--navy), var(--navy-2));
  color: #fff;
  border-bottom: 4px solid var(--blue);
}
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: .3px; line-height: 1.15; }
.brand-tag { font-size: 12.5px; opacity: .85; line-height: 1.2; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.14); color: #fff;
  display: grid; place-items: center;
}
.icon-btn:active { background: rgba(255,255,255,.28); }

/* ---------- Main scrolling area ---------- */
#main {
  padding: calc(var(--top-h) + env(safe-area-inset-top) + 8px) max(16px, env(safe-area-inset-right, 0px))
           calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px) max(16px, env(safe-area-inset-left, 0px));
  max-width: 1100px; margin: 0 auto;
}
body.has-actionbar #main { padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 96px); }
.hint { margin: 10px 4px 12px; color: var(--muted); font-size: 15px; line-height: 1.35; }

/* ---------- Card grid: 2 across on phones, more on tablets ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 165px), 1fr));
  gap: 12px;
}
@media (min-width: 560px)  { .grid { grid-template-columns: repeat(auto-fill, minmax(175px, 1fr)); gap: 14px; } }
@media (min-width: 900px)  { .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; } }

.card {
  position: relative;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(11,42,107,.16);
  overflow: hidden;
  line-height: 0;
  transition: transform .12s ease, box-shadow .12s ease;
}
.card-main {
  display: block; width: 100%; padding: 0; border: 0; background: none;
  border-radius: var(--radius);
}
.card-main img { width: 100%; height: auto; display: block; pointer-events: none; }
.card:has(.card-main:active) { transform: scale(.97); }
.card.pressed { transform: scale(.97); }
.card.chosen { box-shadow: 0 0 0 5px var(--ring), 0 4px 14px rgba(11,42,107,.28); }

/* Speaker button sits on the navy wave at the top-right, away from the printed words */
.speak {
  position: absolute; top: 6px; right: 6px;
  width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid var(--cyan);
  background: #fff; color: var(--navy);
  display: grid; place-items: center; padding: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.28);
}
.speak:active { background: #dff4ff; transform: scale(.94); }
.speak svg { width: 24px; height: 24px; display: block; }
.big-cards .speak { width: 56px; height: 56px; top: 10px; right: 10px; }
.big-cards .speak svg { width: 30px; height: 30px; }

/* Selection state (Choose Two grid) */
.card.selectable .card-main { cursor: pointer; }
.card.selected { box-shadow: 0 0 0 5px var(--ring), 0 4px 14px rgba(11,42,107,.28); }
.badge {
  position: absolute; top: 8px; left: 8px;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--ring); color: #fff; font-weight: 800; font-size: 20px; line-height: 38px; text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}

/* Scenario grid cards show title below image for the caregiver */
.scen-card { line-height: 1.2; }
.scen-card .scen-title { display: none; }

/* ---------- Buttons ---------- */
.btn {
  min-height: 52px; padding: 0 20px; border-radius: 14px;
  border: 2px solid var(--navy); background: var(--surface); color: var(--navy);
  font-weight: 700; font-size: 17px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { background: #e3ecfb; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:active { background: var(--navy-2); }
.btn[disabled] { opacity: .45; cursor: default; }
.btn.small { min-height: 46px; padding: 0 16px; font-size: 16px; }
.btn.big { min-height: 64px; padding: 0 32px; font-size: 21px; border-radius: 18px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn, :root[data-theme="dark"] .btn { color: #eaf1ff; border-color: #6fb0ff; }
  :root:not([data-theme="light"]) .btn.primary, :root[data-theme="dark"] .btn.primary { background: #2b6fe0; border-color: #2b6fe0; color: #fff; }
}

.scen-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between; }
.scen-top .hint { flex: 1 1 240px; }

/* ---------- Choose Two action bar ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; z-index: 9;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 2px solid var(--line);
  padding: 10px 12px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  box-shadow: 0 -4px 14px rgba(11,42,107,.12);
}
.actionbar-count { font-weight: 700; flex: 1 1 100%; text-align: center; font-size: 15px; color: var(--muted); }
@media (min-width: 640px) { .actionbar-count { flex: 0 0 auto; margin-right: 8px; } }

/* ---------- Bottom tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--surface); border-top: 2px solid var(--line);
}
.tab-btn {
  flex: 1; border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 13px; font-weight: 700;
}
.tab-btn.active { color: var(--ring); box-shadow: inset 0 4px 0 var(--ring); }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 30; background: var(--bg);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.overlay-top {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px;
}
.overlay-hint { flex: 1; text-align: center; color: var(--muted); font-size: 13.5px; line-height: 1.25; }
@media (max-width: 520px) { .overlay-hint { display: none; } }
.stage {
  flex: 1 1 auto; min-height: 0; padding: 4px 12px 12px;
  display: flex; align-items: center; justify-content: center; gap: 14px;
}
.overlay-bottom { flex: 0 0 auto; padding: 4px 12px 14px; display: flex; justify-content: center; }
.stage .card { flex: 0 0 auto; }

.scen-stage { gap: 14px; }
.scen-card-region, .scen-choice-region {
  min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; gap: 12px;
}

/* ---------- Settings sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(8,20,55,.55);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: min(560px, 100%); background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 22px; } }
.sheet h2 { margin: 0 0 14px; font-size: 22px; }
.field { display: block; margin: 0 0 18px; }
.field > span { display: block; font-weight: 700; margin-bottom: 8px; }
.field select, .field input[type=range] { width: 100%; }
.field select { min-height: 50px; font-size: 17px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); color: var(--ink); padding: 0 10px; }
.field input[type=range] { height: 40px; accent-color: var(--ring); }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; }
.fine { color: var(--muted); font-size: 13.5px; margin: 14px 0 0; line-height: 1.35; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px); z-index: 60;
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 15px; max-width: 90vw; text-align: center;
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
:focus-visible { outline: 4px solid var(--ring); outline-offset: 2px; }

/* ---------- Scenario stage layout (portrait = stacked, landscape = side by side) ---------- */
.scen-stage { flex-direction: column; }
.scen-stage.land { flex-direction: row; }
.scen-card-region { flex: 1 1 0; width: 100%; }
.scen-choice-region { flex: 1 1 0; width: 100%; }
.scen-stage.revealed .scen-card-region { flex: 0 0 44%; }
.scen-stage.land .scen-card-region { width: auto; }
.scen-stage.land .scen-choice-region { width: auto; }
.scen-stage.revealed.land .scen-card-region { flex: 0 0 34%; }
.choice-stage-fix { display: none; }

/* ---------- Fix: regions must take the full stage height so cards never spill over the buttons or each other ---------- */
.scen-stage { align-items: stretch; }
.scen-card-region, .scen-choice-region { align-self: stretch; overflow: hidden; }
.scen-stage:not(.land) .scen-card-region, .scen-stage:not(.land) .scen-choice-region { width: 100%; }
.scen-stage.land .scen-card-region { flex: 1 1 0; }
.scen-stage.revealed.land .scen-card-region { flex: 0 0 38%; }
.scen-stage.land .scen-choice-region { flex: 1 1 0; }

/* ---------- Free preview / unlock ---------- */
.promo { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between;
  margin: 12px 0 4px; padding: 12px 14px; border-radius: 14px; background: var(--surface);
  border: 2px solid var(--blue); font-weight: 600; font-size: 15px; line-height: 1.35; }
.promo span { flex: 1 1 220px; }
.card.locked { line-height: 1.2; box-shadow: 0 2px 8px rgba(11,42,107,.12); }
.lock-main { aspect-ratio: 0.76; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 12px; text-align: center; color: #fff; font-weight: 800; font-size: 17px;
  background: linear-gradient(160deg, var(--navy), var(--navy-2)); }
.lock-main svg { width: 42px; height: 42px; opacity: .92; }
.lock-sub { font-size: 13px; font-weight: 600; opacity: .8; }
.field input[type=text] { width: 100%; min-height: 54px; font-size: 20px; letter-spacing: 1px; text-transform: uppercase;
  border-radius: 12px; border: 2px solid var(--line); background: var(--bg); color: var(--ink); padding: 0 12px; }
.err { color: #c62828; min-height: 1.4em; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .err { color: #ff8a80; } }
:root[data-theme="dark"] .err { color: #ff8a80; }

/* ---------- Home screen (your artwork, with tap areas laid over the buttons) ---------- */
.home { position: fixed; inset: 0; z-index: 20; background: #0b2a6b; display: flex; justify-content: center; align-items: flex-start; overflow: hidden; }
.home-art { position: relative; flex: none; width: min(100vw, 66.666vh); aspect-ratio: 1024 / 1536; }
@supports (height: 100dvh) { .home-art { width: min(100vw, 66.666dvh); } }
.home-art img { width: 100%; height: 100%; display: block; user-select: none; -webkit-user-drag: none; }
.home-hit { position: absolute; border: 0; padding: 0; background: transparent; border-radius: 4%/18%; }
.home-hit:active { background: rgba(255,255,255,.22); }
.home-hit:focus-visible { outline: 4px solid #fff; outline-offset: -4px; }
.about-line { margin: 0 0 12px; line-height: 1.45; font-size: 16px; }

/* Home v2: the artwork is cut into pieces so it fills tall phones without empty space */
.home-art { height: 100vh; display: flex; flex-direction: column; justify-content: space-between; background: #fdfdfd; aspect-ratio: auto; }
@supports (height: 100dvh) { .home-art { height: 100dvh; } }
.home-art img { height: auto; }
.home-btn { display: block; width: 100%; padding: 0; border: 0; background: transparent; line-height: 0; }
.home-btn:active { filter: brightness(.9); }
.home-btn:focus-visible { outline: 4px solid #0b2a6b; outline-offset: -4px; }
.home-bottom { position: relative; line-height: 0; }
.home-hit { border-radius: 0; }

/* ---------- Top navigation (colors match the home screen) + brand footer ---------- */
:root { --tabs-h: 0px; --top-h: 70px; --c-blue: #12a4f5; --c-green: #3fc45a; --c-yellow: #ffd23f; }
.top { background: var(--surface); color: var(--ink); border-bottom: 2px solid var(--line);
  padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left)); gap: 8px; }
.top .icon-btn { flex: 0 0 auto; width: 46px; height: 46px; background: var(--navy); color: #fff; }
.top .icon-btn:active { background: var(--navy-2); }
.navtabs { flex: 1 1 auto; min-width: 0; display: flex; gap: 8px; max-width: 640px; margin: 0 auto; }
.navtab { flex: 1 1 0; min-width: 0; min-height: 52px; padding: 4px 6px; border: 0; border-radius: 14px;
  color: var(--navy); font-weight: 800; font-size: clamp(12.5px, 3.4vw, 19px); line-height: 1.1; text-align: center;
  box-shadow: 0 2px 5px rgba(11,42,107,.2); }
.nt-cards { background: var(--c-blue); }
.nt-choose { background: var(--c-green); }
.nt-scen { background: var(--c-yellow); }
.navtab:active { filter: brightness(.92); }
.navtab.active { box-shadow: 0 0 0 4px var(--surface), 0 0 0 7px var(--navy); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .navtab.active { box-shadow: 0 0 0 4px var(--surface), 0 0 0 7px #fff; } }
:root[data-theme="dark"] .navtab.active { box-shadow: 0 0 0 4px var(--surface), 0 0 0 7px #fff; }
.brand-foot { text-align: center; margin: 32px 0 8px; padding: 18px 8px 4px; border-top: 2px solid var(--line); line-height: 1.3; }
.foot-name { font-weight: 800; font-size: 17px; color: var(--ink); letter-spacing: .3px; }
.foot-tag { font-size: 14px; color: var(--muted); }

/* ---------- Finder: search, categories, A-Z, Today star ---------- */
.finder { display: grid; gap: 8px; margin: 0 0 12px; }
.f-search { position: relative; }
.f-search input { width: 100%; min-height: 52px; font-size: 18px; padding: 0 48px 0 16px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink); -webkit-appearance: none; appearance: none; }
.f-search input:focus { border-color: var(--ring); outline: none; }
.f-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: var(--line); color: var(--ink); font-size: 24px; line-height: 1; }
.f-chips, .f-az { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.chip { flex: 0 0 auto; min-height: 44px; padding: 0 16px; border-radius: 999px; border: 2px solid var(--line); background: var(--surface);
  color: var(--ink); font-weight: 700; font-size: 16px; }
.az { flex: 0 0 auto; width: 42px; min-height: 42px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface);
  color: var(--ink); font-weight: 800; font-size: 17px; padding: 0; }
.chip.on, .az.on { background: var(--navy); border-color: var(--navy); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.on, :root:not([data-theme="light"]) .az.on { background: #2b6fe0; border-color: #2b6fe0; } }
:root[data-theme="dark"] .chip.on, :root[data-theme="dark"] .az.on { background: #2b6fe0; border-color: #2b6fe0; }
.empty { grid-column: 1 / -1; margin: 18px 4px; color: var(--muted); font-size: 16px; line-height: 1.4; }
.star { position: absolute; top: 6px; right: 6px; width: 46px; height: 46px; border-radius: 50%; border: 3px solid var(--yellow);
  background: #fff; color: #b9b9c4; display: grid; place-items: center; padding: 0; box-shadow: 0 2px 6px rgba(0,0,0,.28); }
.star svg { width: 26px; height: 26px; display: block; }
.star.on { background: var(--yellow); color: var(--navy); border-color: #f0b800; }

/* upgrade note inside Choose Two */
.upsell { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between;
  margin: 8px 0 4px; padding: 12px 14px; border-radius: 16px; background: #eaf3ff; color: #0b2a66; }
.upsell p { margin: 0; flex: 1 1 220px; font-size: 16px; line-height: 1.35; }

/* text for screen readers only (not shown on screen) */
.sr-only { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; line-height: normal; }

/* About: install steps */
.about-sub { margin: 16px 0 6px; font-size: 18px; }
.install-steps { margin: 0 0 8px; padding-left: 20px; line-height: 1.45; font-size: 16px; }
.install-steps li { margin: 0 0 8px; }
.sheet { max-height: 92vh; overflow-y: auto; }
