:root {
  --bg: #F4F9FC;
  --surface: #FFFFFF;
  --blue-50: #E9F4FB;
  --blue-100: #D6ECF8;
  --blue-300: #A9D2EC;
  --blue-600: #2F7FAF;
  --ink: #13303F;
  --muted: #5B7482;
  --faint: #8BA0AB;
  --line: #E1ECF2;
  --green: #1E7A55;
  --green-press: #17633F;
  --green-50: #E4F4EC;
  --amber-bg: #FBF3E1;
  --amber-ink: #7A5410;
  --danger: #B23B3B;
  --radius: 16px;
  --tap: 52px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1A21;
    --surface: #15242D;
    --blue-50: #172C38;
    --blue-100: #1D3746;
    --blue-300: #2C5267;
    --blue-600: #8CC4E6;
    --ink: #E6F1F6;
    --muted: #9DB3BE;
    --faint: #6E8693;
    --line: #213641;
    --green: #47B884;
    --green-press: #3AA273;
    --green-50: #173328;
    --amber-bg: #33290F;
    --amber-ink: #E8C677;
    --danger: #E77B7B;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 20px calc(env(safe-area-inset-bottom) + 40px);
}

a { color: inherit; text-decoration: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

h1 { font-size: 30px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 36px 4px 10px; }
.page-title { margin: 8px 0 24px; font-size: 26px; }

/* top bar */
.top { display: flex; align-items: center; justify-content: space-between; min-height: 48px; margin-bottom: 16px; }
.top h1 { margin-top: 12px; }
.back { display: inline-flex; align-items: center; gap: 2px; color: var(--blue-600); font-weight: 500; margin-left: -6px; padding: 8px 6px; }
.link { color: var(--blue-600); font-weight: 500; padding: 8px 0; }

/* lists */
.list { list-style: none; margin: 0 0 12px; padding: 0; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 14px; padding: 14px 16px; min-height: var(--tap); }
.row.plain { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.row-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 17px; }
.row-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.row-sub.faint { color: var(--faint); }
.chev { color: var(--faint); }
.safe-row:active, .sched-row .row-main:active { opacity: .6; }

.badge { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.badge.locked { background: var(--green-50); color: var(--green); }
.badge.unlocked { background: var(--blue-50); color: var(--blue-600); }
.badge.offline { background: var(--line); color: var(--faint); }

/* safe hero */
.hero { text-align: center; padding: 20px 0 28px; }
.hero-icon { width: 112px; height: 112px; border-radius: 32px; margin: 0 auto 20px; display: grid; place-items: center; transition: background .25s, color .25s; }
.hero-icon svg { width: 52px; height: 52px; stroke-width: 1.6; }
.hero.locked .hero-icon { background: var(--green-50); color: var(--green); }
.hero.unlocked .hero-icon { background: var(--blue-100); color: var(--blue-600); }
.hero.offline .hero-icon { background: var(--line); color: var(--faint); }
.hero-status { font-size: 18px; font-weight: 600; margin: 10px 0 0; }
.hero.locked .hero-status { color: var(--green); }
.hero.unlocked .hero-status { color: var(--blue-600); }
.hero-sub { color: var(--muted); margin: 2px 0 0; }

/* buttons */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px; border-radius: 14px; border: 0;
  font: inherit; font-weight: 600; font-size: 17px; cursor: pointer;
  transition: background .15s, opacity .15s, transform .1s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn.wide, .btn.big { width: 100%; }
.btn.big { min-height: 60px; font-size: 18px; border-radius: 18px; }
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:active:not(:disabled) { background: var(--green-press); }
.btn.primary:disabled { background: var(--blue-100); color: var(--faint); cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--blue-600); border: 1.5px dashed var(--blue-300); }
.btn.danger-text { background: transparent; color: var(--danger); margin-top: 28px; }

.hint { color: var(--muted); font-size: 14px; text-align: center; margin: 12px 8px 0; }
.hint.left { text-align: left; margin: 4px 4px 20px; }
.note { background: var(--amber-bg); color: var(--amber-ink); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin: 0 0 14px; }
.empty { color: var(--muted); text-align: center; padding: 32px 12px; }
.empty.small { padding: 4px 4px 14px; text-align: left; font-size: 15px; }

/* switch */
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--blue-100); border-radius: 99px; transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 25px; height: 25px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.18); transition: transform .2s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:disabled + span { opacity: .45; }
.switch input:focus-visible + span { outline: 2px solid var(--blue-600); outline-offset: 2px; }

/* activity */
.activity { list-style: none; margin: 0; padding: 0 4px; }
.activity li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; font-size: 15px; border-bottom: 1px solid var(--line); }
.activity li:last-child { border-bottom: 0; }
.activity time { color: var(--faint); white-space: nowrap; }

