.stories-main { padding-bottom: clamp(2.5rem, 6vw, 5rem); }

.stories-masthead {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: grid;
  align-items: end;
  min-height: clamp(18rem, 34vw, 27rem);
  padding: clamp(1.65rem, 5.2vw, 5rem);
  border: .4rem solid var(--ink);
  outline: 1px solid var(--rule);
  background:
    linear-gradient(90deg, #391d19 8%, #4c241fee 38%, #3b201b65 74%, #2a171464),
    repeating-linear-gradient(162deg, transparent 0 12px, #3218126b 13px 15px),
    radial-gradient(ellipse at 81% 26%, #bd7350, transparent 70%),
    #48251f;
  box-shadow: .35rem .45rem #0a0706;
}

.stories-masthead::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: .65rem;
  border: 1px solid #ffbd7957;
  background-image: radial-gradient(circle, #100907 1px, transparent 1.15px);
  background-size: 4px 4px;
  mask-image: linear-gradient(105deg, #000a, transparent 72%);
}

.stories-masthead::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background: linear-gradient(0deg, #180e0cba, transparent 75%);
}

.stories-intro h1 {
  font: clamp(4.4rem, 12vw, 10.1rem)/.87 var(--display);
  letter-spacing: -.025em;
  text-transform: uppercase;
  text-shadow: .045em .055em #170c0a;
}

.stories-intro p {
  margin-top: clamp(.85rem, 2.2vw, 1.5rem);
  color: #ffe6c6;
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: 625;
}

.story-library { margin-top: clamp(2rem, 4.65vw, 4rem); }

.story-section-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: clamp(1rem, 2.25vw, 1.75rem);
  padding-bottom: .7rem;
  border-bottom: 1px solid var(--rule);
}

.story-section-heading h2 {
  color: var(--paper);
  font: clamp(1.6rem, 3.15vw, 2.6rem)/1.1 var(--display);
  letter-spacing: .025em;
  text-transform: uppercase;
}

.story-mode-switch {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: .35rem;
  min-height: 2.75rem;
  padding: .3rem .15rem;
  border: 0;
  border-radius: .2rem;
  background: transparent;
  color: var(--muted);
  font: 700 .83rem/1 var(--text);
  cursor: pointer;
}

.story-mode-track {
  position: relative;
  width: 2.45rem;
  height: 1.35rem;
  border: 1px solid #9a6c54;
  border-radius: 999px;
  background: #301e17;
}

.story-mode-track::after {
  content: "";
  position: absolute;
  inset: .15rem auto auto .18rem;
  width: .925rem;
  height: .925rem;
  border-radius: 50%;
  background: var(--amber);
  transition: transform 170ms ease-out;
}

.story-mode-switch[aria-checked="true"] .story-mode-track::after { transform: translateX(1.05rem); }
.story-mode-switch[aria-checked="false"] .story-mode-book-label,
.story-mode-switch[aria-checked="true"] .story-mode-scroll-label { color: var(--paper); }
.story-mode-switch:hover .story-mode-track { border-color: var(--amber); }
.story-mode-switch:focus-visible { outline-offset: 3px; }

.story-library-status {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(.8rem, 3.8vw, 2.25rem);
  min-height: 9.5rem;
  padding: clamp(1rem, 3.6vw, 2.6rem);
  border: 1px dashed #7e5542;
  border-inline-start: .25rem solid #a85842;
  background:
    repeating-linear-gradient(130deg, #bb765c0b 0 1px, transparent 1px 5px),
    #251b17;
}

.story-library-status .loader {
  --size: .85px;
  display: none;
}

.story-library-status.is-loading .loader { display: inline-block; }
.story-library-status.is-loading .story-status-icon { display: none; }

.story-status-icon {
  display: grid;
  width: clamp(2rem, 5vw, 3.2rem);
  aspect-ratio: .77;
  place-items: center;
  rotate: -7deg;
  border: 2px solid #d59568;
  background: #482822;
  box-shadow: .25rem .25rem #241512, .35rem .35rem #d59568;
}

.story-status-icon::before {
  content: "";
  width: 52%;
  height: 56%;
  border: 1px solid #d59568;
  background:
    linear-gradient(164deg, transparent 48%, #d59568 48% 52%, transparent 52%),
    #66392d;
}

#story-status-title {
  color: var(--paper);
  font-size: 1.05rem;
  font-weight: 750;
}

#story-status-detail, .story-no-js {
  margin-top: .2rem;
  color: var(--muted);
}

#story-status-detail:empty { display: none; }

.story-poster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15.5rem), 1fr));
  column-gap: clamp(1.35rem, 2.6vw, 2.25rem);
  row-gap: clamp(2.1rem, 4vw, 3.4rem);
  margin: 0;
  padding: 0;
  list-style: none;
}

