:root {
  --story-charcoal: #11100f;
  --story-iron: #292725;
  --story-stone: #b7a58b;
  --story-parchment: #d8c4a2;
  --story-brown: #3a2c25;
  --story-plum: #7b304c;
  --story-slate: #5d7892;
  --story-viewport-height: 100svh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

.story-experience,
.story-experience *,
.story-experience *::before,
.story-experience *::after {
  box-sizing: border-box;
}

html:has(.story-experience) {
  background: #080706;
  scroll-behavior: auto;
}

body:has(.story-experience) {
  min-height: 100svh;
  overflow-x: clip;
  background:
    radial-gradient(circle at 50% 12%, rgba(93, 120, 146, 0.18), transparent 42%),
    #080706;
  overscroll-behavior-x: none;
}

.story-page {
  margin: 0;
  min-height: 100svh;
}

.story-page .night {
  opacity: 0.34;
}

.story-experience {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  min-height: 100svh;
  color: #f6efe3;
  background: #080706;
  touch-action: pan-y;
}

.story-shell {
  position: relative;
  width: min(100%, 430px);
  min-height: 100svh;
  margin-inline: auto;
  background: var(--story-charcoal);
  box-shadow: 0 0 64px rgba(0, 0, 0, 0.78);
  isolation: isolate;
}

.story-entry {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  min-height: 100svh;
  min-height: 100dvh;
  padding:
    max(28px, var(--safe-top))
    max(22px, var(--safe-right))
    max(32px, var(--safe-bottom))
    max(22px, var(--safe-left));
  color: #f6efe3;
  text-align: center;
  background:
    radial-gradient(circle at 50% 38%, rgba(183, 165, 139, 0.2), transparent 36%),
    linear-gradient(180deg, rgba(41, 39, 37, 0.62), rgba(17, 16, 15, 0.96)),
    var(--story-charcoal);
}

.story-entry[hidden],
.story-timeline[hidden],
.story-orientation[hidden] {
  display: none;
}

.story-entry__button,
.story-entry__restart {
  min-width: 168px;
  min-height: 52px;
  padding: 12px 24px;
  border: 1px solid rgba(216, 196, 162, 0.64);
  border-radius: 999px;
  color: #fffaf1;
  background: linear-gradient(150deg, rgba(123, 48, 76, 0.94), rgba(58, 44, 37, 0.94));
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.36), inset 0 1px rgba(255, 255, 255, 0.15);
  cursor: pointer;
  font: 700 0.96rem/1 "Courier New", Courier, monospace;
  letter-spacing: 0.04em;
}

.story-entry__restart {
  min-height: 48px;
  border-color: rgba(216, 196, 162, 0.34);
  background: rgba(17, 16, 15, 0.72);
}

.story-entry p {
  max-width: 25ch;
  color: rgba(246, 239, 227, 0.82);
  font: 0.9rem/1.5 Georgia, "Times New Roman", serif;
}

.story-mode-notice {
  font-family: "Courier New", Courier, monospace !important;
  font-size: 0.76rem !important;
  letter-spacing: 0.04em;
}

.story-timeline {
  position: relative;
  width: 100%;
  min-height: 100svh;
  background: var(--story-charcoal);
}

.story-stage {
  position: sticky;
  top: 0;
  z-index: 10;
  width: 100%;
  min-height: 100svh;
  height: var(--story-viewport-height, 100svh);
  max-height: 100dvh;
  overflow: hidden;
  color: #fffaf1;
  background: var(--story-charcoal);
  contain: layout paint style;
  touch-action: pan-y;
}

@supports (height: 100dvh) {
  .story-stage {
    height: min(var(--story-viewport-height, 100dvh), 100dvh);
  }
}

.story-visual,
.story-visual__layers,
.story-visual__frame,
.story-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.story-visual {
  z-index: 0;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 32%, rgba(183, 165, 139, 0.18), transparent 42%),
    var(--story-charcoal);
}

.story-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(8, 7, 6, 0.34) 0%, transparent 18%, transparent 54%, rgba(8, 7, 6, 0.62) 76%, #080706 100%),
    linear-gradient(90deg, rgba(8, 7, 6, 0.18), transparent 12%, transparent 88%, rgba(8, 7, 6, 0.18));
}

.story-visual__frame {
  opacity: 0;
  transition: opacity 260ms ease;
}

.story-visual__frame.is-visible {
  opacity: 1;
}

.story-visual__frame.is-leaving {
  opacity: 0;
}

