/* Live Covenant UX v2 — additive migration layer.
 * Authority: docs/design/LIVE_COVENANT_UX_V2_IMPLEMENTATION_CONTRACT.md
 * Existing product state/business semantics remain authoritative.
 */

:root {
  --lc-v2-safe-top: env(safe-area-inset-top, 0px);
  --lc-v2-safe-right: env(safe-area-inset-right, 0px);
  --lc-v2-safe-bottom: env(safe-area-inset-bottom, 0px);
  --lc-v2-safe-left: env(safe-area-inset-left, 0px);
  --lc-v2-viewport-height: 100dvh;
  --lc-v2-surface: rgba(14, 11, 28, .76);
  --lc-v2-surface-soft: rgba(14, 11, 28, .42);
  --lc-v2-border: rgba(233, 221, 197, .14);
  --lc-v2-gold: rgba(214, 177, 112, .92);
  --lc-v2-ivory: #f5efe5;
  --lc-v2-muted: rgba(231, 222, 232, .68);
}

html[data-lc-keyboard='open'] {
  --lc-v2-viewport-height: var(--lc-visual-viewport-height, 100dvh);
}

/* R0 — modal/sheet contract */
.modal-dim-backdrop {
  box-sizing: border-box;
  max-width: 100vw;
  max-height: var(--lc-v2-viewport-height);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-top: max(12px, var(--lc-v2-safe-top));
  padding-right: max(12px, var(--lc-v2-safe-right));
  padding-bottom: max(12px, var(--lc-v2-safe-bottom));
  padding-left: max(12px, var(--lc-v2-safe-left));
}

.modal-dim-backdrop > .modal-vellum-card,
.modal-dim-backdrop > .cov-affairs-sheet,
.modal-dim-backdrop > .our-state-sheet,
.modal-dim-backdrop > .drawer-sheet,
.modal-dim-backdrop > [class*='sheet'] {
  max-width: min(100%, 100vw);
  max-height: calc(var(--lc-v2-viewport-height) - max(24px, var(--lc-v2-safe-top)) - max(24px, var(--lc-v2-safe-bottom)));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* R0 — Auth blocker fix: utility first, art second. */
#authOverlay {
  align-items: center;
  justify-content: center;
}

#authOverlay > .modal-vellum-card {
  width: min(100%, 440px);
  max-height: calc(var(--lc-v2-viewport-height) - max(24px, var(--lc-v2-safe-top)) - max(24px, var(--lc-v2-safe-bottom)));
  overflow-y: auto;
  scroll-padding-bottom: calc(96px + var(--lc-v2-safe-bottom));
}

#authOverlay input,
#authOverlay button,
#authOverlay select,
#authOverlay textarea {
  scroll-margin-block: 24px 112px;
}

#authOverlay button,
#authOverlay .btn-study-micro,
#covenantAffairsModal button,
#puppySoulMapModal button,
#communicationInboxModal button,
#lcV2TaskReviewModal button {
  min-height: 44px;
}

@media (max-width: 599px), (max-height: 700px) {
  #authOverlay { align-items: flex-start; }

  #authOverlay > .modal-vellum-card {
    margin: auto 0;
    border-radius: 20px;
  }

  #authOverlay .scene-entry-banner {
    min-height: 82px !important;
    margin-bottom: 10px !important;
  }

  #authOverlay .scene-entry-banner-content {
    min-height: 82px !important;
    padding: 10px 14px !important;
  }

  #authOverlay .scene-entry-subtitle { display: none; }
}

@media (max-height: 520px) {
  #authOverlay .scene-entry-banner { display: none !important; }
  #authOverlay > .modal-vellum-card { border-radius: 16px; }
  #authOverlay .modal-title { margin-bottom: 6px !important; }
  #authOverlay .modal-title + p { margin-bottom: 8px !important; }
  #authOverlay .form-group { margin-bottom: 8px !important; }
}

html[data-lc-keyboard='open'] #authOverlay { align-items: flex-start; }
html[data-lc-keyboard='open'] #authOverlay .scene-entry-banner { display: none !important; }
html[data-lc-keyboard='open'] #authOverlay > .modal-vellum-card { margin-block: 0; }

/* Home v2 — room first, one Focus, then lightweight HUD. */
html[data-lc-section='home'] .experience-home-projection {
  width: min(100%, 980px);
  margin-inline: auto;
  isolation: isolate;
}

