/* ── tokens ─────────────────────────────────────────────────── */
:root {
  --bg:        #f5f5f2;
  --bg-tint:   #ecece8;
  --card:      #ffffff;
  --card-alt:  #efefec;
  --ink:       #1e1f1d;
  --ink-soft:  #6f736e;
  --ink-mute:  #a5a8a2;
  --green:     #2e4b3c;
  --green-2:   #4c6b58;
  --mint:      #cfe8d8;
  --mint-soft: #e2f1e8;
  --line:      #e4e4df;
  --danger:    #a4483c;

  --r-lg: 24px;
  --r-md: 18px;
  --r-sm: 12px;
  --shadow: 0 2px 10px rgba(30, 40, 34, .05);
  --shadow-lift: 0 10px 30px rgba(30, 40, 34, .10);

  --safe-b: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 78px;
}

* { box-sizing: border-box; }

/* class-level `display` would otherwise beat the UA rule for [hidden] */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Poppins, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }

svg {
  width: 22px; height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

::selection { background: var(--mint); }

/* ── shell ──────────────────────────────────────────────────── */
.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 22px 14px;
  padding-top: calc(18px + env(safe-area-inset-top, 0px));
  background: var(--bg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--green);
  margin-right: auto;
}
.brand-mark { border-radius: 50%; display: block; }
.brand-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.rail { display: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  color: var(--ink-soft);
  transition: background .18s, color .18s;
}
.icon-btn:hover { background: var(--bg-tint); color: var(--ink); }
.icon-btn svg { width: 21px; height: 21px; stroke-width: 1.4; }

.stage {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 4px 22px calc(var(--tabbar-h) + var(--safe-b) + 24px);
}

/* ── bottom nav ─────────────────────────────────────────────── */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(252, 252, 250, .92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.tab {
  display: grid;
  place-items: center;
  width: 52px; height: 52px;
  border-radius: 50%;
  color: var(--ink-mute);
  transition: background .2s, color .2s, transform .2s;
}
.tab svg { width: 23px; height: 23px; }
.tab.on { background: var(--mint-soft); color: var(--green); }
.tab:active { transform: scale(.93); }

/* ── shared bits ────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.eyebrow.spaced { margin: 26px 0 12px; }

.cta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 16px 28px;
  border-radius: 999px;
  background: var(--green-2);
  color: #fff;
  font-size: 16px;
  font-weight: 500;
  box-shadow: var(--shadow-lift);
  transition: transform .18s, background .18s, opacity .18s;
}
.cta:hover { background: var(--green); }
.cta:active { transform: scale(.97); }
.cta:disabled { opacity: .45; box-shadow: none; cursor: default; transform: none; }
.cta svg { width: 19px; height: 19px; }

.round-btn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--card);
  color: var(--ink-soft);
  box-shadow: var(--shadow);
  transition: color .18s, transform .18s;
}
.round-btn:hover { color: var(--green); }
.round-btn:active { transform: scale(.92); }

.view { animation: rise .32s cubic-bezier(.2,.7,.3,1); }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── write ──────────────────────────────────────────────────── */
.view-write {
  min-height: calc(100vh - var(--tabbar-h) - 120px);
  display: grid;
  grid-template-columns: minmax(0, 1fr);   /* an auto column would shrink to the text width */
  align-content: center;
}
.write-sheet {
  display: grid;
  grid-template-columns: minmax(0, 1fr);   /* an auto column would shrink the card to its text */
  justify-items: center;
  gap: 26px;
  padding: 22px 0 40px;
}

.today { text-align: center; }
.today-weekday {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.today-date {
  margin: 0;
  font-size: clamp(28px, 8vw, 34px);
  font-weight: 300;
  letter-spacing: -.01em;
}
.today-date b { font-weight: 600; }
.today-time {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--ink-mute);
}

.compose {
  position: relative;
  width: 100%;
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 22px 22px 34px;
  transition: box-shadow .25s;
}
.compose:focus-within { box-shadow: var(--shadow-lift); }
.compose textarea {
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  background: none;
  font-size: 17px;
  line-height: 1.55;
  min-height: 84px;
}
.compose textarea::placeholder { color: var(--ink-mute); }
.counter {
  position: absolute;
  right: 22px; bottom: 14px;
  font-size: 13px;
  color: var(--ink-mute);
  transition: color .2s;
}
.counter.low { color: var(--danger); }

.write-note {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
}

/* ── calendar ───────────────────────────────────────────────── */
.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin: 20px 0 16px;
}
.month-title {
  margin: 0;
  font-size: clamp(28px, 8vw, 34px);
  font-weight: 600;
  letter-spacing: -.01em;
}
.month-nav { display: flex; gap: 10px; }

