/* ===== CSS Variables & Reset ===== */
:root {
  --bg: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-nav: #16162a;
  --text: #f0f0f0;
  --text-muted: #8888aa;
  --accent: #e94560;
  --accent-glow: rgba(233, 69, 96, 0.3);
  --border: rgba(255,255,255,0.08);
  --radius: 16px;
  --nav-height: 70px;
  --top-bar-height: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

.light-mode {
  --bg: #f5f5fa;
  --bg-card: #ffffff;
  --bg-nav: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b6b8a;
  --accent-glow: rgba(233, 69, 96, 0.15);
  --border: rgba(0,0,0,0.08);
}

.light-mode .top-bar {
  box-shadow: 0 1px 8px rgba(0,0,0,0.06);
}

.light-mode .bottom-nav {
  box-shadow: 0 -1px 8px rgba(0,0,0,0.06);
}

.light-mode .countdown-card::before {
  background: rgba(0,0,0,0.1);
}

.light-mode .card-past {
  opacity: 0.85;
}

.light-mode .toast {
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
}

.light-mode .toggle-slider {
  background: rgba(0,0,0,0.18);
}

.light-mode .color-swatch.active {
  border-color: var(--text);
}

.light-mode .countdown-card {
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.light-mode .alt-format,
.light-mode .detail-fun-fact {
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.light-mode .detail-action-btn {
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.light-mode .modal-card {
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.light-mode .search-input {
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

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

html, body {
  height: 100%;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  height: 100%;
  position: relative;
}

/* ===== Views ===== */
.view {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: none;
  flex-direction: column;
  padding-top: calc(var(--top-bar-height) + var(--safe-top));
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.view.active { display: flex; }

/* ===== Top Bar ===== */
.top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--top-bar-height) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  border-bottom: 1px solid var(--border);
  padding-left: 16px;
  padding-right: 16px;
}

.top-bar h1 {
  font-size: 18px;
  font-weight: 600;
}

.logo {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, #e94560, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background 0.2s;
}
.btn-icon:hover { background: var(--border); }

.top-bar .btn-icon:first-child { position: absolute; left: 12px; }
.top-bar .btn-delete-icon { position: absolute; right: 12px; }

/* ===== Bottom Nav ===== */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-nav);
  display: flex;
  align-items: center;
  justify-content: space-around;
  border-top: 1px solid var(--border);
  z-index: 100;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  padding: 8px 16px;
  border-radius: 12px;
  transition: all 0.3s ease;
  min-width: 72px;
}

.nav-btn.active {
  color: var(--accent);
}

.nav-icon { font-size: 22px; }
.nav-label { font-size: 11px; font-weight: 500; }

/* ===== List Toolbar (Category Filters + Sort) ===== */
.list-toolbar {
  padding: 8px 16px 0;
  flex-shrink: 0;
}

.category-filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.category-filters::-webkit-scrollbar { display: none; }

.filter-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-family: 'Poppins', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.filter-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.filter-count {
  background: rgba(255,255,255,0.15);
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
}

.filter-chip.active .filter-count {
  background: rgba(255,255,255,0.25);
}

.sort-selector-wrap {
  display: flex;
  justify-content: flex-end;
  padding: 4px 0 8px;
}

.sort-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-family: 'Poppins', sans-serif;
  font-size: 12px;
  padding: 5px 10px;
  cursor: pointer;
  outline: none;
}

.sort-select:focus {
  border-color: var(--accent);
}

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 40px 20px;
  opacity: 0;
  animation: fadeIn 0.5s ease forwards;
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
  animation: bounce 2s ease infinite;
}

.empty-state h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.5;
}

/* ===== Countdown List ===== */
.countdowns-list {
  padding: 4px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.countdown-card {
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  opacity: 0;
  animation: slideUp 0.4s ease forwards;
}

.countdown-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.2);
  pointer-events: none;
}

