:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e3e5e9;
  --border-strong: #cfd3da;
  --text: #1f2328;
  --muted: #7a818c;
  --primary: #2f6fed;
  --primary-text: #ffffff;
  --primary-soft: #e8efff;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --track: #e6e8ec;
  --work: #2f6fed;
  --personal: #12a37c;
  --study: #8a5cf5;
  --star: #f5a524;
  --focus: #1f2328;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04);
  --radius: 12px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --card: #181b21;
  --border: #2a2f38;
  --border-strong: #3a404b;
  --text: #e7e9ec;
  --muted: #9aa2ad;
  --primary: #4c86ff;
  --primary-text: #ffffff;
  --primary-soft: #1d2a45;
  --danger: #ff6b6f;
  --danger-soft: #3a1f22;
  --track: #2a2f38;
  --work: #5b92ff;
  --personal: #2fc496;
  --study: #a685ff;
  --star: #ffbf47;
  --focus: #e7e9ec;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd { font-family: inherit; }

.wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 22px 24px 48px;
  padding-top: max(22px, env(safe-area-inset-top));
  padding-bottom: max(48px, env(safe-area-inset-bottom));
}

.muted { color: var(--muted); }

/* ---------- 상단 */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; margin: 0; display: flex; align-items: center; gap: 10px; }
.pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 26px; padding: 0 10px; border-radius: 999px;
  background: var(--primary); color: var(--primary-text);
  font-size: 14px; font-weight: 600; letter-spacing: 0;
}
.top-right { display: flex; align-items: center; gap: 12px; }

.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; display: inline-block; }
.sync[data-state="syncing"] i { background: var(--star); animation: pulse 1s infinite; }
.sync[data-state="offline"] i { background: #9aa2ad; }
.sync[data-state="error"] i { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }

.switch {
  position: relative; width: 50px; height: 28px; border-radius: 999px;
  border: 0; background: var(--track); padding: 0; flex: none;
  transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .2s;
}
.switch[aria-checked="true"] { background: var(--primary); }
.switch[aria-checked="true"]::after { transform: translateX(22px); }

/* ---------- 진행률 */
.progress { margin-top: 18px; }
.progress-text { font-size: 15px; margin-bottom: 8px; }
.bar { height: 10px; border-radius: 999px; background: var(--track); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--primary); border-radius: 999px; transition: width .35s ease; }
.quote { text-align: center; color: var(--muted); font-style: italic; font-size: 14px; margin: 14px 0 0; }

/* ---------- 입력 */
.add { display: flex; gap: 10px; margin-top: 22px; }
.add input {
  flex: 1; min-width: 0; height: 50px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: 10px; background: var(--card);
}
.add select {
  height: 50px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--card); min-width: 84px; max-width: 120px;
}
input:focus, select:focus { outline: 2px solid var(--focus); outline-offset: -1px; }
button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.search {
  display: block; width: 100%; height: 44px; margin-top: 20px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: 10px; background: var(--card);
}

.btn {
  height: 50px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--card); font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:active { filter: brightness(.95); }
.btn.block { width: 100%; }
.btn.small { height: 36px; padding: 0 12px; font-size: 14px; font-weight: 500; }
.btn.danger-outline { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); background: transparent; }
.btn.danger-outline:disabled { opacity: .45; cursor: default; }

/* ---------- 필터 */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.filters button {
  height: 38px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--card); font-size: 14px; display: inline-flex; align-items: center; gap: 6px;
}
.filters button .n { font-size: 12px; color: var(--muted); }
.filters button kbd { font-size: 12px; color: var(--muted); }
.filters button.active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.filters button.active .n, .filters button.active kbd { color: rgba(255,255,255,.85); }

.list-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.hint { font-size: 12px; color: var(--muted); }

/* ---------- 목록 */
.list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.item {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 12px 12px 16px; min-height: 62px; box-shadow: var(--shadow);
  transition: background .2s, opacity .2s;
}
.item.flash { animation: flash 1.2s ease; }
@keyframes flash { 0% { background: var(--primary-soft); } 100% { background: var(--card); } }
.item.starred { border-color: color-mix(in srgb, var(--star) 55%, var(--border)); }

