.card-story {
  background:
    radial-gradient(circle at 79% 25%, rgba(255, 55, 96, .29), transparent 31%),
    radial-gradient(circle at 18% 95%, rgba(255, 190, 72, .13), transparent 34%),
    linear-gradient(145deg, #26080f, #09090d 72%);
}

.card-story .card-top > b {
  color: #ff496c;
}

.story-card-preview {
  position: absolute;
  z-index: 1;
  top: 73px;
  right: 28px;
  width: 194px;
  height: 148px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  padding: 13px;
  overflow: hidden;
  border: 1px solid rgba(255, 73, 108, .38);
  background:
    linear-gradient(rgba(255, 255, 255, .055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .055) 1px, transparent 1px),
    rgba(3, 4, 8, .63);
  background-size: 22px 22px;
  transform: skewX(-4deg);
  box-shadow: 8px 8px 0 rgba(255, 73, 108, .08);
}

.story-card-preview::before {
  content: "";
  position: absolute;
  inset: auto 10px 10px;
  height: 2px;
  background: linear-gradient(90deg, transparent, #ff496c, transparent);
  box-shadow: 0 0 13px rgba(255, 73, 108, .62);
}

.story-card-preview i {
  position: relative;
  display: block;
  border: 1px solid rgba(255, 255, 255, .14);
  background: linear-gradient(180deg, rgba(255, 73, 108, .04), rgba(255, 73, 108, .18));
}

.story-card-preview i::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 17%;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ffbe48;
  transform: translateX(-50%);
  box-shadow: 0 0 15px rgba(255, 190, 72, .9);
}

.story-card-preview i:nth-of-type(1)::before,
.story-card-preview i:nth-of-type(3)::before {
  content: "×";
  position: absolute;
  left: 50%;
  top: 22%;
  color: #ff496c;
  font: 950 27px/1 monospace;
  transform: translateX(-50%);
}

.story-card-preview > b {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 45%;
  font-size: 42px;
  filter: drop-shadow(0 0 13px rgba(255, 190, 72, .48));
  transform: translate(-50%, -50%);
}

.story-card-preview > span {
  position: absolute;
  z-index: 2;
  right: 8px;
  top: 8px;
  padding: 6px 7px;
  color: #19070b;
  background: #ffbe48;
  font: 950 8px/1 monospace;
  letter-spacing: .08em;
}

.story-panel {
  --story-red: #ff315d;
  --story-red-dark: #8c102e;
  --story-gold: #ffbe48;
  --story-ice: #6ee9ff;
  --story-ink: #07070b;
  color: #fff6f7;
  background: var(--story-ink);
}

.story-panel[hidden] {
  display: none;
}

.story-panel .story-hud,
.story-panel > .mini-hud {
  min-height: 72px;
  height: auto;
  padding: 10px 24px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  border-bottom: 1px solid rgba(255, 49, 93, .28);
  background:
    linear-gradient(90deg, rgba(255, 49, 93, .08), transparent 45%),
    #09090d;
}

.story-panel .story-hud > div,
.story-panel > .mini-hud > div {
  min-width: 0;
  text-align: center;
}

.story-panel .story-hud > div + div,
.story-panel > .mini-hud > div + div {
  border-left: 1px solid rgba(255, 255, 255, .09);
}

.story-panel .story-hud small,
.story-panel > .mini-hud small {
  color: #8f7c83;
  font: 850 7px/1 monospace;
  letter-spacing: .13em;
}

.story-panel .story-hud strong,
.story-panel > .mini-hud strong {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: var(--story-gold);
  font: 950 clamp(17px, 3.2vw, 26px)/1 monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#storyLives {
  color: var(--story-red);
  letter-spacing: .08em;
}

#storyCombo {
  color: var(--story-ice);
}

#storyRecord {
  color: #f8f2f3;
  font-size: clamp(13px, 2.4vw, 20px);
}