.story-poster {
  position: relative;
  display: grid;
  isolation: isolate;
  width: 100%;
  aspect-ratio: 2 / 3;
  padding: .3rem;
  overflow: hidden;
  border: .1rem solid #774f3c;
  border-bottom: .3rem solid #bf7954;
  background:
    radial-gradient(50% 50% at 45% 36%, #754a35, transparent),
    repeating-linear-gradient(141deg, #bb765c18 0 1px, transparent 1px 6px),
    #231512;
  box-shadow: .3rem .38rem #100d0b;
  color: var(--paper);
  font: 700 .88rem/1.1 var(--text);
  cursor: pointer;
  transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}

.story-poster:hover {
  transform: translateY(-.22rem);
  border-color: var(--amber);
  box-shadow: .45rem .65rem #100d0b;
}

.story-poster img {
  position: absolute;
  z-index: -1;
  inset: .3rem;
  width: calc(100% - .6rem);
  height: calc(100% - .6rem);
  object-fit: cover;
  pointer-events: none;
}

.story-card-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .55rem;
  margin: 1rem 0 .35rem;
}

.story-card-heading h3 {
  margin: 0;
  color: var(--paper);
  font: 1.52rem/1.18 var(--display);
  letter-spacing: .025em;
  overflow-wrap: anywhere;
}

.story-card-heading span {
  color: #e0b298;
  font: 650 .78rem/1.2 var(--text);
  white-space: nowrap;
}

.story-card p {
  color: var(--muted);
  font-size: .93rem;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.story-library-status[hidden],
.story-retry[hidden],
.story-poster-grid[hidden],
.story-detail [hidden],
.reader-stage[hidden],
.reader-controls[hidden],
.reader-scroll[hidden],
.story-poster img[hidden],
.reader-leaf img[hidden] { display: none; }

body:has(.comic-reader[open], .story-detail[open]) { overflow: hidden; }

.story-detail {
  width: min(94vw, 58rem);
  max-width: none;
  max-height: 92dvh;
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid #a67559;
  background:
    radial-gradient(ellipse at top right, #5b3327a6, transparent 70%),
    repeating-linear-gradient(145deg, #ce8b620c 0 1px, transparent 1px 5px),
    #201511;
  color: var(--paper);
  box-shadow: .45rem .55rem #0d0908, 0 1.4rem 5rem #000b;
}

.story-detail::backdrop { background: #0c0807dc; }

.story-detail-close {
  position: sticky;
  z-index: 3;
  inset-block-start: .65rem;
  display: grid;
  place-items: center;
  margin: .65rem .65rem -3.4rem auto;
}

.story-detail-layout {
  display: grid;
  grid-template-columns: minmax(0, .94fr) minmax(0, 1.06fr);
  align-items: center;
  gap: clamp(1.25rem, 3.6vw, 3rem);
  padding: clamp(1.1rem, 3.7vw, 3rem);
}

.story-detail-layout:has(.story-detail-cover[hidden]) { grid-template-columns: minmax(0, 1fr); }

.story-detail-cover {
  display: block;
  width: 100%;
  max-height: min(72dvh, 38rem);
  aspect-ratio: 4 / 5;
  padding: .26rem;
  border: 1px solid #98694e;
  object-fit: contain;
  background: #140c09;
  box-shadow: .36rem .45rem #0e0907;
  pointer-events: none;
}

.story-detail-copy {
  display: grid;
  align-content: center;
  justify-items: start;
  gap: clamp(.85rem, 2vw, 1.35rem);
  min-width: 0;
  overflow-wrap: anywhere;
}

.story-detail-copy h2 {
  margin: 0;
  padding-inline-end: 1.6rem;
  color: var(--paper);
  font: clamp(2rem, 5vw, 4rem)/1.02 var(--display);
  letter-spacing: -.015em;
  text-transform: uppercase;
  text-shadow: .04em .05em #110a08;
}

.story-detail-description {
  max-width: 42ch;
  margin: 0;
  color: var(--muted);
  font-size: .99rem;
  line-height: 1.56;
  white-space: pre-line;
}

.story-detail-ratings {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  width: 100%;
  margin: 0 0 -.28rem;
  padding: 0 0 1.65rem;
  list-style: none;
}

.story-rating-icon {
  position: relative;
  display: grid;
  width: 2.45rem;
  height: 2.45rem;
  place-items: center;
  border: 1px solid #795640;
  border-radius: .15rem;
  background: #2a1b16;
  color: #ffd2a3;
  font: 800 1rem/1 var(--text);
}

.story-rating-icon:is(:hover, :focus-visible) {
  border-color: var(--amber);
  color: var(--amber);
}

.story-rating-age {
  border-color: #b4774d;
  background: #59321f;
  font-size: 1.04rem;
  font-variant-numeric: tabular-nums;
}

.story-rating-tooltip {
  position: absolute;
  inset: auto auto 0 0;
  max-width: 100%;
  visibility: hidden;
  color: #ffe2bd;
  font: 700 .88rem/1.25 var(--text);
  pointer-events: none;
}

.story-rating:hover .story-rating-tooltip,
.story-rating:focus-within .story-rating-tooltip { visibility: visible; }

.story-detail-ratings:has(.story-rating:hover) .story-rating:not(:hover) .story-rating-tooltip {
  visibility: hidden;
}

.story-rating-icon[data-warning="blood-violence"]::before {
  content: "";
  width: .65rem;
  height: .65rem;
  border-radius: 0 65% 65%;
  background: currentColor;
  transform: rotate(45deg);
}

.story-rating-icon[data-warning="gore"]::before {
  content: "";
  width: 1.15rem;
  height: 1.15rem;
  background: currentColor;
  clip-path: polygon(52% 0, 63% 37%, 91% 11%, 77% 47%, 100% 52%, 70% 66%, 86% 96%, 56% 78%, 44% 100%, 38% 72%, 10% 92%, 27% 62%, 0 54%, 31% 44%, 15% 13%, 40% 36%);
}

.story-rating-icon[data-warning="strong-language"]::before { content: "#!"; }
.story-rating-icon[data-warning="sexual-content"]::before { content: "♥"; font-size: 1.23rem; }

.story-rating-icon[data-warning="nudity"]::before {
  content: "";
  width: .95rem;
  height: 1.15rem;
  background: currentColor;
  clip-path: polygon(31% 0, 40% 14%, 60% 14%, 69% 0, 77% 8%, 100% 20%, 81% 43%, 72% 33%, 75% 62%, 88% 83%, 79% 100%, 59% 100%, 50% 91%, 41% 100%, 21% 100%, 12% 83%, 25% 62%, 28% 33%, 19% 43%, 0 20%, 23% 8%);
}

.story-rating-icon[data-warning="psychological-horror"]::before {
  content: "";
  width: .84rem;
  height: .84rem;
  border: 1px solid currentColor;
  border-radius: 70% 8%;
  transform: rotate(45deg);
}

.story-rating-icon[data-warning="psychological-horror"]::after {
  content: "";
  position: absolute;
  width: .31rem;
  height: .31rem;
  border-radius: 50%;
  background: currentColor;
}

.story-rating-icon[data-warning="anxiety-depression"]::before {
  content: "☁";
  align-self: start;
  margin-top: .42rem;
  font-size: 1.2rem;
}

.story-rating-icon[data-warning="anxiety-depression"]::after {
  content: "";
  position: absolute;
  bottom: .45rem;
  width: 1px;
  height: .25rem;
  background: currentColor;
  box-shadow: .23rem 0 currentColor, -.23rem 0 currentColor;
  transform: skewX(-20deg);
}

.story-rating-icon[data-warning="substance-use"]::before {
  content: "";
  width: 1.15rem;
  height: .58rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: linear-gradient(90deg, currentColor 50%, transparent 50%);
  transform: rotate(-42deg);
}

.story-detail-read {
  min-width: 7rem;
  min-height: 2.85rem;
  padding: .5rem 1.5rem;
  border: 1px solid #ffcf96;
  background: var(--amber);
  color: #21150f;
  font: 800 1rem/1.1 var(--text);
  cursor: pointer;
  box-shadow: .18rem .25rem #100b08;
}

.story-detail-read:hover { background: #ffe1b9; }

.comic-reader {
  width: min(96vw, 72rem);
  max-width: none;
  max-height: 96dvh;
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid #9a6c54;
  background: #211612;
  color: var(--paper);
  box-shadow: .5rem .65rem 0 #0b0807, 0 1.5rem 5rem #000b;
}

.comic-reader::backdrop { background: #0c0807dc; }

.comic-reader[data-mode="book"][open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(98vw, 90rem);
  height: 97dvh;
  max-height: 97dvh;
}

.comic-reader[data-mode="book"] .reader-stage {
  grid-template-rows: minmax(0, 1fr);
  --book-padding: clamp(.35rem, 1.2vw, .9rem);
}

.comic-reader[data-mode="book"][open] .reader-book {
  height: 100%;
  min-height: 0;
  max-width: 46rem;
}

.comic-reader[data-mode="book"][open] :is(.reader-book, .reader-turn).is-spread {
  max-width: none;
}

.comic-reader[data-mode="book"] .reader-turn {
  max-width: 46rem;
}

.comic-reader[data-mode="scroll"][open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 96dvh;
  overflow: hidden;
}

.reader-scroll {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable both-edges;
  background: #100a09;
}

.reader-scroll:focus-visible { outline-offset: -2px; }

.reader-scroll .reader-leaf {
  display: block;
  width: min(100%, 60rem);
  margin: 0 auto;
  border: 0;
  background: transparent;
}

.reader-scroll .reader-leaf.is-loading {
  min-height: clamp(20rem, 85dvh, 60rem);
}

.reader-scroll .reader-leaf img {
  position: static;
  width: 100%;
  height: auto;
}

.reader-scroll .reader-leaf-note { color: var(--muted); }

.reader-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  padding: .65rem clamp(.8rem, 2.6vw, 1.5rem);
  border-bottom: 1px solid var(--rule);
}

.reader-header h2 {
  font: clamp(1.25rem, 4vw, 2rem)/1.15 var(--display);
  letter-spacing: .025em;
  overflow-wrap: anywhere;
}

.reader-header form { margin: 0; }

.story-detail-close, .reader-close, .reader-step, .story-retry {
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: .45rem clamp(.55rem, 2vw, .95rem);
  border: 1px solid #9a6c54;
  background: #301e17;
  color: var(--paper);
  font: 700 .94rem/1.15 var(--text);
  cursor: pointer;
}

.story-detail-close, .reader-close {
  width: 2.75rem;
  padding: 0;
  font-size: 1.6rem;
  line-height: 1;
}

.story-detail-close:hover,
.reader-close:hover,
.reader-step:enabled:hover,
.story-retry:hover {
  border-color: var(--amber);
  background: var(--amber);
  color: #21150f;
}

.reader-step:disabled { opacity: .44; cursor: default; }

.reader-stage {
  --book-padding: clamp(.55rem, 2.35vw, 1.3rem);
  position: relative;
  display: grid;
  justify-items: center;
  min-height: 0;
  padding: var(--book-padding);
  background:
    radial-gradient(ellipse at center, #64423466, transparent 76%),
    repeating-linear-gradient(130deg, #dba57e08 0 1px, transparent 1px 6px),
    #100a09;
  perspective: 80rem;
  touch-action: pan-y pinch-zoom;
}

.reader-book {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  max-width: 38rem;
  height: min(71dvh, 60rem);
  min-height: 10rem;
  box-shadow: 0 .5rem 1.3rem #0009;
}

.reader-book.is-spread {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-width: none;
}

.reader-book.is-spread::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0 auto 0 calc(50% - .8rem);
  width: 1.6rem;
  background: linear-gradient(90deg, transparent, #170d0880 50%, #1c10074a 51%, transparent);
  pointer-events: none;
}

.reader-leaf {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #a78569;
  background: #e7d0ae;
  color: #301e15;
}

.reader-leaf img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.reader-leaf-note {
  padding: .75rem;
  color: #482a1d;
  font-size: .9rem;
  text-align: center;
}

.reader-blank-leaf {
  background:
    radial-gradient(ellipse at 70% 40%, #f0dfc4, transparent),
    #dec4a2;
}

.reader-turn {
  position: absolute;
  z-index: 2;
  inset: var(--book-padding);
  width: calc(100% - 2 * var(--book-padding));
  max-width: 38rem;
  margin-inline: auto;
  perspective: 74rem;
  pointer-events: none;
}

.reader-turn.is-spread { max-width: none; }

.reader-turn-sheet {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #e7d0ae;
  box-shadow: 0 0 1.75rem #140a08a6;
  pointer-events: none;
  backface-visibility: hidden;
}

.reader-turn.is-spread .reader-turn-sheet {
  left: auto;
  width: 50%;
}

.reader-turn.is-spread .reader-turn-sheet.is-previous {
  right: auto;
  left: 0;
}

.reader-turn-sheet::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #210e08b3, transparent 67%);
  opacity: .48;
}

.reader-turn-sheet.is-next {
  transform-origin: left center;
  animation: comic-flip-next .39s cubic-bezier(.5, .15, .55, 1) both;
}

.reader-turn-sheet.is-previous {
  transform-origin: right center;
  animation: comic-flip-previous .39s cubic-bezier(.5, .15, .55, 1) both;
}

.reader-turn-sheet .reader-leaf { width: 100%; height: 100%; }

@keyframes comic-flip-next {
  from { opacity: 1; transform: rotateY(0); }
  to { opacity: .4; transform: rotateY(-100deg); }
}

@keyframes comic-flip-previous {
  from { opacity: 1; transform: rotateY(0); }
  to { opacity: .4; transform: rotateY(100deg); }
}

.reader-controls {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(.65rem, 3vw, 1.6rem);
  padding: .75rem clamp(.8rem, 2.6vw, 1.5rem);
  border-top: 1px solid var(--rule);
}

.reader-position {
  color: var(--muted);
  font-size: .83rem;
  font-weight: 650;
  text-align: center;
}

.reader-position progress {
  display: block;
  appearance: none;
  width: min(100%, 14rem);
  height: .28rem;
  margin: .35rem auto 0;
  border: none;
  background: #604337;
  color: var(--amber);
}

.reader-position progress::-webkit-progress-bar { background: #604337; }
.reader-position progress::-webkit-progress-value { background: var(--amber); }
.reader-position progress::-moz-progress-bar { background: var(--amber); }

@media (max-width: 42rem) {
  .story-detail-layout {
    grid-template-columns: minmax(0, 1fr);
    padding-block-start: 1.35rem;
  }
  .story-detail-cover {
    justify-self: center;
    width: min(100%, 21rem);
    max-height: 39dvh;
  }
  .story-detail-copy h2 { padding-inline-end: 0; }
  .reader-book { height: min(67dvh, 48rem); }
}

@media (max-width: 30rem) {
  .story-section-heading { gap: .45rem; }
  .story-poster-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .story-card-heading { display: grid; gap: .2rem; }
  .story-card-heading h3 { font-size: 1.22rem; }
  .story-library-status { grid-template-columns: auto minmax(0, 1fr); }
  .story-retry { grid-column: 2; justify-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  .story-poster { transition: none; }
  .story-mode-track::after { transition: none; }
  .reader-turn-sheet { animation-duration: .001s; }
}