.countdown-card:active { transform: scale(0.98); }

.countdown-card .card-content {
  position: relative;
  z-index: 1;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
  flex: 1;
}

.card-badges {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.card-badge {
  font-size: 14px;
  background: rgba(255,255,255,0.2);
  padding: 2px 6px;
  border-radius: 8px;
  line-height: 1.2;
}

.badge-recurring {
  font-size: 11px;
}

.badge-countup {
  font-size: 11px;
}

.card-date {
  font-size: 12px;
  color: rgba(255,255,255,0.7);
  margin-bottom: 12px;
}

.card-days {
  font-size: 42px;
  font-weight: 800;
  color: #fff;
  line-height: 1;
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.card-days-label {
  font-size: 14px;
  color: rgba(255,255,255,0.85);
  font-weight: 500;
}

.card-past {
  opacity: 0.7;
}

.card-past .card-days {
  font-size: 32px;
}

/* Count-up cards have a subtle pulsing border */
.card-countup {
  box-shadow: 0 0 0 2px rgba(255,255,255,0.15);
}

/* ===== Mode Toggle ===== */
.mode-toggle {
  display: flex;
  background: var(--bg-card);
  border-radius: 14px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.mode-btn {
  flex: 1;
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-radius: 11px;
  color: var(--text-muted);
  font-family: 'Poppins', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.mode-btn:active {
  transform: scale(0.97);
}

.mode-icon {
  font-size: 16px;
}

/* ===== Create Form ===== */
.create-form {
  padding: 16px;
}

.templates-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.templates-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 8px;
}

.template-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 12px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  transition: all 0.2s ease;
}

.template-btn:active { transform: scale(0.97); }

.template-emoji { font-size: 24px; display: block; margin-bottom: 4px; }
.template-name { font-size: 13px; font-weight: 600; }
.template-date { font-size: 11px; color: var(--text-muted); }

.form-divider {
  display: flex;
  align-items: center;
  margin: 20px 0;
  color: var(--text-muted);
  font-size: 13px;
}

.form-divider::before,
.form-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border);
}

.form-divider span { padding: 0 12px; }

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group input[type="date"],
.form-group input[type="time"] {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: 'Poppins', sans-serif;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-select {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: 'Poppins', sans-serif;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238888aa' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}

.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Category Picker (Create Form) */
.category-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.category-chip {
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-family: 'Poppins', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.category-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 8px var(--accent-glow);
}

.category-chip:active { transform: scale(0.95); }

/* Color Picker */
.color-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: all 0.2s ease;
  position: relative;
}

.color-swatch.active {
  border-color: #fff;
  transform: scale(1.15);
  box-shadow: 0 0 12px rgba(255,255,255,0.3);
}

.color-swatch.active::after {
  content: '\2713';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* Format Selector */
.format-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.format-btn {
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  font-family: 'Poppins', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.format-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Primary Button */
.btn-primary {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--accent), #f59e0b);
  border: none;
  border-radius: 14px;
  color: #fff;
  font-family: 'Poppins', sans-serif;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: all 0.3s ease;
  opacity: 0.5;
}

.btn-primary:not(:disabled) {
  opacity: 1;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:not(:disabled):active {
  transform: scale(0.97);
}

/* ===== Detail View ===== */
.detail-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  text-align: center;
}

.detail-hero {
  width: 100%;
  max-width: 480px;
  border-radius: 24px;
  padding: 32px 28px;
  position: relative;
  overflow: hidden;
}

.detail-hero::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.15);
  pointer-events: none;
}

.detail-hero > * { position: relative; z-index: 1; }

.detail-emoji {
  font-size: 48px;
  margin-bottom: 12px;
  animation: pulse 2s ease infinite;
}

.detail-name {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.detail-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-bottom: 20px;
}

