:root {
  color-scheme: light;
  --ink: #17383a;
  --muted: #607173;
  --paper: #fffdf8;
  --surface: #ffffff;
  --line: #dce7e4;
  --teal: #0b5b5f;
  --teal-2: #15777a;
  --mint: #dff2ec;
  --cream: #fff4dc;
  --peach: #ffb27d;
  --gold: #eab84d;
  --danger: #a83d42;
  --shadow: 0 16px 42px rgba(28, 75, 72, .1);
  --radius: 22px;
  font-family: Inter, ui-rounded, "SF Pro Rounded", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
}

:root[data-accent="blue"] {
  --teal: #285b91;
  --teal-2: #3672ad;
  --mint: #e4effa;
}

:root[data-accent="coral"] {
  --teal: #9b4d40;
  --teal-2: #b96552;
  --mint: #fae9e3;
}

* { box-sizing: border-box; }

html { background: #eef5f2; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(255, 199, 132, .28), transparent 32rem),
    radial-gradient(circle at 98% 16%, rgba(88, 178, 166, .2), transparent 28rem),
    #eef5f2;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid rgba(11, 91, 95, .3);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: -60px;
  z-index: 20;
  background: var(--surface);
  color: var(--teal);
  padding: 10px 14px;
  border-radius: 10px;
}
.skip-link:focus { top: 12px; }

.app-shell {
  width: min(100%, 820px);
  min-height: 100vh;
  margin: 0 auto;
  background: rgba(255, 253, 248, .92);
  box-shadow: 0 0 60px rgba(22, 69, 66, .08);
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 72px;
  padding: 12px 18px;
  padding-top: calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid rgba(220, 231, 228, .8);
  background: rgba(255, 253, 248, .92);
  backdrop-filter: blur(18px);
}

.brand-button {
  border: 0;
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  text-align: left;
}
.brand-button img { border-radius: 12px; }
.brand-button strong { display: block; letter-spacing: .08em; font-size: 17px; }
.brand-button small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-button, .pill-button, .primary-button, .secondary-button, .danger-button, .text-button {
  border-radius: 999px;
  min-height: 44px;
  font-weight: 750;
}
.icon-button {
  min-width: 44px;
  padding: 0 11px;
  border: 1px solid var(--line);
  color: var(--teal);
  background: var(--surface);
}

.demo-badge {
  border-radius: 999px;
  padding: 7px 10px;
  background: #ffe29f;
  color: #684813;
  font-size: 12px;
  font-weight: 800;
}

.demo-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 9px 16px;
  background: #fff0c6;
  color: #654b16;
  font-size: 13px;
}
.demo-banner .text-button { min-height: 32px; }

main { padding: 18px; }
.screen { display: grid; gap: 16px; }
.hidden { display: none !important; }

.loading-card, .card, .hero-card, .stat-card, .module-card, .setup-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.loading-card { padding: 28px; text-align: center; color: var(--muted); }