.story-stage {
  --story-time-left: 0%;
  position: relative;
  min-height: 630px;
  padding: 24px clamp(18px, 4vw, 42px) 25px;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: 11px;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 5%, rgba(255, 190, 72, .16), transparent 27%),
    radial-gradient(circle at 50% 72%, rgba(255, 49, 93, .13), transparent 42%),
    linear-gradient(180deg, #100b11 0 25%, #10070b 25% 100%);
  overscroll-behavior: contain;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.story-stage::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 24% -8% -13%;
  opacity: .8;
  background:
    linear-gradient(78deg, transparent 0 32.6%, rgba(255, 255, 255, .13) 32.8% 33.1%, transparent 33.3% 66.1%, rgba(255, 255, 255, .13) 66.3% 66.6%, transparent 66.8%),
    repeating-linear-gradient(0deg, transparent 0 58px, rgba(255, 255, 255, .045) 59px 60px),
    linear-gradient(180deg, rgba(255, 49, 93, .04), rgba(255, 49, 93, .12));
  clip-path: polygon(25% 0, 75% 0, 100% 100%, 0 100%);
}

.story-stage::after {
  content: "";
  position: absolute;
  z-index: 20;
  left: 0;
  bottom: 0;
  width: var(--story-time-left);
  height: 6px;
  background: linear-gradient(90deg, var(--story-red), var(--story-gold), var(--story-ice));
  box-shadow: 0 -3px 18px rgba(255, 49, 93, .48);
  transition: width .08s linear;
}

.story-stage[data-phase="correct"] {
  box-shadow: inset 0 0 70px rgba(70, 255, 178, .11);
}

.story-stage[data-phase="wrong"],
.story-stage[data-phase="lost"] {
  box-shadow: inset 0 0 90px rgba(255, 49, 93, .18);
}

.story-stage.has-shield {
  box-shadow: inset 0 0 0 2px rgba(110, 233, 255, .34), inset 0 0 55px rgba(110, 233, 255, .08);
}

.story-stage-copy,
.story-stage > .story-copy {
  position: relative;
  z-index: 3;
  min-height: 106px;
  text-align: center;
}

.story-scene-head {
  position: relative;
  z-index: 3;
  min-height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}

.story-scene-head > small {
  color: #806f75;
  font: 850 7px/1 monospace;
  letter-spacing: .13em;
}

#storyChapter {
  display: block;
  margin: 0;
  color: var(--story-red);
  font: 900 8px/1.2 monospace;
  letter-spacing: .17em;
  text-transform: uppercase;
}

#storyScene {
  position: relative;
  z-index: 3;
  width: min(100%, 650px);
  min-height: 35px;
  margin: 0 auto;
  color: #b9a9ae;
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

#storyPrompt {
  position: relative;
  z-index: 3;
  margin: 0;
  color: #fff;
  font-size: clamp(19px, 4vw, 31px);
  font-style: italic;
  font-weight: 950;
  line-height: 1;
  letter-spacing: -.025em;
  text-align: center;
}

.story-lanes {
  position: relative;
  z-index: 3;
  min-height: 315px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(7px, 1.7vw, 14px);
  align-items: stretch;
  perspective: 900px;
}

.story-lanes::before {
  content: "⚽";
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: 14px;
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border: 4px solid rgba(255, 190, 72, .46);
  border-radius: 50%;
  background: rgba(5, 5, 9, .9);
  font-size: 43px;
  line-height: 1;
  filter: drop-shadow(0 13px 8px rgba(0, 0, 0, .5));
  transform: translateX(-50%);
  transition: left .2s cubic-bezier(.2, .85, .25, 1), transform .2s ease;
  pointer-events: none;
}

.story-stage[data-player-lane="0"] .story-lanes::before {
  left: 16.666%;
}

.story-stage[data-player-lane="1"] .story-lanes::before {
  left: 50%;
}

.story-stage[data-player-lane="2"] .story-lanes::before {
  left: 83.333%;
}

.story-lanes button {
  position: relative;
  min-width: 0;
  min-height: 240px;
  padding: 23px 8px 86px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 11px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .14);
  color: #ad9ba1;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .03), rgba(255, 49, 93, .07)),
    rgba(5, 5, 9, .47);
  cursor: pointer;
  transform: rotateX(2deg);
  transform-origin: bottom;
  transition: border-color .15s ease, color .15s ease, background .15s ease, transform .15s ease, box-shadow .15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.story-lanes button::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .5;
  background:
    repeating-linear-gradient(0deg, transparent 0 40px, rgba(255, 255, 255, .05) 41px 42px);
  pointer-events: none;
}