.detail-cat {
  font-size: 12px;
  color: rgba(255,255,255,0.8);
  background: rgba(255,255,255,0.15);
  padding: 2px 10px;
  border-radius: 10px;
  margin-bottom: 4px;
}

.detail-target-date {
  font-size: 13px;
  color: rgba(255,255,255,0.7);
}

.detail-countup-label {
  font-size: 14px;
  color: rgba(255,255,255,0.6);
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: 600;
  margin-bottom: 8px;
}

.detail-countdown {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 20px;
  flex-wrap: nowrap;
}

.detail-unit {
  text-align: center;
}

.detail-number {
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  line-height: 1.1;
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
  display: block;
  transition: transform 0.15s ease;
}

.detail-label {
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 500;
}

.detail-separator {
  font-size: 20px;
  font-weight: 300;
  color: rgba(255,255,255,0.4);
  align-self: flex-start;
  padding-top: 4px;
}

/* Progress bar */
.detail-progress {
  margin-top: 16px;
}

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

.progress-label {
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.progress-pct {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: rgba(255,255,255,0.85);
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* Recurring badge */
.detail-recurring-badge {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 12px;
  border-radius: 20px;
  margin-bottom: 8px;
}

/* ===== Milestones ===== */
.detail-milestones {
  margin-top: 20px;
  text-align: left;
  width: 100%;
}

.milestones-title {
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,0.6);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
}

.milestone-item {
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

.milestone-reached {
  display: flex;
  align-items: center;
  gap: 10px;
}

.milestone-emoji {
  font-size: 22px;
}

.milestone-label {
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  flex: 1;
}

.milestone-check {
  font-size: 16px;
}

.milestone-next-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.milestone-away {
  color: rgba(255,255,255,0.6);
  font-size: 12px;
  font-weight: 500;
  margin-left: auto;
}

.milestone-progress {
  display: flex;
  align-items: center;
  gap: 10px;
}

.milestone-progress-bar {
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
  overflow: hidden;
}

.milestone-progress-fill {
  height: 100%;
  background: rgba(255,255,255,0.8);
  border-radius: 3px;
  transition: width 0.5s ease;
}

.milestone-progress-pct {
  font-size: 12px;
  color: rgba(255,255,255,0.7);
  font-weight: 600;
  min-width: 32px;
  text-align: right;
}

/* Milestone celebration (for countdown events) */
.milestone-celebration {
  margin-top: 16px;
  padding: 12px;
  background: rgba(255,255,255,0.12);
  border-radius: 14px;
  text-align: center;
  animation: milestoneGlow 2s ease infinite;
}

.milestone-celebration-emoji {
  font-size: 32px;
  animation: bounce 1.5s ease infinite;
}

.milestone-celebration-text {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  margin-top: 4px;
}

@keyframes milestoneGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.1); }
  50% { box-shadow: 0 0 20px 4px rgba(255,255,255,0.15); }
}

/* ===== Detail Actions (Share / Copy) ===== */
.detail-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  width: 100%;
  max-width: 480px;
}

.detail-action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  font-family: 'Poppins', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.detail-action-btn:active {
  transform: scale(0.96);
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.action-icon {
  font-size: 18px;
}

.action-text {
  font-size: 13px;
}

.detail-alt-formats {
  margin-top: 24px;
  width: 100%;
  max-width: 480px;
}

.alt-format {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border);
}

.alt-format-label {
  font-size: 13px;
  color: var(--text-muted);
}

.alt-format-value {
  font-size: 15px;
  font-weight: 600;
}

.detail-fun-fact {
  margin-top: 16px;
  background: var(--bg-card);
  border-radius: 14px;
  padding: 16px;
  width: 100%;
  max-width: 480px;
  text-align: center;
  border: 1px solid var(--border);
}

.fun-fact-emoji { font-size: 28px; }
.fun-fact-text {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.4;
}

/* Past event detail */
.detail-past-badge {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 14px;
  border-radius: 20px;
  margin-bottom: 12px;
}

