/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, "PingFang SC", "Helvetica Neue", sans-serif; }

/* ===== Theme Variables ===== */
body.light {
  --bg: #F4F5FA;
  --surface: #FFFFFF;
  --on-surface: #1C1B2E;
  --on-surface-muted: rgba(28,27,46,0.5);
  --on-surface-faint: rgba(28,27,46,0.08);
  --primary: #5B5FEF;
  --primary-text: #FFFFFF;
  --error: #E53935;
  --shadow: rgba(0,0,0,0.10);
  --shadow-card: rgba(0,0,0,0.13);
  --status-bar: #F4F5FA;
}
body.dark {
  --bg: #121218;
  --surface: #1E1E2A;
  --on-surface: #E4E3F3;
  --on-surface-muted: rgba(228,227,243,0.5);
  --on-surface-faint: rgba(228,227,243,0.08);
  --primary: #7B7FFF;
  --primary-text: #FFFFFF;
  --error: #FF6B6B;
  --shadow: rgba(0,0,0,0.4);
  --shadow-card: rgba(0,0,0,0.5);
  --status-bar: #121218;
}

body {
  background: var(--bg);
  color: var(--on-surface);
  transition: background .3s, color .3s;
  overflow: hidden;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  padding: 16px 20px 10px;
  background: var(--bg);
  transition: background .3s;
  flex-shrink: 0;
}
.app-title {
  flex: 1;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.icon-btn {
  width: 40px; height: 40px;
  border: none; background: none;
  border-radius: 50%;
  cursor: pointer;
  color: var(--on-surface);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn:hover { background: var(--on-surface-faint); }

/* ===== Main ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding-bottom: 80px;
}

/* ===== Counter ===== */
.counter {
  font-size: 14px;
  color: var(--on-surface-muted);
  font-weight: 500;
  margin-bottom: 16px;
  letter-spacing: 0.5px;
  display: none;
}

/* ===== Card Viewport ===== */
.card-viewport {
  width: 100%;
  overflow: hidden;
  position: relative;
  display: none;
}
.card-track {
  display: flex;
  transition: transform .38s cubic-bezier(.4,0,.2,1);
  will-change: transform;
  align-items: center;
}

/* ===== Card ===== */
.card-slide {
  flex-shrink: 0;
  padding: 10px 14px;
  transition: transform .38s cubic-bezier(.4,0,.2,1), opacity .38s;
}
.card {
  background: var(--surface);
  border-radius: 28px;
  box-shadow: 0 8px 32px var(--shadow-card), 0 2px 8px var(--shadow);
  padding: 26px 24px 22px;
  display: flex;
  flex-direction: column;
  min-height: 420px;
  transition: background .3s, box-shadow .3s;
  position: relative;
  overflow: hidden;
}

/* priority accent bar */
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  border-radius: 28px 28px 0 0;
}
.card.p-high::before  { background: #E53935; }
.card.p-medium::before { background: #5B5FEF; }
.card.p-low::before   { background: #00BFA5; }

.card-top {
  display: flex;
  align-items: center;
  margin-bottom: 18px;
}
.priority-badge {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  color: var(--on-surface-muted);
  letter-spacing: 0.3px;
}
.status-icon {
  width: 30px; height: 30px;
  cursor: pointer;
  color: var(--primary);
  flex-shrink: 0;
}
.status-icon svg { width: 100%; height: 100%; }

.card-divider {
  height: 1px;
  background: var(--on-surface-faint);
  margin-bottom: 20px;
}

.card-spacer { flex: 1; }

.card-title {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.25;
  word-break: break-word;
  margin-bottom: 14px;
  transition: opacity .2s;
}
.card-title.done { opacity: 0.45; text-decoration: line-through; }

.card-desc {
  font-size: 15px;
  color: var(--on-surface-muted);
  line-height: 1.6;
  word-break: break-word;
  margin-bottom: 18px;
}

.card-date {
  font-size: 12px;
  color: var(--on-surface-muted);
  opacity: 0.7;
  margin-bottom: 16px;
}

.card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.btn-outline {
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid;
  background: none;
  transition: background .15s, opacity .15s;
}
.btn-complete {
  border-color: var(--primary);
  color: var(--primary);
}
.btn-complete:hover { background: rgba(91,95,239,0.08); }
.btn-delete {
  border-color: var(--error);
  color: var(--error);
}
.btn-delete:hover { background: rgba(229,57,53,0.08); }

/* neighbor card scale */
.card-slide.neighbor { opacity: 0.55; }
.card-slide.neighbor .card { transform: scaleY(0.91); }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  color: var(--on-surface-muted);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.empty-icon { font-size: 48px; margin-bottom: 4px; }
.empty-state > div:nth-child(2) { font-size: 18px; font-weight: 600; color: var(--on-surface); opacity: 0.5; }
.empty-sub { font-size: 14px; opacity: 0.6; }

/* ===== FAB ===== */
.fab {
  position: fixed;
  bottom: 28px; right: 24px;
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-text);
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(91,95,239,0.45);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, box-shadow .15s;
  z-index: 100;
}
.fab:hover { transform: scale(1.07); box-shadow: 0 8px 28px rgba(91,95,239,0.55); }
.fab:active { transform: scale(0.95); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 28px 28px 0 0;
  padding: 28px 24px 32px;
  width: 100%;
  max-width: 520px;
  animation: slideUp .28s cubic-bezier(.4,0,.2,1);
}
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-title {
  font-size: 22px; font-weight: 700;
  margin-bottom: 20px;
}

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  color: var(--on-surface-muted);
  margin-bottom: 7px;
  font-weight: 500;
}
.form-group input,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--on-surface-faint);
  background: var(--bg);
  color: var(--on-surface);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
  resize: none;
}
.form-group input:focus,
.form-group textarea:focus { border-color: var(--primary); }