html[data-lc-section='home'] .experience-home-grid {
  display: grid !important;
  grid-template-columns: 1fr !important;
  gap: clamp(8px, 1.5vw, 14px) !important;
}

html[data-lc-section='home'] .experience-home-panel.primary {
  min-height: clamp(176px, 28vh, 310px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-color: rgba(214,177,112,.24) !important;
  background:
    linear-gradient(180deg, rgba(20,13,29,.34), rgba(9,7,17,.62)) !important;
  box-shadow: 0 26px 68px rgba(0,0,0,.24) !important;
}

html[data-lc-section='home'] .lc-v2-legacy-secondary {
  display: none !important;
}

/* Covenant Whisper */
.lc-v2-covenant-whisper {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  padding: clamp(20px, 6vw, 54px);
  pointer-events: none;
  opacity: 0;
  transition: opacity 420ms ease;
  background: linear-gradient(180deg, rgba(5,4,11,.24), rgba(5,4,11,.42));
}

.lc-v2-covenant-whisper.is-visible { opacity: 1; }

.lc-v2-covenant-whisper-text {
  max-width: 36rem;
  text-align: center;
  color: rgba(247,241,230,.97);
  font-family: var(--font-serif, 'Cormorant Garamond', serif);
  font-size: clamp(1.12rem, 3.4vw, 1.85rem);
  line-height: 1.35;
  letter-spacing: .005em;
  text-shadow: 0 4px 24px rgba(0,0,0,.62);
  text-wrap: balance;
}

/* Presence: environmental state, no toast. */
.experience-home-projection::before,
.experience-home-projection::after {
  content: '';
  position: absolute;
  top: 8%;
  bottom: 18%;
  width: 24%;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 520ms ease, transform 950ms cubic-bezier(.2,.7,.2,1);
  filter: blur(18px);
}

.experience-home-projection::before {
  left: -4%;
  background: radial-gradient(ellipse at center, rgba(214,177,112,.16), transparent 70%);
}

.experience-home-projection::after {
  right: -4%;
  background: radial-gradient(ellipse at center, rgba(158,151,186,.14), transparent 70%);
}

html[data-lc-daddy-online='true'] .experience-home-projection::before { opacity: .82; }
html[data-lc-puppy-online='true'] .experience-home-projection::after { opacity: .82; }

.experience-home-projection.lc-v2-presence-converge::before {
  opacity: 1;
  transform: translateX(54%);
}
.experience-home-projection.lc-v2-presence-converge::after {
  opacity: 1;
  transform: translateX(-54%);
}

/* Home HUD is intentionally open/quiet rather than another card dashboard. */
.lc-v2-home-hud {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: clamp(12px, 2.4vw, 28px);
  align-items: end;
  margin-top: clamp(8px, 1.6vw, 16px);
  padding: 10px 2px 0;
  border-top: 1px solid rgba(238,228,211,.10);
}

.lc-v2-hud-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
  min-width: 0;
}

