:root {
  --bg: #efe8dc;
  --bg-deep: #e7dfd0;
  --card: #faf6ee;
  --card-hi: #fffdf8;
  --ink: #2c261e;
  --muted: #6e6458;
  --line: #e2d8c8;
  --acc: #c47a5a;
  --acc-deep: #9e5a3e;
  --sage: #6f8f7a;
  --blue: #6b86a8;
  --rose: #c98b8b;
  --lavender: #9a8bb0;
  --note: #fff4c8;
  --rail: #f3ebdf;
  --shadow: 0 8px 28px rgba(70, 50, 30, 0.08), 0 2px 6px rgba(70, 50, 30, 0.04);
  --radius: 22px;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 16px/1.45 var(--sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  min-height: 100%;
  min-height: 100dvh;
}

/* ---- Left rail (tablet+) ---- */
.rail {
  display: none;
  width: 88px;
  flex-shrink: 0;
  background: var(--rail);
  border-right: 1px solid var(--line);
  padding: 18px 10px 14px;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100dvh;
}
.rail-logo {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--acc-deep);
  letter-spacing: 0.02em;
  margin-bottom: 10px;
  width: 44px; height: 44px;
  border-radius: 14px;
  background: var(--card-hi);
  box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  flex: 1;
}
.rail-nav button,
.rail-sleep {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 16px;
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font: 600 0.68rem/1 var(--sans);
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.rail-nav button svg,
.rail-sleep svg { width: 22px; height: 22px; }
.rail-nav button.on,
.rail-nav button[aria-current="page"] {
  background: #f0d5c6;
  color: var(--acc-deep);
}
.rail-nav button:hover,
.rail-sleep:hover { background: #ebe2d4; color: var(--ink); }
.rail-sleep { margin-top: auto; color: var(--muted); }

.stage {
  flex: 1;
  min-width: 0;
  padding: 14px 14px 96px;
  position: relative;
}

/* ---- Header ---- */
.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 4px 4px 14px;
  flex-wrap: wrap;
}
.top h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.6rem, 3.5vw, 2.05rem);
  letter-spacing: 0.01em;
  color: var(--ink);
}
.top-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.92rem;
}
.clock { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.dot { opacity: 0.5; }
.wx-strip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border-radius: 999px;
  padding: 4px 12px;
  box-shadow: var(--shadow);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink);
}
.top-right { text-align: right; }
.date-line {
  margin: 6px 0 0;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.9rem;
}
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  background: #e7dfd0;
  color: var(--muted);
  padding: 3px 10px;
  border-radius: 999px;
}

/* ---- Views / cards ---- */
.view { display: none; }
.view.active { display: block; }

.card.bubble,
.card {
  background: var(--card);
  border: 1px solid rgba(226, 216, 200, 0.7);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 0;
  box-shadow: var(--shadow);
  position: relative;
}
.card h2 {
  font-size: 1.02rem;
  margin: 0 0 12px;
  font-weight: 650;
}
.card h2.sub { margin-top: 16px; }
small, .card small {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.72rem;
  margin-left: 6px;
}
.note { background: var(--note); }

.pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  margin: 0 0 8px;
}
.pill.soft { background: #efe0d4; color: var(--acc-deep); }

.muted { color: var(--muted); margin: 4px 0 0; }
.big { font-size: 2.5rem; font-weight: 700; letter-spacing: -0.02em; }
.big2 { font-size: 1.3rem; font-weight: 700; margin: 0; }
.now { display: flex; gap: 14px; align-items: center; }
.serif-date {
  font-family: var(--serif);
  font-size: 1.55rem;
  font-weight: 600;
  margin: 0 0 10px !important;
}
.quote {
  margin: 14px 0 0;
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  font-size: 0.98rem;
}
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tag {
  background: #efe0d4;
  color: var(--acc-deep);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}
.muted-tag { background: #e8e2d6; color: var(--muted); }

.quiet-list { list-style: none; margin: 0; padding: 0; }
.quiet-list li { padding: 6px 0; border-top: 1px solid var(--line); font-size: 0.94rem; }
.quiet-list li:first-child { border-top: 0; padding-top: 0; }

.chip-btn {
  margin-top: 12px;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--acc);
  color: #fff;
  font: 600 0.9rem var(--sans);
  cursor: pointer;
}
.chip-btn.done { background: var(--sage); }

/* Home grid */
.home-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.forecast-card { margin-top: 12px; }
.forecast {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  text-align: center;
  font-size: 0.8rem;
}
.forecast > div {
  background: var(--card-hi);
  border-radius: 14px;
  padding: 8px 4px;
  border: 1px solid var(--line);
}
.forecast b { display: block; margin-bottom: 2px; }
.forecast .hi { font-weight: 700; }

.event-blocks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.event-blocks li {
  border-radius: 14px;
  padding: 10px 12px;
  background: #f3ebe1;
  border-left: 4px solid var(--sage);
  font-size: 0.94rem;
}
.event-blocks li.will { border-left-color: var(--blue); background: #eaf0f6; }
.event-blocks li.emilia { border-left-color: var(--rose); background: #f7ecec; }
.event-blocks li.shared { border-left-color: var(--lavender); background: #f0ecf5; }
.event-blocks li.meal { border-left-color: var(--acc); background: #f6ebe4; }
.event-blocks b { display: block; font-size: 0.75rem; color: var(--muted); font-weight: 600; margin-bottom: 2px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 11px 0; border-top: 1px solid var(--line); min-height: 44px; }
.list li:first-child { border-top: 0; }
.list.compact li { padding: 8px 0; min-height: 36px; font-size: 0.92rem; }
.list label { display: flex; gap: 10px; align-items: center; min-height: 44px; }
.list input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--acc); }
.list .price { margin-left: auto; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.total { text-align: right; font-weight: 700; margin: 10px 0 0; }
.list .x {
  float: right;
  min-width: 44px; min-height: 32px;
  border: 0; background: none;
  font-size: 1.1rem; color: var(--muted); cursor: pointer;
}

/* Meals */
.dinner-cards { display: flex; flex-direction: column; gap: 10px; }
.dinner-card-item {
  background: var(--card-hi);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
}
.dinner-card-item.tonight { border-color: #e8b59a; background: #fff5ef; }
.dinner-card-item .when {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--acc-deep);
  margin: 0 0 4px;
}
.dinner-card-item h3 { margin: 0; font-size: 1.02rem; }
.dinner-card-item p { margin: 4px 0 0; color: var(--muted); font-size: 0.88rem; }

.meals-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

/* Calendar */
.cal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.person-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pp {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
}
.pp.will { background: #d9e5f2; color: #355578; }
.pp.emilia { background: #f3d9d9; color: #7a4545; }
.pp.shared { background: #e5dff0; color: #5a4a72; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.seg button {
  min-height: 40px;
  font: 600 0.9rem var(--sans);
  border: 1px solid var(--line);
  background: #f3ebe1;
  border-radius: 999px;
  padding: 0 16px;
  color: var(--ink);
  cursor: pointer;
}
.seg button.on {
  background: #3d342c;
  color: #fff;
  border-color: #3d342c;
}

.day {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}
.day:first-child { border-top: 0; }
.day h3 { margin: 0 0 6px; font-size: 0.95rem; }
.day .ev-chip {
  display: inline-block;
  margin: 3px 4px 3px 0;
  padding: 5px 10px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 550;
}
.day .ev-chip.will { background: #d9e5f2; color: #355578; }
.day .ev-chip.emilia { background: #f3d9d9; color: #7a4545; }
.day .ev-chip.shared { background: #e5dff0; color: #5a4a72; }
.day .ev-chip.meal { background: #f6ebe4; color: #7a4a34; }
.day .ev-chip.house { background: #e5ebe4; color: #3f5a48; }
.day p.none { margin: 0; color: var(--muted); font-size: 0.88rem; }

.month {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  font-size: 0.8rem;
}
.month div {
  min-height: 48px;
  background: var(--card-hi);
  border-radius: 10px;
  padding: 4px;
  border: 1px solid transparent;
}
.month .h {
  min-height: auto;
  background: none;
  border: 0;
  font-weight: 700;
  text-align: center;
  color: var(--muted);
}
.month .ev { background: #e8f0ec; }
.month .td { outline: 2px solid var(--acc); outline-offset: -1px; }

/* Gym */
.log { width: 100%; border-collapse: collapse; }
.log th, .log td {
  padding: 8px 4px;
  text-align: left;
  border-top: 1px solid var(--line);
  font-size: 0.92rem;
}
.log th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.log input {
  width: 100%;
  min-height: 44px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 8px;
  background: var(--card-hi);
  color: var(--ink);
}
svg#chart { width: 100%; height: auto; background: var(--card-hi); border-radius: 14px; }

.caption {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
  margin: 10px 0 0;
}

textarea, .row input {
  width: 100%;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fffdf8;
  color: var(--ink);
  min-height: 44px;
  resize: vertical;
}
.note textarea { background: #fffceb; }
.row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 6px;
  margin-top: 8px;
}
.save {
  min-height: 44px;
  font: 600 0.95rem var(--sans);
  border: 0;
  border-radius: 999px;
  padding: 0 18px;
  margin-top: 10px;
  background: var(--acc);
  color: #fff;
  cursor: pointer;
}
.save:hover { background: var(--acc-deep); }

/* Bottom tabs (phone) */
.tabs {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--card-hi);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 40;
  box-shadow: 0 -6px 20px rgba(70, 50, 30, 0.06);
}
.tabs button {
  border: 0;
  background: none;
  font: 600 0.7rem/1.1 var(--sans);
  color: var(--muted);
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-radius: 12px;
  cursor: pointer;
  padding: 4px;
}
.tabs button svg { width: 20px; height: 20px; }
.tabs button.on {
  color: var(--acc-deep);
  background: #f0d5c6;
}

/* Flora accent */
.flora {
  position: fixed;
  right: -20px;
  bottom: 70px;
  width: min(240px, 42vw);
  pointer-events: none;
  z-index: 1;
  opacity: 0.9;
}
.flora svg { width: 100%; height: auto; display: block; }

/* Sleep overlay */
.sleep {
  position: fixed;
  inset: 0;
  z-index: 100;
  background:
    linear-gradient(110deg, #f3ebe0 0%, #efe6d8 45%, #e8dfd0 100%);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 8vw;
  cursor: pointer;
  overflow: hidden;
}
.sleep[hidden] { display: none !important; }
.sleep-art {
  position: absolute;
  right: -2%;
  bottom: -4%;
  width: min(52vw, 420px);
  opacity: 0.85;
  pointer-events: none;
}
.sleep-art svg { width: 100%; height: auto; }
.sleep-copy { position: relative; z-index: 2; max-width: 480px; }
.sleep-time {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(3.5rem, 12vw, 6rem);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
}
.sleep-date {
  margin: 8px 0 0;
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--muted);
}
.sleep-wx {
  margin: 14px 0 0;
  font-weight: 550;
  color: var(--ink);
}
.sleep-next {
  margin-top: 22px;
  background: #f3d9d9;
  border-radius: 16px;
  padding: 12px 16px;
  max-width: 360px;
}
.sleep-next p { margin: 6px 0 0; font-weight: 600; }
.sleep-quote {
  margin: 22px 0 0;
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  max-width: 360px;
}
.sleep-wake {
  margin: 36px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* Responsive */
@media (min-width: 720px) {
  .rail { display: flex; }
  .tabs { display: none; }
  .stage { padding: 18px 22px 28px; }
  .flora { bottom: 20px; right: 10px; width: 260px; }
  .home-grid {
    grid-template-columns: 1.1fr 1.1fr 0.95fr;
    grid-template-areas:
      "reminder weekend weekend"
      "date schedule sticky"
      "date dinner reminders";
  }
  .reminder-card { grid-area: reminder; }
  .weekend-card { grid-area: weekend; }
  .date-card { grid-area: date; }
  .schedule-card { grid-area: schedule; }
  .sticky-card { grid-area: sticky; }
  .dinner-card { grid-area: dinner; }
  .reminders-home { grid-area: reminders; }
  .meals-layout { grid-template-columns: 1.3fr 1fr; }
}

@media (min-width: 1100px) {
  .stage { padding: 22px 32px 36px; max-width: 1180px; }
  .home-grid {
    grid-template-columns: 1fr 1.15fr 1fr 0.95fr;
    grid-template-areas:
      "reminder reminder weekend weekend"
      "date schedule schedule sticky"
      "date dinner reminders sticky";
  }
}

@media (max-width: 719px) {
  .flora { opacity: 0.35; bottom: 80px; width: 160px; }
  .forecast { font-size: 0.72rem; gap: 3px; }
  .row { grid-template-columns: 1fr; }
}
