:root {
  --bg: #f2f2f7;
  --bg-card: #ffffff;
  --bg-secondary: #e5e5ea;
  --bg-tertiary: #f9f9f9;
  --text: #1c1c1e;
  --text-secondary: #8e8e93;
  --text-tertiary: #aeaeb2;
  --accent: #007aff;
  --accent-light: rgba(0,122,255,0.1);
  --red: #ff3b30;
  --orange: #ff9500;
  --green: #34c759;
  --separator: rgba(60,60,67,0.12);
  --shadow: 0 2px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-card: #1c1c1e;
    --bg-secondary: #2c2c2e;
    --bg-tertiary: #1c1c1e;
    --text: #ffffff;
    --text-secondary: #8e8e93;
    --text-tertiary: #636366;
    --separator: rgba(84,84,88,0.34);
    --shadow: 0 2px 16px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 500px;
  margin: 0 auto;
  position: relative;
}

.hidden { display: none !important; }

/* Header */
.header {
  padding: calc(var(--safe-top) + 12px) 20px 0;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.header-title {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.btn-icon:active { background: var(--accent-light); }

/* Search */
.search-bar {
  margin-bottom: 12px;
}
.search-bar input {
  width: 100%;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 16px;
  outline: none;
  font-family: var(--font);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  padding-bottom: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 8px 18px;
  border-radius: 20px;
  border: none;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  font-family: var(--font);
}
.tab.active {
  background: var(--accent);
  color: #fff;
}

/* Stats */
.stats {
  display: flex;
  gap: 10px;
  padding: 8px 20px 16px;
}
.stat-card {
  flex: 1;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-number {
  display: block;
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}
.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Task list */
.task-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 100px;
  -webkit-overflow-scrolling: touch;
}

.task-item {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: all 0.3s ease;
  animation: slideIn 0.3s ease;
}
.task-item.done { opacity: 0.5; }
.task-item.done .task-name { text-decoration: line-through; }
.task-item.removing { animation: slideOut 0.3s ease forwards; }

@keyframes slideIn {
  from { transform: translateY(-10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes slideOut {
  to { transform: translateX(80px); opacity: 0; height: 0; padding: 0; margin: 0; }
}

.task-check {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
  background: none;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.task-check.checked {
  background: var(--accent);
  border-color: var(--accent);
}
.task-check.checked::after {
  content: '';
  width: 6px;
  height: 10px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translateY(-1px);
}

.task-check.priority-high { border-color: var(--red); }
.task-check.priority-medium { border-color: var(--orange); }
.task-check.priority-low { border-color: var(--green); }

.task-content { flex: 1; min-width: 0; }
.task-name {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
  word-wrap: break-word;
}
.task-note {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.3;
}
.task-meta {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.task-tag {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 500;
}
.task-date {
  font-size: 11px;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 4px;
}
.task-date.overdue { color: var(--red); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}
.empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-text { font-size: 20px; font-weight: 600; color: var(--text-secondary); }
.empty-sub { font-size: 14px; color: var(--text-tertiary); margin-top: 8px; }

/* Bottom bar */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 500px;
  padding: calc(12px + var(--safe-bottom)) 20px 12px;
  background: var(--bg-card);
  border-top: 1px solid var(--separator);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 5;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(255,255,255,0.85);
}
@media (prefers-color-scheme: dark) {
  .bottom-bar { background: rgba(28,28,30,0.85); }
}

.fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,122,255,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.fab:active { transform: scale(0.92); }

.voice-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.voice-btn:active { transform: scale(0.92); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-card);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 10px;
}
.modal-title { font-size: 20px; font-weight: 700; }
.modal-body { padding: 10px 20px; }
.modal-footer { padding: 10px 20px 30px; }

.input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 16px;
  outline: none;
  margin-bottom: 12px;
  font-family: var(--font);
  transition: box-shadow 0.2s;
}
.input:focus { box-shadow: 0 0 0 2px var(--accent); }
.textarea { resize: none; }

.modal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--separator);
}
.modal-label { font-size: 15px; font-weight: 500; }

.select {
  background: var(--bg-secondary);
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
}
.date-input {
  margin-bottom: 0;
  width: auto;
  padding: 8px 12px;
  font-size: 14px;
}

.priority-picker { display: flex; gap: 6px; }
.priority-btn {
  padding: 6px 12px;
  border-radius: 8px;
  border: none;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.2s;
}
.priority-btn.active { color: #fff; }
.priority-btn[data-priority="low"].active { background: var(--green); }
.priority-btn[data-priority="medium"].active { background: var(--orange); }
.priority-btn[data-priority="high"].active { background: var(--red); }

.btn-primary {
  width: 100%;
  padding: 16px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: opacity 0.2s;
}
.btn-primary:active { opacity: 0.8; }

/* Voice overlay */
.voice-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.voice-modal { text-align: center; color: #fff; }
.voice-waves {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 30px;
}
.wave {
  width: 6px;
  height: 30px;
  background: var(--accent);
  border-radius: 3px;
  animation: waveAnim 1s ease-in-out infinite;
}
.wave:nth-child(2) { animation-delay: 0.15s; height: 45px; }
.wave:nth-child(3) { animation-delay: 0.3s; height: 35px; }
@keyframes waveAnim {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1.2); }
}
.voice-text { font-size: 22px; font-weight: 600; margin-bottom: 12px; }
.voice-transcript { font-size: 16px; color: rgba(255,255,255,0.7); min-height: 24px; margin-bottom: 30px; }
.voice-cancel {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  padding: 12px 32px;
  border-radius: 25px;
  font-size: 16px;
  cursor: pointer;
  font-family: var(--font);
}

/* Context menu */
.context-menu {
  position: fixed;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 150;
  overflow: hidden;
  min-width: 180px;
  animation: scaleIn 0.15s ease;
}
@keyframes scaleIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.ctx-btn {
  display: block;
  width: 100%;
  padding: 14px 20px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  font-family: var(--font);
  border-bottom: 1px solid var(--separator);
}
.ctx-btn:last-child { border-bottom: none; }
.ctx-btn:active { background: var(--bg-secondary); }
.ctx-danger { color: var(--red); }

/* Side menu */
.side-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  animation: fadeIn 0.2s ease;
}
.side-menu {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 280px;
  background: var(--bg-card);
  padding: calc(var(--safe-top) + 20px) 20px 20px;
  display: flex;
  flex-direction: column;
  animation: slideRight 0.3s ease;
}
@keyframes slideRight { from { transform: translateX(-100%); } to { transform: translateX(0); } }
.side-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 30px;
}
.side-header h2 { font-size: 24px; font-weight: 700; }
.side-nav { flex: 1; }
.side-item {
  display: block;
  width: 100%;
  padding: 14px 0;
  border: none;
  background: none;
  color: var(--text);
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  font-family: var(--font);
}
.side-item:active { color: var(--accent); }
.side-divider { border: none; border-top: 1px solid var(--separator); margin: 8px 0; }
.side-footer { color: var(--text-tertiary); font-size: 12px; }

/* Toast notification */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  opacity: 0;
  transition: all 0.3s ease;
  max-width: 80%;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
