:root {
  --bg: #12141c;
  --bg-elev: #1a1d29;
  --bg-elev2: #222738;
  --border: #2b3242;
  --text: #e8eaf0;
  --text-dim: #9aa1b4;
  --accent: #f5c043;
  --accent-ink: #2a2005;
  --accent2: #4cd08a;
  --danger: #f2647c;
  --radius: 10px;
  --shadow: 0 4px 18px rgba(0,0,0,.35);
}
html[data-theme="light"] {
  --bg: #f4f2ec;
  --bg-elev: #ffffff;
  --bg-elev2: #eceadf;
  --border: #ddd8c8;
  --text: #262319;
  --text-dim: #6b6656;
  --accent: #c9821a;
  --accent-ink: #fff7e6;
  --accent2: #1f9d63;
  --danger: #c8324a;
  --shadow: 0 4px 18px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

/* #shell and #demo-banner both set their own `display` below for when
   they're visible — an ID selector like `#shell { display: flex }` has
   higher specificity than the browser's own `[hidden] { display: none }`
   rule, so without this override, toggling the `hidden` attribute via JS
   does nothing and the element stays visible (and empty) underneath
   whatever's actually showing. This bit everyone: the landing page
   rendered fine, but an empty "Household" shell sat visible right below
   it because #shell's hidden attribute was being silently ignored. */
#gate[hidden], #shell[hidden], #demo-banner[hidden] { display: none !important; }

#shell { display: flex; min-height: 100vh; }

/* --- Gate (auth / create-join family) --- */
#gate {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; max-width: 380px; width: 100%; box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 6px; font-size: 1.5rem; }
.auth-card .field { margin-bottom: 10px; }
.auth-card input { width: 100%; }
.auth-card [data-mode][data-active="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* --- Sidebar / nav --- */
#nav {
  width: 220px; flex: 0 0 auto; background: var(--bg-elev); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 10px; gap: 4px;
}
.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px 12px;
  border: none; background: transparent; color: var(--text-dim); border-radius: var(--radius);
  font-size: .92rem; font-weight: 600;
}
.nav-btn .ic { font-size: 1.05rem; width: 1.3em; text-align: center; }
.nav-btn:hover { background: var(--bg-elev2); color: var(--text); }
.nav-btn[data-active="true"] { background: var(--accent); color: var(--accent-ink); }

/* --- Header --- */
#main-col { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 22px;
  border-bottom: 1px solid var(--border); background: var(--bg-elev); gap: 12px; flex-wrap: wrap;
}
#topbar .household { font-weight: 700; font-size: 1.05rem; }
#topbar .clock { color: var(--text-dim); font-variant-numeric: tabular-nums; font-size: .9rem; text-align: right; }

#main { flex: 1 1 auto; padding: 22px; overflow-y: auto; }

h2.section-title { margin: 0 0 4px; font-size: 1.3rem; }
p.section-sub { margin: 0 0 18px; color: var(--text-dim); font-size: .88rem; }

.card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px;
  font-size: .74rem; font-weight: 700; background: var(--bg-elev2); color: var(--text-dim);
}
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

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

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: .74rem; color: var(--text-dim); font-weight: 600; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], input[type=email], select, textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 7px; padding: 7px 9px;
}
input[type=color] { width: 40px; height: 32px; padding: 2px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); }
textarea { resize: vertical; min-height: 44px; }