.hero-card {
  position: relative;
  overflow: hidden;
  padding: 26px;
  background: linear-gradient(135deg, #e9f7f2 0%, #fff7e6 70%, #ffe6d3 100%);
}
.hero-card::after {
  content: "";
  position: absolute;
  width: 170px;
  height: 170px;
  right: -60px;
  bottom: -86px;
  border-radius: 50%;
  background: rgba(11, 91, 95, .08);
}
.eyebrow { color: var(--teal); font-weight: 850; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(30px, 7vw, 48px); line-height: 1.04; letter-spacing: -.035em; }
h2 { margin-bottom: 12px; font-size: 21px; }
h3 { margin-bottom: 6px; font-size: 17px; }
.lead { max-width: 600px; color: var(--muted); font-size: 17px; line-height: 1.65; }
.muted { color: var(--muted); }
.fine-print { color: var(--muted); font-size: 12px; line-height: 1.55; }

.button-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.primary-button, .secondary-button, .danger-button, .pill-button {
  border: 0;
  padding: 11px 17px;
}
.primary-button { color: white; background: var(--teal); box-shadow: 0 9px 20px rgba(11, 91, 95, .2); }
.primary-button:hover { background: var(--teal-2); }
.secondary-button { color: var(--teal); background: var(--mint); }
.danger-button { color: #fff; background: var(--danger); }
.text-button { border: 0; background: transparent; color: var(--teal); padding: 4px 8px; }
button:disabled { cursor: not-allowed; opacity: .45; }

.card, .setup-card { padding: 20px; }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.card-header > * { margin-bottom: 0; }

.module-grid, .task-grid, .reward-grid, .stats-grid, .template-grid {
  display: grid;
  gap: 12px;
}
.module-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.module-card { padding: 20px; min-height: 210px; display: flex; flex-direction: column; }
.module-card .module-icon { font-size: 38px; margin-bottom: 14px; }
.module-card .button-row { margin-top: auto; }
.module-state { width: fit-content; margin-bottom: 10px; border-radius: 999px; padding: 5px 9px; background: var(--mint); color: var(--teal); font-size: 11px; font-weight: 800; }

.stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-card { padding: 16px; box-shadow: none; }
.stat-card small { display: block; color: var(--muted); line-height: 1.35; }
.stat-card strong { display: block; margin-top: 4px; color: var(--teal); font-size: clamp(25px, 7vw, 38px); }

.progress-track { height: 12px; margin-top: 14px; overflow: hidden; border-radius: 999px; background: rgba(11, 91, 95, .1); }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal), #62b997); }

.task-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.task-button {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 11px;
  min-height: 76px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 17px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}
.task-button:hover { border-color: #92bbb2; transform: translateY(-1px); }
.task-button .emoji { font-size: 25px; }
.task-button .task-points { color: var(--teal); font-weight: 900; }

.reward-grid { grid-template-columns: 1fr; }
.reward-row, .history-row, .settings-row {
  display: grid;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-top: 1px solid var(--line);
}
.settings-row input {
  min-width: 0;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.reward-row:first-child, .history-row:first-child, .settings-row:first-child { border-top: 0; }
.reward-row { grid-template-columns: auto 1fr auto; }
.reward-row .emoji { font-size: 25px; }
.history-row { grid-template-columns: 1fr auto; }
.history-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.history-amount { font-size: 17px; font-weight: 900; color: var(--teal); }
.history-amount.minus { color: var(--danger); }
.history-actions { grid-column: 1 / -1; }

.template-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.template-option {
  min-height: 88px;
  padding: 13px;
  border: 2px solid var(--line);
  border-radius: 16px;
  color: var(--ink);
  background: #fff;
  font-weight: 800;
}
.template-option.selected { border-color: var(--teal); background: var(--mint); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.field { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
.field.full { grid-column: 1 / -1; }
.field input, .field select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--ink);
  background: #fff;
}
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--ink);
  background: #fff;
  resize: vertical;
}
.check-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; }
.check-row input { width: 20px; height: 20px; accent-color: var(--teal); }