.lc-v2-hud-item {
  display: inline-grid;
  gap: 2px;
  min-width: 78px;
  min-height: 42px;
  align-content: center;
  padding: 5px 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.lc-v2-hud-item.is-static { cursor: default; }
.lc-v2-hud-label {
  color: rgba(231,222,232,.48);
  font-size: .61rem;
  font-weight: 650;
  letter-spacing: .11em;
  text-transform: uppercase;
}
.lc-v2-hud-value,
.lc-v2-routine-dots {
  color: rgba(247,241,230,.90);
  font-size: .75rem;
  line-height: 1.2;
}
.lc-v2-routine-dots { letter-spacing: .12em; }
.lc-v2-hud-item.is-care .lc-v2-hud-value { color: rgba(219,198,162,.72); }

/* Signature weather object. No dashboard-card treatment. */
.lc-v2-weather-bottle {
  display: grid;
  grid-template-columns: 42px auto;
  gap: 8px;
  align-items: center;
  min-width: 138px;
  color: var(--lc-v2-ivory);
}

.lc-v2-weather-glass {
  position: relative;
  width: 38px;
  height: 52px;
  border: 1px solid rgba(239,231,215,.32);
  border-radius: 16px 16px 12px 12px;
  background:
    linear-gradient(180deg, rgba(245,241,235,.10), rgba(104,96,116,.07) 62%, rgba(24,17,28,.22));
  box-shadow:
    inset 0 0 16px rgba(255,255,255,.05),
    0 6px 16px rgba(0,0,0,.28);
  overflow: hidden;
}
.lc-v2-weather-glass::after {
  content: '';
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 2px;
  height: 6px;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(90deg,#171016,#7b5c36,#171016);
  opacity: .82;
}
.lc-v2-weather-glass span {
  position: absolute;
  width: 2px;
  height: 8px;
  top: 8px;
  border-radius: 999px;
  background: rgba(216,229,239,.52);
  opacity: 0;
}
.lc-v2-weather-glass span:nth-child(1) { left: 10px; }
.lc-v2-weather-glass span:nth-child(2) { left: 19px; top: 16px; }
.lc-v2-weather-glass span:nth-child(3) { left: 28px; top: 11px; }

.lc-v2-weather-bottle[data-weather*='rain'] .lc-v2-weather-glass span {
  opacity: .75;
  animation: lc-v2-rain 1.8s linear infinite;
}
.lc-v2-weather-bottle[data-weather*='snow'] .lc-v2-weather-glass span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  opacity: .72;
  animation: lc-v2-snow 3.2s ease-in-out infinite;
}
.lc-v2-weather-bottle[data-weather*='fog'] .lc-v2-weather-glass {
  background: linear-gradient(180deg, rgba(230,226,225,.20), rgba(159,157,164,.14) 70%, rgba(24,17,28,.22));
}
.lc-v2-weather-bottle[data-weather*='cloud'] .lc-v2-weather-glass {
  box-shadow: inset 0 18px 18px rgba(196,198,207,.08), 0 6px 16px rgba(0,0,0,.28);
}
.lc-v2-weather-bottle[data-weather*='clear'] .lc-v2-weather-glass {
  box-shadow: inset 0 0 22px rgba(224,186,117,.13), 0 6px 16px rgba(0,0,0,.28);
}
.lc-v2-weather-bottle[data-weather*='thunder'] .lc-v2-weather-glass {
  animation: lc-v2-thunder 7s linear infinite;
}

.lc-v2-weather-copy { display: grid; gap: 2px; }
.lc-v2-weather-copy > span { font-size: .72rem; line-height: 1.2; }
.lc-v2-weather-copy small { color: rgba(231,222,232,.54); font-size: .63rem; }

@keyframes lc-v2-rain {
  from { transform: translateY(-10px); }
  to { transform: translateY(38px); }
}
@keyframes lc-v2-snow {
  0%,100% { transform: translate(0,-5px); }
  50% { transform: translate(3px,28px); }
}
@keyframes lc-v2-thunder {
  0%,47%,49%,100% { box-shadow: inset 0 0 16px rgba(255,255,255,.05),0 6px 16px rgba(0,0,0,.28); }
  48% { box-shadow: inset 0 0 28px rgba(230,226,245,.20),0 6px 16px rgba(0,0,0,.28); }
}

/* Tasks v2 — Tasks is a workspace, not an incidental bottom sheet. */
html[data-lc-section='tasks'] #covenantAffairsModal {
  padding: 0;
  align-items: stretch !important;
}

html[data-lc-section='tasks'] #covenantAffairsModal > .cov-affairs-sheet {
  width: min(100%, 1100px);
  max-width: 1100px;
  min-height: min(820px, var(--lc-v2-viewport-height));
  max-height: var(--lc-v2-viewport-height);
  margin: auto;
  border-radius: 0;
}

.lc-v2-tasks-now {
  margin: 2px 0 18px;
  padding: clamp(14px,2vw,20px) 0 16px;
  border-bottom: 1px solid rgba(238,228,211,.12);
}
.lc-v2-now-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.lc-v2-now-head > div { display: grid; gap: 2px; }
.lc-v2-now-head span {
  color: var(--lc-v2-gold);
  font-size: .62rem;
  letter-spacing: .15em;
  font-weight: 700;
}
.lc-v2-now-head strong {
  color: var(--lc-v2-ivory);
  font-family: var(--font-serif, serif);
  font-size: clamp(1.16rem,2.2vw,1.5rem);
  font-weight: 600;
}
.lc-v2-now-head small { color: var(--lc-v2-muted); font-size: .68rem; white-space: nowrap; }

