:root {
  --bg: #edf4ff;
  --surface: #ffffff;
  --surface-subtle: #f3f8ff;
  --border: #cfe0fc;
  --text: #0f2147;
  --text-muted: #47608a;
  --accent: #1d4ed8;
  --accent-soft: #dbeafe;
  --accent-border: #93c5fd;
  --accent-dark: #1e40af;
  --header-bg: linear-gradient(135deg, #1d4ed8 0%, #2563eb 55%, #0284c7 100%);
  --header-text: #ffffff;
  --header-muted: rgba(255, 255, 255, 0.86);
  --star: #d97706;
  --star-soft: #fef3c7;
  --success: #15803d;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --shadow-sm: 0 2px 6px rgba(29, 78, 216, 0.08);
  --shadow-md: 0 10px 28px rgba(15, 33, 71, 0.14);
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

[data-theme="sky"] {
  --accent: #0284c7;
  --accent-soft: #e0f2fe;
  --accent-border: #7dd3fc;
  --accent-dark: #0369a1;
  --header-bg: linear-gradient(135deg, #0369a1 0%, #0284c7 55%, #2563eb 100%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #071226;
    --surface: #0d1c38;
    --surface-subtle: #15294d;
    --border: #243d6b;
    --text: #f0f6ff;
    --text-muted: #9bb4db;
    --accent: #3b82f6;
    --accent-soft: rgba(59, 130, 246, 0.22);
    --accent-border: rgba(96, 165, 250, 0.5);
    --accent-dark: #93c5fd;
    --header-bg: linear-gradient(135deg, #0f2a5c 0%, #1d4ed8 100%);
    --header-text: #f8fafc;
    --header-muted: rgba(224, 242, 254, 0.85);
    --star: #fbbf24;
    --star-soft: rgba(251, 191, 36, 0.2);
    --success: #4ade80;
    --success-soft: rgba(34, 197, 94, 0.18);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.18);
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.5);
  }

  [data-theme="sky"] {
    --accent: #38bdf8;
    --accent-soft: rgba(56, 189, 248, 0.2);
    --accent-border: rgba(125, 211, 252, 0.5);
    --accent-dark: #7dd3fc;
    --header-bg: linear-gradient(135deg, #0c3559 0%, #0284c7 100%);
  }
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  min-height: 100%;
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 200;
}

.confetti-piece {
  position: absolute;
  top: -12px;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  opacity: 0.95;
  animation: confetti-fall var(--dur, 1.8s) cubic-bezier(0.2, 0.7, 0.4, 1) forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--dx, 40px), 105vh, 0) rotate(var(--rot, 540deg));
    opacity: 0;
  }
}

.app-shell {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--header-bg);
  color: var(--header-text);
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
  padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 14px;
  box-shadow: var(--shadow-md);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.app-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--header-text);
}

.week-subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--header-muted);
  font-weight: 600;
}

.sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.28);
  font-size: 12px;
  font-weight: 600;
  color: var(--header-text);
  white-space: nowrap;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
}

.sync-badge.saving .sync-dot {
  background: #fbbf24;
}

.sync-badge.offline .sync-dot {
  background: #f87171;
}

