:root {
  color-scheme: light;
  font-family: system-ui, sans-serif;
  color: #261a34;
  background: #f2ecf8;
  --ink: #261a34;
  --ink-soft: #61546e;
  --accent: #901b51;
  --line: #c9b9d6;
  --paper: #fffbff;
}

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

[hidden] {
  display: none !important;
}

body {
  margin: 0;
}

.story {
  width: min(100%, 520px);
  margin-inline: auto;
  padding: 12px 16px 0;
  overflow-anchor: none;
}

.story-header {
  margin-bottom: 15px;
}

.cover-image {
  display: block;
  width: 100%;
  height: clamp(200px, 59vw, 240px);
  object-fit: cover;
  object-position: center 42%;
  border: 1px solid var(--ink);
  border-radius: 13px 13px 5px 5px;
  background: #e0d3e9;
  color: var(--ink);
}

h1 {
  margin: 13px 0 5px;
  font-family: Georgia, serif;
  font-size: clamp(1.75rem, 8vw, 2.65rem);
  line-height: 1.06;
  letter-spacing: -0.035em;
}

.subtitle {
  margin: 0 0 14px;
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.4;
}

.progress-strip {
  padding: 9px 11px 10px;
  border-radius: 6px;
  background: var(--ink);
  color: #f5e9fb;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.69rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  font-weight: 700;
}

#story-count {
  color: #ffd8a4;
  font-size: 0.75rem;
  letter-spacing: 0.035em;
  font-variant-numeric: tabular-nums;
}

progress {
  display: block;
  appearance: none;
  width: calc(100% + 4px);
  height: 7px;
  margin-top: 7px;
  border: 0;
  overflow: hidden;
  background: #5b486b;
  color: #f79ac3;
  /* The native value paints one cell for each of the eight parts. */
  mask-image: repeating-linear-gradient(90deg, #000 0 calc(12.5% - 4px), transparent calc(12.5% - 4px) 12.5%);
}

progress::-webkit-progress-bar {
  background: #5b486b;
}

progress::-webkit-progress-value {
  background: linear-gradient(90deg, #f79ac3 0 calc(100% - 2px), transparent calc(100% - 2px));
}

progress::-moz-progress-bar {
  background: linear-gradient(90deg, #f79ac3 0 calc(100% - 2px), transparent calc(100% - 2px));
}

.story-part {
  margin-bottom: 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  scroll-margin: 12px;
}

.story-part:has(.part-toggle[aria-expanded="true"]) {
  border-color: var(--ink);
  box-shadow: 0 3px 0 #ddcce9;
}

.story-part h2 {
  margin: 0;
  font-size: 1rem;
}

button {
  font: inherit;
  touch-action: manipulation;
}

.part-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 8px 14px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-size: 0.91rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.part-toggle[aria-expanded="true"] {
  border-radius: 6px 6px 0 0;
  background: #e9ddf2;
  box-shadow: inset 3px 0 var(--accent);
  color: var(--ink);
  font-weight: 800;
}

.part-toggle:disabled {
  color: var(--ink-soft);
  opacity: 1;
  cursor: default;
}

.chevron {
  flex: 0 0 7px;
  height: 7px;
  margin-right: 2px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}

.part-toggle[aria-expanded="true"] .chevron {
  transform: translateY(2px) rotate(225deg);
}

.part-toggle:disabled .chevron {
  opacity: 0.6;
}

.part-panel {
  padding: 11px 13px 13px;
}

.part-panel p,
.ending p {
  margin: 0;
  font-family: Georgia, serif;
  font-size: 1.15rem;
  line-height: 1.4;
}

.part-panel p {
  padding: 2px 0 2px 10px;
  border-left: 2px solid #dca8c6;
}

.next-step {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  width: 100%;
  min-height: 48px;
  margin-top: 11px;
  padding: 6px 8px 6px 14px;
  border: 1px solid #68143d;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
}

.next-step span {
  display: grid;
  width: 32px;
  height: 30px;
  place-items: center;
  border-radius: 3px;
  background: #f3c5d9;
  color: #631136;
  font-size: 1.15rem;
}

.next-step:active {
  background: #68143d;
}

button:focus-visible,
#ending-title:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.ad-slot {
  margin: 24px 0 21px;
  color: var(--ink-soft);
  text-align: center;
}

.ad-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.68rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.ad-content {
  display: grid;
  place-items: center;
  min-height: 250px;
}

.ending {
  margin-top: 16px;
  padding: 22px 15px;
  border: 1px solid var(--ink);
  border-radius: 7px;
  background: var(--paper);
  text-align: center;
  scroll-margin: 12px;
}

.ending h2 {
  margin: 0 0 9px;
  color: var(--accent);
  font-family: Georgia, serif;
  font-size: 1.25rem;
  letter-spacing: 0.14em;
}

.story-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
  padding: 16px 0 24px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.75rem;
}
