/* /me — life grid first. The four-thousand-weeks field is the product. */

body.me-life {
  --life-signal: var(--kind-observed, #7fedc7);
}

body.me-life .scanlines {
  display: none;
}

/* Legacy page chrome — replaced by .me-life-head */
body.me-life .page-head,
body.me-life .page-title,
body.me-life .page-meta,
body.me-life #me-weeks .section-label,
body.me-life .mw-ro,
body.me-life .mw-ro-root {
  display: none !important;
}

body.me-life main.me-life-main {
  max-width: none;
  width: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    max(72px, calc(60px + env(safe-area-inset-top, 0px)))
    max(8px, env(safe-area-inset-left, 0px))
    calc(72px + env(safe-area-inset-bottom, 0px))
    max(8px, env(safe-area-inset-right, 0px));
}

body.me-life .me-life-head {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  margin-bottom: 8px;
  max-width: none;
  padding: 0 8px;
}

@media (min-width: 721px) {
  body.me-life .me-life-head {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 12px;
  }

  body.me-life .me-life-stat {
    flex: 1 1 auto;
    min-width: 0;
  }

  body.me-life .me-week-loop {
    flex: 0 1 auto;
    justify-content: flex-end;
    margin: 0;
    max-width: min(52%, 520px);
  }
}

body.me-life .me-life-stat-kicker {
  font-family: var(--font-meta);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  color: var(--ink-3);
  margin-bottom: 8px;
}

body.me-life .me-life-stat-line {
  font-family: var(--font-self);
  font-size: clamp(22px, 4vw, 28px);
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.12;
  color: var(--ink-1);
  text-wrap: balance;
  margin: 0;
}

body.me-life .me-life-stat-sub {
  margin: 8px 0 0;
  font-family: var(--font-meta);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  line-height: 1.4;
  color: var(--ink-3);
}

body.me-life .me-week-loop {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 16px;
  padding: 0 4px;
}

body.me-life .me-week-loop-part {
  font-family: var(--font-meta);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: lowercase;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--ink-2, #bbb);
  white-space: nowrap;
}

body.me-life .me-week-loop-part.tone-new {
  border-color: rgba(127, 237, 199, 0.45);
  color: #7FEDC7;
}

body.me-life .me-week-loop-part.tone-warn {
  border-color: rgba(245, 166, 35, 0.45);
  color: #f5a623;
}

body.me-life .me-week-loop-part.tone-mute {
  border-color: rgba(255, 255, 255, 0.08);
  color: var(--ink-3, #888);
}

body.me-life .me-week-loop-part:hover {
  background: rgba(255, 255, 255, 0.06);
}

body.me-life .me-life-stat-prompt {
  font-family: var(--font-self);
  font-size: clamp(17px, 2.4vw, 22px);
  font-weight: 300;
  line-height: 1.35;
  letter-spacing: -0.02em;
  color: var(--ink-2);
  max-width: 36ch;
}

body.me-life .mw-feed-nudge {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(245, 166, 35, 0.08);
  border: 1px solid rgba(245, 166, 35, 0.22);
}

body.me-life .mw-feed-nudge p {
  margin: 0;
  flex: 1 1 200px;
  font: 300 14px/1.45 var(--font-display, system-ui);
  color: var(--ink-1, #eee);
}

body.me-life .mw-feed-nudge-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  background: #fff;
  color: #000;
  font: 500 14px var(--font-display, system-ui);
  text-decoration: none;
  white-space: nowrap;
}

body.me-life .mw-compile-nudge {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(127, 237, 199, 0.08);
  border: 1px solid rgba(127, 237, 199, 0.18);
}

body.me-life .mw-compile-nudge p {
  margin: 0;
  flex: 1 1 200px;
  font: 300 14px/1.45 var(--font-display, system-ui);
  color: var(--ink-1, #eee);
}

body.me-life .mw-compile-nudge-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  background: #fff;
  color: #000;
  font: 500 14px var(--font-display, system-ui);
  text-decoration: none;
  white-space: nowrap;
}

body.me-life .me-life-stage {
  max-width: none;
  margin: 0;
  width: 100%;
}

body.me-life .mw-grid-root {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.me-life .me-life-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.me-life #me-weeks-mount {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.me-life .mw-grid-viewport {
  flex: 1;
  min-height: calc(100dvh - 200px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  border-radius: 0;
  touch-action: pan-y;
  width: 100%;
}

body.me-life .mw-grid-canvas {
  display: block;
  width: 100%;
  touch-action: pan-y;
}

body.me-life .mw-scrub-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 0 8px;
  width: 100%;
  position: relative;
}

body.me-life .mw-scrub {
  flex: 1;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid var(--surface-edge, rgba(255, 255, 255, 0.06));
  background: var(--whisper-bg, rgba(8, 12, 22, 0.4));
  backdrop-filter: blur(16px) saturate(130%);
  -webkit-backdrop-filter: blur(16px) saturate(130%);
  font-family: var(--font-self);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--ink-1);
  text-transform: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  text-align: left;
  transition: border-color var(--dur-fast, 180ms) var(--ease-soft, ease), background var(--dur-fast, 180ms) var(--ease-soft);
}

body.me-life .mw-scrub:focus-visible {
  outline: none;
  border-color: rgba(127, 237, 199, 0.35);
}

body.me-life .mw-grid-back {
  flex-shrink: 0;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--surface-edge, rgba(255, 255, 255, 0.08));
  background: transparent;
  color: var(--ink-2);
  font-family: var(--font-meta);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  cursor: pointer;
}

