/* Edition V · performance-safe polish, explicit states, and readable mobile depth. */
:root{
  --focus-ring: #ffe4a9;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html{scrollbar-gutter:stable both-edges;text-rendering:optimizeLegibility}
body{overscroll-behavior-x:none}
a,button,input,select,textarea{touch-action:manipulation}
:where(.sr-only){position:absolute!important;width:1px!important;height:1px!important;padding:0!important;margin:-1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;white-space:nowrap!important;border:0!important}
:where(a,button,input,select,textarea,[tabindex]):focus-visible{outline:2px solid var(--focus-ring);outline-offset:3px}
.profile-controls button[role="tab"][aria-selected="true"],.playlist-tabs button[role="tab"][aria-selected="true"]{border-color:var(--gold);color:var(--gold);background:color-mix(in srgb,var(--gold) 10%,var(--bg))}

/* A quiet invitation replaces the old timed route change. */
.story-invite{position:fixed;right:clamp(16px,3vw,46px);bottom:calc(94px + var(--safe-bottom));z-index:38;width:min(430px,calc(100vw - 32px));padding:22px 24px 20px;border:1px solid color-mix(in srgb,var(--gold) 65%,transparent);background:color-mix(in srgb,var(--surface) 94%,#060812 6%);box-shadow:0 18px 70px #0009,0 0 34px color-mix(in srgb,var(--gold) 15%,transparent);backdrop-filter:blur(18px);opacity:0;transform:translateY(16px);transition:opacity .28s ease,transform .28s cubic-bezier(.16,1,.3,1)}
.story-invite.show{opacity:1;transform:translateY(0)}
.story-invite-kicker{font:700 10px/1.2 Body,Symbols,sans-serif;letter-spacing:.18em;color:var(--gold);margin-bottom:10px}
.story-invite h2{font:400 clamp(24px,3vw,34px)/1.05 Editorial,Georgia,serif;margin:0 0 10px;color:var(--ink)}
.story-invite p{font-size:14px;line-height:1.65;color:var(--muted);margin:0;max-width:42ch}
.story-invite-actions{display:flex;gap:10px;flex-wrap:wrap;margin-top:18px}
.story-invite-actions a,.story-invite-actions button{min-height:42px;padding:10px 14px;border:1px solid var(--gold);font:600 12px/1.3 Body,Symbols,sans-serif;letter-spacing:.02em}
.story-invite-actions a{background:var(--gold);color:#11131b}
.story-invite-actions button{background:transparent;color:var(--ink)}
.story-invite-actions a:hover,.story-invite-actions button:hover{transform:translateY(-1px);filter:brightness(1.08)}

/* All five lives have the same visual weight. Three cards followed by two
   centered cards preserve portrait detail without stretching a lead image. */
.faction-cast .grand-people{display:flex;flex-wrap:wrap;justify-content:center;align-items:stretch;gap:20px}
.faction-cast .grand-person{
  box-sizing:border-box;flex:0 1 calc((100% - 40px)/3);
  min-width:0;min-height:0;height:390px;
}
.faction-cast .grand-person>div{padding:22px 18px}

/* Decorative moon sprites must never enter the accessible reading tree. */
.origin-moon img,.split-moon img,.landing-moons img{pointer-events:none}

/* Avoid text being hidden behind the persistent player, including notched phones. */
#reader-content{padding-bottom:calc(184px + var(--safe-bottom))}
.site-footer{padding-bottom:calc(130px + var(--safe-bottom))}
.music-player{bottom:max(18px,var(--safe-bottom));}

/* The Daylight Truce is a calm interpolation, not a hard theme swap. */
.temple-bg,.temple-shade,.portal-daywash,.site-header,.music-player,.daylight-story{transition-duration:var(--daylight-ms,1250ms);transition-timing-function:cubic-bezier(.22,.61,.36,1)}
.cinematic-landed .sanctuary-heading,.cinematic-landed .portals{animation:landedArrival .82s cubic-bezier(.16,1,.3,1) both}
@keyframes landedArrival{from{opacity:.45}to{opacity:1}}

/* Long reading surfaces stay cheap while retaining the neoclassical cadence. */
.archive-section,.faction-chapter,.faction-cast,.hollow-chapter,.hollow-cast,.hollow-lore,.profile-gallery{content-visibility:auto;contain-intrinsic-size:1px 520px}
/* The gallery can grow to forty images. Let its real height participate in the
   scroll layout so opening it does not replace a 520px placeholder mid-scroll. */
#reader[data-page=profile] .profile-gallery{content-visibility:visible;contain-intrinsic-size:auto}
.grand-person>img,.gallery-grid img,.affinity-portrait img,.place-entry-art img{background:linear-gradient(135deg,#111421,#241b2b);}
.quality-lite .story-invite{backdrop-filter:none;box-shadow:0 12px 38px #0008}

@media(max-width:1100px){
  .faction-cast .grand-people{gap:16px}
  .faction-cast .grand-person{flex-basis:calc((100% - 16px)/2);height:360px}
}
@media(max-width:760px){
  .story-invite{right:12px;bottom:calc(76px + var(--safe-bottom));width:calc(100vw - 24px);max-height:calc(100svh - 158px - var(--safe-bottom));overflow:auto;padding:18px 18px 16px}
  .story-invite h2{font-size:27px}
  .story-invite p{font-size:14px;line-height:1.52}
  .story-invite-actions{display:grid;grid-template-columns:1fr;gap:8px}
  .story-invite-actions a,.story-invite-actions button{text-align:center;width:100%;min-height:44px;font-size:14px}
  .faction-cast .grand-people{gap:12px}
  .faction-cast .grand-person{flex-basis:calc((100% - 12px)/2);height:300px}
  #reader-content{padding-bottom:calc(208px + var(--safe-bottom))}
  .site-footer{padding-bottom:calc(150px + var(--safe-bottom))}
}
@media(max-width:430px){
  #reader[data-page=faction] .faction-cast .grand-person{
    flex-basis:100%;height:clamp(350px,108vw,430px);
  }
}
@media(max-width:760px) and (max-height:620px){
  .story-invite{max-height:calc(100svh - 140px - var(--safe-bottom));padding:14px 16px}
  .story-invite h2{font-size:23px}
  .story-invite p{font-size:13px;line-height:1.45}
  .story-invite-actions{display:flex;margin-top:12px}
  .story-invite-actions a,.story-invite-actions button{flex:1 1 140px}
}
@media(prefers-reduced-motion:reduce){
  .story-invite,.story-invite.show{transition:none;transform:none}
  .cinematic-landed .sanctuary-heading,.cinematic-landed .portals{animation:none}
}
