:root {
  --bg: #fff9f6;
  --surface: #ffffff;
  --surface-soft: #fff1ec;
  --text: #2f2927;
  --muted: #817572;
  --line: #eadfdb;
  --primary: #ff8d7b;
  --primary-strong: #f56f5c;
  --accent: #fff0cb;
  --breast-accent: #fff2e9;
  --shadow: 0 10px 28px rgba(67, 44, 39, 0.08);
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="dark"] {
  --bg: #171413;
  --surface: #221e1c;
  --surface-soft: #2a2220;
  --text: #f9efeb;
  --muted: #b9aaa5;
  --line: #3b312e;
  --primary: #ff9d8e;
  --primary-strong: #ff806d;
  --accent: #493b24;
  --breast-accent: #332723;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { background: var(--bg); color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button, .quick-btn { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow {
  margin: 0 0 4px;
  color: var(--primary-strong);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: .12em;
}

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 16px calc(96px + var(--safe-bottom));
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 24px 2px 18px;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(1.55rem, 4vw, 2rem); line-height: 1.25; }
h2 { margin-bottom: 0; font-size: 1.25rem; }
h3 { margin-bottom: 8px; }
.topbar p:last-child { margin-bottom: 0; font-size: .93rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.icon-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  font-size: 1.25rem;
  display: grid;
  place-items: center;
}
.text-btn {
  border: 0;
  background: transparent;
  color: var(--primary-strong);
  font-weight: 800;
  cursor: pointer;
}
.profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.profile-avatar {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--surface-soft);
  font-size: 1.4rem;
}
.profile-copy { flex: 1; display: grid; gap: 2px; }
.profile-copy span { font-size: .84rem; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.summary-card {
  min-height: 118px;
  padding: 16px;
  display: grid;
  align-content: start;
  gap: 6px;
}
.summary-card .summary-icon { font-size: 1.3rem; }
.summary-label { color: var(--muted); font-size: .78rem; line-height: 1.3; overflow-wrap: anywhere; }
.summary-card strong { font-size: 1rem; line-height: 1.35; }
.summary-metric { display: grid; gap: 2px; align-content: start; }
.summary-metric .metric-top { display: block; white-space: normal; overflow-wrap: anywhere; }
.summary-metric .metric-bottom { display: block; white-space: normal; overflow-wrap: anywhere; }
.summary-metric .metric-bottom.soft { color: var(--text); }
.feed-breakdown { gap: 4px; font-size: .92rem !important; }
.feed-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; line-height: 1.35; }
.feed-row > span:first-child { color: var(--muted); font-size: .8rem; font-weight: 700; }
.feed-row > span:last-child { white-space: nowrap; font-weight: 800; }
.stat-breakdown { display: grid; gap: 5px; font-size: 1rem !important; }
.accent-card { background: linear-gradient(145deg, var(--surface), var(--accent)); }
.breast-total-card { background: linear-gradient(145deg, var(--surface), var(--breast-accent)); }
.sleep-total-card { background: linear-gradient(145deg, var(--surface), var(--surface-soft)); }

