:root {
  --bg: #fff6ee;
  --surface: #ffffff;
  --surface-2: #fbede1;
  --text: #3b2f27;
  --muted: #8a7a6d;
  --line: #f0e0d2;
  --accent: #e8875f;
  --accent-text: #ffffff;
  --danger: #d9534f;
  --shadow: 0 2px 10px rgba(120, 80, 50, 0.08);
  --radius: 18px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1a18;
    --surface: #28231f;
    --surface-2: #332c27;
    --text: #f3e9e1;
    --muted: #b0a196;
    --line: #3d342e;
    --accent: #f0956c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }

/* ---------- 레이아웃 ---------- */
#main {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px calc(var(--tabbar-h) + 150px + env(safe-area-inset-bottom));
}
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  max-width: 640px; margin: 0 auto;
}
.baby-switch { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.baby-switch strong, .baby-switch select { font-size: 20px; font-weight: 700; }
.baby-switch select { border: none; background: transparent; padding: 0; }
.baby-switch small, .fam { color: var(--muted); font-size: 13px; white-space: nowrap; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar button {
  border: none; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 12px; color: var(--muted);
}
.tabbar button span { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabbar button.on { color: var(--text); font-weight: 700; }
.tabbar button.on span { filter: none; opacity: 1; }

/* ---------- 공통 요소 ---------- */
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin: 12px 0;
}
.card h3 { font-size: 16px; margin-bottom: 6px; }
.card h4 { font-size: 14px; margin: 14px 0 4px; color: var(--muted); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-head small { color: var(--muted); font-size: 12px; }
.page-title { font-size: 20px; margin: 12px 0 4px; }
.page-head { display: flex; justify-content: space-between; align-items: center; }
.help { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

.btn {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px;
  padding: 10px 16px; font-weight: 600; cursor: pointer; min-height: 44px;
}
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn.big { font-size: 18px; padding: 14px 28px; }
.icon-btn {
  border: none; background: var(--surface-2); width: 40px; height: 40px; border-radius: 50%;
  font-size: 20px; cursor: pointer;
}
.icon-btn:disabled { opacity: .3; }

.form .row { display: flex; gap: 8px; }
.form .row input { flex: 1; min-width: 0; }
input, select {
  border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; min-height: 44px; width: 100%;
}
.form .row .btn { flex: none; }
.field { display: block; margin: 10px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.choice { border: none; padding: 0; margin: 10px 0; }
.choice legend { font-size: 13px; color: var(--muted); margin-bottom: 4px; padding: 0; }
.choice label { display: inline-block; margin: 0 6px 6px 0; }
.choice input { position: absolute; opacity: 0; width: 0; height: 0; }
.choice span {
  display: inline-block; padding: 10px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); cursor: pointer;
}
.choice input:checked + span { background: var(--c, var(--accent)); border-color: transparent; color: #3b2f27; font-weight: 700; }
.choice input:focus-visible + span { outline: 2px solid var(--accent); }

/* ---------- 홈 ---------- */
.timers { display: grid; gap: 8px; margin: 8px 0; }
.timer {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--c) 35%, var(--surface)); box-shadow: var(--shadow);
}
.timer-icon { font-size: 28px; }
.timer-body { flex: 1; min-width: 0; }
.timer-label { font-size: 13px; }
.timer-clock { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }

.since-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.since { background: var(--surface); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); min-width: 0; }
.since-label { font-size: 12px; color: var(--muted); }
.since-val { font-size: 17px; font-weight: 800; margin: 2px 0; }
.since-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.quick-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; min-height: 68px;
  border: none; border-radius: 16px; cursor: pointer; font-size: 13px; font-weight: 600;
  background: color-mix(in srgb, var(--c) 30%, var(--surface));
}
.quick-btn .qi { font-size: 24px; }
.quick-btn:active { transform: scale(.96); }

.timeline { margin-top: 16px; }
.day-nav { display: flex; align-items: center; justify-content: space-between; }
.day-nav h2 { font-size: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { background: var(--surface); border-radius: 999px; padding: 4px 10px; font-size: 13px; box-shadow: var(--shadow); }
.tl { list-style: none; margin: 0; padding: 0; }
.tl li {
  display: grid; grid-template-columns: 74px 32px 1fr auto; align-items: center; gap: 6px;
  padding: 10px 8px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.tl time { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl .dot {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in srgb, var(--c) 45%, var(--surface)); font-size: 16px;
}
.tl .note { font-size: 13px; color: var(--muted); }
.tl .by { font-size: 12px; color: var(--muted); }
.live { font-style: normal; font-size: 12px; color: var(--accent); font-weight: 700; }

/* ---------- 음성 ---------- */
.voice-dock {
  position: fixed; left: 0; right: 0; z-index: 9;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; padding: 8px 12px;
}
.voice-dock[hidden] { display: none; }
.vd-log { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.bubble {
  max-width: 85%; padding: 8px 12px; border-radius: 16px; font-size: 14px; box-shadow: var(--shadow);
}
.bubble.me { align-self: flex-end; background: var(--surface-2); }
.bubble.bot { align-self: flex-start; background: var(--surface); }
.vd-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; border-radius: 999px;
  background: var(--surface); box-shadow: 0 4px 20px rgba(120, 80, 50, .18); border: 1px solid var(--line);
}
.vd-status { flex: 1; min-width: 0; }
.vd-text { font-size: 14px; font-weight: 600; }
.vd-text.state-command { color: var(--accent); }
.vd-text.state-denied { color: var(--danger); }
.vd-heard { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1em; }
.mic {
  width: 56px; height: 56px; border-radius: 50%; border: none; font-size: 24px; cursor: pointer;
  background: var(--accent); color: #fff; flex: none;
}
.mic.state-command, .mic.state-thinking { animation: pulse 1s ease-in-out infinite; }
.mic.state-speaking { background: #7fb7a8; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--accent) 25%, transparent); } }

.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .2s; cursor: pointer; }
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); }

/* ---------- 통계 / 성장 ---------- */
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; height: 150px; align-items: end; margin-top: 8px; }
.bar-col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; min-width: 0; }
.bar { width: 70%; border-radius: 6px 6px 0 0; min-height: 2px; }
.bar-val { font-size: 10px; color: var(--muted); white-space: nowrap; }
.bar-label { font-size: 11px; color: var(--muted); margin-top: 4px; }
.line-chart { width: 100%; height: auto; }
.line-chart .axis { font-size: 11px; fill: var(--muted); }
.gtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.gtable th, .gtable td { padding: 8px 4px; text-align: center; border-bottom: 1px solid var(--line); }
.gtable th { color: var(--muted); font-weight: 600; font-size: 12px; }
.gtable tr[data-action] { cursor: pointer; }