.story-lanes button::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 1px;
  height: 75%;
  background: linear-gradient(transparent, rgba(255, 255, 255, .13));
  pointer-events: none;
}

.story-lanes button:not(:disabled):hover {
  border-color: var(--story-gold);
  color: #fff;
  background: rgba(255, 190, 72, .09);
  transform: translateY(-3px);
}

.story-lanes button:disabled {
  cursor: default;
}

.story-lanes button:focus-visible,
.story-cover button:focus-visible {
  outline: 3px solid #fff;
  outline-offset: -5px;
}

.story-lane-number {
  position: relative;
  z-index: 2;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid currentColor;
  font: 950 10px/1 monospace;
}

.story-lane-icon {
  position: relative;
  z-index: 2;
  min-height: 76px;
  display: grid;
  place-items: center;
  color: inherit;
  font: 950 clamp(42px, 8vw, 69px)/1 monospace;
  filter: drop-shadow(0 0 14px currentColor);
}

.story-lane-label {
  position: relative;
  z-index: 2;
  font: 900 8px/1 monospace;
  letter-spacing: .12em;
}

.story-lanes button.is-blocked {
  color: var(--story-red);
  border-color: rgba(255, 49, 93, .56);
  background: rgba(140, 16, 46, .19);
}

.story-lanes button.is-blocked .story-lane-icon {
  animation: story-danger-pulse .58s ease-in-out infinite alternate;
}

.story-lanes button.is-cue {
  color: var(--story-ice);
  border-color: rgba(110, 233, 255, .78);
  background: rgba(110, 233, 255, .15);
  box-shadow: inset 0 0 35px rgba(110, 233, 255, .14), 0 0 25px rgba(110, 233, 255, .11);
  animation: story-memory-flash .52s ease-in-out infinite alternate;
}

.story-lanes button.is-keeper {
  color: var(--story-gold);
  border-color: rgba(255, 190, 72, .62);
  background: rgba(255, 190, 72, .11);
}

.story-lanes button.is-selected {
  transform: translateY(-6px) scale(1.015);
}

.story-lanes button.is-safe {
  border-color: rgba(72, 255, 177, .65);
  color: #48ffb1;
  background: rgba(72, 255, 177, .1);
}

.story-lanes button.is-correct {
  border-color: #48ffb1;
  color: #04150e;
  background: #48ffb1;
  box-shadow: 0 0 31px rgba(72, 255, 177, .31);
}

.story-lanes button.is-wrong {
  border-color: var(--story-red);
  color: #fff;
  background: var(--story-red-dark);
  box-shadow: 0 0 31px rgba(255, 49, 93, .29);
}

.story-feedback {
  position: relative;
  z-index: 4;
  min-height: 48px;
  margin: 0;
  padding: 13px 16px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .12);
  color: #b9a9ae;
  background: rgba(6, 6, 10, .76);
  text-align: center;
  font: 900 9px/1.35 monospace;
  letter-spacing: .11em;
}

.story-feedback.is-correct {
  border-color: rgba(72, 255, 177, .43);
  color: #48ffb1;
}

.story-feedback.is-wrong {
  border-color: rgba(255, 49, 93, .47);
  color: #ff6a89;
}

.story-feedback.is-shield {
  border-color: rgba(110, 233, 255, .48);
  color: var(--story-ice);
}

.story-cover[hidden],
.story-cover.is-hidden {
  display: none;
}

.story-cover {
  position: absolute;
  z-index: 30;
  inset: 0;
  padding: clamp(22px, 5vw, 49px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: auto;
  color: #fff;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 49, 93, .22), transparent 31%),
    rgba(5, 5, 9, .94);
  backdrop-filter: blur(10px);
  text-align: center;
}

.story-cover::before {
  content: "STORY MODE";
  margin-bottom: 12px;
  color: var(--story-red);
  font: 950 8px/1 monospace;
  letter-spacing: .2em;
}

.story-cover h3,
#storyCoverTitle {
  max-width: 660px;
  margin: 0;
  color: #fff;
  font-size: clamp(36px, 7vw, 66px);
  font-style: italic;
  line-height: .86;
  letter-spacing: -.045em;
}

.story-cover > p,
#storyCoverText {
  max-width: 610px;
  margin: 18px auto 23px;
  color: #baaab0;
  font-size: 13px;
  line-height: 1.55;
}

