.story-header-tools {
  grid-template-columns: minmax(190px, 230px) auto;
}
.story-utilities {
  flex-wrap: wrap;
  justify-content: flex-end;
}
.story-button {
  border-color: color-mix(in srgb, var(--accent), transparent 45%);
  color: var(--text);
}
.story-panel {
  --story-duration: 5200ms;
  position: relative;
  min-width: 0;
  overflow: hidden;
  padding: clamp(13px, 1.35vw, 26px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--surface);
  background-image: var(--panel-pattern);
  box-shadow: 0 12px 36px var(--shadow);
  outline: none;
  transition: border-color 0.5s, background-color 0.5s, box-shadow 0.5s;
}
.story-panel:focus-visible {
  border-color: var(--accent);
}
.story-panel.attention {
  border-color: var(--accent);
  box-shadow: 0 12px 42px var(--shadow), 0 0 0 1px color-mix(in srgb, var(--accent), transparent 45%);
}
.story-accent {
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--danger), transparent 74%);
  opacity: 0.75;
}
.story-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding: 1px 2px 15px;
  border-bottom: 1px solid var(--border);
}
.story-heading-copy {
  min-width: 0;
}
.story-heading-copy h2 {
  margin: 0;
  color: var(--text);
  font-size: clamp(17px, 1.3vw, 24px);
  line-height: 1;
}
.story-heading-copy p {
  margin: 7px 0 0;
  color: var(--quiet);
  font-size: 8px;
}
.story-controls {
  display: grid;
  grid-template-columns: 34px minmax(64px, auto) 34px;
  gap: 5px;
}
.story-control {
  min-height: 34px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  cursor: pointer;
  transition: color 0.5s, border-color 0.5s, background-color 0.5s, transform 0.5s, box-shadow 0.5s;
}
.story-control:hover,
.story-control:focus-visible {
  border-color: var(--accent);
  color: var(--text);
  transform: translateY(-2px);
  box-shadow: 0 6px 17px var(--shadow);
}
.story-control.play {
  color: var(--accent);
  font-size: 8px;
  letter-spacing: 0.07em;
}
.story-control[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent), var(--surface-2) 86%);
  color: var(--text);
}
.story-chapters {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  margin: 0 -2px;
  padding: 12px 2px 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
  scroll-snap-type: x proximity;
}
.story-chapter {
  flex: 0 0 auto;
  min-width: 84px;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface-2);
  color: var(--quiet);
  font-size: 7px;
  font-weight: 850;
  letter-spacing: 0.025em;
  scroll-snap-align: center;
  cursor: pointer;
  transition: color 0.5s, border-color 0.5s, background-color 0.5s, transform 0.5s;
}
.story-chapter:hover,
.story-chapter:focus-visible {
  color: var(--text);
  transform: translateY(-2px);
}
.story-chapter.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent), transparent 89%);
  color: var(--text);
  box-shadow: inset 0 -2px var(--accent);
}
.story-stage {
  min-width: 0;
  padding: clamp(12px, 1.1vw, 20px);
  border: 1px solid var(--border);
  border-radius: 3px;
  background: color-mix(in srgb, var(--surface-2), transparent 18%);
}
.story-stage-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}
.story-stage-head h3 {
  margin: 4px 0 0;
  color: var(--text);
  font-size: clamp(22px, 2.1vw, 36px);
  letter-spacing: -0.04em;
  line-height: 0.9;
}
.story-kicker,
.story-position {
  font-size: 7px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.story-kicker {
  color: var(--accent);
}
.story-position {
  color: var(--quiet);
}
.story-copy {
  display: grid;
  grid-template-columns: minmax(180px, 0.7fr) minmax(280px, 1.3fr);
  gap: 18px;
  align-items: baseline;
  min-height: 52px;
  padding: 12px 0 10px;
}
.story-copy strong {
  color: var(--text);
  font-size: 12px;
}
.story-copy p {
  margin: 0;
  color: var(--quiet);
  font-size: 9px;
  line-height: 1.5;
}
.story-rail-wrap {
  padding: 10px 10px 4px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
}
.story-rail-labels {
  display: flex;
  justify-content: space-between;
  color: var(--quiet);
  font-size: 6px;
  font-weight: 900;
  letter-spacing: 0.09em;
}
.story-rail {
  position: relative;
  height: 74px;
  margin: 0 17px;
}
.story-rail::before {
  content: '';
  position: absolute;
  inset: 35px 0 auto;
  height: 1px;
  background: linear-gradient(90deg, var(--quiet), var(--border) 50%, var(--accent));
  opacity: 0.8;
}
.story-rail::after {
  content: '';
  position: absolute;
  top: 29px;
  left: 50%;
  width: 1px;
  height: 13px;
  background: var(--quiet);
  opacity: 0.45;
}
.story-marker-group {
  position: absolute;
  z-index: 2;
  top: calc(13px + var(--story-lane-offset, 0px));
  left: var(--story-position);
  display: grid;
  justify-items: center;
  width: 42px;
  transform: translateX(-50%);
  transition: left 0.5s ease-out, opacity 0.5s, transform 0.5s;
}
.story-marker-group::before {
  content: '';
  position: absolute;
  z-index: -1;
  top: var(--story-connector-top, 0px);
  left: 50%;
  width: 1px;
  height: var(--story-connector-height, 2px);
  background: var(--ring-color, var(--quiet));
  opacity: 0.28;
}
.story-marker-group:hover,
.story-marker-group:focus-within {
  z-index: 5;
  transform: translateX(-50%) scale(1.08);
}
.story-rings {
  position: relative;
  width: 42px;
  height: 42px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.story-ring {
  position: absolute;
  inset: 50% auto auto 50%;
  width: var(--ring-size);
  height: var(--ring-size);
  border: 2px solid var(--ring-color);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 0 10px color-mix(in srgb, var(--ring-color), transparent 58%);
  transform: translate(-50%, -50%);
}
.story-ring.core {
  background: var(--ring-color);
}
.story-group-count {
  margin-top: 2px;
  padding: 1px 4px;
  border-radius: 1px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 6px;
  font-weight: 900;
}
.story-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 7px;
  padding-top: 10px;
}
.story-card {
  --car-color: var(--accent);
  position: relative;
  min-width: 0;
  overflow: hidden;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface);
  transition: opacity 0.5s, transform 0.5s, border-color 0.5s, background-color 0.5s, box-shadow 0.5s;
}
.story-card:hover,
.story-card:focus-within {
  z-index: 2;
  border-color: var(--car-color);
  transform: translateY(-4px);
  box-shadow: 0 10px 24px var(--shadow);
}
.story-card.reference {
  border-color: var(--car-color);
  background: color-mix(in srgb, var(--car-color), var(--surface) 95%);
  box-shadow: inset 0 -2px var(--car-color);
}
.story-card-image {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16/9;
  border-radius: 2px;
  background: var(--surface-3);
}
.story-card-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.9) contrast(1.04);
  transition: opacity 0.5s, transform 0.5s, filter 0.5s;
}
.story-card-image:hover img {
  transform: scale(1.035);
  filter: saturate(1.05) contrast(1.07);
}
.story-image-cycle {
  position: absolute;
  inset: auto 5px 5px auto;
  min-height: 24px;
  padding: 4px 7px;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 2px;
  background: rgba(0,0,0,0.66);
  color: #fff;
  font-size: 6px;
  font-weight: 900;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background-color 0.5s, transform 0.5s;
}
.story-image-cycle:hover,
.story-image-cycle:focus-visible {
  background: rgba(0,0,0,0.88);
  transform: translateY(-1px);
}
.story-card-rank {
  position: absolute;
  inset: 6px auto auto 6px;
  min-width: 24px;
  padding: 4px 6px;
  border-radius: 1px;
  background: rgba(0,0,0,0.76);
  color: #fff;
  font-size: 7px;
  font-weight: 950;
}
.story-card-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
  align-items: start;
  padding: 8px 2px 2px;
}
.story-car-name {
  min-width: 0;
}
.story-car-name strong,
.story-car-name small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.story-car-name strong {
  color: var(--car-color);
  font-size: 10px;
}
.story-car-name small {
  margin-top: 3px;
  color: var(--quiet);
  font-size: 7px;
}
.story-reading {
  text-align: right;
}
.story-reading strong,
.story-reading span,
.story-reading small {
  display: block;
}
.story-reading strong {
  color: var(--car-color);
  font-size: 12px;
  white-space: nowrap;
}
.story-reading span {
  margin-top: 3px;
  font-size: 8px;
  font-weight: 900;
}
.story-reading small {
  max-width: 105px;
  margin-top: 2px;
  color: var(--quiet);
  font-size: 6px;
  line-height: 1.25;
}
.story-pin {
  grid-column: 1/-1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 26px;
  margin-top: 3px;
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface-2);
  color: var(--quiet);
  font-size: 6px;
  font-weight: 900;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: color 0.5s, border-color 0.5s, background-color 0.5s;
}
.story-pin:hover,
.story-pin:focus-visible,
.story-pin[aria-pressed="true"] {
  border-color: var(--car-color);
  color: var(--text);
}
.story-pin[aria-pressed="true"] {
  background: color-mix(in srgb, var(--car-color), transparent 90%);
}
.story-panel.is-changing .story-stage-head,
.story-panel.is-changing .story-copy,
.story-panel.is-changing .story-cards {
  opacity: 0.42;
  transform: translateY(3px);
}
.story-stage-head,
.story-copy,
.story-cards {
  transition: opacity 0.5s, transform 0.5s;
}
.story-progress {
  height: 3px;
  overflow: hidden;
  margin-top: 9px;
  border-radius: 1px;
  background: var(--surface-3);
}
.story-progress span {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--danger));
  transform-origin: left;
  transform: scaleX(0);
}
.story-panel.playing .story-progress span {
  animation: story-progress var(--story-duration) linear infinite;
}
.story-panel.playing.paused .story-progress span {
  animation-play-state: paused;
}
.story-empty {
  grid-column: 1/-1;
  padding: 28px;
  border: 1px dashed var(--border);
  color: var(--quiet);
  font-size: 9px;
  text-align: center;
}
body.chart-focus .story-panel {
  display: none;
}
html[data-theme="retro-terminal"] .story-image-cycle,
html[data-theme="retro-terminal"] .story-card-rank {
  border-radius: 0;
}
html[data-theme="vaporwave-1996"] .story-panel {
  box-shadow: 9px 9px 0 rgba(246,1,157,0.08), -6px -6px 0 rgba(45,226,230,0.05);
}
html[data-theme="vaporwave-1996"] .story-accent {
  box-shadow: 0 0 14px var(--accent);
}
html[data-theme="manga-ink"] .story-panel,
html[data-theme="manga-ink"] .story-stage {
  border-width: 2px;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.12);
  background-size: 6px 6px;
}
html[data-theme="manga-ink"] .story-card-rank {
  background: var(--text);
}
html[data-theme="grand-tourer"] .story-stage {
  box-shadow: inset 0 1px rgba(255,255,255,0.035);
}
@media (min-width: 2300px) {
  .story-header-tools {
    grid-template-columns: 290px auto;
  }
  .story-chapter {
    min-width: 112px;
    min-height: 36px;
    font-size: 8px;
  }
  .story-stage {
    padding: 24px;
  }
  .story-rail {
    height: 92px;
  }
  .story-rail::before {
    top: 44px;
  }
  .story-rail::after {
    top: 37px;
  }
  .story-marker-group {
    top: calc(22px + var(--story-lane-offset, 0px));
  }
  .story-marker-group::before {
    top: var(--story-connector-top, 0px);
    height: var(--story-connector-height, 2px);
  }
  .story-cards {
    grid-template-columns: repeat(auto-fit, minmax(255px, 1fr));
    gap: 10px;
  }
  .story-card {
    padding: 9px;
  }
  .story-car-name strong {
    font-size: 12px;
  }
  .story-reading strong {
    font-size: 14px;
  }
}
@media (max-width: 900px) {
  .story-copy {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .story-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 620px) {
  .story-utilities {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .story-utilities .story-button {
    grid-column: 1/-1;
  }
  .story-heading {
    display: grid;
    align-items: start;
    gap: 12px;
  }
  .story-controls {
    width: 100%;
    grid-template-columns: 42px minmax(0, 1fr) 42px;
  }
  .story-chapter {
    min-width: 78px;
  }
  .story-stage {
    padding: 9px;
  }
  .story-stage-head h3 {
    font-size: 24px;
  }
  .story-copy {
    min-height: 72px;
  }
  .story-rail-wrap {
    padding-inline: 6px;
  }
  .story-rail {
    margin-inline: 12px;
  }
  .story-cards {
    grid-template-columns: 1fr;
  }
  .story-card {
    display: grid;
    grid-template-columns: 118px minmax(0, 1fr);
    min-height: 122px;
  }
  .story-card-image {
    aspect-ratio: auto;
    min-height: 104px;
  }
  .story-card-body {
    grid-template-columns: minmax(0, 1fr) auto;
    align-content: center;
    padding: 5px 3px 3px 8px;
  }
  .story-reading small {
    max-width: 82px;
  }
  .story-pin {
    min-height: 29px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .story-panel.playing .story-progress span {
    animation: none;
  }
}
@-moz-keyframes story-progress {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}
@-webkit-keyframes story-progress {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}
@-o-keyframes story-progress {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}
@keyframes story-progress {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}