.lc-v2-now-list { display: grid; gap: 8px; }
.lc-v2-now-card {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 76px;
  padding: 12px 14px;
  border: 1px solid rgba(223,209,185,.15);
  border-radius: 14px;
  background: linear-gradient(100deg, rgba(80,44,55,.18), rgba(18,13,27,.28));
}
.lc-v2-now-card > div { display: grid; gap: 3px; min-width: 0; }
.lc-v2-now-card span { color: rgba(214,177,112,.75); font-size: .64rem; letter-spacing: .08em; text-transform: uppercase; }
.lc-v2-now-card strong { color: var(--lc-v2-ivory); font-size: .88rem; line-height: 1.35; overflow-wrap: anywhere; }
.lc-v2-now-action {
  min-width: 92px;
  border: 1px solid rgba(214,177,112,.38);
  border-radius: 999px;
  background: rgba(214,177,112,.09);
  color: #fff5e5;
  padding: 8px 12px;
  font: 650 .72rem/1.1 var(--font-ui);
}
.lc-v2-now-empty { color: var(--lc-v2-muted); padding: 12px 2px; font-size: .76rem; }
.lc-v2-now-routine { display: flex; gap: 9px; margin-top: 10px; color: rgba(244,236,223,.76); font-size: .74rem; letter-spacing: .11em; }

/* Daddy review: one dominant decision. */
.lc-v2-task-review-overlay {
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2800;
}
.lc-v2-task-review {
  width: min(100%, 720px) !important;
  max-height: calc(var(--lc-v2-viewport-height) - max(24px,var(--lc-v2-safe-top)) - max(24px,var(--lc-v2-safe-bottom))) !important;
  padding: 18px !important;
  background: linear-gradient(180deg,#181118,#0c090e) !important;
  border-color: rgba(214,177,112,.30) !important;
}
.lc-v2-review-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.lc-v2-review-head > div { display: grid; gap: 2px; }
.lc-v2-review-head span,
.lc-v2-review-body section > span,
.lc-v2-review-note > span {
  color: rgba(214,177,112,.72);
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .12em;
}
.lc-v2-review-head h2,
.lc-v2-review-requirement h3 { margin: 0; color: var(--lc-v2-ivory); font-family: var(--font-serif,serif); }
.lc-v2-review-head h2 { font-size: 1.32rem; }
.lc-v2-review-requirement h3 { font-size: 1.12rem; margin-top: 3px; }
.lc-v2-review-body { display: grid; gap: 16px; }
.lc-v2-review-body p { margin-top: 6px; color: rgba(237,229,219,.76); font-size: .79rem; line-height: 1.55; white-space: pre-wrap; }
.lc-v2-review-media-list { display: grid; grid-template-columns: repeat(auto-fit,minmax(150px,1fr)); gap: 10px; margin-top: 8px; }
.lc-v2-review-media { margin: 0; min-width: 0; border-radius: 12px; overflow: hidden; border: 1px solid rgba(239,230,214,.10); background:#050406; }
.lc-v2-review-media img,
.lc-v2-review-media video { display:block; width:100%; max-height:320px; object-fit:contain; background:#050406; }
.lc-v2-review-audio audio { width:100%; }
.lc-v2-review-empty { color: var(--lc-v2-muted); font-size:.73rem; padding:8px 0; }
.lc-v2-review-note { display:grid; gap:7px; }
.lc-v2-review-note textarea {
  width:100%;
  min-height:92px;
  resize:vertical;
  border:1px solid rgba(239,230,214,.14);
  border-radius:12px;
  background:rgba(255,255,255,.035);
  color:var(--lc-v2-ivory);
  padding:11px 12px;
  font:400 16px/1.45 var(--font-ui);
}
.lc-v2-review-actions {
  display:flex;
  justify-content:flex-end;
  align-items:center;
  gap:10px;
  position:sticky;
  bottom:-18px;
  margin-inline:-18px;
  padding:12px 18px calc(12px + var(--lc-v2-safe-bottom));
  background:linear-gradient(180deg,rgba(12,9,14,.62),#0c090e 38%);
  border-top:1px solid rgba(239,230,214,.09);
}
.lc-v2-review-primary,
.lc-v2-review-secondary {
  min-height:44px;
  border-radius:999px;
  padding:9px 18px;
  font:650 .76rem/1 var(--font-ui);
}
.lc-v2-review-primary { border:1px solid rgba(214,177,112,.52); background:rgba(214,177,112,.15); color:#fff4df; min-width:110px; }
.lc-v2-review-secondary { border:1px solid rgba(239,230,214,.16); background:transparent; color:rgba(239,230,214,.78); }
.lc-v2-review-more { color:rgba(239,230,214,.48); font-size:.68rem; }
.lc-v2-review-more summary { cursor:pointer; min-height:38px; display:flex; align-items:center; width:max-content; }
.lc-v2-review-more button { border:0; background:transparent; color:#d8a3a3; padding:8px 0; }

/* Us v2: profile/radar primary; everyday preferences deliberately secondary. */
html[data-lc-section='us'] #puppySoulMapModal {
  align-items: center !important;
}
html[data-lc-section='us'] #puppySoulMapModal > .modal-vellum-card {
  width: min(94vw,760px) !important;
  max-width: 760px !important;
}
html[data-lc-section='us'] #btnProfileTabInsights,
html[data-lc-section='us'] #btnProfileTabBoundaries {
  font-weight: 650;
}
html[data-lc-section='us'] #btnProfileTabSoulMap.lc-v2-life-tab {
  opacity: .56;
  border-color: transparent !important;
  background: transparent !important;
  font-size: .72rem;
}
html[data-lc-section='us'] #btnProfileTabSoulMap.lc-v2-life-tab.active {
  opacity: .86;
  color: rgba(238,226,204,.82);
}
html[data-lc-section='us'] #paneProfileInsights.lc-v2-profile-primary #profileInsightsContent {
  padding-top: 8px !important;
}
html[data-lc-section='us'] #paneProfileSoulMap.lc-v2-life-profile {
  padding-top: 8px;
}
html[data-lc-section='us'] #paneProfileSoulMap.lc-v2-life-profile::before {
  content: 'Outside the Covenant · 生活里的 Puppy';
  display:block;
  margin-bottom:12px;
  color:rgba(230,219,229,.56);
  font-size:.66rem;
  letter-spacing:.10em;
}