body.me-life .mw-grid-back:hover {
  color: var(--ink-1);
  border-color: rgba(127, 237, 199, 0.28);
}

body.me-life .mw-jump-now {
  flex-shrink: 0;
  min-width: 56px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--surface-edge, rgba(255, 255, 255, 0.08));
  background: transparent;
  color: var(--ink-2);
  font-family: var(--font-meta);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: lowercase;
  cursor: pointer;
  touch-action: manipulation;
  transition: color var(--dur-fast, 180ms) var(--ease-soft), border-color var(--dur-fast, 180ms) var(--ease-soft), background var(--dur-fast, 180ms) var(--ease-soft);
}

body.me-life .mw-jump-now:hover {
  color: var(--ink-1);
  border-color: rgba(127, 237, 199, 0.28);
  background: rgba(127, 237, 199, 0.06);
}

body.me-life .mw-month-picker {
  position: absolute;
  z-index: 120;
  left: 8px;
  right: 8px;
  bottom: calc(100% + 8px);
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--surface-edge, rgba(255, 255, 255, 0.1));
  background: rgba(8, 12, 22, 0.96);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

body.me-life .mw-month-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

body.me-life .mw-month-picker-year {
  font: 500 15px var(--font-self);
  color: var(--ink-1);
}

body.me-life .mw-month-picker-y {
  border: none;
  background: transparent;
  color: var(--ink-2);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}

body.me-life .mw-month-picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

body.me-life .mw-month-picker-cell {
  min-height: 40px;
  border: 1px solid var(--surface-edge, rgba(255, 255, 255, 0.08));
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink-1);
  font: 400 13px var(--font-display, system-ui);
  cursor: pointer;
}

body.me-life .mw-month-picker-cell.is-active {
  border-color: rgba(127, 237, 199, 0.45);
  color: #7fedc7;
}

/* Sync line — quiet, not a second header */
body.me-life .mw-sync-strip {
  max-width: 1200px;
  margin: 0 auto 10px;
  padding: 0;
  border: none;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: lowercase;
  color: var(--ink-3);
}

body.me-life .mw-sync-strip a {
  text-transform: lowercase;
  letter-spacing: 0.12em;
}

body.me-life .mw-foot {
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: lowercase;
  color: var(--ink-3);
}

body.me-life .mw-legend {
  justify-content: center;
  text-transform: lowercase;
  letter-spacing: 0.1em;
}

body.me-life .mw-mode-btn {
  text-transform: lowercase;
  letter-spacing: 0.12em;
}

body.me-life .sparse-banner {
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

body.me-life .ask-cosmos-fab {
  display: none !important;
}

body.me-life .graph-depth {
  margin-top: 0;
  border-top: none;
}

body.me-life .graph-depth-summary {
  max-width: 1200px;
  margin: 32px auto 0;
  padding: 16px 0;
  border-top: 1px solid var(--ink-line);
  text-transform: lowercase;
  letter-spacing: 0.14em;
}

/* Full-screen graph layer — opened from a week panel */
body.graph-layer-open {
  overflow: hidden;
}

body.graph-layer-open #graph-depth {
  position: fixed;
  inset: 0;
  z-index: 90;
  margin: 0;
  border: none;
  background: #000;
  display: block;
}

