/* Cameron Cal — shared styles. Mobile-first, system fonts, light+dark.
   Palette: Dad = emerald, Mom = violet, neutrals = warm slate, holiday = amber. */

:root {
  /* Family convention colors (possession) */
  --dad: #059669;
  --mom: #7C3AED;
  /* Readable deep variants for text/accents on light surfaces */
  --dad-deep: #047857;
  --mom-deep: #6D28D9;
  /* Fills used in calendar cells / strips (white/near-white text on these) */
  --d-fill: #10B981;
  --m-fill: #8B5CF6;
  --d-soft: #D1FAE5;
  --m-soft: #EDE9FE;
  /* Holiday accent */
  --holiday: #F59E0B;
  /* Near-white text on possession fills */
  --on-fill: #FCFCFB;

  --bg: #FAFAF9;
  --card: #FFFFFF;
  --card-2: #F5F5F4;
  --text: #292524;
  --muted: #78716C;
  --line: #E7E5E4;
  --shadow: 0 2px 12px rgba(41, 37, 36, 0.07);
  --ring: #292524;
  --radius: 18px;
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1C1917;
    --card: #292524;
    --card-2: #322E2B;
    --text: #FAFAF9;
    --muted: #A8A29E;
    --line: #44403C;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
    --ring: #FAFAF9;
    --dad: #10B981;
    --mom: #8B5CF6;
    --dad-deep: #34D399;
    --mom-deep: #A78BFA;
    --d-fill: #065F46;
    --m-fill: #5B21B6;
    --d-soft: #0B3A2C;
    --m-soft: #2C1D52;
    --holiday: #FBBF24;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px 24px;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 6px;
  max-width: 640px;
  margin: 0 auto;
}
.app-header img { width: 30px; height: 30px; border-radius: 8px; }
.app-header h1 { font-size: 1.05rem; font-weight: 700; margin: 0; letter-spacing: 0.01em; }
.app-header .spacer { flex: 1; }
.offline-badge {
  display: none;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
}
body.is-offline .offline-badge { display: inline-block; }
.app-header .gear {
  color: var(--muted);
  text-decoration: none;
  font-size: 1.05rem;
  line-height: 1;
  padding: 8px 2px 8px 8px;
  opacity: 0.65;
}
.app-header .gear:hover,
.app-header .gear:active { opacity: 1; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 700;
}

/* ---------- Tonight hero ---------- */
.hero {
  border-radius: 22px;
  padding: 22px 18px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  text-align: center;
  background: var(--card);
  border-top: 6px solid var(--line);
}
.hero.owner-D { background: var(--d-soft); border-top-color: var(--dad); }
.hero.owner-M { background: var(--m-soft); border-top-color: var(--mom); }
.hero-kicker { font-size: 0.9rem; color: var(--muted); font-weight: 600; margin: 0; }
.hero-name {
  font-size: clamp(2.4rem, 11vw, 3.2rem);
  font-weight: 800;
  margin: 2px 0 8px;
  letter-spacing: -0.02em;
}
.hero.owner-D .hero-name { color: var(--dad-deep); }
.hero.owner-M .hero-name { color: var(--mom-deep); }
.hero-range { font-size: 0.92rem; color: var(--muted); margin: 0 0 12px; }
.hero-range strong { color: var(--text); font-weight: 650; }
.countdown {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  background: var(--card);
  border-radius: 999px;
  padding: 8px 16px;
  box-shadow: var(--shadow);
}
.countdown .cd-num { font-size: 1.25rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.countdown .cd-label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }

