/* ==========================================================
   Habitly | style.css
   1. Design tokens (CSS variables)   5. Add-habit form
   2. Base + helpers                  6. Chart
   3. Layout + header                 7. Habit cards + filters
   4. Quote + stats                   8. Footer, animations, responsive
   ========================================================== */

/* ---------- 1. Design tokens ---------- */
:root {
  --navy: #0B1F3A;
  --teal: #14B8A6;

  --bg: #F6F8FB;
  --surface: #FFFFFF;
  --text: #0B1F3A;
  --muted: #566478;
  --border: #E1E7EF;
  --accent: #14B8A6;        /* teal fills (buttons, bars) */
  --on-accent: #0B1F3A;     /* navy text on teal = good contrast */
  --accent-text: #0F766E;   /* darker teal for text on light surfaces */
  --accent-soft: #E6F7F5;
  --bar: #A9BBD1;
  --danger: #C0281C;
  --danger-text: #B42318;
  --shadow: 0 1px 2px rgba(11, 31, 58, 0.06), 0 8px 24px rgba(11, 31, 58, 0.08);

  --radius: 16px;
  /* 8px spacing scale */
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;

  color-scheme: light;
}

/* Dark theme: script.js sets data-theme="dark" on <html> */
:root[data-theme="dark"] {
  --bg: #071428;
  --surface: #0B1F3A;
  --text: #EAF0F8;
  --muted: #9DB0C8;
  --border: #1D3659;
  --accent-text: #2DD4BF;
  --accent-soft: #0F3340;
  --bar: #3A5E8C;
  --danger: #DC2626;
  --danger-text: #FDA29B;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);

  color-scheme: dark;
}

/* ---------- 2. Base + helpers ---------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  transition: background-color 0.3s, color 0.3s; /* smooth theme switch */
}

h1, h2, h3, p, blockquote { margin: 0; }
h2 { font-size: 1.125rem; font-weight: 600; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* The hidden attribute must always win over display rules */
[hidden] { display: none !important; }

/* Visible to screen readers only */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- 3. Layout + header ---------- */
.container { max-width: 1040px; margin: 0 auto; padding: var(--space-2); }

/* Space between the main sections */
main > * + * { margin-top: var(--space-3); }

.header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-2); padding: var(--space-1) 0 var(--space-3);
}
.logo { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
.logo::after { content: "."; color: var(--accent); }
.date { color: var(--muted); font-size: 0.9375rem; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; font-size: 1.25rem;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform 0.2s, background-color 0.3s;
}
.icon-btn:hover { transform: rotate(15deg); }

/* A card is the basic building block of the page */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-2);
  transition: background-color 0.3s, border-color 0.3s;
}

/* ---------- 4. Quote + stats ---------- */
.quote {
  background: linear-gradient(135deg, #0B1F3A, #123A63);
  border-color: transparent;
  color: #fff;
  padding: var(--space-3);
}
.quote-text { font-size: 1.25rem; font-weight: 500; line-height: 1.4; max-width: 60ch; }
.quote-author { margin-top: var(--space-1); color: #5EEAD4; font-weight: 500; }
.quote.loading .quote-text { animation: pulse 1.2s ease-in-out infinite; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-1); }
.stat { display: flex; flex-direction: column; gap: 4px; padding: var(--space-2) var(--space-1); text-align: center; }
.stat-value { font-size: clamp(1.25rem, 5vw, 1.75rem); font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 0.8125rem; color: var(--muted); }

/* ---------- 5. Add-habit form ---------- */
.add-row { display: flex; gap: var(--space-1); margin-top: var(--space-2); }

.add-row input {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 var(--space-2);
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
}
.add-row input:focus-visible { border-color: var(--accent); }
.add-row input[aria-invalid="true"] { border-color: var(--danger-text); }

.btn {
  min-height: 48px; padding: 0 var(--space-3); border: 0; border-radius: 12px;
  background: var(--accent); color: var(--on-accent); font-weight: 600;
  transition: filter 0.2s, transform 0.1s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.97); }

.emoji-row { display: flex; flex-wrap: wrap; gap: var(--space-1); margin-top: var(--space-2); }
.emoji-btn {
  width: 44px; height: 44px; font-size: 1.375rem; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--border);
}
.emoji-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

.form-message { min-height: 24px; margin-top: var(--space-1); font-size: 0.875rem; color: var(--danger-text); }