/* ---------- 설정 ---------- */
.invite { font-size: 32px; font-weight: 800; letter-spacing: 6px; text-align: center; padding: 12px; background: var(--bg); border-radius: 12px; margin-bottom: 10px; }
.members { padding-left: 18px; margin: 6px 0; }
.members small { color: var(--muted); }
.tips { padding-left: 18px; margin: 0; font-size: 14px; color: var(--muted); }
.tips li { margin: 4px 0; }

/* ---------- 시트 ---------- */
#sheet-root { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#sheet-root:empty { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); opacity: 0; transition: opacity .2s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto;
  max-height: 90vh; overflow-y: auto; background: var(--surface);
  border-radius: 22px 22px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .22s ease-out;
}
#sheet-root.open { pointer-events: auto; }
#sheet-root.open .sheet-backdrop { opacity: 1; }
#sheet-root.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.sheet-head h2 { flex: 1; font-size: 18px; }
.sheet-icon {
  font-size: 24px; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%;
  background: color-mix(in srgb, var(--c) 45%, var(--surface));
}
.sheet-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.sheet-actions .primary { flex: 1; }

/* ---------- 토스트 ---------- */
#toast {
  position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top)); z-index: 30;
  transform: translate(-50%, -150%); transition: transform .25s;
  background: #3b2f27; color: #fff; border-radius: 999px; padding: 10px 16px; font-size: 14px;
  display: flex; gap: 12px; align-items: center; max-width: calc(100vw - 32px);
}
#toast.show { transform: translate(-50%, 0); }
#toast button { border: none; background: none; color: #ffc9a8; font-weight: 700; cursor: pointer; padding: 0; }

/* ---------- 로그인 / 온보딩 ---------- */
.center { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px; text-align: center; }
.logo { font-size: 64px; }
.center h1 { font-size: 32px; }
.onboard { max-width: 440px; margin: 0 auto; padding: calc(24px + env(safe-area-inset-top)) 16px 40px; text-align: center; }
.onboard .card { text-align: left; }
.or { color: var(--muted); margin: 4px 0; }
.err { white-space: pre-wrap; font-size: 12px; color: var(--muted); max-width: 100%; }

@media (max-width: 360px) {
  .since-grid { grid-template-columns: 1fr 1fr; }
  .quick { grid-template-columns: repeat(3, 1fr); }
}
