/* ============ 테마 변수 ============ */
:root {
  --bg: #f3f2fb;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-strong: rgba(255, 255, 255, 0.92);
  --border: rgba(30, 24, 80, 0.08);
  --text: #17152e;
  --muted: #7d7a99;
  --accent: #6d5efc;
  --accent-2: #ff6fb5;
  --accent-soft: rgba(109, 94, 252, 0.12);
  --high: #ff5d73;
  --mid: #ffae3d;
  --low: #22c39a;
  --shadow: 0 12px 36px -16px rgba(50, 36, 140, 0.28);
  --shadow-lg: 0 22px 50px -18px rgba(50, 36, 140, 0.38);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0c0b16;
  --surface: rgba(30, 28, 52, 0.62);
  --surface-strong: rgba(36, 34, 62, 0.92);
  --border: rgba(255, 255, 255, 0.08);
  --text: #efeefa;
  --muted: #9895b8;
  --accent-soft: rgba(140, 128, 255, 0.18);
  --shadow: 0 12px 36px -16px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 22px 50px -18px rgba(0, 0, 0, 0.8);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { display: block; }

body {
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.5s var(--ease), color 0.5s var(--ease);
}

/* ============ 배경 오로라 ============ */
.blobs { position: fixed; inset: 0; z-index: -1; overflow: hidden; filter: blur(80px); opacity: 0.55; transition: opacity 0.5s; }
[data-theme="dark"] .blobs { opacity: 0.32; }
.blob { position: absolute; border-radius: 50%; animation: float 20s ease-in-out infinite alternate; }
.b1 { width: 460px; height: 460px; background: #8f7dff; top: -140px; left: -120px; }
.b2 { width: 400px; height: 400px; background: #ff8fcb; bottom: -120px; right: -80px; animation-delay: -7s; }
.b3 { width: 320px; height: 320px; background: #5fd3ff; top: 38%; left: 52%; animation-delay: -13s; }
@keyframes float {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(70px, -50px) scale(1.12); }
  100% { transform: translate(-50px, 60px) scale(0.94); }
}

/* ============ 레이아웃 ============ */
.app { max-width: 620px; margin: 0 auto; padding: 44px 20px 60px; animation: appIn 0.8s var(--ease) both; }
@keyframes appIn { from { opacity: 0; transform: translateY(16px); } }

.topbar { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; }
.date { font-size: 14px; color: var(--muted); font-weight: 500; letter-spacing: 0.01em; }
.greeting { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; margin-top: 4px; }
.actions { display: flex; gap: 8px; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  transition: transform 0.25s var(--spring), background 0.3s;
}
.icon-btn:hover { transform: translateY(-2px); }
.icon-btn:active { transform: scale(0.9); }
.icon-btn svg {
  grid-area: 1 / 1; width: 20px; height: 20px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  transition: transform 0.5s var(--spring), opacity 0.3s;
}
.ic-moon, .ic-off { opacity: 0; transform: rotate(-90deg) scale(0.4); }
[data-theme="dark"] .ic-sun { opacity: 0; transform: rotate(90deg) scale(0.4); }
[data-theme="dark"] .ic-moon { opacity: 1; transform: none; }
.muted .ic-on { opacity: 0; transform: scale(0.4); }
.muted .ic-off { opacity: 1; transform: none; }

/* ============ 진행 카드 ============ */
.hero {
  position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 26px 28px; border-radius: 28px; color: #fff;
  background: linear-gradient(130deg, #6d5efc 0%, #9b5cff 50%, #ff6fb5 100%);
  background-size: 200% 200%;
  animation: heroShift 12s ease infinite;
  box-shadow: 0 24px 50px -20px rgba(109, 94, 252, 0.75);
}
@keyframes heroShift { 0%,100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
.hero::before, .hero::after {
  content: ""; position: absolute; border-radius: 50%; background: rgba(255, 255, 255, 0.14); pointer-events: none;
}
.hero::before { width: 220px; height: 220px; top: -110px; right: 60px; }
.hero::after { width: 140px; height: 140px; bottom: -80px; left: -30px; }
.hero-label { font-size: 13px; font-weight: 600; opacity: 0.8; }
.hero-title { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin: 6px 0 4px; }
.hero-sub { font-size: 14px; opacity: 0.85; }
.hero.celebrate { animation: heroShift 12s ease infinite, wiggle 0.7s var(--spring); }
@keyframes wiggle { 30% { transform: scale(1.03) rotate(-1deg); } 60% { transform: scale(1.02) rotate(1deg); } }

.ring { position: relative; width: 88px; height: 88px; flex-shrink: 0; z-index: 1; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; stroke-linecap: round; }
.ring-track { stroke: rgba(255, 255, 255, 0.25); }
.ring-bar { stroke: #fff; stroke-dasharray: 213.63; stroke-dashoffset: 213.63; transition: stroke-dashoffset 0.9s var(--ease); }
.ring-num { position: absolute; inset: 0; display: grid; place-content: center; grid-auto-flow: column; align-items: baseline; font-weight: 800; font-size: 22px; font-variant-numeric: tabular-nums; }
.ring-num small { font-size: 12px; margin-left: 1px; opacity: 0.85; }

/* ============ 입력 ============ */
.composer {
  margin-top: 18px; padding: 10px; border-radius: 24px;
  background: var(--surface); border: 1px solid var(--border);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  transition: box-shadow 0.3s, border-color 0.3s;
}
.composer:focus-within { border-color: rgba(109, 94, 252, 0.45); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-lg); }
.composer-row { display: flex; gap: 8px; }
#taskInput {
  flex: 1; min-width: 0; padding: 14px 14px; font: inherit; font-size: 16px; font-weight: 500;
  color: var(--text); background: transparent; border: 0; outline: none;
}
#taskInput::placeholder { color: var(--muted); font-weight: 400; }
.composer.shake { animation: shake 0.42s; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }

.add-btn {
  width: 50px; height: 50px; border-radius: 16px; flex-shrink: 0;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 22px -8px rgba(109, 94, 252, 0.8);
  transition: transform 0.3s var(--spring), box-shadow 0.3s;
}
.add-btn svg { width: 22px; height: 22px; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; transition: transform 0.4s var(--spring); }
.add-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 26px -8px rgba(109, 94, 252, 0.9); }
.add-btn:hover svg { transform: rotate(90deg); }
.add-btn:active { transform: scale(0.9); }

.composer-opts { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 4px 2px; flex-wrap: wrap; }
.prio-group { display: flex; gap: 6px; }
.prio-chip {
  --c: var(--mid);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted);
  border: 1px solid var(--border); transition: all 0.25s var(--ease);
}
.prio-chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); transition: transform 0.3s var(--spring); }
.prio-chip[data-prio="low"] { --c: var(--low); }
.prio-chip[data-prio="high"] { --c: var(--high); }
.prio-chip:hover { color: var(--text); }
.prio-chip.active { color: var(--text); border-color: color-mix(in srgb, var(--c) 50%, transparent); background: color-mix(in srgb, var(--c) 14%, transparent); }
.prio-chip.active::before { transform: scale(1.35); }