#storyRules {
  width: min(100%, 650px);
  margin: 0 0 22px;
}

#storyRules[hidden] {
  display: none;
}

#storyRules ol,
#storyRules ul {
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  list-style: none;
}

#storyRules li {
  min-height: 112px;
  padding: 15px 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, .13);
  color: #c7b9bd;
  background: rgba(255, 255, 255, .035);
  font-size: 10px;
  line-height: 1.38;
}

#storyRules li > div {
  min-width: 0;
}

#storyRules li strong {
  display: block;
  margin-bottom: 5px;
  color: #fff;
  font: 900 8px/1.2 monospace;
  letter-spacing: .06em;
}

#storyRules li p {
  margin: 0;
  color: #a9989e;
  font-size: 8px;
  line-height: 1.35;
}

.story-rule-summary {
  margin: 9px 0 0;
  color: #89787e;
  font: 850 7px/1.4 monospace;
  letter-spacing: .08em;
}

.story-rule-summary i {
  color: var(--story-red);
  font-style: normal;
}

#storyRules li > i,
#storyRules li > span:first-child,
#storyRules li > b:first-child {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border: 1px solid var(--story-red);
  color: var(--story-red);
  font: 950 10px/1 monospace;
}

.story-cover button {
  width: min(100%, 650px);
  min-height: 58px;
  padding: 13px 20px;
  border: 0;
  color: #18070b;
  background: linear-gradient(90deg, var(--story-red), var(--story-gold));
  cursor: pointer;
  font: 950 10px/1.25 monospace;
  letter-spacing: .1em;
  box-shadow: 8px 8px 0 rgba(255, 49, 93, .11);
  transition: filter .16s ease, transform .16s ease;
  touch-action: manipulation;
}

.story-cover button:hover:not(:disabled) {
  filter: brightness(1.12);
  transform: translateY(-2px);
}

.story-cover button:disabled {
  color: #8c7c81;
  background: rgba(255, 255, 255, .08);
  cursor: wait;
  box-shadow: none;
}

#discardStorySave {
  min-height: 42px;
  margin-top: 12px;
  color: #95858a;
  border: 1px solid rgba(255, 255, 255, .13);
  background: transparent;
  box-shadow: none;
}

#discardStorySave[hidden] {
  display: none;
}

@keyframes story-danger-pulse {
  from {
    opacity: .64;
    transform: scale(.92);
  }
  to {
    opacity: 1;
    transform: scale(1.06);
  }
}

@keyframes story-memory-flash {
  from {
    box-shadow: inset 0 0 18px rgba(110, 233, 255, .08);
  }
  to {
    box-shadow: inset 0 0 48px rgba(110, 233, 255, .24), 0 0 30px rgba(110, 233, 255, .18);
  }
}