body.graph-layer-open .graph-depth-summary {
  display: none;
}

body.graph-layer-open .graph-depth-body {
  height: 100%;
  padding: 0;
  display: flex;
  flex-direction: column;
}

body.graph-layer-open .graph-sheet-bar {
  display: flex;
}

body.graph-layer-open .stage {
  flex: 1;
  height: auto;
  min-height: 0;
}

body.graph-layer-open .ask-cosmos-fab {
  display: none !important;
}

.graph-sheet-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--ink-line);
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(12px);
}

.graph-sheet-title {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  color: var(--life-signal, #7fedc7);
}

.graph-sheet-close {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: lowercase;
  padding: 8px 12px;
  border: 1px solid var(--ink-line);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}

.graph-sheet-close:hover {
  color: var(--ink-1);
  border-color: var(--ink-3);
}

/* Week panel — fixed shell; body scrolls, footer stays put.
   Enter/exit is driven by JS (shared-element grow from the tapped cell,
   collapse back on close); no CSS entry animation so the two never fight. */
body.me-life .mw-panel {
  position: fixed;
  z-index: 200;
  display: flex;
  flex-direction: column;
  background: var(--overlay-bg, rgba(4, 6, 12, 0.88));
  border: 1px solid var(--whisper-edge, rgba(127, 231, 220, 0.1));
  top: max(76px, calc(64px + env(safe-area-inset-top, 0px)));
  right: max(20px, env(safe-area-inset-right, 0px));
  left: auto;
  width: min(400px, calc(100vw - 40px));
  max-height: calc(100dvh - 88px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow: hidden;
  padding: 0;
  border-radius: 20px;
  box-shadow:
    inset 0 0 0 1px var(--surface-edge, rgba(255, 255, 255, 0.06)),
    0 24px 80px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
}

/* While the sheet is in flight the backdrop blur is suspended — recomputing
   a 20px blur under a scaling surface drops frames on phones. The background
   goes near-opaque instead, so nothing visibly changes until the surface
   rests and the glass fades back in. */
body.me-life .mw-panel.is-moving {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  background: rgba(5, 8, 15, 0.97);
}

/* Grab handle — drag-to-dismiss affordance, mobile sheet only */
body.me-life .mw-panel-grab {
  display: none;
}

body.me-life .mw-panel-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 8px;
  transition: color var(--dur-fast, 180ms) var(--ease-soft);
}

body.me-life .mw-panel-close:hover {
  color: var(--ink-1, #fff);
}

body.me-life .mw-panel-hd {
  flex-shrink: 0;
  margin: 0;
  padding: 18px 44px 0 18px;
}

body.me-life .mw-panel-kicker {
  font-family: var(--font-meta);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  color: var(--ink-3);
  margin: 0 0 5px;
}

body.me-life .mw-panel-title {
  font-family: var(--font-cosmos);
  font-variation-settings: var(--font-cosmos-opsz-body);
  font-weight: 400;
  font-size: 23px;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--ink-1);
  margin: 0;
}

body.me-life .mw-panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 10px 18px 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

body.me-life .mw-panel-scroll::-webkit-scrollbar {
  width: 6px;
}

body.me-life .mw-panel-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 3px;
}

body.me-life .mw-panel-footer {
  flex-shrink: 0;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--surface-edge, rgba(255, 255, 255, 0.06));
  background: rgba(4, 6, 12, 0.72);
}

body.me-life .mw-panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
}

body.me-life .mw-panel-actions-reflect {
  margin-bottom: 8px;
}

body.me-life .mw-panel-actions-nav .mw-gps-cta {
  opacity: 0.82;
}

body.me-life .mw-panel-footer .mw-gps-cta {
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  box-sizing: border-box;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(127, 237, 199, 0.12);
  font: inherit;
}

/* Feedback floats bottom-right — hide while week panel is open */
body.me-week-panel-open .cfb-btn,
body.me-week-panel-open .cfb-card {
  display: none !important;
}