.due-wrap { position: relative; display: flex; align-items: center; }
.due-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--muted); border: 1px solid var(--border); transition: all 0.25s var(--ease);
}
.due-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.due-btn:hover { color: var(--text); }
.due-wrap.has-date .due-btn { color: var(--accent); background: var(--accent-soft); border-color: transparent; padding-right: 30px; }
.due-clear {
  position: absolute; right: 6px; width: 20px; height: 20px; border-radius: 50%; font-size: 15px; line-height: 1;
  color: var(--accent); opacity: 0; pointer-events: none; transform: scale(0.5); transition: all 0.25s var(--spring);
}
.due-wrap.has-date .due-clear { opacity: 1; pointer-events: auto; transform: none; }
.due-clear:hover { background: var(--accent-soft); }
#dueInput { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* ============ 탭 ============ */
.tabs {
  position: relative; display: flex; margin: 26px 0 14px; padding: 5px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--border);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.tab {
  position: relative; z-index: 1; flex: 1; padding: 10px 0; border-radius: 12px;
  font-size: 14px; font-weight: 600; color: var(--muted); transition: color 0.3s;
}
.tab.active { color: var(--text); }
.tab em {
  font-style: normal; font-size: 12px; margin-left: 4px; padding: 1px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-variant-numeric: tabular-nums;
}
.tab-indicator {
  position: absolute; top: 5px; bottom: 5px; left: 0; border-radius: 12px;
  background: var(--surface-strong); box-shadow: 0 4px 14px -4px rgba(40, 30, 120, 0.25);
  transition: transform 0.45s var(--spring), width 0.45s var(--spring);
}

/* ============ 목록 ============ */
.list { list-style: none; min-height: 4px; }
.item {
  --c: var(--mid);
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 15px 14px 15px 20px; margin-bottom: 10px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--border);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  transition: transform 0.3s var(--ease), box-shadow 0.3s, opacity 0.35s, background 0.3s;
}
.item[data-prio="low"] { --c: var(--low); }
.item[data-prio="high"] { --c: var(--high); }
.item::before {
  content: ""; position: absolute; left: 0; top: 16px; bottom: 16px; width: 4px; border-radius: 0 4px 4px 0; background: var(--c);
  transition: opacity 0.3s;
}
.item:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.item.enter { animation: itemIn 0.55s var(--spring) both; }
@keyframes itemIn { from { opacity: 0; transform: translateY(14px) scale(0.96); } }
.item.done { opacity: 0.62; }
.item.done::before { opacity: 0.3; }
.item.dragging { opacity: 0.4; transform: scale(0.98); box-shadow: none; }

.handle {
  width: 18px; height: 28px; margin-left: -8px; display: grid; place-items: center; cursor: grab;
  color: var(--muted); opacity: 0; transition: opacity 0.2s;
}
.handle svg { width: 12px; height: 18px; fill: currentColor; }
.item:hover .handle { opacity: 0.6; }
.handle:active { cursor: grabbing; }

