:root {
  --bg: #fbf7f4;
  --card: #ffffff;
  --card-2: #fbf6f1;
  --text: #4a4560;
  --muted: #9a93ac;
  --accent: #f6c88a;
  --accent-2: #a3ddc4;
  --border: #efe7f0;
  --shadow: 0 8px 24px rgba(120, 100, 140, 0.08);
  --font-display: "Fredoka", "Baloo 2", "Segoe UI", system-ui, sans-serif;
  --font-body: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

/* Headings share the rounded, playful display face for a livelier feel. */
h1, h2, .home-greeting, .drawer-title { font-family: var(--font-display); }

/* ---- Top app header: bright, sunny, alive ---- */
.app-header {
  position: relative;
  overflow: hidden;
  text-align: center;
  padding: 32px 20px 26px;
  background: linear-gradient(120deg, #0e9db0 0%, #3aa7e0 46%, #63d6c4 100%);
  border-radius: 0 0 30px 30px;
  box-shadow: 0 12px 30px rgba(14, 120, 160, 0.28);
}
/* Warm sun-glow drifting in the top corner adds depth and life. */
.app-header::before {
  content: "";
  position: absolute;
  top: -90px;
  right: -40px;
  width: 240px;
  height: 240px;
  background: radial-gradient(circle, rgba(255, 236, 150, 0.85), rgba(255, 236, 150, 0) 68%);
  pointer-events: none;
}
.app-header::after {
  content: "";
  position: absolute;
  bottom: -120px;
  left: -60px;
  width: 260px;
  height: 260px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 70%);
  pointer-events: none;
}
.app-header h1 {
  position: relative;
  margin: 0;
  font-size: clamp(26px, 6.5vw, 38px);
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #fff;
  text-shadow: 0 3px 14px rgba(10, 74, 104, 0.38);
}
.subtitle {
  position: relative;
  margin: 8px 0 0;
  color: rgba(255, 255, 255, 0.94);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

/* Offline badge — shown in the header only when the browser reports no network. */
.offline-badge {
  position: relative;
  display: inline-block;
  margin: 10px auto 0;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: #fff;
  background: rgba(74, 69, 96, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
}
.offline-badge[hidden] { display: none; }

/* Elegant hand-drawn sprig flourish beneath the title — classy and lightly
   playful, drawn in fine white strokes so it reads as a refined divider. */
.title-flourish {
  position: relative;
  display: block;
  margin: 10px auto 0;
  line-height: 0;
}
.title-flourish svg {
  overflow: visible;
  opacity: 0.92;
  filter: drop-shadow(0 2px 6px rgba(10, 74, 104, 0.3));
}
.title-flourish path,
.title-flourish circle {
  fill: none;
  stroke: rgba(255, 255, 255, 0.95);
  stroke-width: 1.6;
  stroke-linecap: round;
}
.title-flourish .tf-leaf { fill: rgba(255, 255, 255, 0.95); stroke: none; }
.title-flourish .tf-dot  { fill: rgba(255, 255, 255, 0.95); stroke: none; }

/* ---- Burger menu button (top-left of header) ---- */
.menu-toggle {
  position: absolute;
  top: 22px;
  left: 16px;
  z-index: 5;
  width: 44px;
  height: 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  padding: 0;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(10, 74, 104, 0.2);
  transition: transform 0.12s ease, background 0.15s ease;
}
.menu-toggle:active { transform: scale(0.94); }
.menu-toggle span {
  display: block;
  width: 20px;
  height: 2.5px;
  border-radius: 999px;
  background: #1497b3;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

/* ---- Slide-in category drawer ---- */
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 82vw;
  background: var(--card);
  box-shadow: 6px 0 28px rgba(120, 100, 140, 0.16);
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 40;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 12px;
}
.drawer-title { font-size: 18px; font-weight: 800; color: var(--text); }
.drawer-close {
  width: 34px;
  height: 34px;
  border: none;
  background: var(--card-2);
  border-radius: 10px;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}
.drawer-nav { list-style: none; margin: 0; padding: 6px 12px 20px; }
.drawer-link {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 4px;
  background: transparent;
  border: none;
  border-radius: 12px;
  font: inherit;
  font-weight: 700;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}
.drawer-link:hover { background: var(--card-2); }
.drawer-link.active { background: color-mix(in srgb, var(--accent, #a3ddc4) 22%, var(--card)); }
.drawer-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--muted);
}
.drawer-label { flex: 1; }
.drawer-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

/* ---- Scrim behind the open drawer ---- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(74, 69, 96, 0.32);
  opacity: 0;
  transition: opacity 0.25s ease;
  z-index: 35;
}
.drawer-overlay.show { opacity: 1; }

/* ---- Photo credits at the foot of the drawer ---- */
.drawer-credits {
  margin-top: auto;
  padding: 14px 18px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.drawer-credits-title {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 6px;
}
.drawer-credit-line { font-size: 11px; color: var(--muted); line-height: 1.5; }

/* The category menu is a burger-triggered slide-in drawer at every screen size,
   so the content area is simply centred regardless of width. */

/* main spans the available area; each view sets its own comfortable width. */
main { margin: 0 auto; padding: 16px 20px 48px; }
/* Detail (checklist) view stays a tidy, readable single column. */
.detail-view { max-width: 640px; margin: 0 auto; }
/* Home view gets a wide canvas so the photo tiles are big, not cramped. */
.home-view { max-width: 1200px; margin: 0 auto; }

/* Categories stack vertically in a single clean list. */
.checklist-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.hidden { display: none; }

/* ---- Home screen: summery activity tiles ---- */
/* Left-aligned so the greeting lines up cleanly with the tile grid below. */
.home-hero { text-align: left; padding: 6px 2px 22px; }
.home-greeting {
  margin: 0;
  font-size: clamp(26px, 5.5vw, 34px);
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: 0.3px;
  background: linear-gradient(92deg, #ff6a3d 0%, #ff4f8b 55%, #b45be0 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: #ff4f8b; /* fallback for browsers without background-clip: text */
}
.home-tagline {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 16px;
  font-weight: 600;
}

/* A masonry-style mosaic: a fine row grid (8px units) lets each tile choose its
   own height via `grid-row: span N`, so tiles stagger like bricks instead of
   sitting in an even grid of equal squares. `dense` packing back-fills the gaps
   a mix of tall/short tiles would otherwise leave. */
.home-tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: 8px;
  grid-auto-flow: row dense;
  gap: 16px;
}
/* Very small phones: single, tall column reads better than cramped pairs. */
@media (max-width: 419px) {
  .home-tiles { grid-template-columns: 1fr; gap: 14px; }
}
/* Laptops / very wide: keep two generous columns so the mosaic stays legible. */
@media (min-width: 720px) {
  .home-tiles { gap: 22px; }
}

.home-tile {
  position: relative;
  grid-row: span 19; /* ~150px default (short) tile */
  border: none;
  border-radius: 20px;
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  background: var(--card-2);
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
/* Tall tiles rise above their neighbours to create the staggered brick rhythm. */
.home-tile-tall { grid-row: span 27; } /* ~220px */
/* Featured banner tiles span the full row, short and wide, to anchor the mosaic
   at the top and bottom. */
.home-tile-wide {
  grid-column: 1 / -1;
  grid-row: span 17; /* ~135px banner */
}
.home-tile-wide .home-tile-emoji { font-size: 34px; }
.home-tile-wide .home-tile-label { font-size: 20px; }
@media (max-width: 419px) {
  /* Single column already — even out heights so the stack reads cleanly. */
  .home-tile,
  .home-tile-tall { grid-row: span 22; }
  .home-tile-wide { grid-row: span 20; }
}
.home-tile:hover { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(120, 100, 140, 0.16); }
.home-tile:hover .home-tile-img { transform: scale(1.06); }
.home-tile:active { transform: scale(0.97); }
.home-tile:focus-visible { outline: 3px solid var(--accent, #7a6a9a); outline-offset: 2px; }
.home-tile-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  transition: transform 0.35s ease;
}
.home-tile-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 4px;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 35%, rgba(45, 35, 55, 0.72) 100%);
}
.home-tile-emoji { font-size: 28px; line-height: 1; filter: drop-shadow(0 1px 3px rgba(0,0,0,0.4)); }
.home-tile-label {
  color: #fff;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.2px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.55);
}
/* Per-tile photo controls (top-right corner): change / reset the tile image. */
.home-tile-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  z-index: 2;
}
.tile-photo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  font-size: 16px;
  line-height: 1;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.15s ease, transform 0.15s ease, background 0.15s ease;
}
/* Reveal controls on hover/focus; always show once the tile has a custom photo. */
.home-tile:hover .tile-photo-btn,
.home-tile:focus-within .tile-photo-btn,
.tile-photo-reset:not(.hidden) { opacity: 1; transform: scale(1); }
.tile-photo-btn:hover { background: #fff; }
.tile-photo-btn:focus-visible { outline: 3px solid var(--accent, #7a6a9a); outline-offset: 2px; }
/* Touch devices have no hover — keep the controls visible so they're reachable. */
@media (hover: none) {
  .tile-photo-btn { opacity: 1; transform: scale(1); }
}

.home-credit { text-align: center; color: var(--muted); font-size: 12px; margin: 18px 0 0; }

/* ---- Back button on the detail view ---- */
.back-home {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 12px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}
.back-home:active { transform: scale(0.96); }
.back-home:hover { background: var(--card-2); }

/* ---- Hero: big reactive emoji + chunky bar ---- */
.hero { display: flex; align-items: center; gap: 16px; }
.hero-emoji {
  font-size: 52px;
  line-height: 1;
  flex-shrink: 0;
  animation: float 3s ease-in-out infinite;
}
.hero-emoji.pop { animation: pop 0.5s ease, float 3s ease-in-out infinite 0.5s; }
.hero-copy { flex: 1; min-width: 0; }
.hero-copy h2 { margin: 0 0 8px; font-size: 22px; }
.hero-bar {
  height: 14px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.hero-bar-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffb59e, #f6c88a, #a3ddc4);
  transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.hero-sub { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.hero-sub b { color: var(--text); }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
@keyframes pop {
  0% { transform: scale(0.4) rotate(-12deg); }
  60% { transform: scale(1.25) rotate(6deg); }
  100% { transform: scale(1) rotate(0); }
}

.all-done {
  background: var(--accent-2);
  color: #2f5c4a;
  font-weight: 700;
  font-size: 16px;
  text-align: center;
  padding: 14px;
  border-radius: 12px;
  margin-top: 14px;
}


/* ---- Sections ---- */
.checklist-group {
  --accent: var(--accent-2);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  border-left: 4px solid var(--accent);
  box-shadow: var(--shadow);
}
.group-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--card-2);
  border: none;
  cursor: pointer;
  font: inherit;
  color: var(--text);
  text-align: left;
}
.sec-title { flex: 1; font-size: 15px; font-weight: 700; }
.sec-meta { display: flex; align-items: center; gap: 10px; }
.sec-count { font-size: 13px; font-weight: 700; color: var(--muted); }
.sec-bar {
  width: 56px;
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.sec-bar-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.sec-caret { color: var(--muted); transition: transform 0.2s ease; }
.checklist-group:not(.collapsed) .sec-caret { transform: rotate(90deg); }
.checklist-group.collapsed .group-rows { display: none; }
.checklist-group.complete { border-left-color: var(--accent-2); }
.checklist-group.complete .sec-count { color: var(--accent-2); }
.checklist-group.complete .sec-caret::after { content: " ✓"; }

.group-rows { padding: 12px; animation: slideDown 0.25s ease; }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}
.check-row:last-child { margin-bottom: 0; }
.check-row:active { transform: scale(0.98); }
.check-row input[type="checkbox"] {
  width: 24px;
  height: 24px;
  accent-color: var(--accent);
  flex-shrink: 0;
}
.check-text { flex: 1; font-size: 16px; }
.check-row.done {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--card));
  animation: tickBounce 0.35s ease;
}
.check-row.done .check-text {
  text-decoration: line-through;
  color: var(--muted);
}
@keyframes tickBounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

/* ---- Delete button on each item row ---- */
.row-del {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.row-del:hover, .row-del:active {
  opacity: 1;
  color: #e39aa6;
  background: color-mix(in srgb, #e39aa6 20%, transparent);
}

/* ---- Delete control on a custom category's section header ---- */
.sec-del {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 14px;
  line-height: 1;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.sec-del:hover, .sec-del:active, .sec-del:focus-visible {
  opacity: 1;
  background: color-mix(in srgb, #e39aa6 20%, transparent);
  outline: none;
}

/* ---- Add-item input row (per section) ---- */
.add-item-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.add-item-input {
  flex: 1;
  min-width: 0;
  padding: 12px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--card-2);
  border: 2px dashed var(--border);
  border-radius: 12px;
}
.add-item-input:focus {
  outline: none;
  border-style: solid;
  border-color: var(--accent);
}
.add-item-btn {
  flex-shrink: 0;
  width: 44px;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.add-item-btn:active { transform: scale(0.92); }

/* ---- Chores / paid categories (money rewards) ---- */
.reward-badge {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 800;
  color: #2f5c4a;
  background: color-mix(in srgb, var(--accent) 30%, var(--card));
  padding: 3px 9px;
  border-radius: 999px;
}
.sec-earned {
  font-size: 13px;
  font-weight: 800;
  color: #2f5c4a;
  background: color-mix(in srgb, var(--accent) 30%, var(--card));
  padding: 2px 8px;
  border-radius: 999px;
}
.add-item-amount {
  width: 64px;
  flex-shrink: 0;
  padding: 12px 8px;
  font: inherit;
  font-size: 15px;
  text-align: center;
  color: var(--text);
  background: var(--card-2);
  border: 2px dashed var(--border);
  border-radius: 12px;
}
.add-item-amount:focus {
  outline: none;
  border-style: solid;
  border-color: var(--accent);
}
.hero-earned {
  margin: 6px 0 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
}
.hero-earned.hidden { display: none; }

/* ---- New-category control (footer tile at the end of the list) ---- */
.add-category {
  display: flex;
  gap: 8px;
  padding: 14px;
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: 16px;
}
.add-category .add-item-input { border-color: var(--border); background: var(--card-2); }
.add-category-btn {
  flex-shrink: 0;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  color: var(--text);
  background: var(--card-2);
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
}
.add-category-btn:active { transform: scale(0.96); }

.result-actions { display: flex; gap: 12px; margin-top: 4px; }
.btn-secondary {
  flex: 1;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
}

/* Backup / restore row (export + import your custom items and progress). */
.data-actions { display: flex; gap: 12px; margin-top: 12px; }
.data-actions .btn-secondary { font-size: 14px; }

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
}

.app-footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 0 16px 24px;
}

/* ---- Respect users who prefer reduced motion ---- */
/* Turns off the decorative/large-movement animations and long transitions for
   people with vestibular sensitivities, while keeping the UI fully usable. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .hero-emoji,
  .hero-emoji.pop { animation: none !important; }
}