.calendar { padding: 20px 16px 22px; }
.dow, .grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.dow {
  margin-bottom: 10px;
  text-align: center;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .1em;
  color: var(--ink-mute);
}
/* column-gap keeps the circles apart on narrow screens, where each one fills its track */
.grid { row-gap: 6px; column-gap: 4px; }

/* Square by aspect-ratio, capped and centred in its track — a fixed height with a
   fluid 1fr width would go oval as the viewport resizes, and collide when wide. */
.day {
  position: relative;
  width: 100%;
  max-width: 42px;
  aspect-ratio: 1;
  justify-self: center;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 15px;
  color: var(--ink);
  transition: background .18s, color .18s;
}
.day.mute { color: var(--ink-mute); }
.day.future { color: #c9cbc6; }
.day:not(.mute):hover { background: var(--bg-tint); }
.day.today { background: var(--bg-tint); font-weight: 500; }
.day.sel {
  background: var(--green);
  color: #fff;
  font-weight: 500;
}
.day .dot {
  position: absolute;
  bottom: 5px;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--green);
}
.day.mute .dot, .day.future .dot { background: var(--ink-mute); }
.day.sel .dot { background: #fff; }

/* selected-day panel */
.entry-card {
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 22px;
}
.entry-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.date-pill {
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--mint-soft);
  color: var(--green);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.entry-time { font-size: 12px; color: var(--ink-mute); }
.entry-text {
  margin: 0;
  font-size: clamp(19px, 5vw, 22px);
  font-weight: 300;
  line-height: 1.45;
}
.entry-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
}
.entry-foot svg { width: 18px; height: 18px; color: var(--green); }
.link-btn {
  font-size: 13px;
  font-weight: 500;
  color: var(--green);
  padding: 6px 2px;
  border-bottom: 1px solid transparent;
}
.link-btn:hover { border-bottom-color: currentColor; }
.link-btn.warn { color: var(--danger); }

.hint {
  margin-top: 14px;
  padding: 30px 24px;
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
  background: var(--bg-tint);
  text-align: center;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-soft);
}
.hint .link-btn { display: inline-block; margin-top: 8px; }

/* ── journal ────────────────────────────────────────────────── */
.search {
  position: relative;
  display: flex;
  align-items: center;
  margin: 16px 0 18px;
}
.search svg {
  position: absolute;
  left: 18px;
  width: 19px; height: 19px;
  color: var(--ink-mute);
  pointer-events: none;
}
.search input {
  width: 100%;
  padding: 16px 18px 16px 48px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--card-alt);
  outline: none;
  font-size: 15px;
  transition: background .2s, border-color .2s;
}
.search input::placeholder { color: var(--ink-mute); }
.search input:focus { background: var(--card); border-color: var(--mint); }
.search input::-webkit-search-cancel-button { cursor: pointer; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.segmented { display: flex; gap: 8px; }
.seg {
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--card-alt);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
  transition: background .18s, color .18s;
}
.seg.on { background: var(--green); color: #fff; }

.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 6px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.filter-btn svg { width: 17px; height: 17px; }
.filter-btn:hover { color: var(--ink); }

.filter-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 4px;
  animation: rise .2s ease;
}
.filter-menu button {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-soft);
  transition: border-color .18s, color .18s;
}
.filter-menu button.on { border-color: var(--green); color: var(--green); }

.feed { padding-top: 10px; }
.feed-date {
  margin: 22px 0 8px;
  text-align: right;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .1em;
  color: var(--ink-mute);
}
.feed-item {
  padding: 20px 22px;
  border-radius: var(--r-md);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 15.5px;
  line-height: 1.65;
  cursor: pointer;
  transition: transform .18s, box-shadow .18s;
}
.feed-item:nth-child(4n) { background: var(--card-alt); box-shadow: none; }
.feed-item:hover { transform: translateY(-1px); box-shadow: var(--shadow-lift); }
.feed-item mark {
  background: var(--mint);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

.sentinel { height: 1px; }
.feed-end, .empty {
  margin: 26px 0 8px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-mute);
}
.empty { padding: 40px 20px; line-height: 1.7; }

