:root {
  --bg: #ffffff;
  --surface: #f5f6f8;
  --text: #191b1f;
  --muted: #9097a0;
  --line: #eceef1;
  --accent: #191b1f;
  --danger: #e5484d;
  --tab-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316;
    --surface: #1d1f23;
    --text: #eceef1;
    --muted: #7d848d;
    --line: #26292e;
    --accent: #eceef1;
    --danger: #f2555a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
/* 월별 배경 그림이 body 뒤에 가려지지 않게 body는 투명 (html 배경이 화면 전체를 칠함) */
body { background: transparent; }
/* 더블탭 확대를 막는다 */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 15px;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select { font: inherit; color: inherit; }

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  padding: env(safe-area-inset-top) 16px calc(var(--tab-h) + 24px + env(safe-area-inset-bottom));
}
.view { display: none; }
.view.active { display: block; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* 상단 바 */
.topbar { display: flex; align-items: center; gap: 4px; padding: 16px 0 8px; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 700; }
.spacer { flex: 1; }
.icon-btn { width: 32px; height: 32px; font-size: 22px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface); }
.chip { padding: 5px 11px; border-radius: 999px; background: var(--surface); font-size: 13px; }

/* 달력 */
.weekdays, .calendar { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
.weekdays { font-size: 12px; color: var(--muted); padding: 4px 0; }
.weekdays span:first-child { color: var(--danger); }
.day {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 0 8px; border-radius: 10px;
}
.day.other { opacity: 0.35; }
.day .badge {
  width: 26px; height: 26px; border-radius: 9px;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  background: var(--surface); color: var(--muted);
}
/* 완료한 카테고리 색으로 채운 칸: 남은 개수나 ✓를 흰 글자로 */
.day .badge.filled { color: #fff; text-shadow: 0 0 2px rgba(0, 0, 0, 0.35); }
.day .badge.filled.plain { color: var(--bg); text-shadow: none; }
.day .num { font-size: 12px; line-height: 1; padding: 3px 6px; border-radius: 999px; }
.day.today .num { font-weight: 800; }
.day.selected .num { background: var(--accent); color: var(--bg); }

.day-head { display: flex; align-items: baseline; gap: 8px; margin: 18px 0 6px; }
.day-head h2 { margin: 0; font-size: 16px; }

/* 카테고리 그룹 */
.group { margin-top: 14px; }
.cat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface); font-weight: 700; font-size: 14px;
}
.cat-pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.cat-pill .plus { margin-left: 4px; font-size: 16px; color: var(--muted); }

.todo { display: flex; align-items: center; gap: 10px; padding: 9px 2px; }
.check {
  flex: none; width: 22px; height: 22px; border-radius: 7px;
  border: 2px solid var(--c); display: grid; place-items: center;
  color: #fff; font-size: 13px; font-weight: 800; line-height: 1;
  padding: 0; -webkit-appearance: none; appearance: none;
}
/* 완료하면 테두리를 투명하게 하고 같은 크기의 칸 전체를 채워, 테두리와 채움이 어긋나 겹쳐 보이지 않게 한다 */
.todo.done .check { background: var(--c); border-color: transparent; background-clip: border-box; }
.todo .text { flex: 1; word-break: break-word; }
.todo.done .text { color: var(--muted); }
.todo .meta { font-size: 12px; color: var(--muted); }
.todo.inactive { opacity: 0.4; }
.todo .more { color: var(--muted); padding: 2px 8px; font-size: 18px; }

.inline-add { display: flex; gap: 8px; align-items: center; padding: 6px 2px; }
.inline-add input {
  flex: 1; border: none; border-bottom: 1.5px solid var(--text);
  background: transparent; padding: 6px 0; outline: none;
}
.empty-hint { color: var(--muted); text-align: center; padding: 28px 0; }

/* 하단 탭 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; justify-content: center;
  background: var(--bg); border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; max-width: 173px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; color: var(--muted);
}
.tabbar button span { font-size: 20px; line-height: 1.1; filter: grayscale(0.6); opacity: 0.55; transition: opacity 0.15s; }
/* 이모지 아이콘은 색을 바꿀 수 없어서, 고른 탭만 원래 색으로 또렷하게 보인다 */
.tabbar button.active span { filter: none; opacity: 1; }
.tabbar button.active { color: var(--text); font-weight: 700; }