.story-layer {
  display: block;
  object-fit: cover;
  object-position: var(--focal-x, 50%) var(--focal-y, 42%);
  transform-origin: var(--focal-x, 50%) var(--focal-y, 42%);
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.story-layer--poster {
  z-index: 0;
}

.story-layer--poster.story-layer--fallback {
  opacity: 0;
}

.story-layer--depth {
  z-index: calc(2 + var(--layer-index, 0));
}

.story-hud {
  position: absolute;
  z-index: 30;
  top: max(14px, calc(var(--safe-top) + 8px));
  right: max(18px, calc(var(--safe-right) + 12px));
  left: max(18px, calc(var(--safe-left) + 12px));
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
  color: rgba(255, 250, 241, 0.82);
  font: 700 0.68rem/1.25 "Courier New", Courier, monospace;
  letter-spacing: 0.08em;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.88);
  text-transform: uppercase;
}

.story-text-panel {
  position: absolute;
  z-index: 40;
  right: max(18px, calc(var(--safe-right) + 14px));
  bottom: max(86px, calc(var(--safe-bottom) + 78px));
  left: max(18px, calc(var(--safe-left) + 14px));
  display: grid;
  align-content: end;
  gap: 10px;
  max-height: min(55%, calc(100% - 176px));
  padding: 14px 15px;
  overflow: hidden;
  border: 1px solid rgba(216, 196, 162, 0.32);
  border-radius: 13px;
  background: linear-gradient(155deg, rgba(17, 16, 15, 0.91), rgba(41, 39, 37, 0.88));
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.44), inset 0 1px rgba(255, 255, 255, 0.08);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}

.story-text {
  display: grid;
  gap: 5px;
  margin: 0;
  color: #fffaf1;
  font: clamp(16px, 2.15dvh, 18px)/1.44 Georgia, "Times New Roman", serif;
  text-wrap: pretty;
}

.story-text__content {
  white-space: pre-line;
}

.story-text__speaker {
  color: #e8cfc0;
  font: 700 0.72rem/1.2 "Courier New", Courier, monospace;
  letter-spacing: 0.1em;
}

.story-text--title {
  color: #fffaf1;
  font: 700 clamp(19px, 2.8dvh, 26px)/1.16 "Courier New", Courier, monospace;
  text-align: center;
  text-wrap: balance;
}

.story-text--subtitle,
.story-text--quoted-thought {
  color: #efe1cf;
  font-style: italic;
}

.story-text--dialogue {
  padding-left: 11px;
  border-left: 2px solid rgba(123, 48, 76, 0.82);
}

.story-text--disclaimer {
  border-color: rgba(216, 196, 162, 0.52);
  color: #fff3dc;
  font-family: "Courier New", Courier, monospace;
  font-size: clamp(14px, 1.85dvh, 16px);
}

.story-controls {
  position: absolute;
  z-index: 50;
  right: max(12px, calc(var(--safe-right) + 8px));
  bottom: max(10px, var(--safe-bottom));
  left: max(12px, calc(var(--safe-left) + 8px));
  display: grid;
  gap: 7px;
  min-height: 64px;
  padding: 7px;
  border: 1px solid rgba(216, 196, 162, 0.24);
  border-radius: 14px;
  background: rgba(17, 16, 15, 0.92);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.46);
}

.story-progress {
  width: 100%;
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

.story-progress__value {
  display: block;
  width: var(--story-progress, 0%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--story-plum), var(--story-stone), var(--story-slate));
  transition: width 80ms linear;
}

.story-controls__actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.story-control {
  min-width: 0;
  min-height: 48px;
  padding: 7px 3px;
  border: 1px solid rgba(216, 196, 162, 0.3);
  border-radius: 9px;
  color: #fffaf1;
  background: rgba(58, 44, 37, 0.74);
  cursor: pointer;
  font: 700 clamp(0.64rem, 2.9vw, 0.78rem)/1.15 "Courier New", Courier, monospace;
}

.story-control:disabled {
  opacity: 0.38;
  cursor: default;
}

.story-control:focus-visible,
.story-entry__button:focus-visible,
.story-entry__restart:focus-visible {
  outline: 3px solid #91e9ff;
  outline-offset: 2px;
}

.story-track {
  position: relative;
  z-index: 0;
  width: 1px;
  margin-inline: auto;
  pointer-events: none;
}

.story-beat {
  width: 1px;
  min-height: var(--beat-scroll, 120svh);
}

.story-beat:last-child {
  min-height: max(var(--beat-scroll, 120svh), 100svh);
}

.story-transcript,
.story-skip-dialog {
  width: min(calc(100% - 24px), 430px);
  max-height: calc(100dvh - max(24px, var(--safe-top)) - max(24px, var(--safe-bottom)));
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(216, 196, 162, 0.4);
  border-radius: 15px;
  color: #fffaf1;
  background: #171513;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.72);
}

