:root {
  --bg-1: #ffd6e8;
  --bg-2: #e0c3fc;
  --bg-3: #c9f2ff;
  --pink: #ff6fa3;
  --pink-dark: #e0457e;
  --purple: #9d6cff;
  --purple-dark: #7a4ce0;
  --yellow: #ffd166;
  --green: #5ddba5;
  --text: #3a2b4d;
  --text-soft: #7a6b8e;
  --card: rgba(255, 255, 255, 0.78);
  --card-strong: rgba(255, 255, 255, 0.95);
  --shadow: 0 10px 30px rgba(157, 108, 255, 0.18);
  --radius: 22px;
  --nav-h: 72px;
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: 'Tajawal', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, var(--bg-1) 0%, var(--bg-2) 50%, var(--bg-3) 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle at 10% 20%, rgba(255, 255, 255, 0.5) 0, transparent 30%),
    radial-gradient(circle at 90% 80%, rgba(255, 255, 255, 0.4) 0, transparent 35%);
  pointer-events: none;
  z-index: 0;
}

button {
  font-family: inherit;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 520px;
  margin: 0 auto;
  padding-bottom: calc(var(--nav-h) + max(env(safe-area-inset-bottom), 16px));
  min-height: 100vh;
  min-height: 100dvh;
}

.view {
  padding: max(env(safe-area-inset-top), 20px) 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: fadeSlide 0.3s ease;
}

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

/* ===== Header ===== */
.header {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.header-compact {
  padding-top: 4px;
}

.page-title {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  color: var(--purple-dark);
}

.page-subtitle {
  margin: 4px 0 0;
  color: var(--text-soft);
  font-size: 14px;
}

.greeting {
  display: flex;
  align-items: center;
  gap: 14px;
}

.avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fff, #ffe6f1);
  display: grid;
  place-items: center;
  font-size: 32px;
  box-shadow: var(--shadow);
  animation: float 4s ease-in-out infinite;
}

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

.greeting-text h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  color: var(--purple-dark);
}

.date {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--text-soft);
}

.progress-card {
  background: var(--card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.7);
}

.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-weight: 700;
}

#progress-count {
  color: var(--pink-dark);
  font-size: 18px;
}

.progress-bar {
  height: 12px;
  background: rgba(157, 108, 255, 0.15);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--pink), var(--purple), var(--green));
  border-radius: 999px;
  transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.stars {
  margin-top: 10px;
  font-size: 14px;
  color: var(--text-soft);
  font-weight: 500;
}

/* ===== Main / Sections ===== */
.main {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--purple-dark);
  padding: 0 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ===== Form / Input ===== */
.task-form {
  display: flex;
  gap: 8px;
  background: var(--card-strong);
  padding: 8px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.task-form input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 14px 18px;
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  outline: none;
  text-align: right;
}

.task-form input::placeholder {
  color: var(--text-soft);
  opacity: 0.7;
}

.task-form button {
  width: 50px;
  height: 50px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: white;
  font-size: 28px;
  font-weight: 300;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(255, 111, 163, 0.45);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.task-form button:active {
  transform: scale(0.92);
}

/* ===== Task list ===== */
.task-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card-strong);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: 0 6px 18px rgba(157, 108, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.8);
  animation: slideIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

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

.task-item.removing {
  opacity: 0;
  transform: translateX(40px) scale(0.9);
}

.task-checkbox {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid var(--purple);
  background: white;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
  position: relative;
  padding: 0;
}

.task-checkbox::after {
  content: "✓";
  color: white;
  font-weight: 800;
  font-size: 18px;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.task-item.done .task-checkbox {
  background: linear-gradient(135deg, var(--green), var(--purple));
  border-color: transparent;
}

.task-item.done .task-checkbox::after {
  opacity: 1;
  transform: scale(1);
}

.task-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.task-text {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
  cursor: pointer;
  user-select: none;
  text-align: right;
}

.task-meta {
  font-size: 12px;
  color: var(--text-soft);
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.task-meta .badge {
  background: linear-gradient(135deg, #ffe9f2, #ece1ff);
  color: var(--purple-dark);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 11px;
}

.task-item.done .task-text {
  text-decoration: line-through;
  color: var(--text-soft);
  opacity: 0.7;
}

.task-delete {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-soft);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  padding: 0;
}

.task-delete:active {
  background: rgba(255, 100, 100, 0.15);
  color: #e04545;
  transform: scale(0.9);
}

/* Routine items in TODAY view */
.task-item.routine {
  border-left: 4px solid var(--purple);
}

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  background: var(--card);
  border-radius: var(--radius);
  border: 2px dashed rgba(157, 108, 255, 0.3);
}

.empty-emoji {
  font-size: 60px;
  margin-bottom: 12px;
  animation: bounce 2s ease-in-out infinite;
}

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

.empty-state p {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--purple-dark);
}

.empty-state small {
  display: block;
  margin-top: 6px;
  color: var(--text-soft);
  font-size: 14px;
}