.skeleton {
  height: 76px;
  margin-top: 12px;
  border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--card-alt) 25%, #f6f6f4 50%, var(--card-alt) 75%);
  background-size: 400% 100%;
  animation: shimmer 1.3s infinite linear;
}
@keyframes shimmer { to { background-position: -100% 0; } }

/* ── settings sheet ─────────────────────────────────────────── */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(24, 30, 26, .34);
  backdrop-filter: blur(2px);
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed;
  z-index: 41;
  left: 0; right: 0; bottom: 0;
  max-height: 88vh;
  overflow-y: auto;
  padding: 12px 24px calc(28px + var(--safe-b));
  background: var(--bg);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  animation: slide .3s cubic-bezier(.2,.8,.3,1);
}
@keyframes slide { from { transform: translateY(100%); } }
.sheet-grab {
  width: 40px; height: 4px;
  margin: 0 auto 14px;
  border-radius: 999px;
  background: var(--line);
}
.sheet h2 {
  margin: 0 0 18px;
  font-size: 20px;
  font-weight: 600;
}
.sheet .cta { width: 100%; justify-content: center; margin-top: 22px; }
.cta.subtle { background: var(--ink); }
.cta.subtle:hover { background: #000; }

.row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 15px 0;
  border-top: 1px solid var(--line);
}
.row div { flex: 1; min-width: 0; }
.row strong { display: block; font-size: 15px; font-weight: 500; }
.row small { display: block; margin-top: 2px; font-size: 12.5px; color: var(--ink-mute); }
.row.danger strong { color: var(--danger); }

.ghost {
  padding: 9px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  transition: border-color .18s, color .18s;
}
.ghost:hover { border-color: var(--green); color: var(--green); }
.ghost.warn { color: var(--danger); }
.ghost.warn:hover { border-color: var(--danger); }

/* ── toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px);
  transform: translate(-50%, 14px);
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .24s, transform .24s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ── desktop ────────────────────────────────────────────────── */
@media (min-width: 900px) {
  :root { --tabbar-h: 0px; }

  .app {
    display: grid;
    grid-template-columns: 250px 1fr;
    grid-template-areas: "side stage";
    min-height: 100vh;
  }

  .topbar {
    grid-area: side;
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 34px 22px 26px;
    border-right: 1px solid var(--line);
  }
  .brand { margin: 0 0 38px; padding-left: 8px; }

  .rail { display: grid; gap: 6px; }
  .rail-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-radius: 999px;
    color: var(--ink-soft);
    font-size: 14.5px;
    font-weight: 500;
    text-align: left;
    transition: background .18s, color .18s;
  }
  .rail-btn:hover { background: var(--bg-tint); color: var(--ink); }
  .rail-btn[aria-current] { background: var(--mint-soft); color: var(--green); }
  .rail-btn svg { width: 20px; height: 20px; }

  .settings-btn { margin-top: auto; align-self: flex-start; }
  .tabbar { display: none; }

  .stage {
    grid-area: stage;
    max-width: 1080px;
    padding: 46px 56px 80px;
  }

  .view-write { min-height: calc(100vh - 130px); }
  /* auto margins would make this grid item shrink-to-fit, so center it explicitly */
  .write-sheet { width: 100%; max-width: 620px; justify-self: center; gap: 32px; }
  .compose { padding: 30px 30px 42px; }
  .compose textarea { font-size: 20px; min-height: 108px; }

  .view-calendar {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
    gap: 44px;
    align-items: start;
  }
  .section-head { margin-top: 0; }
  .cal-col:last-child .eyebrow.spaced { margin-top: 6px; }
  .calendar { padding: 26px 22px 28px; }
  .day { max-width: 48px; font-size: 16px; }

  .view-journal { max-width: 720px; }
  .search { margin-top: 0; }

  .toast { bottom: 28px; }

  .scrim { background: rgba(24, 30, 26, .28); }
  .sheet {
    left: 50%; bottom: auto; top: 50%;
    width: min(480px, 92vw);
    max-height: 84vh;
    transform: translate(-50%, -50%);
    border-radius: var(--r-lg);
    padding: 26px 30px 30px;
    box-shadow: 0 30px 70px rgba(20, 30, 24, .25);
    animation: pop .26s cubic-bezier(.2,.8,.3,1);
  }
  @keyframes pop {
    from { opacity: 0; transform: translate(-50%, -46%) scale(.97); }
  }
  .sheet-grab { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
