/* endings.shoggoth.lol: the game's dark tokens (as music.shoggoth.lol), paper for the films */
:root {
  --bg: #090b1a; --bg2: #0e1128; --card: #141836; --card2: #1a1f46; --line: #262c5e; --line2: #353d7c;
  --ink: #eef0ff; --muted: #a3a9d6; --dim: #7c83b8;
  --mint: #56f2c0; --amber: #ffb547; --red: #ff4f6d; --violet: #b29cff; --yellow: #ffe39a; --pink: #ff9fd2;
  --paper: #e9e2d2; --paperink: #1c1b2c;
  --grad-brand: linear-gradient(90deg, #ffe39a, #ff9fd2 38%, #b29cff 68%, #56f2c0);
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: "Avenir Next", "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --r: 12px; --tap: 44px;
  --c-good: #56f2c0; --c-neutral: #b29cff; --c-absurd: #ffb547; --c-bad: #ff4f6d; --c-failure: #ff9fd2; --c-scenario: #ffe39a; --c-secret: #ffe39a;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 120px; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
body { overflow-x: hidden; padding-bottom: env(safe-area-inset-bottom);
  background: radial-gradient(1100px 560px at 72% -12%, #262a6a 0%, transparent 60%), radial-gradient(900px 520px at -12% 112%, #2a1548 0%, transparent 60%), var(--bg); }
body.noscroll { overflow: hidden; }
a { color: var(--yellow); }
button { font: inherit; color: inherit; }
.skiplink { position: absolute; left: -999px; top: 8px; background: var(--yellow); color: #000; padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skiplink:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; }

/* ---- header */
.top { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); }
.hero { position: absolute; inset: 0; background-size: cover; background-position: 60% 40%; opacity: .45; filter: saturate(.9); }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(9,11,26,.25) 0%, rgba(9,11,26,.75) 55%, var(--bg) 100%); }
.topin { position: relative; max-width: 1120px; margin: 0 auto; padding: max(26px, env(safe-area-inset-top)) 18px 20px; }
.kicker { margin: 0 0 6px; font: 700 11px/1.3 var(--mono); letter-spacing: .14em; color: var(--muted); }
h1 { font-family: var(--display); font-weight: 900; font-size: clamp(34px, 9vw, 64px); line-height: .98; margin: 0 0 10px; letter-spacing: .01em;
  background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lede { max-width: 660px; margin: 0 0 14px; color: #d8dbf6; font-size: 15.5px; }
.cta { display: flex; flex-wrap: wrap; gap: 8px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 8px 16px; border-radius: 999px; border: 1px solid var(--line2);
  background: rgba(20,24,54,.8); color: var(--ink); text-decoration: none; font-weight: 700; cursor: pointer; }
.btn:hover { border-color: var(--violet); }
.btn.primary { background: var(--yellow); color: #14122a; border-color: var(--yellow); }
.mini { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-height: 38px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line2); background: transparent; color: var(--ink);
  cursor: pointer; font-size: 13.5px; font-weight: 650; text-decoration: none; white-space: nowrap; }
.mini:hover { border-color: var(--violet); }
.mini.hot { background: var(--yellow); color: #14122a; border-color: var(--yellow); }
.mini[disabled] { opacity: .45; cursor: default; }

/* progress */
.prog { margin: 4px 0 14px; max-width: 520px; }
.prog .big { font: 800 18px/1.2 var(--display); }
.prog .big b { font-size: 26px; color: var(--yellow); }
.meter { height: 10px; border-radius: 99px; background: #20254f; overflow: hidden; margin: 6px 0 4px; display: flex; }
.meter i { display: block; height: 100%; }
.meter .m-earned { background: var(--mint); }
.meter .m-peek { background: var(--violet); }
.prog .det { font-size: 13px; color: var(--muted); }

/* ---- toolbar (sticky) */
.tools { position: sticky; top: 0; z-index: 20; background: rgba(9,11,26,.94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.toolsin { max-width: 1120px; margin: 0 auto; padding: 8px max(12px, env(safe-area-inset-left)); display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.row1 { display: flex; gap: 8px; align-items: center; }
.search { flex: 1; min-width: 0; min-height: 40px; padding: 6px 12px 6px 34px; border-radius: 10px; border: 1px solid var(--line2); background: #10142f url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a3a9d6' stroke-width='2.5'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-4-4'/%3E%3C/svg%3E") no-repeat 11px 50%;
  color: var(--ink); font: inherit; font-size: 16px; }
.search::placeholder { color: var(--dim); }
.status { min-height: 40px; border-radius: 10px; border: 1px solid var(--line2); background: #10142f; color: var(--ink); font: inherit; font-size: 14px; padding: 0 8px; max-width: 40vw; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; min-height: 34px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line2); background: transparent; color: var(--muted); font-weight: 700; font-size: 13px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--card2); color: var(--ink); border-color: var(--violet); }
.chip .n { color: var(--dim); font-weight: 600; margin-left: 2px; }

main { max-width: 1120px; margin: 0 auto; padding: 4px 12px 28px; }
h2 { display: flex; gap: 8px; align-items: baseline; font: 800 13px/1.2 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 26px 4px 2px; }
h2 .n { color: var(--dim); }
.gsub { color: var(--dim); font-size: 13px; margin: 0 4px 10px; }
.empty { padding: 30px 10px; text-align: center; color: var(--muted); }

/* ---- ending cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; }
.ec { position: relative; display: flex; flex-direction: column; min-width: 0; border-radius: var(--r); overflow: hidden; background: linear-gradient(180deg, #171c40, #12163a); border: 1px solid var(--line);
  --kc: var(--c-neutral); scroll-margin-top: 130px; }
.ec[data-g="good"] { --kc: var(--c-good); } .ec[data-g="absurd"] { --kc: var(--c-absurd); } .ec[data-g="bad"] { --kc: var(--c-bad); }
.ec[data-g="failure"] { --kc: var(--c-failure); } .ec[data-g="scenario"] { --kc: var(--c-scenario); } .ec[data-g="secret"] { --kc: var(--c-secret); }
.ec.focus { border-color: var(--yellow); box-shadow: 0 0 0 2px var(--yellow), 0 10px 40px rgba(255,227,154,.18); }
.ec .th { position: relative; aspect-ratio: 16 / 9; background: var(--paper); overflow: hidden; border: 0; padding: 0; display: block; width: 100%; cursor: pointer; }
.ec .th img { width: 100%; height: 100%; object-fit: cover; display: block; transition: filter .35s, transform .35s; }
.ec.locked .th img { filter: blur(16px) saturate(.55); transform: scale(1.12); }
.ec .th .secretart { position: absolute; inset: 0; display: grid; place-items: center; font-size: 54px; background: repeating-linear-gradient(135deg, #1b1f48 0 14px, #161a3d 14px 28px); }
.ec .th .veil { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 10px; }
.ec .th .veil span { font: 800 13px/1.3 var(--sans); color: var(--paperink); background: rgba(247,242,230,.94); padding: 6px 12px; border-radius: 10px; border: 1.5px solid var(--paperink); }
.ec .th .playov { position: absolute; left: 10px; bottom: 10px; font: 800 13px/1 var(--sans); color: #f7f2e6; background: rgba(28,27,44,.86); padding: 8px 12px; border-radius: 999px; }
.ec .th .dur { position: absolute; right: 8px; bottom: 8px; font: 700 11px var(--mono); background: rgba(28,27,44,.82); color: #f7f2e6; padding: 2px 6px; border-radius: 6px; }
.ec .bd { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.ec .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; }
.kchip { font: 800 11px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--kc); border: 1.5px solid var(--kc); border-radius: 999px; padding: 4px 8px; }
.stb { font: 700 12px/1 var(--sans); border-radius: 999px; padding: 4px 8px; }
.stb.earned { background: rgba(86,242,192,.15); color: var(--mint); }
.stb.peeked { background: rgba(178,156,255,.15); color: var(--violet); }
.stb.hidden { color: var(--dim); }
.ec h3 { margin: 0; font: 900 18px/1.18 var(--display); letter-spacing: .01em; overflow-wrap: anywhere; }
.ec.locked.secret h3 { color: var(--muted); }
.ec .hint { margin: 0; color: var(--muted); font-size: 13.5px; }
.ec .hint b { color: var(--ink); font-weight: 700; }
.ec .starts { margin: 0; font-size: 12.5px; color: var(--dim); }
.ec .vnote { margin: 0; font-size: 12.5px; color: var(--muted); }
.ec .acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 4px; }
.ec .acts .grow { flex: 1; }

/* ---- reading sheet (one ending, full text + epilogue cards) */
.sheet { position: fixed; inset: 0; z-index: 60; display: flex; justify-content: center; align-items: flex-end; background: rgba(5,6,16,.7); }
.sheetin { position: relative; width: min(100%, 760px); max-height: 94vh; max-height: 94dvh; overflow-y: auto; overscroll-behavior: contain; background: var(--bg2); border: 1px solid var(--line2); border-radius: 18px 18px 0 0;
  padding: 0 0 calc(24px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 40px #000a; }
@media (min-width: 800px) { .sheet { align-items: center; } .sheetin { border-radius: 18px; max-height: 90vh; } }
.shhead { position: sticky; top: 0; z-index: 2; display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: rgba(14,17,40,.97); border-bottom: 1px solid var(--line); }
.shhead .ttl { flex: 1; min-width: 0; font: 800 14px/1.2 var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shbody { padding: 0 16px; }
.shposter { position: relative; margin: 0 -16px 12px; aspect-ratio: 16 / 9; background: var(--paper); border: 0; padding: 0; width: calc(100% + 32px); display: block; cursor: pointer; }
.shposter img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shposter .playov { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font: 900 16px/1 var(--sans); color: #f7f2e6; background: rgba(28,27,44,.88); padding: 14px 20px; border-radius: 999px; border: 2px solid #f7f2e6; }
.sheet h3.big { margin: 6px 0 2px; font: 900 clamp(24px, 6vw, 36px)/1.05 var(--display); background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sheet .sm { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.story { font: 17px/1.62 var(--serif); color: #e8e9fb; }
.story p { margin: 0 0 14px; }
.sample { font-size: 12px; color: var(--dim); margin: -4px 0 16px; }
.paperc { margin: 16px 0; padding: 14px 16px; background: var(--paper); color: var(--paperink); border-radius: 6px; box-shadow: 0 2px 0 #b9b09b, 0 10px 30px #0006; font-family: var(--serif); }
.paperc .pn { font: 900 12px var(--mono); letter-spacing: .2em; text-transform: uppercase; border-bottom: 2px solid var(--paperink); padding-bottom: 4px; display: flex; justify-content: space-between; gap: 8px; }
.paperc .hl { font: 900 clamp(20px, 5vw, 28px)/1.08 var(--display); margin: 8px 0 6px; overflow-wrap: anywhere; }
.paperc .dk { font-size: 14.5px; line-height: 1.45; margin: 0; }
.blk { margin: 18px 0; }
.blk h4 { margin: 0 0 8px; font: 800 12px/1.2 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.fates { display: grid; gap: 8px; }
.fate { padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.fate b { display: block; } .fate .role { display: block; font-size: 12px; color: var(--dim); margin-bottom: 2px; } .fate p { margin: 0; font-size: 14.5px; color: #dfe1fa; }
.quote { margin: 0; padding: 10px 14px; border-left: 3px solid var(--violet); background: rgba(178,156,255,.07); border-radius: 0 10px 10px 0; font-size: 15px; }
.quote cite { display: block; font-style: normal; font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.chirps { display: grid; gap: 6px; }
.chirp { padding: 8px 12px; background: #10142f; border: 1px solid var(--line); border-radius: 12px; font-size: 14px; overflow-wrap: anywhere; }
.chirp b { color: var(--violet); font-weight: 700; margin-right: 6px; }
.rank { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 12px; background: linear-gradient(90deg, rgba(255,227,154,.14), rgba(178,156,255,.1)); border: 1px solid #5a4f2a; }
.rank .ico { font-size: 28px; } .rank b { display: block; color: var(--yellow); } .rank span { font-size: 13.5px; color: #dfe1fa; }
.variants { display: grid; gap: 8px; }
.vrow { padding: 10px 12px; border: 1px dashed var(--line2); border-radius: 10px; }
.vrow.focus { border-color: var(--yellow); border-style: solid; }
.vrow summary { cursor: pointer; font-weight: 800; list-style: none; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; min-height: 32px; }
.vrow summary::-webkit-details-marker { display: none; }
.vrow .how { font-weight: 500; color: var(--muted); font-size: 13px; }
.vrow .story { font-size: 16px; margin-top: 8px; }
.links { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 6px; }
.links .mini { white-space: normal; text-align: center; max-width: 100%; }
button, a { -webkit-tap-highlight-color: transparent; }
.verdict { font-style: italic; color: var(--muted); font-size: 14px; }

/* ---- dialogs + toast */
.dlg { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; background: rgba(5,6,16,.72); padding: 16px; }
.dlgin { width: min(100%, 460px); background: var(--bg2); border: 1px solid var(--line2); border-radius: 16px; padding: 18px; box-shadow: 0 20px 50px #000c; }
.dlgin h3 { margin: 0 0 8px; font: 900 20px/1.2 var(--display); }
.dlgin p { margin: 0 0 10px; color: #d8dbf6; }
.dlgin textarea { width: 100%; min-height: 80px; border-radius: 10px; border: 1px solid var(--line2); background: #10142f; color: var(--ink); font: 14px var(--mono); padding: 8px; }
.dlgin .btns { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 90; max-width: min(92vw, 520px); padding: 10px 16px; border-radius: 12px;
  background: var(--yellow); color: #14122a; font-weight: 700; box-shadow: 0 8px 30px #000a; }

/* ---- theater (as music.shoggoth.lol) */
.theater { position: fixed; inset: 0; z-index: 100; background: var(--paper); overflow: hidden; touch-action: manipulation; }
.theater canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.thtitle { position: absolute; left: 0; right: 0; top: 22%; text-align: center; color: var(--paperink); pointer-events: none; opacity: 0; transition: opacity .8s; padding: 0 16px; }
.thtitle.on { opacity: 1; }
.thtitle b { display: block; font: 900 clamp(26px, 6vw, 54px)/1.05 var(--display); letter-spacing: .01em; }
.thtitle span { display: inline-block; margin-top: 10px; font: 600 clamp(12px, 2.4vw, 16px)/1.4 var(--sans); background: rgba(247,242,230,.9); padding: 4px 10px; border-radius: 8px; }
.thload { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font: 700 16px var(--sans); color: var(--paperink); background: rgba(247,242,230,.95); padding: 10px 16px; border-radius: 12px; border: 2px solid var(--paperink); }
.thctl { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; align-items: center; padding: 10px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: linear-gradient(180deg, transparent, rgba(20,18,40,.85) 40%); transition: opacity .3s; }
.theater.idle .thctl { opacity: 0; pointer-events: none; }
.theater.idle { cursor: none; }
.thctl button { flex: 0 0 auto; min-width: var(--tap); min-height: var(--tap); border-radius: 50%; border: 0; background: rgba(247,242,230,.92); color: var(--paperink); font: 800 14px var(--sans); cursor: pointer; }
.thctl input { flex: 1; min-width: 40px; accent-color: var(--yellow); min-height: 30px; margin: 0; }
.thtime { font: 700 12px var(--mono); color: #f7f2e6; white-space: nowrap; }
.thsong { position: absolute; right: 12px; top: max(10px, env(safe-area-inset-top)); font: 700 12px var(--sans); color: var(--paperink); background: rgba(247,242,230,.9); padding: 4px 10px; border-radius: 8px; max-width: 70vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity .3s; }
.theater.idle .thsong { opacity: 0; }
.thsr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.foot { max-width: 1120px; margin: 0 auto; padding: 20px 16px 40px; color: var(--dim); font-size: 13px; border-top: 1px solid var(--line); }
.foot .fine { font-size: 12px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media (max-width: 600px) {
  .topin { padding-top: max(18px, env(safe-area-inset-top)); padding-bottom: 14px; }
  .kicker { font-size: 10px; letter-spacing: .1em; }
  .lede { font-size: 14.5px; }
  .cta .btn { min-height: 42px; padding: 6px 12px; font-size: 14px; }
  .story { font-size: 16.5px; }
}
