@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700;900&family=ZCOOL+XiaoWei&display=swap');

:root {
  --ink: #1a2b2c;
  --muted: #4a5f61;
  --paper: #f2ede4;
  --paper-2: #e8e0d2;
  --brand: #0e5a60;
  --brand-deep: #0a3f44;
  --sun: #e07a3a;
  --sun-soft: #f4a261;
  --card-health: #d7efe2;
  --card-health-ink: #1b5c38;
  --card-community: #d8e8f8;
  --card-community-ink: #1a4d7a;
  --card-benefit: #f7e2cf;
  --card-benefit-ink: #8a4a18;
  --card-emergency: #f8d9d5;
  --card-emergency-ink: #9b2b22;
  --card-companion: #efe4cf;
  --card-companion-ink: #6d5324;
  --card-fraud: #f0d8e3;
  --card-fraud-ink: #7a2f4d;
  --card-life: #d5efec;
  --card-life-ink: #175e58;
  --card-family: #e4dff2;
  --card-family-ink: #46386e;
  --safe: #dceee8;
  --danger-bg: #f8e4e1;
  --shadow-soft: 0 10px 28px rgba(26, 43, 44, 0.08);
  --radius: 22px;
  --nav-h: 76px;
  --header-h: 72px;
  --font-display: 'ZCOOL XiaoWei', 'Noto Sans TC', serif;
  --font-body: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(14, 90, 96, 0.12), transparent 55%),
    radial-gradient(900px 400px at 100% 0%, rgba(224, 122, 58, 0.10), transparent 50%),
    linear-gradient(180deg, #f7f3ec 0%, var(--paper) 45%, #ebe4d8 100%);
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(var(--nav-h) + 110px + env(safe-area-inset-bottom));
  font-size: 18px;
}

button, input, textarea, select {
  font: inherit;
}

a { color: var(--brand); }

.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--header-h);
  padding: 12px 16px;
  background: rgba(242, 237, 228, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(26, 43, 44, 0.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--brand);
  display: grid;
  place-items: center;
  color: #fff;
  font-family: var(--font-display);
  font-size: 22px;
  flex-shrink: 0;
}

.brand-text h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1.1;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 15px;
  color: var(--muted);
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 14px;
  background: var(--paper-2);
  color: var(--brand-deep);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 20px;
}

.icon-btn:active { transform: scale(0.96); }

/* Hero welcome */
.hero {
  padding: 18px 16px 8px;
}

.hero-card {
  position: relative;
  overflow: hidden;
  border-radius: 28px;
  padding: 22px 20px 20px;
  background:
    linear-gradient(135deg, rgba(14, 90, 96, 0.95), rgba(10, 63, 68, 0.92)),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 40c10 0 10-10 20-10s10 10 20 10 10-10 20-10' fill='none' stroke='%23ffffff' stroke-opacity='0.08' stroke-width='2'/%3E%3C/svg%3E");
  color: #fff;
  min-height: 148px;
  animation: fadeUp 0.55s ease both;
}

.hero-card::after {
  content: '';
  position: absolute;
  right: -20px;
  bottom: -30px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(244, 162, 97, 0.28);
}

.hero-kicker {
  font-size: 17px;
  opacity: 0.85;
  margin: 0 0 6px;
}

.hero-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 400;
  line-height: 1.15;
  max-width: 12ch;
}

.hero-sub {
  margin: 10px 0 0;
  font-size: 18px;
  line-height: 1.45;
  opacity: 0.92;
  max-width: 28ch;
}

.hero-actions {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  position: relative;
  z-index: 1;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 15px 22px;
  font-size: 19px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.15s ease, background 0.2s ease;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--sun);
  color: #fff;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.28);
}

.btn-solid {
  background: var(--brand);
  color: #fff;
}

  .btn-danger {
  background: #c0392b;
  color: #fff;
}

.btn-block {
  width: 100%;
  justify-content: center;
  min-height: 56px;
  border-radius: 16px;
}

/* Module grid */
.section {
  padding: 8px 16px 24px;
}

.section-title {
  margin: 8px 0 14px;
  font-size: 22px;
  font-weight: 700;
  color: var(--brand-deep);
}

.module-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.module-card {
  border: 1.5px solid rgba(26, 43, 44, 0.06);
  border-radius: var(--radius);
  min-height: 148px;
  padding: 18px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-soft);
  animation: fadeUp 0.5s ease both;
  position: relative;
  overflow: hidden;
}