/* ---------- 6. Weekly chart ---------- */
.chart { display: flex; gap: var(--space-1); height: 200px; margin-top: var(--space-2); }
.bar-col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar-track {
  flex: 1; width: 100%; max-width: 48px; display: flex; align-items: flex-end;
  background: var(--bg); border-radius: 10px; overflow: hidden;
}
.bar-fill {
  width: 100%; height: 0; min-height: 4px; border-radius: 10px; background: var(--bar);
  transition: height 0.7s cubic-bezier(0.2, 0.8, 0.2, 1); /* the bar "grows" */
}
.bar-pct, .bar-day { font-size: 0.75rem; color: var(--muted); }
.bar-day { font-weight: 500; }
.bar-col.today .bar-fill { background: var(--accent); }
.bar-col.today .bar-day { color: var(--accent-text); font-weight: 700; }

/* ---------- 7. Habit cards + filters ---------- */
.list-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
.filters { display: flex; gap: var(--space-1); }
.filter {
  min-height: 44px; padding: 0 var(--space-2); border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); font-weight: 500;
}
.filter[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }

/* One column on phones, more columns as the screen gets wider */
.habit-list {
  list-style: none; margin: var(--space-2) 0 0; padding: 0;
  display: grid; gap: var(--space-2);
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.habit { display: flex; flex-direction: column; gap: var(--space-2); }
.habit.is-done { border-color: var(--accent); }
.habit-top { display: flex; align-items: center; gap: var(--space-2); }
.habit-emoji {
  width: 48px; height: 48px; flex-shrink: 0; display: grid; place-items: center;
  font-size: 1.75rem; background: var(--accent-soft); border-radius: 14px;
}
.habit-info { flex: 1; min-width: 0; }
.habit-name { font-size: 1.0625rem; font-weight: 600; overflow-wrap: anywhere; }
.streak { font-size: 0.875rem; color: var(--muted); }
.streak-num { display: inline-block; font-weight: 700; color: var(--text); }

.delete {
  min-width: 44px; height: 44px; border-radius: 12px; border: 0;
  background: transparent; font-size: 1.125rem;
}
.delete:hover { background: var(--bg); }
.delete.confirming { padding: 0 var(--space-2); background: var(--danger); color: #fff; font-size: 0.9375rem; font-weight: 600; }

/* The big "complete today" button */
.check {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  min-height: 56px; border-radius: 14px; font-weight: 600;
  background: var(--bg); border: 2px solid var(--border);
  transition: background-color 0.2s, border-color 0.2s;
}
.check:hover { border-color: var(--accent); }
.check-box {
  width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%;
  border: 2px solid var(--muted); color: transparent; font-size: 1rem; font-weight: 700;
}
.check.checked { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.check.checked .check-box { background: var(--on-accent); border-color: var(--on-accent); color: var(--accent); }

.empty { padding: 48px var(--space-2); text-align: center; border: 2px dashed var(--border); border-radius: var(--radius); }
.empty-art { font-size: 4rem; animation: float 3s ease-in-out infinite; }
.empty h3 { margin-top: var(--space-1); font-size: 1.125rem; }
.empty p { color: var(--muted); }

/* ---------- 8. Footer, animations, responsive ---------- */
.footer { padding: var(--space-4) 0 var(--space-2); text-align: center; color: var(--muted); font-size: 0.875rem; }
.footer a, .link-btn { color: var(--accent-text); }
.link-btn { min-height: 44px; padding: 0 var(--space-2); background: none; border: 0; text-decoration: underline; }

@keyframes fade-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.35); } 100% { transform: scale(1); } }
@keyframes bump { 40% { transform: scale(1.6); color: var(--accent-text); } }
@keyframes pulse { 50% { opacity: 0.5; } }
@keyframes float { 50% { transform: translateY(-8px); } }

.fade-in { animation: fade-in 0.4s ease-out both; }
.check.pop .check-box { animation: pop 0.45s ease-out; }
.streak-num.bump { animation: bump 0.5s ease-out; }

/* Turn animations off for people who ask for less motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Bigger screens: more breathing room */
@media (min-width: 720px) {
  .container { padding: var(--space-4) var(--space-3); }
  .logo { font-size: 2.25rem; }
  .card { padding: var(--space-3); }
  .stat { padding: var(--space-3) var(--space-2); }
  .quote { padding: var(--space-4); }
  .quote-text { font-size: 1.5rem; }
  .stats { gap: var(--space-2); }
  .chart { height: 240px; gap: var(--space-2); }
}