/* Priority group */
.priority-group {
  display: flex; gap: 10px;
}
.priority-btn {
  flex: 1;
  padding: 9px 6px;
  border-radius: 20px;
  border: 1.5px solid var(--on-surface-faint);
  background: none;
  color: var(--on-surface);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity .15s, border-color .15s;
  font-family: inherit;
}
.priority-btn.active { opacity: 1; border-color: var(--primary); }

.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 22px;
}
.btn-cancel {
  padding: 10px 20px; border-radius: 12px;
  border: none; background: none;
  color: var(--on-surface-muted);
  font-size: 15px; font-weight: 500;
  cursor: pointer; font-family: inherit;
}
.btn-add {
  padding: 10px 24px; border-radius: 12px;
  border: none; background: var(--primary);
  color: #fff; font-size: 15px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  transition: opacity .15s;
}
.btn-add:hover { opacity: 0.88; }

/* ===== Settings ===== */
.settings-modal { border-radius: 28px 28px 0 0; }
.settings-row {
  display: flex; align-items: center;
  padding: 10px 0;
}
.settings-label { font-size: 16px; font-weight: 500; }
.settings-sub { font-size: 13px; color: var(--on-surface-muted); margin-top: 3px; }
.settings-divider { height: 1px; background: var(--on-surface-faint); margin: 14px 0; }
.settings-about { padding: 4px 0; }

/* Toggle Switch */
.toggle {
  position: relative; display: inline-block;
  width: 50px; height: 28px;
  margin-left: auto; flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--on-surface-faint);
  border-radius: 28px;
  cursor: pointer;
  transition: background .25s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 22px; height: 22px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .25s;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(22px); }

/* ===== Swipe hint dots ===== */
.dots {
  display: flex; gap: 6px;
  justify-content: center;
  margin-top: 18px;
}
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--on-surface-faint);
  transition: background .2s, transform .2s;
}
.dot.active {
  background: var(--primary);
  transform: scale(1.3);
}