/* Games and Us: shared viewport safety. */
html[data-lc-section='games'] .modal-dim-backdrop,
html[data-lc-section='us'] .modal-dim-backdrop {
  max-height: var(--lc-v2-viewport-height);
}

@media (max-width: 599px) {
  .lc-v2-home-hud {
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
  }
  .lc-v2-hud-actions { gap: 2px 12px; }
  .lc-v2-hud-item { min-width: 66px; }
  .lc-v2-weather-bottle { min-width: 118px; grid-template-columns: 36px auto; }
  .lc-v2-weather-glass { width:34px; height:46px; }
  .lc-v2-now-card { grid-template-columns:1fr; align-items:start; }
  .lc-v2-now-action { justify-self:start; }
  .lc-v2-now-head { align-items:start; }
  .lc-v2-task-review-overlay { align-items:flex-end; padding:0; }
  .lc-v2-task-review { width:100% !important; max-height:var(--lc-v2-viewport-height) !important; border-radius:22px 22px 0 0 !important; padding:16px !important; }
  .lc-v2-review-actions { bottom:-16px; margin-inline:-16px; padding-inline:16px; }
  html[data-lc-section='us'] #puppySoulMapModal { align-items:flex-end !important; padding:0; }
  html[data-lc-section='us'] #puppySoulMapModal > .modal-vellum-card { width:100% !important; max-width:none !important; max-height:var(--lc-v2-viewport-height) !important; border-radius:22px 22px 0 0 !important; }
}

@media (max-height: 520px) {
  .lc-v2-home-hud { margin-top:4px; padding-top:5px; }
  .lc-v2-weather-bottle { display:none; }
  .lc-v2-tasks-now { padding-top:6px; margin-bottom:8px; }
  .lc-v2-review-head { margin-bottom:7px; }
}

@media (min-width: 900px) {
  html[data-lc-section='tasks'] #covenantAffairsModal {
    align-items: center !important;
    padding: clamp(16px, 3vw, 36px);
  }
  html[data-lc-section='tasks'] #covenantAffairsModal > .cov-affairs-sheet {
    min-height: min(820px, calc(var(--lc-v2-viewport-height) - 48px));
    max-height: calc(var(--lc-v2-viewport-height) - 48px);
    border-radius: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
  .experience-home-panel,
  .scene-entry-banner,
  .presence-chamber-row,
  .lc-v2-covenant-whisper,
  .experience-home-projection::before,
  .experience-home-projection::after,
  .lc-v2-weather-glass,
  .lc-v2-weather-glass span {
    animation: none !important;
    transition-duration: 1ms !important;
  }
}