.story-transcript::backdrop,
.story-skip-dialog::backdrop {
  background: rgba(0, 0, 0, 0.76);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.story-transcript[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.story-transcript__chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, var(--safe-top)) 12px 10px;
  border-bottom: 1px solid rgba(216, 196, 162, 0.24);
  font: 700 0.82rem/1.2 "Courier New", Courier, monospace;
  text-transform: uppercase;
}

.story-transcript__close {
  min-width: 108px;
}

.story-transcript__content {
  overflow: auto;
  overscroll-behavior: contain;
  padding: 22px 20px;
  -webkit-overflow-scrolling: touch;
}

.story-transcript__scene {
  display: grid;
  gap: 15px;
  padding-block: 12px 34px;
}

.story-transcript__item {
  display: grid;
  gap: 5px;
  margin: 0;
  color: #f6efe3;
  font: 1rem/1.55 Georgia, "Times New Roman", serif;
  white-space: pre-line;
}

h2.story-transcript__item {
  color: #fffaf1;
  font: 700 1.34rem/1.25 "Courier New", Courier, monospace;
}

h3.story-transcript__item {
  font-style: italic;
  font-weight: 400;
}

.story-transcript__item--dialogue {
  padding-left: 13px;
  border-left: 2px solid var(--story-plum);
}

.story-transcript__item--disclaimer {
  padding: 14px;
  border: 1px solid rgba(216, 196, 162, 0.38);
  border-radius: 9px;
  background: rgba(58, 44, 37, 0.52);
  font-family: "Courier New", Courier, monospace;
  font-size: 0.9rem;
}

.story-transcript__speaker {
  color: #e8cfc0;
  font: 700 0.74rem/1.2 "Courier New", Courier, monospace;
  letter-spacing: 0.1em;
}

.story-transcript__return {
  margin: 10px max(12px, var(--safe-right)) max(12px, var(--safe-bottom)) max(12px, var(--safe-left));
}

.story-skip-dialog[open] {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.story-skip-dialog p {
  font: 1.05rem/1.45 Georgia, "Times New Roman", serif;
  text-align: center;
}

.story-skip-dialog__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.story-orientation {
  position: fixed;
  z-index: 100;
  inset: 0;
  width: min(100%, 430px);
  min-height: 100svh;
  margin-inline: auto;
  padding:
    max(20px, var(--safe-top))
    max(20px, var(--safe-right))
    max(20px, var(--safe-bottom))
    max(20px, var(--safe-left));
  color: #fffaf1;
  background: rgba(8, 7, 6, 0.96);
}

.story-orientation:not([hidden]) {
  display: grid;
  place-content: center;
  gap: 18px;
}

.story-orientation p {
  max-width: 32ch;
  font: 1rem/1.45 Georgia, "Times New Roman", serif;
  text-align: center;
}

.story-orientation__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.story-orientation__actions .story-control {
  min-width: 132px;
}

.story-shell[data-mode="reduced"] .story-visual__frame,
.story-shell[data-mode="light"] .story-visual__frame,
.story-shell[data-mode="reduced"] .story-progress__value {
  transition-duration: 100ms;
}

.story-shell[data-mode="reduced"] .story-layer,
.story-shell[data-mode="light"] .story-layer {
  transform: none !important;
  will-change: auto !important;
}

@media (min-height: 720px) and (min-aspect-ratio: 9 / 19) {
  .story-text-panel {
    bottom: max(90px, calc(var(--safe-bottom) + 82px));
    max-height: min(44%, calc(100% - 198px));
    padding: 16px 17px;
  }

  .story-text {
    line-height: 1.5;
  }
}

@media (max-width: 340px) {
  .story-text-panel {
    right: max(12px, calc(var(--safe-right) + 10px));
    left: max(12px, calc(var(--safe-left) + 10px));
    padding: 12px;
  }

  .story-controls {
    right: max(8px, calc(var(--safe-right) + 5px));
    left: max(8px, calc(var(--safe-left) + 5px));
  }

  .story-control {
    padding-inline: 3px;
    font-size: 0.62rem;
  }
}

@media (orientation: landscape) {
  .story-shell--landscape-continue .story-stage {
    width: min(100%, 430px);
    min-height: 100svh;
    margin-inline: auto;
  }

  .story-shell--landscape-continue .story-text-panel {
    max-height: 54%;
  }

  .story-shell--landscape-continue .story-visual__frame {
    transition-duration: 100ms;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }

  .story-visual__frame,
  .story-progress__value {
    transition-duration: 100ms !important;
  }
}

@media (forced-colors: active) {
  .story-text-panel,
  .story-controls,
  .story-transcript,
  .story-skip-dialog {
    border: 2px solid CanvasText;
  }
}