.module-card:nth-child(1) { animation-delay: 0.05s; background: var(--card-health); color: var(--card-health-ink); }
.module-card:nth-child(2) { animation-delay: 0.1s; background: var(--card-community); color: var(--card-community-ink); }
.module-card:nth-child(3) { animation-delay: 0.15s; background: var(--card-benefit); color: var(--card-benefit-ink); }
.module-card:nth-child(4) { animation-delay: 0.2s; background: var(--card-emergency); color: var(--card-emergency-ink); }
.module-card:nth-child(5) { animation-delay: 0.25s; background: var(--card-companion); color: var(--card-companion-ink); }
.module-card:nth-child(6) { animation-delay: 0.3s; background: var(--card-fraud); color: var(--card-fraud-ink); }
.module-card:nth-child(7) { animation-delay: 0.35s; background: var(--card-life); color: var(--card-life-ink); }
.module-card:nth-child(8) { animation-delay: 0.4s; background: var(--card-family); color: var(--card-family-ink); }

.module-card::before {
  content: '';
  position: absolute;
  inset: auto -20% -40% auto;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
}

.module-card:active { transform: scale(0.98); }

.module-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 800;
}

.module-name {
  font-size: 24px;
  font-weight: 800;
  margin: 0;
  line-height: 1.2;
}

.module-desc {
  margin: 6px 0 0;
  font-size: 15px;
  opacity: 0.85;
  font-weight: 600;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 252, 247, 0.96);
  border-top: 1px solid rgba(26, 43, 44, 0.08);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  max-width: 560px;
  margin: 0 auto;
}

.nav-item {
  border: none;
  background: transparent;
  border-radius: 16px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
}

.nav-item span.icon { font-size: 24px; line-height: 1; }
.nav-item.active {
  color: var(--brand);
  background: rgba(14, 90, 96, 0.08);
}

/* Floating 小暖 — center, prominent */
.xiaonuan-fab {
  position: fixed;
  left: 50%;
  right: auto;
  bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom));
  z-index: 60;
  width: 92px;
  height: 92px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: linear-gradient(145deg, #ffb06a, #e07a3a 55%, #d4652a);
  color: #fff;
  font-weight: 900;
  font-size: 20px;
  line-height: 1.1;
  box-shadow:
    0 0 0 6px rgba(224, 122, 58, 0.18),
    0 14px 32px rgba(224, 122, 58, 0.45);
  cursor: pointer;
  display: grid;
  place-items: center;
  transform: translateX(-50%);
  animation: pulseSoft 2.2s ease-in-out infinite;
}

.xiaonuan-fab.listening {
  background: linear-gradient(145deg, #e86a5c, #c0392b);
  box-shadow:
    0 0 0 8px rgba(192, 57, 43, 0.22),
    0 14px 32px rgba(192, 57, 43, 0.45);
  animation: pulseHard 1s ease-in-out infinite;
}

.xiaonuan-fab small {
  display: block;
  font-size: 12px;
  font-weight: 700;
  opacity: 0.95;
  margin-top: 2px;
}

/* Panels / views */
.view { display: none; padding-bottom: 24px; }
.view.active { display: block; animation: fadeUp 0.35s ease both; }

.panel {
  margin: 12px 16px;
  background: rgba(255, 252, 247, 0.92);
  border: 1px solid rgba(26, 43, 44, 0.06);
  border-radius: 20px;
  padding: 16px;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 28px;
  font-family: var(--font-display);
  font-weight: 400;
}

.panel h3 {
  margin: 16px 0 8px;
  font-size: 20px;
}

.panel p, .panel li {
  font-size: 18px;
  line-height: 1.55;
  color: var(--ink);
}

.muted { color: var(--muted); font-size: 16px; }

.stack { display: flex; flex-direction: column; gap: 10px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 15px;
  font-weight: 700;
  color: var(--brand-deep);
}

.field input, .field textarea, .field select {
  min-height: 52px;
  border-radius: 14px;
  border: 1.5px solid rgba(14, 90, 96, 0.22);
  background: #fff;
  padding: 12px 14px;
  font-size: 17px;
}

.field textarea { min-height: 100px; resize: vertical; }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: none;
  background: var(--safe);
  color: var(--brand-deep);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.chip:active { background: rgba(14, 90, 96, 0.18); }

.list-card {
  background: #fff;
  border-radius: 16px;
  padding: 14px;
  border: 1px solid rgba(26, 43, 44, 0.06);
}

.list-card + .list-card { margin-top: 8px; }

.list-card strong { display: block; font-size: 20px; margin-bottom: 4px; }
.list-card { font-size: 17px; }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--safe);
  color: var(--brand);
}

