/* ========================================
   K-Habit Tracker — Design System (Vanilla CSS)
   Version 1.1 — No Tailwind dependency
   ======================================== */

/* --- CSS Variables (Design Tokens) --- */
:root {
  --primary: #6b21a8;
  --primary-hover: #581c87;
  --secondary: #d8b4fe;
  --accent: #f472b6;
  --bg: #fdf4ff;
  --card-bg: #ffffff;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f3e8ff;
  --input-bg: #f9fafb;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.04);
  --radius: 16px;
  --radius-sm: 12px;
  --radius-full: 9999px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --font: 'Poppins', sans-serif;
}

.dark {
  --bg: #1e1b4b;
  --card-bg: #312e81;
  --text: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --border: #3730a3;
  --border-light: #3730a3;
  --input-bg: #1e1b4b;
  --shadow: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.25);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.3);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* --- Utilities --- */
.container { max-width: 900px; margin: 0 auto; padding: 2rem 1rem 3rem; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* --- Loading Screen --- */
#loadingScreen {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.5rem;
  background: var(--bg);
  transition: opacity 0.4s ease;
}
#loadingScreen.fade-out { opacity: 0; pointer-events: none; }
.loading-logo { font-size: 2rem; font-weight: 700; color: var(--primary); }
.dark .loading-logo { color: var(--secondary); }
.loading-spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.dark .loading-spinner { border-top-color: var(--secondary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Header --- */
.header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 2rem;
}
.header-brand h1 {
  font-size: 1.75rem; font-weight: 700;
  color: var(--primary); display: flex; align-items: center; gap: 0.5rem;
}
.dark .header-brand h1 { color: var(--secondary); }
.header-brand p { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.15rem; }
.header-actions { display: flex; gap: 0.75rem; align-items: center; }

/* --- Buttons --- */
.btn-icon {
  width: 42px; height: 42px; border-radius: var(--radius-full);
  background: var(--card-bg); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); font-size: 1rem;
  box-shadow: var(--shadow); transition: all var(--transition);
}
.btn-icon:hover { color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-icon:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary {
  width: 100%; padding: 0.65rem 1.25rem; border: none; border-radius: var(--radius-sm);
  background: var(--primary); color: #fff; font-family: var(--font);
  font-size: 0.875rem; font-weight: 500; cursor: pointer;
  box-shadow: var(--shadow-md); transition: all var(--transition);
}
.btn-primary:hover { background: var(--primary-hover); box-shadow: var(--shadow-lg); }
.btn-primary:focus-visible { outline: 2px solid var(--secondary); outline-offset: 2px; }

/* --- Dropdown Menu --- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 0.5rem);
  width: 200px; background: var(--card-bg); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); overflow: hidden; z-index: 100;
  opacity: 0; visibility: hidden; transform: translateY(-8px);
  transition: all 0.2s ease;
}
.dropdown-menu.open { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-menu button {
  width: 100%; text-align: left; padding: 0.75rem 1rem;
  border: none; background: none; cursor: pointer;
  font-family: var(--font); font-size: 0.8rem;
  color: var(--text); display: flex; align-items: center; gap: 0.6rem;
  transition: background var(--transition);
}
.dropdown-menu button:hover { background: rgba(107,33,168,0.06); }
.dark .dropdown-menu button:hover { background: rgba(216,180,254,0.08); }
.dropdown-menu button.danger { color: #ef4444; }
.dropdown-menu button.danger:hover { background: rgba(239,68,68,0.08); }
.dropdown-menu .divider { height: 1px; background: var(--border); }

/* --- Cards --- */
.card {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 1.5rem; box-shadow: var(--shadow);
  transition: background var(--transition), box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-title {
  font-size: 1.15rem; font-weight: 700;
  display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem;
}
.card-title i { color: var(--primary); }
.dark .card-title i { color: var(--secondary); }

/* --- Quote Section --- */
.quote-card {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 1.25rem 1.5rem; box-shadow: var(--shadow);
  text-align: center; border-left: 4px solid var(--accent);
  position: relative; overflow: hidden; margin-bottom: 1.5rem;
  transition: background var(--transition);
}
.quote-card .quote-icon {
  position: absolute; right: -0.25rem; top: -0.25rem;
  font-size: 3.5rem; color: var(--border); opacity: 0.5;
}
.quote-card .quote-text { font-size: 1.05rem; font-weight: 500; font-style: italic; position: relative; z-index: 1; }
.quote-card .quote-translation { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.35rem; display: block; font-style: normal; }

/* --- Grid Layout --- */
.grid-top { display: grid; grid-template-columns: 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }
.grid-main { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }
@media (min-width: 768px) {
  .grid-top { grid-template-columns: 2fr 1fr; }
  .grid-main { grid-template-columns: 7fr 5fr; }
}
.col-stack { display: flex; flex-direction: column; gap: 1.5rem; }

/* --- Progress Card --- */
.progress-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 0.5rem; }
.progress-header h2 { font-size: 1.15rem; font-weight: 700; }
.progress-date { font-size: 0.8rem; color: var(--text-secondary); }
.progress-percent { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.dark .progress-percent { color: var(--secondary); }
.progress-track {
  width: 100%; height: 1rem; background: var(--border);
  border-radius: var(--radius-full); overflow: hidden; margin: 0.5rem 0;
}
.dark .progress-track { background: #1e1b4b; }
.progress-fill {
  height: 100%; width: 0%; border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 1s ease-out; position: relative;
}
.progress-fill::after {
  content: ''; position: absolute; inset: 0;
  background: repeating-linear-gradient(45deg, rgba(255,255,255,0.15) 0, rgba(255,255,255,0.15) 25%, transparent 25%, transparent 50%);
  background-size: 1rem 1rem;
  animation: stripe-move 1s linear infinite;
}
@keyframes stripe-move { to { background-position: 1rem 0; } }
.progress-label { font-size: 0.8rem; text-align: center; color: var(--text-secondary); margin-top: 0.25rem; }

/* --- Streak Card --- */
.streak-card {
  background: linear-gradient(135deg, #f97316, #ef4444);
  border-radius: var(--radius); padding: 1.5rem;
  color: #fff; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  position: relative; overflow: hidden;
  transition: transform var(--transition);
  text-align: center;
}
.streak-card:hover { transform: scale(1.03); }
.streak-card .streak-bg { position: absolute; right: -0.5rem; bottom: -0.5rem; font-size: 4rem; opacity: 0.15; }
.streak-card h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: 0.25rem; position: relative; z-index: 1; }
.streak-value { display: flex; align-items: center; gap: 0.5rem; position: relative; z-index: 1; }
.streak-fire { font-size: 1.75rem; color: #fde047; animation: flicker 2s ease-in-out infinite; display: inline-block; }
.streak-count { font-size: 3rem; font-weight: 700; }
.streak-badge {
  font-size: 0.75rem; font-weight: 500; margin-top: 0.5rem;
  background: rgba(255,255,255,0.2); padding: 0.25rem 0.85rem;
  border-radius: var(--radius-full); backdrop-filter: blur(4px);
  position: relative; z-index: 1;
}
@keyframes flicker {
  0%, 100% { transform: scale(1) rotate(0deg); opacity: 1; }
  25% { transform: scale(1.12) rotate(-3deg); opacity: 0.9; }
  50% { transform: scale(0.95) rotate(3deg); opacity: 1; }
  75% { transform: scale(1.06) rotate(-1deg); opacity: 0.8; }
}

/* --- Task Items --- */
.task-list { display: flex; flex-direction: column; gap: 0.75rem; }
.task-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.15rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: rgba(249,250,251,0.5);
  transition: all var(--transition); cursor: pointer;
}
.dark .task-item { background: rgba(30,27,75,0.3); }
.task-item:hover { border-color: var(--secondary); }
.task-left { display: flex; align-items: center; gap: 1rem; }
.task-checkbox {
  appearance: none; -webkit-appearance: none;
  width: 24px; height: 24px; min-width: 24px;
  border: 2px solid var(--text-muted); border-radius: 6px;
  cursor: pointer; position: relative;
  transition: all var(--transition); background: transparent;
}
.task-checkbox:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.task-checkbox:checked {
  background: var(--primary); border-color: var(--primary); transform: scale(1.1);
}
.dark .task-checkbox { border-color: #4f46e5; }
.dark .task-checkbox:checked { background: var(--secondary); border-color: var(--secondary); }
.task-checkbox:checked::after {
  content: '\f00c'; font-family: 'Font Awesome 6 Free'; font-weight: 900;
  font-size: 13px; color: #fff; position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
}
.dark .task-checkbox:checked::after { color: var(--card-bg); }
.task-label {
  font-weight: 500; font-size: 0.9rem; cursor: pointer;
  display: flex; align-items: center; gap: 0.75rem;
  position: relative; transition: color var(--transition);
}
.task-label::after {
  content: ''; position: absolute; left: 0; top: 50%;
  height: 2px; width: 0; background: currentColor;
  transition: width 0.3s ease-out;
}
.task-icon {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--card-bg); box-shadow: var(--shadow);
  font-size: 0.85rem;
}
.dark .task-icon { background: #1e1b4b; }
.task-item.completed .task-label { color: var(--text-muted); }
.task-item.completed .task-label::after { width: 100%; }

/* --- Goals Section --- */
.goals-summary {
  padding: 1rem; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #faf5ff, #fdf2f8);
  border: 1px solid #e9d5ff;
  display: flex; align-items: flex-start; gap: 0.85rem;
}
.dark .goals-summary { background: linear-gradient(135deg, rgba(49,46,129,0.4), rgba(88,28,135,0.3)); border-color: var(--border); }
.goals-icon-circle {
  width: 40px; height: 40px; min-width: 40px; border-radius: var(--radius-full);
  background: rgba(107,33,168,0.1); display: flex; align-items: center; justify-content: center;
  color: var(--primary);
}
.dark .goals-icon-circle { background: rgba(216,180,254,0.1); color: var(--secondary); }
.goals-info { flex: 1; }
.goals-target { font-size: 0.85rem; font-weight: 600; color: var(--primary); }
.dark .goals-target { color: var(--secondary); }
.goals-duration { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.2rem; display: flex; align-items: center; gap: 0.3rem; }
.goals-edit-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 0.8rem;
  transition: color var(--transition);
}
.goals-edit-btn:hover { color: var(--primary); }
.dark .goals-edit-btn:hover { color: var(--secondary); }

/* --- Forms --- */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 0.35rem; }
.form-input {
  width: 100%; padding: 0.6rem 1rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--input-bg);
  font-family: var(--font); font-size: 0.875rem; color: var(--text);
  transition: all var(--transition); outline: none;
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(107,33,168,0.1); }
textarea.form-input { resize: none; min-height: 180px; line-height: 1.7; }

/* --- Calendar --- */
.calendar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.calendar-month { font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); }
.calendar-weekdays { display: grid; grid-template-columns: repeat(7,1fr); gap: 4px; text-align: center; font-size: 0.7rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.35rem; }
.calendar-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 4px; }
.cal-day {
  aspect-ratio: 1; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 500;
  position: relative; cursor: default; transition: all var(--transition);
}
.cal-day.empty { background: transparent; }
.cal-day.level-0 { background: var(--input-bg); color: var(--text-muted); }
.dark .cal-day.level-0 { background: rgba(30,27,75,0.5); }
.cal-day.level-1 { background: #e9d5ff; color: #6b21a8; }
.dark .cal-day.level-1 { background: rgba(107,33,168,0.4); color: #d8b4fe; }
.cal-day.level-2 { background: var(--primary); color: #fff; box-shadow: var(--shadow); }
.cal-day.today { outline: 2px solid var(--primary); outline-offset: 2px; z-index: 2; }
.dark .cal-day.today { outline-color: var(--secondary); }

/* Calendar Tooltip */
.cal-day .tooltip {
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; font-size: 0.65rem; padding: 0.2rem 0.5rem;
  border-radius: 6px; white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity 0.2s; z-index: 20; box-shadow: var(--shadow-md);
}
.cal-day .tooltip::after {
  content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 4px solid transparent; border-top-color: #1f2937;
}
.cal-day:hover .tooltip { opacity: 1; }

/* --- Monthly Stats --- */
.monthly-stats {
  display: grid; grid-template-columns: repeat(3,1fr); gap: 0.75rem;
  text-align: center; margin-top: 1rem; padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.stat-value { font-size: 1.35rem; font-weight: 700; }
.stat-value.purple { color: var(--primary); }
.dark .stat-value.purple { color: var(--secondary); }
.stat-value.green { color: #22c55e; }
.stat-value.pink { color: var(--accent); }
.stat-label { font-size: 0.6rem; color: var(--text-muted); margin-top: 0.15rem; }

/* --- Notes Section --- */
.notes-hint { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.75rem; }
.notes-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 0.75rem; }
.save-status { font-size: 0.75rem; color: #22c55e; opacity: 0; transition: opacity var(--transition); }
.btn-secondary {
  padding: 0.5rem 1rem; border: none; border-radius: 8px;
  background: var(--input-bg); color: var(--text-secondary);
  font-family: var(--font); font-size: 0.8rem; font-weight: 500;
  cursor: pointer; transition: all var(--transition);
}
.btn-secondary:hover { background: var(--border); color: var(--text); }
.dark .btn-secondary { background: #1e1b4b; }
.dark .btn-secondary:hover { background: #3730a3; color: var(--text); }

/* --- Toast --- */
.toast {
  position: fixed; bottom: 1.25rem; right: 1.25rem;
  background: #1f2937; color: #fff; padding: 0.85rem 1.25rem;
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 0.65rem;
  font-size: 0.85rem; z-index: 300;
  transform: translateY(5rem); opacity: 0;
  transition: all 0.3s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast i { color: #4ade80; }

/* --- Onboarding Modal --- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
}
.modal-content {
  position: relative; background: var(--card-bg);
  border-radius: 1.5rem; box-shadow: var(--shadow-lg);
  max-width: 420px; width: 100%; padding: 2rem;
  transform: scale(0.95); opacity: 0;
  transition: all 0.3s ease;
}
.modal-content.active { transform: scale(1); opacity: 1; }
.modal-dots { display: flex; justify-content: center; gap: 0.5rem; margin-bottom: 1.5rem; }
.modal-dot {
  width: 2rem; height: 4px; border-radius: var(--radius-full);
  background: var(--border); transition: background var(--transition);
}
.modal-dot.active { background: var(--primary); }
.dark .modal-dot.active { background: var(--secondary); }
.modal-step { text-align: center; }
.modal-step .emoji { font-size: 3.5rem; margin-bottom: 1rem; }
.modal-step h2 { font-size: 1.4rem; font-weight: 700; color: var(--primary); margin-bottom: 0.5rem; }
.dark .modal-step h2 { color: var(--secondary); }
.modal-step p { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.7; }
.modal-actions { display: flex; gap: 0.75rem; margin-top: 2rem; }
.modal-actions button { flex: 1; }
.btn-outline {
  padding: 0.65rem 1.25rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: none; color: var(--text-secondary); font-family: var(--font);
  font-size: 0.85rem; font-weight: 500; cursor: pointer;
  transition: all var(--transition);
}
.btn-outline:hover { background: var(--input-bg); }

/* --- Footer --- */
.footer {
  padding: 2rem 1rem 1rem;
  font-size: 0.75rem; color: var(--text-muted);
}
.footer-content {
  display: flex; flex-direction: column; align-items: center; gap: 1rem; text-align: center;
}
@media (min-width: 768px) {
  .footer-content { flex-direction: row; justify-content: space-between; text-align: left; }
}
.social-links {
  display: flex; gap: 1.2rem; align-items: center;
}
.social-links a {
  color: var(--text-muted); font-size: 1.2rem; transition: color var(--transition), transform var(--transition);
}
.social-links a:hover {
  color: var(--primary); transform: translateY(-2px);
}
.dark .social-links a:hover {
  color: var(--secondary);
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 20px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }
.dark ::-webkit-scrollbar-thumb { background: #4f46e5; }
.dark ::-webkit-scrollbar-thumb:hover { background: #6366f1; }
/* Firefox */
html { scrollbar-width: thin; scrollbar-color: #d1d5db transparent; }
.dark { scrollbar-color: #4f46e5 transparent; }

/* --- Card Entrance Animation --- */
.card { opacity: 0; transform: translateY(16px); animation: fadeUp 0.5s ease forwards; }
.card:nth-child(1) { animation-delay: 0.05s; }
.card:nth-child(2) { animation-delay: 0.1s; }
.card:nth-child(3) { animation-delay: 0.15s; }
.card:nth-child(4) { animation-delay: 0.2s; }
@keyframes fadeUp { to { opacity: 1; transform: translateY(0); } }

/* --- Responsive --- */
@media (max-width: 767px) {
  .container { padding: 1.25rem 0.85rem 2rem; }
  .header-brand h1 { font-size: 1.4rem; }
  .streak-count { font-size: 2.5rem; }
  .progress-percent { font-size: 1.4rem; }
}
