:root {
  --bg: #f7f3ed;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8e8e93;
  --border: #f0ece5;
  --amber: #f5a623;
  --shadow-sm: 0 2px 10px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 18px rgba(0,0,0,0.09);
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 8px;
}

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

body {
  margin: 0;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 420px;
  margin: 0 auto;
  background: var(--bg);
  min-height: 100vh;
  padding-bottom: 90px;
}

/* ── Header ─────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 15px 14px;
}

.menu-btn, .notif-btn {
  background: var(--card);
  border: none;
  width: 50px;
  height: 50px;
  border-radius: var(--r-sm);
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.greeting {
  flex: 1;
  padding: 0 12px;
}

.greeting h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1rem;
  font-weight: 300;
  font-style: normal;
  margin: 0 0 3px;
  line-height: 1.2;
}

.greeting .subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

/* ── Stats ──────────────────────────────── */
.stats {
  margin: 4px 20px 16px;
  background: var(--card);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.stat {
  padding: 14px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  border-right: 1px solid var(--border);
}

.stat:last-child { border-right: none; }

.stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stat-label {
  font-size: 0.62rem;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.3;
  text-align: center;
}

/* ── Legend ─────────────────────────────── */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 2px 20px 16px;
  background: var(--card);
  margin: 0 20px 16px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  padding: 12px 16px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--muted);
}

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-dot.past     { background: #f0a030; }
.legend-dot.current  { background: #f5c86a; }
.legend-dot.future   { background: #a8c8f0; }
.legend-dot.note     { background: #c0b0f0; }
.legend-dot.birthday { background: transparent; border: 2px solid #bbb; border-radius: 50%; }

/* ── Timeline Container ─────────────────── */
.timeline-container {
  padding: 0 6px;
}

.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 0px 15px;
}

.timeline-header h2 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
}

.zoom-controls {
  display: flex;
  gap: 6px;
}

.zoom-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: var(--card);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: background 0.15s;
}

.zoom-btn svg {
  width: 16px;
  height: 16px;
}

.zoom-btn:active { background: var(--border); }

.zoom-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.timeline-card {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 14px 12px;
  box-shadow: var(--shadow-sm);
}

/* ── Sticky top group ───────────────────── */
.page-top-sticky {
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--bg);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.timeline-top {
  padding: 0 6px 2px;
}

/* ── Grid Mode Toggle ───────────────────── */
.timeline-selector {
  padding: 0 10px 0px;
}

.grid-mode-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.grid-mode-btn {
  flex: 1;
  padding: 7px 0;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  background: transparent;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.grid-mode-btn.active {
  background: var(--amber);
  border-color: var(--amber);
  color: #fff;
  font-weight: 600;
}

/* ── Timeline Layout (grid + tabs) ─────── */
.timeline-layout {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

#timeline-grid {
  flex: 1;
  min-width: 0;
}

.stage-tabs {
  position: sticky;
  top: 165px;
  height: calc(100vh - 225px);
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex-shrink: 0;
  width: 26px;
  padding-top: 20px;
}

.stage-tab {
  flex: 1;
  border: solid 1px var(--border);
  border-radius: 3px;
  writing-mode: vertical-lr;
  transform: rotate(180deg);
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 4px;
  overflow: hidden;
  transition: background 0.5s, color 0.2s, font-weight 0.2s;
}

/* Default: very light stage tint */
.stage-tab[data-stage="early"]   { background: #eef4fd; }
.stage-tab[data-stage="school"]  { background: #edf8ed; }
.stage-tab[data-stage="hs"]      { background: #fdf9e4; }
.stage-tab[data-stage="college"] { background: #fdf1e4; }
.stage-tab[data-stage="career"]  { background: #fde9e9; }
.stage-tab[data-stage="retire"]  { background: #f2f2f8; }

/* Active: full stage color */
.stage-tab.active[data-stage="early"]   { background: #b8cef5; color: #1a4a90; font-weight: 700; }
.stage-tab.active[data-stage="school"]  { background: #aee0ae; color: #1a6a1a; font-weight: 700; }
.stage-tab.active[data-stage="hs"]      { background: #f0d870; color: #5a4000; font-weight: 700; }
.stage-tab.active[data-stage="college"] { background: #f5bc7a; color: #5a3000; font-weight: 700; }
.stage-tab.active[data-stage="career"]  { background: #f09898; color: #601010; font-weight: 700; }
.stage-tab.active[data-stage="retire"]  { background: #c0c0cc; color: #202060; font-weight: 700; }

/* ── Timeline Grid ──────────────────────── */
.tl-header-row {
  display: flex;
  align-items: flex-end;
  margin-bottom: 4px;
}

.tl-corner {
  width: 30px;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-align: right;
  padding-right: 5px;
  flex-shrink: 0;
}

.tl-x-header {
  flex: 1;
  position: relative;
  height: 16px;
}

.tl-x-label {
  position: absolute;
  font-size: 10px;
  color: var(--muted);
  transform: translateX(-50%);
  bottom: 0;
}

.tl-row {
  display: flex;
  align-items: center;
  margin-bottom: 1px;  
}

.tl-row.year-end {
  margin-bottom: 1px;
  border-bottom: solid 1px white;
}

#timeline-grid[data-zoom="0"] .tl-row.year-end {
  margin-bottom: 1px;
}

.tl-y-label {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}

.tl-y-year {
  display: block;
  font-size: 10px;
  opacity: 0.6;
  line-height: 1;
}

#timeline-grid[data-zoom="0"] .tc {
  border-radius: 1px;
}

.tl-y-label {
  width: 30px;
  font-size: 11px;
  color: var(--text);
  text-align: center;
  padding-right: 10px;
  flex-shrink: 0;
  line-height: 1;
  align-self: center;
}

.tl-cells {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(var(--tl-cols, 26), 1fr);
  gap: 1px;
}

.tc {
  aspect-ratio: 1 / 1;
  border-radius: 3px;
  width: 100%;
}

/* Life-stage colors */
.tc-early   { background: #b8cef5; }
.tc-school  { background: #aee0ae; }
.tc-hs      { background: #f0d870; }
.tc-college { background: #f5bc7a; }
.tc-career  { background: #f09898; }
.tc-retire  { background: #c0c0cc; }

/* Future: faded */
.tc-future  { opacity: 0.42; }

/* Current week: amber outline, white fill */
.tc-current {
  opacity: 1 !important;
  background: #fffbe8 !important;
  outline: 1.5px solid var(--amber);
  outline-offset: 0;
  position: relative;
  z-index: 1;
}

.timeline-caption {
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
  margin: 12px 0 0;
}

/* ── Quote ──────────────────────────────── */
.quote {
  margin: 20px 20px 8px;
  font-style: normal;
}

.quote-mark {
  display: block;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2.8rem;
  line-height: 0.5;
  color: #ccc;
  margin-bottom: 10px;
}

.quote p {
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.6;
  margin: 0;
}

/* ── Add Note Button ────────────────────── */
.add-note-wrapper {
  display: flex;
  justify-content: flex-end;
  padding: 12px 20px 24px;
}

.add-note-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 13px 24px;
  background: var(--amber);
  color: #fff;
  border: none;
  border-radius: 100px;
  font-size: 0.92rem;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(245,166,35,0.45);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.add-note-btn:active {
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(245,166,35,0.3);
}

/* ── Screens ─────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

/* ── Life Stages Header ─────────────────── */
.page-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
}

.back-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text);
  padding: 2px 6px 2px 0;
  line-height: 1;
}

/* ── Life Stages Content ─────────────────── */
.life-stages-content {
  padding: 0 20px 24px;
}

.section-desc {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 18px;
  line-height: 1.55;
}

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

.stage-card {
  background: var(--card);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  padding: 13px 14px 13px 18px;
  gap: 13px;
  position: relative;
  overflow: hidden;
}

/* Left colored accent bar */
.stage-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: 4px 0 0 4px;
}

.stage-card.early   ::before,
.stage-card.early::before   { background: #6b9fe8; }
.stage-card.school::before  { background: #5bc85b; }
.stage-card.hs::before      { background: #e8c030; }
.stage-card.college::before { background: #e89040; }
.stage-card.career::before  { background: #e06060; }
.stage-card.retire::before  { background: #9090c0; }

.stage-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stage-card.early   .stage-icon { background: #e8f0fc; }
.stage-card.school  .stage-icon { background: #e8f8e8; }
.stage-card.hs      .stage-icon { background: #fdf5d0; }
.stage-card.college .stage-icon { background: #fde8d0; }
.stage-card.career  .stage-icon { background: #fce0e0; }
.stage-card.retire  .stage-icon { background: #eeeef8; }

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

.stage-info strong {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 3px;
}

.stage-years {
  font-size: 0.78rem;
  color: var(--muted);
}

.stage-weeks-label {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
  line-height: 1.5;
  flex-shrink: 0;
  white-space: nowrap;
}

/* ── Stage Footer Card ───────────────────── */
.stage-footer-card {
  margin-top: 14px;
  background: var(--card);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 16px;
}

.footer-sun {
  font-size: 1.8rem;
  flex-shrink: 0;
}

.footer-text strong {
  display: block;
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 3px;
}

.footer-text span {
  font-size: 0.78rem;
  color: var(--muted);
}

/* ── Placeholder Screens ─────────────────── */
.placeholder-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  padding: 2rem;
  gap: 12px;
}

.placeholder-icon { font-size: 3.5rem; opacity: 0.35; }
.placeholder-content p { font-size: 0.9rem; color: var(--muted); }

/* ── Week Modal ─────────────────────────── */
.week-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s;
}

.week-modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.week-modal {
  background: var(--card);
  border-radius: 24px 24px 0 0;
  padding: 0 20px 36px;
  width: 100%;
  max-width: 420px;
  max-height: 65vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.34, 1.1, 0.64, 1);
}

.week-modal-overlay.open .week-modal {
  transform: translateY(0);
}

.week-modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 20px;
}

.week-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.week-modal-info { flex: 1; }

.week-modal-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 100px;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.week-modal-badge.early   { background: #b8cef5; color: #1a4a90; }
.week-modal-badge.school  { background: #aee0ae; color: #1a6a1a; }
.week-modal-badge.hs      { background: #f0d870; color: #5a4000; }
.week-modal-badge.college { background: #f5bc7a; color: #5a3000; }
.week-modal-badge.career  { background: #f09898; color: #601010; }
.week-modal-badge.retire  { background: #c0c0cc; color: #202060; }

.week-modal-dates {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--text);
}

.week-modal-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
}

.week-modal-close {
  background: var(--bg);
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
}

.week-event {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.week-event:last-child { border-bottom: none; }

.week-event-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.week-event-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

.no-events {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
  margin: 0;
}

/* Cell with events */
.tc-has-event {
  box-shadow: inset 0 0 0 1.5px rgba(0, 0, 0, 0.4);
}

/* ── Bottom Navigation ───────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 420px;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 10px 10px 22px;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -3px 20px rgba(0,0,0,0.07);
  z-index: 100;
}

.nav-btn {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 0.6rem;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 10px;
  transition: color 0.18s;
}

.nav-icon {
  width: 22px;
  height: 22px;
  display: block;
  flex-shrink: 0;
}

.nav-btn.active { color: var(--amber); }

.nav-btn.add {
  background: var(--amber);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  margin-top: -26px;
  font-size: 1.6rem;
  color: #fff;
  box-shadow: 0 4px 16px rgba(245,166,35,0.5);
  justify-content: center;
  padding: 0;
}

.nav-btn.add::before {
  content: '+';
  font-size: 1.7rem;
  display: block;
}

@media (max-width: 440px) {
  #app, .bottom-nav { max-width: 100vw; }
}