@media (max-width: 720px) {
  body.me-life main.me-life-main {
    padding-top: max(72px, calc(56px + env(safe-area-inset-top, 0px)));
    padding-left: max(14px, env(safe-area-inset-left, 0px));
    padding-right: max(14px, env(safe-area-inset-right, 0px));
  }

  body.me-life .me-life-head {
    margin-bottom: 12px;
  }

  body.me-life .me-life-stat-line {
    font-size: clamp(22px, 5.8vw, 28px);
  }

  body.me-life .me-life-stage {
    margin-bottom: 16px;
  }

  body.me-life .me-life-stage .mw-scroll {
    margin: 0 -4px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    touch-action: pan-x;
    scrollbar-width: none;
  }

  body.me-life .me-life-stage .mw-wrap canvas {
    touch-action: pan-x;
  }

  body.me-life .me-life-stage .mw-scroll::-webkit-scrollbar {
    display: none;
  }

  body.me-life .me-life-stage .mw-wrap {
    aspect-ratio: auto;
    min-height: min(56vh, 420px);
    height: min(56vh, 420px);
  }

  body.me-life .mw-scrub {
    font-size: 10px;
    padding: 10px 12px;
  }

  body.me-life .mw-foot,
  body.me-life .mw-legend {
    font-size: 9px;
    gap: 10px;
    line-height: 1.45;
  }

  body.me-life .mw-mode-bar {
    margin-bottom: 8px;
  }

  body.me-life .mw-mode-btn {
    min-height: 44px;
    padding: 10px 14px;
  }

  body.me-life .sparse-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    font-size: 13px;
  }

  /* Fixed detent: the sheet always opens at the same height, so content
     arriving never resizes it mid-animation. */
  body.me-life .mw-panel {
    left: 0;
    right: 0;
    width: 100%;
    top: auto;
    bottom: 0;
    height: min(84dvh, calc(100dvh - 56px));
    max-height: min(88dvh, calc(100dvh - 56px));
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    box-shadow: 0 -12px 48px rgba(0, 0, 0, 0.55);
  }

  body.me-life .mw-panel-grab {
    display: block;
    flex-shrink: 0;
    width: 36px;
    height: 5px;
    margin: 8px auto 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
  }

  body.me-life .mw-panel-hd {
    padding-top: 10px;
  }

  body.cosmos-app-has-tabs .mw-panel {
    bottom: calc(58px + env(safe-area-inset-bottom, 0px));
    height: min(74dvh, calc(100dvh - 130px));
    max-height: min(78dvh, calc(100dvh - 120px));
  }

  body.me-life .mw-panel-footer .mw-gps-cta {
    flex: 1 1 calc(50% - 4px);
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  body.me-life .mw-panel-close {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    min-width: 44px;
    min-height: 44px;
  }

  body.me-life .mw-panel-scroll {
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
  }

  body.me-life .mw-panel-ritual .wr-preview-grid {
    max-width: 100%;
  }

  body.me-life .mw-panel-ritual .wr-actions-row {
    flex-direction: column;
  }

  body.me-life .mw-panel-ritual .wr-actions-row .wr-secondary {
    width: 100%;
  }

  body.me-life .mw-panel-ritual .wr-primary,
  body.me-life .mw-panel-ritual .wr-secondary {
    min-height: 48px;
  }
}

/* Scrim — a real element so JS can fade it in and out symmetrically.
   pointer-events stays off: taps land on the grid, and the document-level
   dismiss listener decides whether they close the sheet. */
.mw-scrim {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(4, 6, 12, 0.62);
  pointer-events: none;
}

@media (max-width: 480px) {
  body.me-life main.me-life-main {
    padding-top: max(64px, calc(50px + env(safe-area-inset-top, 0px)));
  }

  body.me-life .me-life-head {
    margin-bottom: 6px;
  }

  body.me-life .me-life-stat-kicker {
    margin-bottom: 4px;
  }

  body.me-life .me-life-stat-line {
    font-size: clamp(16px, 4.6vw, 20px);
    line-height: 1.2;
  }

  body.me-life .me-life-stat-sub {
    margin-top: 4px;
    font-size: 10px;
    letter-spacing: 0.06em;
  }

  body.me-life .mw-sync-strip {
    margin-bottom: 6px;
  }

  body.me-life .mw-scrub-row {
    margin-bottom: 6px;
  }
}