/* ===== Footer / Clear button ===== */
.footer {
  display: flex;
  justify-content: center;
  margin-top: 4px;
}

.clear-btn {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  padding: 10px 20px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-soft);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(157, 108, 255, 0.1);
}

.clear-btn:active {
  transform: scale(0.95);
  background: var(--card-strong);
}

/* ===== Routine card (settings page) ===== */
.routine-card {
  background: var(--card-strong);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.8);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--purple-dark);
}

.routine-input {
  width: 100%;
  border: 2px solid rgba(157, 108, 255, 0.2);
  background: white;
  border-radius: 14px;
  padding: 14px 16px;
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  outline: none;
  text-align: right;
  transition: border-color 0.2s ease;
}

.routine-input:focus {
  border-color: var(--purple);
}

.routine-input::placeholder {
  color: var(--text-soft);
  opacity: 0.7;
}

.picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.picker-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.optional {
  color: var(--text-soft);
  font-weight: 400;
  font-size: 12px;
}

.day-chips, .time-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  background: white;
  border: 2px solid rgba(157, 108, 255, 0.25);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.chip.selected {
  background: linear-gradient(135deg, var(--pink), var(--purple));
  border-color: transparent;
  color: white;
  box-shadow: 0 4px 12px rgba(255, 111, 163, 0.35);
}

.quick-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.quick-pick {
  background: transparent;
  border: 1px dashed rgba(157, 108, 255, 0.4);
  color: var(--purple-dark);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.quick-pick:active {
  transform: scale(0.95);
  background: rgba(157, 108, 255, 0.1);
}

.primary-btn {
  background: linear-gradient(135deg, var(--pink), var(--purple));
  border: none;
  color: white;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  padding: 14px 20px;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(255, 111, 163, 0.4);
  transition: transform 0.15s ease;
}

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

/* Saved routines list */
.routine-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.routine-row {
  background: var(--card-strong);
  border-radius: 18px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 6px 18px rgba(157, 108, 255, 0.1);
  display: flex;
  gap: 12px;
  align-items: center;
  animation: slideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.routine-row.removing {
  opacity: 0;
  transform: translateX(40px) scale(0.9);
}

.routine-row-body {
  flex: 1;
  min-width: 0;
}

.routine-row-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.routine-row-meta {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.routine-row-meta .day-pill {
  background: linear-gradient(135deg, #ffe9f2, #ece1ff);
  color: var(--purple-dark);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.routine-row-meta .time-pill {
  background: #fff7e0;
  color: #b57e1c;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

/* ===== Bottom Navigation ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(157, 108, 255, 0.15);
  padding: 6px 0 max(env(safe-area-inset-bottom), 6px);
  z-index: 50;
  box-shadow: 0 -4px 20px rgba(157, 108, 255, 0.08);
}

.nav-btn {
  flex: 1;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text-soft);
  transition: color 0.2s ease;
  position: relative;
  max-width: 200px;
}

.nav-icon {
  font-size: 24px;
  transition: transform 0.2s ease;
}

.nav-label {
  font-size: 12px;
  font-weight: 700;
}

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

.nav-btn.active .nav-icon {
  transform: scale(1.15);
}

.nav-btn.active::after {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: linear-gradient(90deg, var(--pink), var(--purple));
}

/* ===== Celebration ===== */
.celebration {
  position: fixed;
  inset: 0;
  background: rgba(58, 43, 77, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  z-index: 100;
  animation: fadeIn 0.3s ease;
  cursor: pointer;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.celebration-content {
  background: white;
  padding: 40px 30px;
  border-radius: 28px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  max-width: 320px;
  margin: 20px;
  animation: pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop {
  from { opacity: 0; transform: scale(0.5) rotate(-10deg); }
  to { opacity: 1; transform: scale(1) rotate(0deg); }
}

.celebration-emoji {
  font-size: 80px;
  margin-bottom: 12px;
  animation: spin 1s ease;
}

@keyframes spin {
  from { transform: rotate(-180deg) scale(0); }
  to { transform: rotate(0) scale(1); }
}

.celebration h2 {
  margin: 0 0 8px;
  color: var(--pink-dark);
  font-size: 28px;
  font-weight: 800;
}

.celebration p {
  margin: 0;
  color: var(--text-soft);
  font-size: 16px;
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + max(env(safe-area-inset-bottom), 16px) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  z-index: 80;
  animation: toastIn 0.3s ease;
  max-width: calc(100% - 40px);
  text-align: center;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ===== Utility ===== */
.hidden {
  display: none !important;
}

/* ===== Responsive tweaks ===== */
@media (max-width: 360px) {
  .greeting-text h1 { font-size: 20px; }
  .task-form input { font-size: 15px; padding: 12px 14px; }
  .chip { padding: 7px 10px; font-size: 13px; }
}

@media (min-width: 600px) {
  .view { padding-top: 32px; }
}
