:root {
  --primary: #6E6188;
  --primary-hover: #4F4566;
  --bg: #F2F1F3;
  --surface: #FFFFFF;
  --border: #DEDCE1;
  --track: #E6E4E9;
  --text: #232127;
  --muted: #696670;
  --placeholder: #8C8893;
  --future-text: #98929F;
  --future-border: #D3D1D7;
  --me-bg: #ECEAEF;
  --me-border: #CFCAD8;
  --sage: #7E9A86;
  --sage-light: #D6E2D8;
  --sage-text: #4F6B58;
  --sage-pill-text: #2F4636;
  --sage-card: #F0F4F0;
  --sage-card-border: #D3DFD5;
  --dark: #232127;
  --dark-muted: #CFCAD6;
  --nav-h: 72px;
  --font: Inter, 'Noto Sans KR', system-ui, -apple-system, 'Apple SD Gothic Neo', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input { font-family: inherit; color: inherit; }
button { touch-action: manipulation; -webkit-appearance: none; appearance: none; margin: 0; }
button:disabled { cursor: default; }
a { color: var(--primary); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

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

.eyebrow { font-size: 13px; font-weight: 600; color: var(--primary); }
.muted { color: var(--muted); }

/* ---------- Welcome ---------- */
.welcome {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: calc(56px + env(safe-area-inset-top)) 20px calc(32px + env(safe-area-inset-bottom));
}
.welcome .intro { display: flex; flex-direction: column; gap: 6px; }
.welcome h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.welcome .meta { font-size: 14px; color: var(--muted); }
.section { display: flex; flex-direction: column; gap: 12px; }
.section-title { font-size: 15px; font-weight: 600; }
.names { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.name-btn {
  height: 48px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.name-btn[aria-pressed='true'] { background: var(--primary); border-color: var(--primary); color: #fff; }
.join { display: flex; flex-direction: column; gap: 10px; }
.join label { font-size: 15px; font-weight: 600; }
.join-row { display: flex; gap: 8px; }
.join-row input {
  flex: 1;
  min-width: 0;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0 14px;
  /* 16px keeps iOS Safari from zooming in when the field is focused. */
  font-size: 16px;
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}
.join-row input::placeholder { color: var(--placeholder); }
.join-row input:focus { outline: none; border-color: var(--primary); }
.btn-outline {
  height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--primary);
  background: var(--surface);
  color: var(--primary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.field-error { font-size: 13px; color: #A33A3A; }
.spacer { flex: 1; }
.welcome { min-height: 100vh; min-height: 100dvh; }
.cta-wrap { display: flex; flex-direction: column; gap: 12px; }
.cta {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.cta:disabled { background: var(--track); color: var(--muted); }
.footnote { font-size: 13px; color: var(--muted); text-align: center; }

@media (hover: hover) {
  .cta:not(:disabled):hover { background: var(--primary-hover); }
  .btn-outline:hover { border-color: var(--primary-hover); color: var(--primary-hover); }
  .name-btn[aria-pressed='true']:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
  a:hover { color: var(--primary-hover); }
}

/* ---------- Tabs (My check-ins, Everyone) ---------- */
.tab {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: calc(28px + env(safe-area-inset-top)) 16px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom));
}
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.head .titles { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.head h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.who {
  min-height: 44px;
  min-width: 44px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: right;
  flex-shrink: 0;
  max-width: 45%;
}
.who .who-name { font-size: 15px; font-weight: 600; color: var(--text); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .who-sub { font-size: 12px; color: var(--muted); }

.progress-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 18px;
  transition: background-color .3s, border-color .3s;
}
.progress-card.done { background: var(--sage-card); border-color: var(--sage-card-border); }
.ring { position: relative; width: 96px; height: 96px; flex-shrink: 0; }
.ring svg { display: block; }
.ring .bar { transition: stroke-dasharray .35s ease, stroke .3s; }
.ring .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .big { font-size: 28px; font-weight: 700; line-height: 1; }
.ring .of { font-size: 12px; color: var(--muted); margin-top: 2px; }
.progress-info { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.pill {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--sage-light);
  color: var(--sage-pill-text);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}
.status { font-size: 18px; font-weight: 700; line-height: 1.3; }
.week { font-size: 14px; color: var(--muted); }

.calendar { display: flex; flex-direction: column; gap: 6px; }
.cal-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.wd { text-align: center; font-size: 12px; font-weight: 500; color: var(--muted); padding-bottom: 2px; }
.day {
  width: 100%;
  height: 52px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  user-select: none;
  -webkit-user-select: none;
}
.day .num { font-size: 13px; font-weight: 600; line-height: 1; white-space: nowrap; }
.day.today { border: 2px solid var(--primary); }
.day.future { background: transparent; color: var(--future-text); border: 1px dashed var(--future-border); }
.day.checked { background: var(--primary); color: #fff; border: 1px solid var(--primary); }
.day:active:not(:disabled) { transform: scale(0.96); }
.bonus-row { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.bonus-row .day { width: 52px; flex-shrink: 0; }
.bonus-row .day .num { font-size: 12px; }
.bonus-note { font-size: 13px; color: var(--muted); }

/* ---------- Everyone ---------- */
.summary {
  background: var(--dark);
  color: #fff;
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.summary .label, .summary .sub { font-size: 13px; color: var(--dark-muted); }
.summary .total { font-size: 30px; font-weight: 700; line-height: 1.15; }
.rows { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.row.me { background: var(--me-bg); border-color: var(--me-border); }
.row-top { display: flex; align-items: center; gap: 10px; }
.rank { width: 20px; font-size: 13px; font-weight: 600; color: var(--muted); text-align: center; flex-shrink: 0; }
.row-name { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; }
.row-name .n { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; font-weight: 600; color: #fff; background: var(--primary); padding: 2px 7px; border-radius: 999px; flex-shrink: 0; }
.count { font-size: 14px; font-weight: 600; white-space: nowrap; color: var(--text); }
.count.done { color: var(--sage-text); }
.track { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; margin-left: 30px; }
.fill { height: 100%; border-radius: 4px; background: var(--primary); }
.fill.done { background: var(--sage); }
.empty { font-size: 14px; color: var(--muted); text-align: center; padding: 24px 0; }

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.nav-inner { max-width: 480px; margin: 0 auto; height: var(--nav-h); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-decoration: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
.nav-item[aria-current='page'] { color: var(--primary); font-weight: 600; }
@media (hover: hover) { .nav-item:hover { color: var(--primary-hover); } }

/* ---------- States ---------- */
.state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; min-height: 100vh; min-height: 100dvh; padding: 24px; text-align: center; }
.state p { margin: 0; color: var(--muted); font-size: 15px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--track); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--dark);
  color: #fff;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 12px;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .15);
}

@media (prefers-reduced-motion: reduce) {
  .ring .bar, .progress-card { transition: none; }
  .spinner { animation-duration: 2s; }
}