.kid-switcher {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.kid-tab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 2px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  font-weight: 700;
  font-size: 16px;
  transition: transform 0.12s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.kid-tab:active {
  transform: scale(0.98);
}

.kid-tab.active {
  border-color: #ffffff;
  background: #ffffff;
  color: #0f2147;
  box-shadow: 0 4px 12px rgba(15, 33, 71, 0.18);
}

.kid-tab-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.kid-avatar {
  font-size: 20px;
}

.kid-stars {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  color: #fef3c7;
  font-size: 13px;
  font-weight: 800;
}

.kid-tab.active .kid-stars {
  background: #dbeafe;
  color: #1d4ed8;
}

.app-main {
  flex: 1;
  padding: 14px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.starter-banner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  font-size: 13.5px;
  color: var(--text);
}

.banner-dismiss {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 6px;
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.view-toggle {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}

.view-btn {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
}

.view-btn.active {
  background: var(--accent);
  color: #ffffff;
}

.today-pill {
  border: 1px solid var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.day-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.day-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 9px 4px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  min-height: 60px;
}

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

.day-btn.today:not(.active) {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

.day-name {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  opacity: 0.8;
}

.day-dot {
  font-size: 13px;
  line-height: 1;
}

.progress-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

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

.progress-title {
  font-size: 15px;
  font-weight: 700;
}

.progress-count {
  font-size: 15px;
  font-weight: 800;
  color: var(--star);
}

.progress-track {
  height: 12px;
  border-radius: 999px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--star));
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-cheer {
  margin: 10px 0 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.progress-card.complete .progress-cheer {
  color: var(--success);
}

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

.chore-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 2px solid var(--border);
  background: var(--surface);
  text-align: left;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, border-color 0.15s ease, background-color 0.15s ease;
  min-height: 70px;
}

.chore-card:active {
  transform: scale(0.985);
}

.chore-card.done {
  border-color: var(--success);
  background: var(--success-soft);
}

.chore-check {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  background: var(--surface-subtle);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 18px;
  font-weight: 800;
  color: transparent;
  transition: all 0.15s ease;
}

.chore-card.done .chore-check {
  border-color: var(--success);
  background: var(--success);
  color: #ffffff;
}

.chore-emoji {
  font-size: 26px;
  flex-shrink: 0;
}

.chore-info {
  flex: 1;
  min-width: 0;
}

.chore-name {
  font-size: 17px;
  font-weight: 700;
  word-break: break-word;
}

.chore-card.done .chore-name {
  text-decoration: line-through;
  opacity: 0.78;
}

.chore-star {
  font-size: 20px;
  opacity: 0.25;
  transition: transform 0.2s ease, opacity 0.15s ease;
}

.chore-card.done .chore-star {
  opacity: 1;
  transform: scale(1.15);
}

/* Full Week View */
.week-grid-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}

.week-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 440px;
}

.week-table th,
.week-table td {
  padding: 10px 6px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.week-table th {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-subtle);
}

.week-table th.today-col {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.week-table td.chore-col {
  text-align: left;
  padding-left: 12px;
  font-weight: 600;
  font-size: 14px;
  min-width: 140px;
}

.week-cell-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface-subtle);
  display: inline-grid;
  place-items: center;
  font-size: 16px;
  color: transparent;
}

.week-cell-btn.done {
  border-color: var(--success);
  background: var(--success);
  color: #ffffff;
}

.empty-state {
  text-align: center;
  padding: 36px 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
}

.parent-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex;
  justify-content: center;
  gap: 10px;
}

.parent-btn {
  flex: 1;
  max-width: 300px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  font-size: 15px;
  font-weight: 700;
}

.parent-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.parent-btn.secondary {
  background: var(--surface-subtle);
  color: var(--text);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}

@media (min-width: 600px) {
  .modal-backdrop {
    align-items: center;
  }
}

.modal-sheet {
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  background: var(--surface);
  border-radius: 22px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-compact {
  max-width: 440px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
}

.modal-sub {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.icon-close-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  font-size: 15px;
  display: grid;
  place-items: center;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.add-chore-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
}

.form-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.add-input-row {
  display: flex;
  gap: 8px;
}

.emoji-trigger {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 22px;
  flex-shrink: 0;
}

.text-input {
  flex: 1;
  min-width: 0;
  height: 46px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 16px;
}

.emoji-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.emoji-opt {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 20px;
}

.emoji-opt:hover,
.emoji-opt.selected {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.assign-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.assign-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.assign-pills {
  display: inline-flex;
  gap: 6px;
  flex: 1;
}

.assign-pill {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.assign-pill.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.add-submit-btn {
  padding: 9px 18px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  font-size: 14px;
}

.quick-ideas-label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.idea-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.idea-chip {
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  font-size: 13px;
  font-weight: 600;
}

.section-heading {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.manage-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
}

.manage-emoji {
  font-size: 20px;
}

.manage-name-input {
  flex: 1;
  min-width: 0;
  border: 1px solid transparent;
  background: transparent;
  font-size: 15px;
  font-weight: 600;
  padding: 4px 6px;
  border-radius: 8px;
}

.manage-name-input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
}

.manage-assign-btn {
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.manage-del-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 800;
  flex-shrink: 0;
}

.week-summary-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.summary-card {
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  text-align: center;
}

.summary-kid {
  font-size: 15px;
  font-weight: 700;
}

.summary-stars {
  margin-top: 4px;
  font-size: 22px;
  font-weight: 800;
  color: var(--star);
}

.reset-note {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}

.modal-footer {
  padding: 12px 18px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.modal-footer-split {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 10px;
}

.done-btn,
.confirm-reset-btn,
.cancel-btn {
  width: 100%;
  padding: 13px 16px;
  border-radius: 13px;
  border: none;
  font-size: 15px;
  font-weight: 700;
}

.done-btn {
  background: var(--accent);
  color: #ffffff;
}

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

.confirm-reset-btn {
  background: var(--danger);
  color: #ffffff;
}