@media (max-width: 680px) {
  .story-card-preview {
    right: 20px;
    width: 168px;
    height: 130px;
  }

  .game-modal[data-active-game="story"] {
    padding: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .game-modal[data-active-game="story"] .modal-window {
    width: 100%;
    height: 100dvh;
    max-height: none;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
    border: 0;
    box-shadow: none;
  }

  .game-panel[data-game-panel="story"]:not([hidden]) {
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
  }

  .story-panel .story-hud,
  .story-panel > .mini-hud {
    min-height: 57px;
    padding: 7px 10px;
    gap: 3px;
  }

  .story-panel .story-hud small,
  .story-panel > .mini-hud small {
    font-size: 6px;
    letter-spacing: .08em;
  }

  .story-panel .story-hud strong,
  .story-panel > .mini-hud strong {
    margin-top: 4px;
    font-size: clamp(14px, 4.6vw, 20px);
  }

  #storyRecord {
    font-size: clamp(10px, 3.4vw, 15px);
  }

  .story-stage {
    height: auto;
    min-height: 0;
    padding:
      clamp(12px, 2dvh, 19px)
      10px
      calc(12px + env(safe-area-inset-bottom));
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    gap: clamp(8px, 1.5dvh, 13px);
  }

  .story-stage-copy,
  .story-stage > .story-copy {
    min-height: 84px;
  }

  .story-scene-head {
    min-height: 16px;
  }

  #storyChapter {
    margin-bottom: 5px;
    font-size: 6px;
  }

  #storyScene {
    min-height: 32px;
    margin-bottom: 6px;
    font-size: clamp(9px, 2.6vw, 11px);
    line-height: 1.35;
  }

  #storyPrompt {
    font-size: clamp(17px, 5vw, 24px);
  }

  .story-lanes {
    min-height: 0;
    gap: 6px;
  }

  .story-lanes::before {
    bottom: 9px;
    width: clamp(48px, 15vw, 61px);
    height: clamp(48px, 15vw, 61px);
    border-width: 3px;
    font-size: clamp(33px, 10.5vw, 43px);
  }

  .story-lanes button {
    min-height: 0;
    padding: clamp(11px, 2dvh, 18px) 4px 73px;
    gap: 7px;
  }

  .story-lane-number {
    width: 26px;
    height: 26px;
    font-size: 8px;
  }

  .story-lane-icon {
    min-height: 48px;
    font-size: clamp(34px, 12vw, 56px);
  }

  .story-lane-label {
    font-size: 6px;
    letter-spacing: .07em;
  }

  .story-feedback {
    min-height: 40px;
    padding: 9px 10px;
    font-size: 7px;
  }

  .story-cover {
    justify-content: safe center;
    padding:
      22px
      15px
      calc(22px + env(safe-area-inset-bottom));
  }

  .story-cover h3,
  #storyCoverTitle {
    font-size: clamp(34px, 11vw, 55px);
  }

  .story-cover > p,
  #storyCoverText {
    margin: 14px auto 17px;
    font-size: 11px;
  }

  #storyRules ol,
  #storyRules ul {
    gap: 5px;
  }

  #storyRules li {
    min-height: 98px;
    padding: 11px 6px;
    font-size: 8px;
  }

  .story-cover button {
    min-height: 54px;
  }
}

@media (max-height: 620px) and (pointer: coarse) {
  .game-modal[data-active-game="story"] .modal-head {
    min-height: 52px;
    padding: 6px 12px 6px 16px;
  }

  .game-modal[data-active-game="story"] .modal-head small {
    display: none;
  }

  .game-modal[data-active-game="story"] .modal-head h2 {
    margin: 0;
    font-size: 19px;
  }

  .game-modal[data-active-game="story"] .modal-close {
    width: 39px;
    height: 39px;
  }

  .story-panel .story-hud,
  .story-panel > .mini-hud {
    min-height: 47px;
    padding: 5px 9px;
  }

  .story-stage {
    gap: 5px;
    padding: 6px 9px calc(7px + env(safe-area-inset-bottom));
  }

  .story-stage-copy,
  .story-stage > .story-copy {
    min-height: 62px;
  }

  .story-scene-head {
    min-height: 14px;
  }

  #storyScene {
    min-height: 24px;
    margin-bottom: 4px;
    font-size: 8px;
  }

  #storyPrompt {
    font-size: 17px;
  }

  .story-lanes button {
    padding-top: 8px;
    padding-bottom: 54px;
  }

  .story-lane-icon {
    min-height: 34px;
    font-size: 32px;
  }

  .story-lanes::before {
    width: 43px;
    height: 43px;
    font-size: 31px;
  }

  .story-feedback {
    min-height: 31px;
    padding: 6px 8px;
  }

  .story-cover {
    padding: 13px;
  }

  .story-cover::before {
    margin-bottom: 7px;
  }

  .story-cover h3,
  #storyCoverTitle {
    font-size: 31px;
  }

  .story-cover > p,
  #storyCoverText {
    margin: 8px auto 10px;
    font-size: 9px;
  }

  #storyRules {
    margin-bottom: 9px;
  }

  #storyRules li {
    min-height: 66px;
    padding: 7px 5px;
    font-size: 7px;
  }

  #storyRules li > i,
  #storyRules li > span:first-child,
  #storyRules li > b:first-child {
    width: 20px;
    height: 20px;
    font-size: 8px;
  }

  .story-cover button {
    min-height: 43px;
    padding: 8px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .story-card-preview i::after,
  .story-lanes button,
  .story-lanes::before,
  .story-lanes button.is-blocked .story-lane-icon,
  .story-lanes button.is-cue,
  .story-stage::after,
  .story-cover button {
    animation: none !important;
    transition: none !important;
  }
}