.editor-row { display: grid; grid-template-columns: minmax(0, 1fr) 100px auto; gap: 9px; margin-top: 9px; }
.editor-labels { display: grid; grid-template-columns: minmax(0, 1fr) 80px 80px auto; gap: 9px; color: var(--muted); font-size: 11px; font-weight: 750; text-align: center; }
.editor-row input { min-width: 0; min-height: 44px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 12px; }
.bilingual-name-fields { display: grid; gap: 6px; min-width: 0; }
.round-delete { width: 42px; height: 42px; border: 0; border-radius: 50%; background: #fde9e7; color: var(--danger); font-weight: 900; }

.notice {
  padding: 13px 15px;
  border-left: 4px solid var(--gold);
  border-radius: 12px;
  background: var(--cream);
  color: #644f25;
  line-height: 1.55;
}

.now-card {
  display: grid;
  gap: 5px;
  margin-top: 18px;
  padding: 18px;
  border-radius: 18px;
  background: rgba(255, 255, 255, .78);
  box-shadow: 0 10px 28px rgba(28, 75, 72, .08);
}
.now-card small { color: var(--muted); font-weight: 750; }
.now-card strong { color: var(--teal); font-size: clamp(24px, 6vw, 36px); }
.now-card span { color: var(--muted); }
.next-activity { margin: 14px 0 0; color: var(--muted); }
.routine-list, .routine-editor-list { display: grid; gap: 12px; }
.routine-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
}
.routine-item:first-child { border-top: 0; }
.routine-item.complete .routine-item-body { opacity: .62; }
.routine-item.complete h3 { text-decoration: line-through; }
.routine-complete {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  width: 70px;
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--teal);
  background: var(--mint);
  font-size: 24px;
  font-weight: 900;
}
.routine-complete span { font-size: 10px; }
.routine-time { color: var(--teal); font-size: 12px; font-weight: 850; }
.routine-item h3 { margin: 3px 0 6px; font-size: 20px; }
.routine-checklist { display: grid; gap: 7px; margin-top: 10px; }
.routine-checklist label { display: flex; align-items: flex-start; gap: 8px; }
.routine-checklist input { width: 20px; height: 20px; accent-color: var(--teal); }
.empty-state { padding: 20px 0; text-align: center; color: var(--muted); }
.routine-editor {
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fffdfa;
}
.routine-editor .card-header { align-items: center; }
.field-group { display: grid; gap: 8px; margin-top: 15px; }
.mini-check-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.mini-check {
  position: relative;
  display: inline-flex;
  min-width: 44px;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.mini-check input { position: absolute; opacity: 0; }
.mini-check span {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}
.mini-check input:checked + span { border-color: var(--teal); color: var(--teal); background: var(--mint); }
.mini-check input:focus-visible + span { outline: 3px solid rgba(11, 91, 95, .3); outline-offset: 2px; }
.mini-check-grid.months .mini-check { min-width: 42px; }
.routine-suggestions { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 14px; }
.upload-button { display: inline-flex; align-items: center; margin-top: 14px; cursor: pointer; }
.unresolved { margin-top: 14px; border-color: var(--danger); }
.confirm-row { margin-top: 10px; font-weight: 800; }

.caregiver-simple .routine-hero h1 { font-size: clamp(38px, 10vw, 58px); }
.caregiver-simple .now-card strong { font-size: clamp(34px, 9vw, 52px); }
.caregiver-simple .routine-item h3 { font-size: 28px; }
.caregiver-simple .routine-complete { width: 88px; min-height: 88px; font-size: 34px; }

.install-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  margin: 16px 0;
}
.install-steps div {
  display: grid;
  place-items: center;
  gap: 5px;
  min-height: 112px;
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fffdfa;
  text-align: center;
}
.install-steps div > span { color: var(--teal); font-size: 28px; font-weight: 900; line-height: 1; }
.install-steps div > strong { color: var(--muted); font-size: 11px; }
.install-steps div > small { min-height: 30px; color: var(--ink); font-weight: 750; line-height: 1.35; }

.bottom-nav {
  position: fixed;
  z-index: 9;
  left: 50%;
  bottom: 0;
  width: min(100%, 820px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 248, .94);
  backdrop-filter: blur(18px);
}
.bottom-nav button {
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 54px;
  border: 0;
  border-radius: 16px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  font-weight: 800;
}
.bottom-nav button span:first-child { font-size: 20px; }
.bottom-nav button.active { color: var(--teal); background: var(--mint); }

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  max-width: calc(100% - 36px);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  padding: 11px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  transition: .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

dialog {
  width: min(92vw, 500px);
  border: 0;
  border-radius: 22px;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 30px 80px rgba(12, 47, 45, .25);
  max-height: 88vh;
  overflow: auto;
}
dialog::backdrop { background: rgba(14, 43, 42, .48); backdrop-filter: blur(3px); }
.dialog-content { padding: 22px; }

@media (max-width: 620px) {
  main { padding: 14px; }
  .topbar { padding-inline: 14px; }
  .brand-button small { display: none; }
  .module-grid, .stats-grid, .template-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
  .stat-card { padding: 12px 9px; }
  .stat-card strong { font-size: 24px; }
  .task-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .editor-row { grid-template-columns: minmax(0, 1fr) 78px auto; }
  .editor-labels { grid-template-columns: minmax(0, 1fr) 68px 68px auto; }
  [data-milestone-row] { grid-template-columns: minmax(0, 1fr) 68px 68px auto !important; }
  [data-deduction-form] { grid-template-columns: minmax(0, 1fr) 72px !important; }
  [data-deduction-form] .danger-button { grid-column: 1 / -1; }
  .hero-card, .card, .setup-card { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

.simple-page { max-width: 650px; margin: 36px auto; padding: 20px; }
.activation-code { font-size: 1.5rem; }