.check {
  position: relative; width: 26px; height: 26px; flex-shrink: 0; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid color-mix(in srgb, var(--muted) 55%, transparent);
  transition: border-color 0.25s, background 0.25s, transform 0.25s var(--spring);
}
.check:hover { border-color: var(--accent); transform: scale(1.08); }
.check:active { transform: scale(0.85); }
.check svg {
  width: 15px; height: 15px; fill: none; stroke: #fff; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 24; stroke-dashoffset: 24; transition: stroke-dashoffset 0.35s 0.08s cubic-bezier(0.65, 0, 0.35, 1);
}
.item.done .check { border-color: transparent; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.item.done .check svg { stroke-dashoffset: 0; }
.check.pop { animation: pop 0.45s var(--spring); }
@keyframes pop { 0% { transform: scale(0.7); } 60% { transform: scale(1.22); } 100% { transform: scale(1); } }

.body { flex: 1; min-width: 0; }
.text {
  display: inline; font-size: 15.5px; font-weight: 500; line-height: 1.5; word-break: break-word; outline: none;
  background: linear-gradient(var(--muted), var(--muted)) no-repeat 0 58% / 0% 2px;
  transition: background-size 0.45s var(--ease), color 0.3s;
  border-radius: 6px;
}
.item.done .text { background-size: 100% 2px; color: var(--muted); }
.text[contenteditable="true"] {
  display: block; padding: 2px 6px; margin: -2px -6px; background: var(--accent-soft); box-shadow: 0 0 0 2px rgba(109, 94, 252, 0.45);
}
.meta { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.meta:empty { display: none; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
}
.badge svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.badge.today { background: color-mix(in srgb, var(--mid) 18%, transparent); color: color-mix(in srgb, var(--mid) 80%, var(--text)); }
.badge.over { background: color-mix(in srgb, var(--high) 16%, transparent); color: var(--high); }

.del {
  width: 34px; height: 34px; flex-shrink: 0; border-radius: 11px; display: grid; place-items: center;
  color: var(--muted); opacity: 0; transform: scale(0.8); transition: all 0.25s var(--spring);
}
.del svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.item:hover .del { opacity: 1; transform: none; }
.del:hover { color: var(--high); background: color-mix(in srgb, var(--high) 12%, transparent); }
.del:hover svg { animation: trash 0.5s; }
@keyframes trash { 25% { transform: rotate(-12deg); } 75% { transform: rotate(10deg); } }

@media (hover: none) {
  .del { opacity: 0.7; transform: none; }
  .handle { opacity: 0.4; }
}

/* ============ 빈 상태 ============ */
.empty { text-align: center; padding: 36px 0 20px; animation: itemIn 0.6s var(--ease) both; }
.empty-art { width: 110px; margin: 0 auto 14px; animation: bob 3.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-2deg); } }
.ea-paper { fill: var(--surface-strong); stroke: var(--border); stroke-width: 2; }
.ea-clip { fill: var(--accent); }
.ea-dot { fill: none; stroke: var(--accent); stroke-width: 2.5; opacity: 0.6; }
.ea-line { fill: var(--accent-soft); }
.empty-title { font-size: 17px; font-weight: 700; }
.empty-sub { font-size: 14px; color: var(--muted); margin-top: 4px; }

/* ============ 푸터 ============ */
.footer { display: flex; justify-content: space-between; align-items: center; padding: 8px 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.text-btn { font-size: 13px; font-weight: 600; color: var(--muted); padding: 6px 10px; border-radius: 10px; transition: all 0.2s; }
.text-btn:hover:not(:disabled) { color: var(--high); background: color-mix(in srgb, var(--high) 10%, transparent); }
.text-btn:disabled { opacity: 0.4; cursor: default; }
.hint { text-align: center; font-size: 12px; color: var(--muted); opacity: 0.7; margin-top: 18px; }

/* ============ 토스트 ============ */
.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 50;
  display: flex; align-items: center; gap: 14px; padding: 12px 12px 12px 18px; border-radius: 16px;
  background: #1c1a33; color: #fff; font-size: 14px; font-weight: 500;
  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, 140%); opacity: 0; transition: transform 0.5s var(--spring), opacity 0.3s;
}
[data-theme="dark"] .toast { background: #f1f0fb; color: #17152e; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast button { font-weight: 700; color: #b3a9ff; padding: 6px 10px; border-radius: 10px; }
[data-theme="dark"] .toast button { color: var(--accent); }
.toast button:hover { background: rgba(127, 110, 255, 0.18); }
.toast.no-undo button { display: none; }

/* ============ 이펙트 ============ */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; }
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 55; }
.spark {
  position: absolute; width: 7px; height: 7px; border-radius: 50%;
  animation: spark 0.6s var(--ease) forwards;
}
@keyframes spark {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0); opacity: 0; }
}

@media (max-width: 480px) {
  .app { padding-top: 28px; }
  .greeting { font-size: 25px; }
  .hero { padding: 22px; }
  .hero-title { font-size: 19px; }
  .ring { width: 76px; height: 76px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