/* forms */
.form { display: flex; flex-direction: column; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 18px; border: 0; padding: 0; min-width: 0; }
.field > span, .field legend { font-size: 14px; font-weight: 600; color: var(--muted); padding: 0 4px; margin-bottom: 6px; }
.field input {
  font: inherit; font-size: 17px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  min-height: var(--tap); padding: 0 14px; width: 100%; -webkit-appearance: none; appearance: none;
}
.field input:focus { outline: none; border-color: var(--blue-600); box-shadow: 0 0 0 3px var(--blue-100); }
.field input.code { letter-spacing: .4em; font-variant-numeric: tabular-nums; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day { position: relative; }
.day input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.day span { display: grid; place-items: center; aspect-ratio: 1; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); font-weight: 600; color: var(--muted); transition: background .15s, color .15s; }
.day input:checked + span { background: var(--green); border-color: var(--green); color: #fff; }
.day input:focus-visible + span { outline: 2px solid var(--blue-600); outline-offset: 2px; }

.steps { color: var(--muted); padding-left: 22px; margin: -8px 0 24px; }
.steps li { margin-bottom: 6px; }

/* toast */
#toast { z-index: 20;
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px;
  font-size: 15px; font-weight: 500; max-width: calc(100% - 40px); text-align: center;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

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

/* auth */
.auth { padding-top: 8vh; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 8px; }
.brand img { border-radius: 16px; }
.lede { color: var(--muted); margin: 0 0 28px; }
.center { text-align: center; }
.page-title.center { margin-top: 24px; }
.auth .lede { text-align: center; }
.field small { color: var(--faint); font-size: 13px; padding: 0 4px; }
.switch-auth { text-align: center; color: var(--muted); margin-top: 24px; }
.switch-auth a { color: var(--blue-600); font-weight: 600; }

/* PIN keypad */
.pinpad { margin: 4px auto 24px; max-width: 300px; }
.dots { display: flex; justify-content: center; gap: 14px; margin-bottom: 28px; }
.dots i { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid var(--blue-300); transition: background .1s, border-color .1s; }
.dots i.on { background: var(--green); border-color: var(--green); }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 20px; }
.keys button {
  height: 64px; border-radius: 50%; border: 0; background: var(--surface); color: var(--ink);
  font: inherit; font-size: 26px; font-weight: 500; cursor: pointer; display: grid; place-items: center;
  box-shadow: inset 0 0 0 1px var(--line); transition: background .1s;
}
.keys button:active { background: var(--blue-100); }
.keys button[data-k=del] { background: transparent; box-shadow: none; color: var(--muted); }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* bottom sheet */
#sheet { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#sheet.open { pointer-events: auto; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(10, 30, 40, .35); opacity: 0; transition: opacity .2s; }
#sheet.open .sheet-backdrop { opacity: 1; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 520px; margin: 0 auto;
  background: var(--bg); border-radius: 24px 24px 0 0;
  padding: 10px 20px calc(env(safe-area-inset-bottom) + 12px);
  transform: translateY(100%); transition: transform .25s ease;
}
#sheet.open .sheet-panel { transform: none; }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet-title { text-transform: none; letter-spacing: -0.01em; font-size: 20px; color: var(--ink); text-align: center; margin: 4px 0 4px; }
.sheet-panel .lede { margin-bottom: 18px; }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; }
.btn.text { background: transparent; color: var(--muted); margin-top: 6px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0; }
.row-title.small { font-size: 13px; font-weight: 500; word-break: break-all; }
#new-safe .btn { margin-bottom: 10px; }

/* kid mode + requests */
.kid-entry { margin-top: 28px; }
.request { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; }
.request p { margin: 0 0 12px; }
.request-actions { display: flex; gap: 10px; }
.request-actions .btn { flex: 1; }
.note.calm { background: var(--blue-50); color: var(--blue-600); }
.ask-dot { color: var(--green); font-weight: 600; }
.hero.now .hero-icon { background: var(--amber-bg); color: var(--amber-ink); }
.hero.now h1 + .hero-sub { color: var(--amber-ink); }
.hero .hero-sub.faint { color: var(--faint); }
.small-btn { min-height: 36px; padding: 0 8px; font-size: 15px; color: var(--danger); margin: 0; }
.link-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; text-align: center; }
.link-card .steps { text-align: left; margin: 0 0 8px; }
.big-code { font-size: 40px; font-weight: 700; letter-spacing: .12em; margin: 8px 0; font-variant-numeric: tabular-nums; }
.qr { width: 180px; margin: 4px auto; background: #fff; border-radius: 12px; padding: 6px; }
.qr svg { width: 100%; height: auto; display: block; }
.field input.code { text-transform: uppercase; }
