:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #d1d5db;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #b91c1c;
  --done: #6b7280;

  --work: #3b82f6;
  --personal: #10b981;
  --study: #f59e0b;
  /* 배지 글자색: 배경색 대비 4.5:1 이상 확보용 어두운 톤 */
  --work-text: #1e40af;
  --personal-text: #065f46;
  --study-text: #92400e;
  --work-bg: #dbeafe;
  --personal-bg: #d1fae5;
  --study-bg: #fef3c7;

  --gap: 12px;
  --radius: 8px;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 레이아웃 ---------- */
.app {
  max-width: 720px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 16px 24px;
  background: var(--bg);
}

.sticky-top {
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: 16px;
  background: var(--bg);
}

/* ---------- 헤더 / 진행률 ---------- */
.app-header {
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--gap);
}

h1 { margin: 0; font-size: 1.5rem; }
.today { color: var(--text-muted); font-size: 0.9rem; }

.progress-text { margin: 12px 0 6px; font-weight: 600; }

.progress-bar {
  height: 10px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.category-progress {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 8px 0 0;
  font-size: 0.875rem;
}
.category-progress .cat-work { color: var(--work-text); }
.category-progress .cat-personal { color: var(--personal-text); }
.category-progress .cat-study { color: var(--study-text); }

/* ---------- 입력 영역 ---------- */
.add-form {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  padding: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.todo-input,
.category-select {
  min-height: 44px;
  padding: 0 12px;
  font: inherit;
  color: inherit;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.todo-input { flex: 1; min-width: 0; }

.btn {
  min-height: 44px;
  padding: 0 16px;
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
}
.btn-primary { color: #fff; background: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger-outline { color: var(--danger); background: #fff; border-color: var(--danger); }
.btn-danger-outline:hover { background: #fef2f2; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 2px;
}

/* ---------- 필터 탭 ---------- */
.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 12px;
}

.tab {
  min-height: 40px;
  padding: 0 14px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.tab .count { margin-left: 4px; color: var(--text-muted); font-size: 0.85em; }
.tab.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.tab.active .count { color: #e0e7ff; }

/* ---------- 목록 ---------- */
.todo-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.todo-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.todo-check {
  flex: none;
  width: 22px;
  height: 22px;
  margin: 0;
  cursor: pointer;
}

.todo-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.todo-item.editing { flex-wrap: wrap; }
.edit-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  font: inherit;
  border: 1px solid var(--primary);
  border-radius: var(--radius);
}
.edit-input.invalid { border-color: var(--danger); background: #fef2f2; }

.todo-item.done .todo-text {
  color: var(--done);
  text-decoration: line-through;
}

.badge {
  flex: none;
  padding: 2px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 999px;
}
.badge-work { color: var(--work-text); background: var(--work-bg); }
.badge-personal { color: var(--personal-text); background: var(--personal-bg); }
.badge-study { color: var(--study-text); background: var(--study-bg); }

.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  font-size: 1rem;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}
.icon-btn:hover { background: #f3f4f6; }

.icon-btn.confirming {
  width: auto;
  padding: 0 10px;
  font-weight: 700;
  color: #fff;
  background: var(--danger);
}
.icon-btn.confirming:hover { background: #991b1b; }

.progress-fill.complete { background: var(--personal); }
.complete-message {
  margin: 8px 0 0;
  font-weight: 600;
  color: var(--personal-text);
}

.app-footer { align-items: center; gap: 8px; flex-wrap: wrap; }
.confirm-msg { margin-right: auto; font-weight: 600; color: var(--danger); }

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

.app-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.notice {
  margin: 0;
  padding: 10px 16px;
  font-size: 0.9rem;
  color: #7f1d1d;
  background: #fee2e2;
  border-bottom: 1px solid #fca5a5;
}
.notice[hidden] { display: none; }

::placeholder { color: var(--text-muted); opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .progress-fill { transition: none; }
}

/* ---------- 모바일 (640px 이하) ---------- */
@media (max-width: 640px) {
  .app { padding: 0 12px 20px; }
  /* 입력창은 한 줄, 카테고리+추가 버튼은 아래 한 줄로 두어 고정 영역 높이를 줄인다 */
  .add-form { flex-wrap: wrap; }
  .add-form .todo-input { flex: 1 1 100%; }
  .add-form .category-select { flex: 1; }
  .add-form .btn { flex: none; }
  .app-header { padding: 12px; }
  .todo-item { flex-wrap: wrap; }
  .todo-text { flex-basis: calc(100% - 40px); }
  .icon-btn { width: 44px; height: 44px; }
}