.btn { border: 1px solid var(--border); background: var(--bg-elev2); color: var(--text); border-radius: 7px; padding: 7px 12px; font-weight: 600; font-size: .85rem; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: .78rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.list-clean { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.item-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.item-row.done { opacity: .55; text-decoration: line-through; }
.item-row input[type=checkbox] { width: 18px; height: 18px; }
.item-row .grow { flex: 1; min-width: 0; }
.muted { color: var(--text-dim); }
.empty-note { color: var(--text-dim); font-size: .88rem; padding: 10px 2px; }

form.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 16px; }

/* Calendar */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; font-size: .72rem; color: var(--text-dim); font-weight: 700; padding-bottom: 4px; }
.cal-day { min-height: 74px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding: 6px; display: flex; flex-direction: column; gap: 3px; cursor: pointer; text-align: left; }
.cal-day:hover { border-color: var(--accent); }
.cal-day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cal-day.selected { background: var(--bg-elev2); }
.cal-day.other-month { opacity: .35; }
.cal-daynum { font-size: .78rem; font-weight: 700; }
.cal-evt { font-size: .68rem; padding: 1px 4px; border-radius: 4px; background: var(--bg-elev2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Meal grid */
.meal-grid { display: grid; grid-template-columns: 90px repeat(7, 1fr); gap: 6px; }
.meal-grid .hdr { font-size: .74rem; font-weight: 700; color: var(--text-dim); padding: 6px 4px; }
.meal-grid textarea { width: 100%; min-height: 54px; font-size: .82rem; }

table.rewards-tbl { width: 100%; border-collapse: collapse; }
table.rewards-tbl th, table.rewards-tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: .88rem; }

.placeholder-card { border: 1px dashed var(--border); border-radius: var(--radius); padding: 40px 20px; text-align: center; color: var(--text-dim); }
.placeholder-card .big { font-size: 2rem; margin-bottom: 10px; }

@media (max-width: 760px) {
  #shell { flex-direction: column; }
  #nav { width: 100%; flex-direction: row; overflow-x: auto; padding: 8px; border-right: none; border-bottom: 1px solid var(--border); }
  .nav-btn { flex: 0 0 auto; }
  .meal-grid { grid-template-columns: repeat(7, minmax(110px, 1fr)); }
  .meal-grid .hdr:first-child { display: none; }
}

/* --- Landing / explainer page --- */
#gate.has-landing, .landing {
  min-height: 100vh;
}
.landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  text-align: center;
  gap: 28px;
}
.landing-hero { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 480px; }
.landing-icon { width: 96px; height: 96px; }
.landing-glow { animation: hearth-pulse 3.2s ease-in-out infinite; transform-origin: center; }
.landing-window { animation: hearth-flicker 2.4s ease-in-out infinite; }
.landing-window-2 { animation-delay: .6s; }
@keyframes hearth-pulse {
  0%, 100% { opacity: .55; r: 44; }
  50% { opacity: .9; r: 50; }
}
@keyframes hearth-flicker {
  0%, 100% { opacity: 1; }
  45% { opacity: .5; }
  55% { opacity: 1; }
}
.landing-hero h1 { margin: 4px 0 0; font-size: 2.2rem; letter-spacing: .01em; }
.landing-tagline { margin: 0; color: var(--text-dim); font-size: 1rem; line-height: 1.5; }

.landing-features {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: 620px;
}
.landing-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-dim);
  opacity: 0;
  animation: landing-chip-in .5s ease-out forwards;
}
.landing-chip .ic { font-size: 1rem; }
@keyframes landing-chip-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.landing-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.landing-btn { padding: 12px 26px; font-size: .95rem; border-radius: 10px; }
.landing-footnote { margin: 0; color: var(--text-dim); font-size: .78rem; max-width: 420px; }

@media (prefers-reduced-motion: reduce) {
  .landing-glow, .landing-window, .landing-chip { animation: none; opacity: 1; }
}

/* --- Demo mode banner --- */
#demo-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 22px;
  background: color-mix(in srgb, var(--accent) 18%, var(--bg-elev));
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
}
#demo-banner button {
  border: 1px solid var(--border);
  background: var(--bg-elev2);
  color: var(--text);
  border-radius: 7px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: .82rem;
  white-space: nowrap;
}
#demo-banner button:hover { border-color: var(--accent); }

/* --- News tab --- */
.news-card h2 { font-size: 1.1rem; margin: 0 0 10px; }
.news-card h2:not(:first-child) { margin-top: 20px; }
.news-card h3 { font-size: .95rem; margin: 18px 0 8px; color: var(--text-dim); }
.news-card p { margin: 0 0 10px; line-height: 1.5; }
.news-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.news-item { display: flex; align-items: flex-start; gap: 9px; font-size: .92rem; line-height: 1.4; }
.news-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; margin-top: 4px; background: var(--text-dim); }
.news-dot.status-done { background: var(--accent2); }
.news-dot.status-progress { background: var(--accent); }
.news-dot.status-planned { background: var(--danger); }