/* ---------- Exchange list ---------- */
.xlist { display: flex; flex-direction: column; }
.xrow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
  min-height: 44px;
}
.xrow:last-child { border-bottom: none; }
.x-when { flex: 1; min-width: 0; }
.x-day { font-weight: 650; font-size: 0.95rem; }
.x-time { font-size: 0.82rem; color: var(--muted); }
.x-kind {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.x-to {
  font-size: 0.82rem;
  font-weight: 750;
  border-radius: 999px;
  padding: 5px 12px;
  white-space: nowrap;
}
.x-to.to-D { background: var(--dad); color: var(--on-fill); }
.x-to.to-M { background: var(--mom); color: var(--on-fill); }

/* ---------- 14-night strip ---------- */
.strip-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
.strip-day {
  border-radius: 10px;
  padding: 6px 0 7px;
  text-align: center;
  background: var(--card-2);
}
.strip-day.n-D { background: var(--d-fill); color: var(--on-fill); }
.strip-day.n-M { background: var(--m-fill); color: var(--on-fill); }
.strip-day .sd-dow { display: block; font-size: 0.62rem; font-weight: 700; opacity: 0.75; letter-spacing: 0.03em; }
.strip-day .sd-num { display: block; font-size: 0.95rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.strip-day.is-today { outline: 2px solid var(--ring); outline-offset: 1px; }
.strip-day .sd-star { font-size: 0.6rem; line-height: 0.6; display: block; color: var(--holiday); }

.legend { display: flex; gap: 16px; justify-content: center; margin-top: 8px; font-size: 0.78rem; color: var(--muted); }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend .dot.d { background: var(--dad); }
.legend .dot.m { background: var(--mom); }

/* ---------- Calendar ---------- */
.cal-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.cal-nav h2 { flex: 1; text-align: center; font-size: 1.1rem; margin: 0; font-weight: 750; }
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 650;
  min-width: 44px;
  min-height: 40px;
  padding: 6px 12px;
  cursor: pointer;
}
.btn:active { transform: scale(0.96); }
.btn-today { font-size: 0.82rem; }

.cal-dows {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
}
.cal-dows span { text-align: center; font-size: 0.68rem; font-weight: 700; color: var(--muted); letter-spacing: 0.04em; }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  touch-action: pan-y;
}
.cal-cell {
  border-radius: 10px;
  min-height: 62px;
  padding: 4px 4px 3px;
  background: var(--card-2);
  border: none;
  font: inherit;
  color: inherit;
  text-align: left;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  overflow: hidden;
}
.cal-cell:disabled { opacity: 0.35; cursor: default; }
.cal-cell.is-today { outline: 2px solid var(--ring); outline-offset: 1px; }
.cal-cell.has-fill { color: var(--on-fill); } /* possession fills carry near-white text */
.cal-cell .cc-num { font-size: 0.85rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cal-cell .cc-holiday {
  margin-top: auto;
  font-size: 0.56rem;
  line-height: 1.15;
  font-weight: 650;
  opacity: 0.85;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.cal-cell.outside { opacity: 0.4; }

/* ---------- Bottom sheet (day detail) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 8, 14, 0.45);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
}
.sheet {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  z-index: 41;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  max-width: 640px;
  margin: 0 auto;
  transform: translateY(105%);
  transition: transform 0.22s ease-out;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.2);
}
body.sheet-open .sheet { transform: translateY(0); }
body.sheet-open .sheet-backdrop { opacity: 1; pointer-events: auto; }
.sheet-handle { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
.sheet h3 { margin: 0 0 2px; font-size: 1.05rem; }
.sheet .sheet-sub { margin: 0 0 10px; font-size: 0.8rem; color: var(--muted); }
.seg-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.seg-row:last-child { border-bottom: none; }
.seg-bar { width: 5px; align-self: stretch; border-radius: 3px; }
.seg-bar.o-D { background: var(--dad); }
.seg-bar.o-M { background: var(--mom); }
.seg-times { flex: 1; }
.seg-owner { font-weight: 700; font-size: 0.92rem; }
.seg-owner.o-D { color: var(--dad-deep); }
.seg-owner.o-M { color: var(--mom-deep); }
.seg-span { font-size: 0.8rem; color: var(--muted); }
.seg-label { font-size: 0.72rem; color: var(--muted); font-style: italic; }

/* ---------- Stats ---------- */
.year-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.year-nav h2 { flex: 1; text-align: center; font-size: 1.15rem; margin: 0; font-weight: 750; font-variant-numeric: tabular-nums; }

.totals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.total-card {
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.total-card.t-D { background: var(--d-soft); }
.total-card.t-M { background: var(--m-soft); }
.total-card .t-name { font-size: 0.8rem; font-weight: 750; }
.total-card.t-D .t-name { color: var(--dad-deep); }
.total-card.t-M .t-name { color: var(--mom-deep); }
.total-card .t-big { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.total-card .t-sub { font-size: 0.74rem; color: var(--muted); }

.mrow { margin-bottom: 12px; }
.mrow .m-name { font-size: 0.8rem; font-weight: 700; margin-bottom: 3px; }
.bar-pair { display: flex; flex-direction: column; gap: 3px; }
.bar-track { display: flex; align-items: center; gap: 8px; }
.bar {
  height: 16px;
  border-radius: 5px;
  min-width: 3px; /* keeps tiny nonzero months visible */
  transition: width 0.35s ease-out;
}
.bar.is-zero { min-width: 0; } /* zero nights = no colored sliver */
.bar.b-D { background: var(--dad); }
.bar.b-M { background: var(--mom); }
.bar-val { font-size: 0.74rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 650;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--text); }

/* ---------- States ---------- */
.skeleton {
  border-radius: var(--radius);
  background: linear-gradient(100deg, var(--card) 40%, var(--card-2) 50%, var(--card) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-hero { height: 190px; margin-bottom: 14px; border-radius: 22px; }
.sk-block { height: 120px; margin-bottom: 14px; }

.empty { color: var(--muted); font-size: 0.88rem; text-align: center; padding: 18px 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
  max-width: 88vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Site login overlay ---------- */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 22px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.login-mark {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(100deg, var(--dad-deep), var(--mom-deep));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.login-hint { margin: 0; font-size: 0.85rem; color: var(--muted); }
.login-card input[type="password"] {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card-2);
  color: var(--text);
  text-align: center;
}
.login-card input[type="password"]:focus { outline: 2px solid var(--dad); outline-offset: 1px; }
.login-btn { background: var(--dad); border-color: var(--dad); color: var(--on-fill); font-weight: 700; }
.login-error { margin: 0; font-size: 0.8rem; color: #DC2626; min-height: 1.1em; }
@keyframes login-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
.login-card.shake { animation: login-shake 0.35s; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