.check { display: flex; align-items: center; flex: none; padding: 4px; margin: -4px; cursor: pointer; }
.check input {
  appearance: none; -webkit-appearance: none; margin: 0;
  width: 20px; height: 20px; border: 1.5px solid var(--border-strong); border-radius: 4px;
  background: var(--card); display: grid; place-content: center; cursor: pointer;
}
.check input::after {
  content: ""; width: 11px; height: 6px; border-left: 2px solid #fff; border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px); opacity: 0;
}
.check input:checked { background: var(--primary); border-color: var(--primary); }
.check input:checked::after { opacity: 1; }
.check input:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.text { flex: 1; min-width: 0; word-break: keep-all; overflow-wrap: anywhere; font-size: 16px; padding-left: 6px; }
.text .age {
  display: inline-block; margin-left: 6px; font-size: 11px; line-height: 18px; padding: 0 6px;
  border-radius: 6px; background: var(--track); color: var(--muted); vertical-align: 1px; white-space: nowrap;
}
.text .age.old { background: var(--danger-soft); color: var(--danger); }
.item.done .text .label { text-decoration: line-through; color: var(--muted); }
.item.done { opacity: .78; }

.star {
  flex: none; width: 32px; height: 32px; border: 0; background: transparent; padding: 0;
  display: grid; place-items: center; color: var(--border-strong); border-radius: 8px;
}
.star svg { width: 20px; height: 20px; }
.star[aria-pressed="true"] { color: var(--star); }
.star:hover { background: var(--track); }

.badge {
  flex: none; height: 26px; padding: 0 10px; border-radius: 999px; border: 0;
  font-size: 13px; font-weight: 600; color: #fff; background: var(--work);
}
.badge.personal { background: var(--personal); }
.badge.study { background: var(--study); }

.ibtn {
  flex: none; height: 38px; padding: 0 12px; border-radius: 8px; font-size: 14px;
  border: 1px solid var(--border-strong); background: var(--card);
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
.ibtn svg { width: 17px; height: 17px; display: none; }
.ibtn.del { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.ibtn.save { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

.edit-input {
  flex: 1; min-width: 0; height: 40px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--card);
}

.empty { text-align: center; color: var(--muted); margin: 36px 0; }

/* ---------- 통계 */
.stats { margin-top: 28px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 12px; }
.stats-head { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; }
.stats-head .muted { font-weight: 400; }
.stats-bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; margin-top: 10px; align-items: end; }
.sb { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); }
.sb .col { width: 100%; max-width: 34px; height: 52px; display: flex; align-items: flex-end; background: var(--track); border-radius: 6px; overflow: hidden; }
.sb .fill { width: 100%; background: var(--primary); border-radius: 6px; min-height: 0; }
.sb .num { color: var(--text); font-weight: 600; font-size: 12px; }
.sb.today .day { color: var(--primary); font-weight: 700; }

/* ---------- 하단·토스트 */
.foot { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 22px; font-size: 13px; color: var(--muted); }
.link { border: 0; background: none; padding: 4px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(20px, env(safe-area-inset-bottom)); z-index: 10;
  display: flex; align-items: center; gap: 14px;
  background: #23262d; color: #fff; padding: 10px 10px 10px 16px; border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18); font-size: 14px; max-width: calc(100% - 32px);
}
.toast button { border: 0; background: rgba(255,255,255,.12); color: #9cc0ff; font-weight: 700; padding: 6px 12px; border-radius: 8px; }
.toast button:empty { display: none; }

/* ---------- 로그인 */
.login { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px 22px; display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-card img { align-self: center; border-radius: 14px; }
.login-card h1 { margin: 4px 0 0; font-size: 22px; }
.login-card p { margin: 0; font-size: 14px; }
.login-card input {
  height: 48px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--card);
}
.error { color: var(--danger); min-height: 1.2em; }

/* ---------- 좁은 화면(폰) */
@media (max-width: 560px) {
  .wrap { padding-left: 16px; padding-right: 16px; }
  .top h1 { font-size: 24px; }
  .sync b { display: none; }
  .add { gap: 8px; margin-top: 18px; }
  .add input, .add select, .add .btn { height: 48px; }
  .add select { min-width: 74px; padding: 0 6px; }
  .add .btn { padding: 0 14px; }
  .filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .filters button { padding: 0 14px; flex: none; }
  .filters kbd { display: none; }
  .hint { display: none; }
  .list-tools { justify-content: flex-end; }
  .item { gap: 6px; padding: 10px 8px 10px 12px; }
  .text { font-size: 15px; padding-left: 4px; }
  .badge { height: 24px; padding: 0 8px; font-size: 12px; }
  .ibtn { width: 34px; height: 34px; padding: 0; }
  .ibtn span { display: none; }
  .ibtn svg { display: block; }
  .ibtn.save, .ibtn.cancel { width: auto; padding: 0 10px; }
  .ibtn.save span, .ibtn.cancel span { display: inline; }
  .star { width: 30px; }
}

/* 터치 기기에서는 단축키 표시를 숨긴다 */
@media (hover: none), (pointer: coarse) {
  .filters kbd { display: none; }
}