/* ===== Settings ===== */
.settings-content {
  padding: 16px;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.setting-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 400;
}

.toggle {
  position: relative;
  width: 48px;
  height: 28px;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border);
  border-radius: 28px;
  transition: 0.3s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 22px; height: 22px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.3s;
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.settings-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

.setting-info {
  padding: 20px 0;
  text-align: center;
}

.setting-info h3 { font-size: 18px; font-weight: 700; }
.setting-info p { font-size: 14px; color: var(--text-muted); margin-top: 4px; }
.setting-info a { color: var(--accent); text-decoration: none; }

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

@keyframes celebrate {
  0% { transform: scale(0) rotate(0deg); opacity: 0; }
  50% { transform: scale(1.2) rotate(180deg); opacity: 1; }
  100% { transform: scale(1) rotate(360deg); opacity: 1; }
}

/* Confetti container */
.confetti-container {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0% { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 200;
  transition: transform 0.3s ease;
  border: 1px solid var(--border);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ===== View Transitions ===== */
.view {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.view.active {
  display: flex;
}

.view.view-visible {
  opacity: 1;
  transform: translateY(0);
}

#view-detail {
  transform: translateX(20px);
}

#view-detail.view-visible {
  transform: translateX(0);
}

/* ===== Search Bar ===== */
.search-bar {
  padding-bottom: 8px;
}

.search-input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: 'Poppins', sans-serif;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%238888aa' viewBox='0 0 24 24'%3E%3Cpath d='M15.5 14h-.79l-.28-.27A6.471 6.471 0 0016 9.5 6.5 6.5 0 109.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

/* ===== Card Polish ===== */
.countdown-card {
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.countdown-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
  transition: left 0.6s ease;
  pointer-events: none;
  z-index: 1;
}

@media (hover: hover) {
  .countdown-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(0,0,0,0.25);
  }
  .countdown-card:hover::after {
    left: 100%;
  }
}

/* Enhanced slideUp animation */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Active nav pulse */
.nav-btn.active .nav-icon {
  animation: gentlePulse 2.5s ease infinite;
}

@keyframes gentlePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

/* Primary button gradient animation */
.btn-primary {
  background-size: 200% 200%;
  background-position: 0% 50%;
  transition: all 0.3s ease, background-position 0.4s ease;
}

.btn-primary:not(:disabled):hover {
  background-position: 100% 50%;
}

/* Template button hover */
@media (hover: hover) {
  .template-btn:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 12px var(--accent-glow);
  }

  .detail-action-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
  }

  .filter-chip:hover:not(.active) {
    border-color: var(--accent);
    color: var(--text);
  }
}

/* ===== Custom Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 20px;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 32px 28px 24px;
  text-align: center;
  width: 100%;
  max-width: 340px;
  transform: scale(0.9) translateY(10px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  border: 1px solid var(--border);
}

.modal-overlay.show .modal-card {
  transform: scale(1) translateY(0);
}

.modal-emoji {
  font-size: 48px;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.modal-text {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-btn {
  flex: 1;
  padding: 12px 16px;
  border-radius: 12px;
  font-family: 'Poppins', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.modal-btn:active {
  transform: scale(0.96);
}

.modal-btn-cancel {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.modal-btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  box-shadow: 0 2px 12px rgba(239, 68, 68, 0.3);
}

.modal-btn-primary {
  background: linear-gradient(135deg, var(--accent), #f59e0b);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}

/* ===== Edit Button ===== */
.top-bar .btn-edit-icon {
  position: absolute;
  right: 52px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 0; }

/* Responsive */
@media (min-width: 600px) {
  .templates-grid { grid-template-columns: repeat(3, 1fr); }
  .detail-number { font-size: 38px; }
  .detail-hero { max-width: 500px; }
  .detail-alt-formats, .detail-fun-fact, .detail-actions { max-width: 500px; }
}