/* 하단 시트 */
.backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35);
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 10;
}
.backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 50%; bottom: 0; width: 100%; max-width: 520px;
  transform: translate(-50%, 100%); transition: transform 0.22s ease;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  z-index: 11; max-height: 85vh; overflow-y: auto;
}
.sheet.open { transform: translate(-50%, 0); }
.sheet .grabber { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 4px 0 14px; font-size: 17px; word-break: break-word; }
.sheet .grid-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sheet .act {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 4px; border-radius: 12px; background: var(--surface); font-size: 13px;
}
.sheet .act span { font-size: 20px; }
.sheet .act.danger { color: var(--danger); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input[type="text"], .field input[type="date"], .field input[type="time"], .field select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { padding: 7px 12px; border-radius: 999px; background: var(--surface); font-size: 13px; }
.seg button.on { background: var(--accent); color: var(--bg); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; }
.swatch.on { border-color: var(--text); }
.primary {
  width: 100%; padding: 13px; border-radius: 12px; margin-top: 6px;
  background: var(--accent); color: var(--bg); font-weight: 700;
}

/* 카테고리 관리 */
.cat-row { display: flex; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.cat-row .dot { width: 14px; height: 14px; border-radius: 50%; }
.cat-row .name { flex: 1; font-weight: 600; }
.wide-btn { width: 100%; padding: 13px; margin: 14px 0; border-radius: 12px; background: var(--surface); font-weight: 600; }
.row-btns { display: flex; gap: 8px; }
.ghost-btn {
  flex: 1; text-align: center; padding: 11px; border-radius: 10px;
  border: 1px solid var(--line); cursor: pointer; font-size: 14px;
}

/* 동기화 */
.sync-row { display: flex; flex-direction: column; gap: 4px; padding: 6px 2px 12px; }
#sync-box .row-btns { margin-bottom: 4px; }
#auth-form input[type="password"] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
#sync-box button.ghost-btn { background: none; }

/* 루틴 */
.routine-card {
  display: flex; align-items: center; gap: 12px; cursor: pointer;
  padding: 14px; margin-bottom: 10px; border-radius: 14px; background: var(--surface);
}
.routine-card .r-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; }
.routine-card .r-main { flex: 1; min-width: 0; }
.routine-card b { font-size: 16px; word-break: break-word; }
.r-prog { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--bg); }
.r-period { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* 카테고리 이모지 */
.emoji { font-size: 16px; line-height: 1; }
.cat-row .emoji { width: 22px; text-align: center; font-size: 18px; }
.routine-card .emoji { flex: none; font-size: 18px; }

/* 아이폰은 16px보다 작은 입력창을 누르면 화면을 확대하므로 입력창 글자를 16px로 둔다 */
input, select, textarea { font-size: 16px !important; }

/* 함께 보기 */
.chip.on { background: var(--accent); color: var(--bg); }
#share-box .cat-row .name { font-weight: 500; word-break: break-all; }
#share-box .cat-row .name .muted { display: block; font-weight: 400; }

/* 연간 목표 */
.goal { border-radius: 14px; background: var(--surface); margin-bottom: 10px; overflow: hidden; }
.goal-head { width: 100%; display: flex; align-items: center; gap: 8px; padding: 14px; text-align: left; }
.goal-name { font-weight: 700; flex: none; }
.goal-preview { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.goal.open .goal-name { flex: 1; }
.goal-arrow { color: var(--muted); flex: none; }
.goal-memo {
  display: block; width: calc(100% - 28px); margin: 0 14px 14px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
  font: inherit; line-height: 1.5; resize: vertical; min-height: 110px;
}
.goal-head .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; }
.goal-tools { display: flex; justify-content: flex-end; gap: 6px; padding: 0 14px 12px; }
.goal-tools .chip { background: var(--bg); }

/* 월별 배경 그림 (특정 계정·휴대폰에서만, app.js에서 켬). 글자가 잘 보이게 흐리게 깐다 */
#month-bg {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: center / cover no-repeat; opacity: 0; transition: opacity 0.3s;
}
#month-bg.on { opacity: 0.38; }
@media (prefers-color-scheme: dark) { #month-bg.on { opacity: 0.34; } }
/* 배경 그림이 켜져 있으면 아래 탭 바를 반투명하게 해서 그림이 비쳐 보이게 한다 */
#month-bg.on ~ .app .tabbar {
  background: rgba(255, 255, 255, 0.3);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border-top-color: rgba(0, 0, 0, 0.06);
}
@media (prefers-color-scheme: dark) {
  #month-bg.on ~ .app .tabbar { background: rgba(18, 19, 22, 0.3); border-top-color: rgba(255, 255, 255, 0.06); }
}
/* 아직 안 한 할 일은 글자를 두껍고 진하게 (배경 그림 위에서도 잘 보이게) */
.todo:not(.done) .text { font-weight: 600; color: var(--text); }
#month-bg.on ~ .app .todo:not(.done) .text { text-shadow: 0 0 3px var(--bg), 0 0 1px var(--bg); }
/* 요일 줄과 "0/2 완료" 현황은 진한 색으로 (배경 그림 위에서도 잘 보이게) */
.weekdays { color: var(--text); font-weight: 600; }
.weekdays span:first-child { color: var(--danger); }
#day-progress { color: var(--text); font-weight: 600; }
.r-noend { display: flex; align-items: center; gap: 8px; margin: -4px 0 14px; font-size: 14px; }
.r-noend input { width: 18px; height: 18px; }
