:root {
  --bg: #eef5fb;
  --card: #ffffff;
  --ink: #12212e;
  --muted: #6b7f92;
  --blue: #1b8ef2;
  --blue-dark: #0f6fc4;
  --blue-soft: #e3f1fd;
  --line: #e0eaf3;
  --ok: #12b886;
  --danger: #e03131;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; }

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--blue-dark);
  outline-offset: 2px;
}

.app { max-width: 480px; margin: 0 auto; min-height: 100vh; }

.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* 상단바 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(238, 245, 251, 0.93);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; margin: 0; text-align: center; font-size: 17px; font-weight: 700; }
.topbar-side { width: 40px; height: 40px; flex: none; }
.icon-btn {
  width: 40px; height: 40px; flex: none;
  border: none; background: transparent; border-radius: 12px;
  font-size: 20px; line-height: 1; color: var(--ink); cursor: pointer;
}
.icon-btn:active { background: var(--blue-soft); }

.content { padding: 16px 16px 44px; display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(18, 33, 46, 0.05);
}
.card-title { margin: 0 0 12px; font-size: 15px; font-weight: 700; }

/* S1 홈 */
.card-label {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; min-height: 56px;
}
.card-label-main { font-size: 17px; font-weight: 700; }
.card-label-sub { font-size: 13px; color: var(--muted); }

.card-counter {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; min-height: 210px; text-align: center;
}
.counter { display: flex; align-items: baseline; gap: 6px; color: var(--blue); transition: transform 0.12s ease; }
.counter.pop { transform: scale(1.12); }
.counter-num { font-size: 76px; font-weight: 800; line-height: 1; letter-spacing: -2px; }
.counter-unit { font-size: 22px; font-weight: 700; }
.goal-text { margin: 0; font-size: 14px; color: var(--muted); }
.progress { width: 100%; height: 10px; border-radius: 99px; background: var(--blue-soft); overflow: hidden; }
.progress-fill { width: 0; height: 100%; border-radius: 99px; background: var(--blue); transition: width 0.25s ease; }
.achieved { margin: 0; font-size: 14px; font-weight: 800; color: var(--ok); }
.card-counter.done .counter { color: var(--ok); }
.card-counter.done .progress-fill { background: var(--ok); }

.btn {
  width: 100%; min-height: 60px;
  border: none; border-radius: 16px; padding: 16px;
  font-size: 18px; font-weight: 700; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-secondary { background: #fff; color: var(--blue); border: 1.5px solid var(--blue); }

/* S2 기록 */
.tabs { display: flex; gap: 4px; padding: 4px; background: #e2ecf5; border-radius: 14px; }
.tab {
  flex: 1; border: none; background: transparent;
  padding: 11px 8px; border-radius: 11px;
  font-size: 14px; font-weight: 700; color: var(--muted); cursor: pointer;
}
.tab.active { background: #fff; color: var(--blue); box-shadow: 0 1px 3px rgba(18, 33, 46, 0.12); }

.tabpanel { display: none; flex-direction: column; gap: 12px; }
.tabpanel.active { display: flex; }

.list-head { display: flex; align-items: center; justify-content: space-between; }
.list-head-title { font-size: 14px; font-weight: 700; color: var(--muted); }
.link-btn {
  border: none; background: transparent; color: var(--blue);
  font-size: 14px; font-weight: 700; padding: 6px 2px; cursor: pointer; text-decoration: underline;
}

.log-list {
  list-style: none; margin: 0; padding: 0;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.log-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.log-item:last-child { border-bottom: none; }
.log-date { font-size: 15px; font-weight: 600; }
.log-cups { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.log-cups strong { font-size: 18px; color: var(--ink); }
.chk { color: var(--ok); font-weight: 800; }

.empty {
  margin: 0; padding: 44px 16px; text-align: center;
  color: var(--muted); font-size: 14px; line-height: 1.7;
  background: var(--card); border: 1px dashed #cfdced; border-radius: var(--radius);
}

.chart-card { min-height: 240px; }
.chart-head { display: flex; justify-content: space-between; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.chart-plot { position: relative; height: 160px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 100%; }
.bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.bar-count { height: 18px; line-height: 18px; font-size: 11px; color: var(--muted); }
.bar {
  width: 100%; max-width: 30px; min-height: 3px;
  border-radius: 7px 7px 3px 3px;
  background: var(--blue-soft); border: 1px solid #cfe6fb;
}
.bar.filled { background: var(--blue); border-color: var(--blue); }
.bar.done { background: var(--ok); border-color: var(--ok); }
.goal-rule { position: absolute; left: 0; right: 0; bottom: 0; border-top: 2px dashed var(--ok); pointer-events: none; }
.goal-rule span {
  position: absolute; right: 0; top: -16px;
  font-size: 11px; font-weight: 700; color: var(--ok);
  background: var(--card); padding: 0 4px;
}
.chart-labels { display: flex; gap: 6px; margin-top: 8px; }
.chart-labels span { flex: 1; text-align: center; font-size: 12px; color: var(--muted); }
.chart-labels span.today { color: var(--blue); font-weight: 800; }
.chart-note { margin: 0; font-size: 12px; color: var(--muted); text-align: center; }

/* S3 설정 */
.stepper { display: flex; align-items: center; gap: 10px; }
.step-btn {
  width: 52px; height: 52px; flex: none;
  border: 1px solid var(--line); border-radius: 14px; background: #f5f9fd;
  font-size: 22px; font-weight: 700; color: var(--blue); cursor: pointer;
}
.stepper input {
  flex: 1; min-width: 0; height: 52px;
  text-align: center; font-size: 24px; font-weight: 800;
  border: 1px solid var(--line); border-radius: 14px; background: #fff; color: var(--ink);
}
.hint { margin: 8px 0 12px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.hint.error { color: var(--danger); font-weight: 700; }
.today-goal { margin: 12px 0 0; font-size: 13px; color: var(--muted); text-align: center; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 16px; font-weight: 600; }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 2; }
.slider { position: absolute; inset: 0; background: #cbd8e4; border-radius: 99px; transition: background 0.18s ease; }
.slider::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 26px; height: 26px; background: #fff; border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); transition: transform 0.18s ease;
}
.switch input:checked + .slider { background: var(--blue); }
.switch input:checked + .slider::after { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--blue-dark); outline-offset: 2px; }

.times-title { display: block; margin: 16px 0 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: #f5f9fd; color: var(--muted);
  border-radius: 99px; padding: 8px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip.on { background: var(--blue); border-color: var(--blue); color: #fff; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  max-width: 88%; padding: 12px 16px;
  background: #12212e; color: #fff; border-radius: 12px;
  font-size: 14px; line-height: 1.5; text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); z-index: 20;
}

@media (min-width: 520px) {
  .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .counter-num { font-size: 88px; }
}

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