.badge.warn { background: #fff1d6; color: #9a5b00; }
.badge.danger { background: var(--danger-bg); color: var(--card-emergency-ink); }

/* Chat / voice sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(14, 30, 32, 0.45);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  max-width: 560px;
  margin: 0 auto;
  background: #fffdf9;
  border-radius: 28px 28px 0 0;
  max-height: min(86vh, 720px);
  transform: translateY(110%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

.sheet.open { transform: translateY(0); }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 8px;
  border-bottom: 1px solid rgba(26, 43, 44, 0.06);
}

.sheet-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 400;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: 88%;
  padding: 14px 16px;
  border-radius: 18px;
  font-size: 19px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.bubble.bot {
  align-self: flex-start;
  background: rgba(14, 90, 96, 0.1);
  color: var(--ink);
  border-bottom-left-radius: 6px;
}

.bubble.user {
  align-self: flex-end;
  background: var(--brand);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.bubble .meta {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  opacity: 0.7;
}

.chat-input-bar {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  padding: 12px 14px 16px;
  border-top: 1px solid rgba(26, 43, 44, 0.06);
  background: #fff;
}

.chat-input-bar input {
  min-height: 52px;
  border-radius: 14px;
  border: 1.5px solid rgba(14, 90, 96, 0.22);
  padding: 0 14px;
  font-size: 17px;
}

.chat-input-bar .btn {
  min-width: 52px;
  justify-content: center;
  border-radius: 14px;
  padding: 0 14px;
}

.voice-status {
  padding: 0 16px 8px;
  font-size: 14px;
  color: var(--muted);
  min-height: 20px;
}

/* Emergency overlay */
.sos-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #8f1e16;
  color: #fff;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.sos-overlay.open { display: flex; animation: fadeUp 0.25s ease both; }

.sos-overlay h2 {
  font-family: var(--font-display);
  font-size: 42px;
  margin: 0 0 12px;
  font-weight: 400;
}

.sos-overlay p { font-size: 18px; line-height: 1.5; max-width: 28ch; }

.sos-actions {
  margin-top: 24px;
  width: min(100%, 360px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sos-actions .btn {
  background: #fff;
  color: #8f1e16;
  justify-content: center;
  min-height: 58px;
  border-radius: 16px;
}

.sos-actions .btn.cancel {
  background: transparent;
  color: #fff;
  border: 1.5px solid rgba(255,255,255,0.5);
}

/* Install banner */
.install-banner {
  display: none;
  margin: 0 16px 12px;
  padding: 14px 16px;
  border-radius: 18px;
  background: #fff;
  border: 1px solid rgba(14, 90, 96, 0.15);
  box-shadow: var(--shadow-soft);
  align-items: center;
  gap: 12px;
}

.install-banner.show { display: flex; }

.install-banner p {
  margin: 0;
  font-size: 15px;
  flex: 1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 90px);
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s ease;
  z-index: 120;
  max-width: 90%;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Family portal tweaks */
.family-shell .hero-card {
  background: linear-gradient(135deg, #5b4d8a, #3d3460);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat {
  background: #fff;
  border-radius: 16px;
  padding: 14px;
  border: 1px solid rgba(26, 43, 44, 0.06);
}

.stat .num {
  font-size: 28px;
  font-weight: 800;
  color: var(--brand);
  line-height: 1;
}

.stat .label {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

.view[data-view="module"] {
  padding-top: 0;
}

.back-row {
  position: sticky;
  top: var(--header-h);
  z-index: 35;
  padding: 10px 16px;
  margin: 0;
  background: rgba(242, 237, 228, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(26, 43, 44, 0.08);
}

.back-btn {
  border: none;
  background: transparent;
  color: var(--brand);
  font-size: 20px;
  font-weight: 800;
  min-height: 48px;
  padding: 10px 4px;
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.media-preview {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 14px;
  background: #ddd;
}

.hidden { display: none !important; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulseSoft {
  0%, 100% {
    transform: translateX(-50%) scale(1);
    box-shadow:
      0 0 0 6px rgba(224, 122, 58, 0.18),
      0 14px 32px rgba(224, 122, 58, 0.45);
  }
  50% {
    transform: translateX(-50%) scale(1.06);
    box-shadow:
      0 0 0 10px rgba(224, 122, 58, 0.12),
      0 18px 38px rgba(224, 122, 58, 0.55);
  }
}

@keyframes pulseHard {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.1); }
}

@media (min-width: 700px) {
  .module-grid { gap: 16px; }
  .module-card { min-height: 160px; }
  .hero-title { font-size: 44px; }
  .module-name { font-size: 26px; }
}

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