/* =============================================
   CSS Variables & Theme
   ============================================= */
:root {
  --bg-primary: #f5f7fa;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: #f0f2f5;
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --accent: #6c63ff;
  --accent-hover: #5a52d5;
  --accent-light: #ede9fe;
  --success: #10b981;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg-primary: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-input: #252540;
  --bg-hover: #252540;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #2d2d4e;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-light: #1e1b4b;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* =============================================
   Reset & Base
   ============================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px 80px;
  transition: background var(--transition), color var(--transition);
}

/* =============================================
   App Container
   ============================================= */
.app {
  width: 100%;
  max-width: 600px;
}

/* =============================================
   Header
   ============================================= */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
}

.title {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: 0.3em;
  background: linear-gradient(135deg, var(--accent), #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.theme-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
}

.theme-toggle:hover {
  transform: scale(1.1) rotate(20deg);
  box-shadow: var(--shadow-md);
}

/* =============================================
   Input Area
   ============================================= */
.input-area {
  margin-bottom: 16px;
}

.input-wrapper {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 6px 6px 16px;
  box-shadow: var(--shadow-md);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-light), var(--shadow-md);
}

.todo-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 1rem;
  color: var(--text-primary);
  padding: 10px 0;
}

.todo-input::placeholder {
  color: var(--text-muted);
}

.add-check-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  width: 44px;
  height: 44px;
  font-size: 1.5rem;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}

.add-check-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.add-check-btn:active {
  transform: scale(0.95);
}

/* =============================================
   Filter Bar
   ============================================= */
.filter-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow-sm);
}

.filter-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: calc(var(--radius) - 4px);
  padding: 8px 12px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.filter-btn:hover:not(.active) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.filter-btn.active {
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow-sm);
}

/* =============================================
   Todo List
   ============================================= */
.todo-list-container {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  min-height: 120px;
}

.todo-list {
  list-style: none;
}

.todo-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
  animation: slideIn 0.2s ease;
  position: relative;
}

.todo-item:last-child {
  border-bottom: none;
}

.todo-item:hover {
  background: var(--bg-hover);
}

.todo-item:hover .delete-btn {
  opacity: 1;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
    transform: translateX(0);
    max-height: 80px;
  }
  to {
    opacity: 0;
    transform: translateX(20px);
    max-height: 0;
    padding: 0;
    border: none;
  }
}

.todo-item.removing {
  animation: fadeOut 0.25s ease forwards;
}

/* Checkbox */
.todo-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--transition), background var(--transition);
  position: relative;
}

.todo-checkbox:checked {
  background: var(--success);
  border-color: var(--success);
}

.todo-checkbox:checked::after {
  content: '';
  display: block;
  width: 5px;
  height: 9px;
  border: 2px solid white;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translate(-1px, -1px);
}

.todo-checkbox:not(:checked):hover {
  border-color: var(--accent);
}

/* Todo Text */
.todo-text {
  flex: 1;
  font-size: 1rem;
  color: var(--text-primary);
  word-break: break-word;
  cursor: pointer;
  padding: 2px 0;
  transition: color var(--transition);
  outline: none;
}

.todo-text[contenteditable="true"] {
  cursor: text;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 2px;
}

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

/* Delete Button */
.delete-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: opacity var(--transition), color var(--transition), background var(--transition);
  flex-shrink: 0;
  line-height: 1;
}

.delete-btn:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* Empty State */
.empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  gap: 12px;
}

.empty-state.visible {
  display: flex;
}

.empty-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-state p {
  font-size: 0.9rem;
  font-weight: 500;
}

/* =============================================
   Footer
   ============================================= */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  margin-top: 12px;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.count {
  font-weight: 500;
}

.clear-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.875rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}

.clear-btn:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.08);
}

/* =============================================
   Drag & Drop
   ============================================= */
.todo-item.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.todo-item.drag-over {
  border-top: 2px solid var(--accent);
}

.todo-item .drag-handle {
  color: var(--text-muted);
  cursor: grab;
  font-size: 1rem;
  opacity: 0;
  transition: opacity var(--transition);
  flex-shrink: 0;
}

.todo-item:hover .drag-handle {
  opacity: 1;
}

/* =============================================
   Responsive
   ============================================= */
@media (max-width: 480px) {
  body {
    padding: 24px 12px 60px;
  }

  .title {
    font-size: 2rem;
  }

  .todo-item {
    padding: 14px 16px;
  }

  .delete-btn {
    opacity: 1;
  }

  .todo-item .drag-handle {
    opacity: 1;
  }
}