.secondary-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.mini-summary-card {
  min-height: 86px;
  padding: 13px 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "icon label" "icon value";
  column-gap: 10px;
  align-content: center;
  align-items: center;
}
.mini-summary-icon { grid-area: icon; font-size: 1.18rem; }
.mini-summary-card .summary-label { grid-area: label; align-self: end; }
.mini-summary-value {
  grid-area: value;
  min-width: 0;
  font-size: .92rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.mini-detail {
  display: grid;
  gap: 1px;
}
.mini-detail .mini-top {
  display: block;
  font-weight: 800;
  white-space: nowrap;
}
.mini-detail .mini-bottom {
  display: block;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.memo-preview {
  display: grid;
  gap: 1px;
  min-width: 0;
}
.memo-preview .memo-time {
  display: block;
  white-space: nowrap;
}
.memo-preview .memo-text {
  display: block;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timers-stack { display: grid; gap: 10px; margin-top: 12px; }
.timer-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.timer-card .timer-copy { flex: 1; min-width: 0; }
.timer-title { display: block; font-weight: 800; }
.timer-value { display: block; margin-top: 2px; font-variant-numeric: tabular-nums; font-size: 1.15rem; }
.timer-actions { display: flex; gap: 6px; }
.small-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 9px 11px;
  cursor: pointer;
  font-weight: 700;
  font-size: .82rem;
}
.small-btn.danger { color: #d9534f; }

.section-block { margin-top: 26px; }
.quick-record-section { margin-top: 14px; }
.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.quick-btn {
  min-height: 108px;
  padding: 13px 8px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  cursor: pointer;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  box-shadow: 0 6px 18px rgba(67,44,39,.045);
}
.quick-btn:active { transform: translateY(1px) scale(.99); }
.quick-btn > span { font-size: 1.35rem; }
.quick-btn strong { font-size: .88rem; }
.quick-btn small { color: var(--muted); font-size: .67rem; line-height: 1.2; }
.pill {
  min-width: 48px;
  padding: 6px 10px;
  text-align: center;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--primary-strong);
  font-size: .78rem;
  font-weight: 800;
}

.timeline { display: grid; gap: 9px; }
.empty-state {
  min-height: 96px;
  place-items: center;
  align-content: center;
  padding: 22px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 18px;
  text-align: center;
}
.timeline-item {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.timeline-time { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline-main { min-width: 0; }
.timeline-main strong { display: block; margin-bottom: 3px; font-size: .92rem; }
.timeline-main span { display: block; color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline-actions { display: flex; gap: 4px; }
.tiny-btn { border: 0; background: transparent; cursor: pointer; padding: 7px; border-radius: 10px; color: var(--muted); }

.view { display: none; }
.view.active { display: block; }
.bottom-nav {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  width: min(calc(100% - 24px), 520px);
  padding: 8px 10px calc(8px + var(--safe-bottom));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: 0 14px 40px rgba(50,35,30,.14);
  backdrop-filter: blur(16px);
}
.nav-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 8px 6px;
  border-radius: 16px;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 2px;
}
.nav-btn span { font-size: 1.08rem; }
.nav-btn small { font-size: .7rem; }
.nav-btn.active { background: var(--surface-soft); color: var(--primary-strong); font-weight: 800; }

.calendar-shell { padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.calendar-header { display: grid; grid-template-columns: 42px 1fr 42px; align-items: center; gap: 8px; }
.calendar-title-wrap { text-align: center; }
.weekday-row, .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.weekday-row { margin-top: 16px; color: var(--muted); font-size: .72rem; text-align: center; }
.calendar-grid { margin-top: 7px; }
.day-cell {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--text);
}
.day-cell.muted-day { color: color-mix(in srgb, var(--muted) 40%, transparent); cursor: default; }
.day-cell.today { outline: 1px solid var(--primary); }
.day-cell.selected { background: var(--surface-soft); color: var(--primary-strong); font-weight: 800; }
.day-cell.has-record::after {
  content: "";
  position: absolute;
  bottom: 7px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--primary);
}
.select {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: .8rem;
}
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 14px; }
.stat-card { min-height: 120px; padding: 16px; display: grid; gap: 6px; align-content: start; }
.stat-card > span { font-size: 1.35rem; }
.stat-card small { color: var(--muted); }
.stat-card strong { font-size: 1.25rem; }
.stat-detail { display: grid; gap: 4px; font-size: 1rem !important; }
.stat-top { font-weight: 800; }
.stat-bottom { font-size: .95rem; line-height: 1.35; overflow-wrap: anywhere; }
.stat-memo .stat-bottom {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  line-height: 1.4;
  max-height: 2.8em;
  word-break: break-all;
  overflow-wrap: anywhere;
}
.info-card { padding: 18px; }
.info-card p { color: var(--muted); margin-bottom: 0; line-height: 1.6; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(20,14,12,.46);
  backdrop-filter: blur(3px);
}
.sheet {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 760px);
  max-height: 88vh;
  overflow-y: auto;
  padding: 10px 18px calc(22px + var(--safe-bottom));
  border-radius: 28px 28px 0 0;
  background: var(--bg);
  box-shadow: 0 -18px 50px rgba(20,14,12,.18);
}
.sheet-handle { width: 44px; height: 5px; border-radius: 999px; background: var(--line); margin: 0 auto 12px; }
.sheet-header { display: flex; justify-content: space-between; gap: 16px; align-items: start; margin-bottom: 18px; }
.sheet-form { display: grid; gap: 13px; }
.field { display: grid; gap: 7px; }
.field > span { font-size: .83rem; font-weight: 800; }
.field em { font-style: normal; color: var(--muted); font-weight: 500; }
.field input, .field textarea, .field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.field textarea { min-height: 94px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
.segmented { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.segmented.three { grid-template-columns: repeat(3, 1fr); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: grid; place-items: center; min-height: 44px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); cursor: pointer; font-weight: 700; font-size: .84rem; }
.segmented input:checked + span { border-color: var(--primary); background: var(--surface-soft); color: var(--primary-strong); }
.primary-btn {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: 16px;
  background: var(--primary-strong);
  color: white;
  font-weight: 900;
  cursor: pointer;
  margin-top: 4px;
}
.secondary-btn {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.toast {
  position: fixed;
  z-index: 70;
  left: 50%;
  bottom: calc(92px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 11px 15px;
  border-radius: 14px;
  background: #2d2927;
  color: white;
  font-size: .82rem;
  box-shadow: var(--shadow);
}

@media (max-width: 520px) {
  .app-shell { padding-inline: 12px; }
  .quick-grid { grid-template-columns: repeat(4, 1fr); gap: 7px; }
  .quick-btn { min-height: 96px; padding-inline: 4px; }
  .quick-btn small { font-size: .61rem; }
  .summary-card { min-height: 108px; padding: 14px; }
  .timeline-item { grid-template-columns: 48px 1fr auto; padding-inline: 12px; }
}

@media (min-width: 680px) {
  .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .secondary-summary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .quick-grid { grid-template-columns: repeat(8, 1fr); }
}
