/* Reading and writing share one viewport-sized book. Complete articles and
   naturally sized form fields scroll within their own content areas. */
body.book-open {
  --reading-art-share: 45%;
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
body.book-open > main { flex: 1; min-height: 0; display: flex; }
body.book-open .campaign-header {
  height: auto; min-height: 60px; flex: none; padding-block: 6px;
}
body.book-open #stories:not([hidden]) {
  display: flex; flex-direction: column; flex: 1; gap: 8px;
  width: 100%; max-width: none; height: 100%; min-height: 0;
  margin: 0; padding: 8px max(26px, 3vw) max(8px, env(safe-area-inset-bottom));
  box-sizing: border-box; animation: none;
}
body.book-open #stories .section-top { display: block; flex: none; margin: 0; }
body.book-open #stories #book-hint { display: block; }
body.book-open #stories:has(.storybook-writing-page) .section-top { visibility: hidden; }
body.book-open #stories .section-top h2 { font-size: 17px; line-height: 1.45; margin: 0; }
body.book-open #published-notice { flex: none; margin: 0; font-size: 13px; }
body.book-open #published-notice:empty { display: none; }
body.book-open #stories .storybook {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  margin: 0; padding: 0; width: 100%;
}
body.book-open #stories .storybook-stage {
  flex: 1 1 0; min-height: 0; height: 0;
  width: 100%; max-width: none; margin: 0; z-index: 2;
}
body.book-open #stories .storybook-page {
  height: 100%; min-height: 0; max-height: 100%;
  display: flex; flex-direction: column; box-sizing: border-box;
  padding: 14px 26px; overflow: visible;
}
body.book-open #stories .storybook-meta {
  flex: none; min-height: 24px; padding-bottom: 8px; margin: 0;
  font-size: 12px; line-height: 1.5;
}
body.book-open #stories .storybook-kia-logo { width: 72px; max-height: 22px; }
body.book-open #stories .storybook-spread,
body.book-open #stories .storybook-write-layout {
  --book-gap: clamp(24px, 3vw, 48px);
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr);
  grid-template-rows: minmax(0, 1fr); gap: var(--book-gap);
  padding-top: 14px; align-items: stretch;
}
body.book-open #stories .storybook-visual {
  height: 100%; max-height: none; min-height: 0; aspect-ratio: auto;
  background-size: cover;
}
.storybook-visual.storybook-visual--grid {
  display: grid; grid-template: repeat(2, minmax(0, 1fr)) / repeat(2, minmax(0, 1fr));
  gap: 6px; overflow: hidden; border: 0; background-color: #f1ede5;
}
.storybook-visual--grid > svg {
  display: block; width: 100%; height: 100%; min-width: 0; min-height: 0; overflow: hidden;
}
body.book-open #stories .storybook-copy {
  height: 100%; min-height: 0; max-height: 100%;
  position: relative; display: flow-root; overflow: visible; padding: 0;
}
/* Anchor the seam to the text column, so it follows the actual grid gap. */
body.book-open #stories .storybook-spread::before { display: none; }
body.book-open #stories .storybook-copy::before {
  content: ''; position: absolute; top: 0; bottom: 0;
  left: calc(var(--book-gap) / -2); width: 1px; pointer-events: none;
  background: linear-gradient(transparent, #e8e2d4 10%, #e8e2d4 90%, transparent);
}
body.book-open #stories .storybook-copy > :first-child { margin-top: 0; }
body.book-open #stories .storybook-copy > :last-child { margin-bottom: 0; }
/* Endnotes sit at the bottom of their reading page, while remaining in the
   measured flow so long notes can continue without covering the story. */
body.book-open #stories .storybook-copy:has(> .storybook-note) {
  display: flex; flex-direction: column; box-sizing: border-box; padding-bottom: 2px;
}
body.book-open #stories .storybook-copy:has(> .storybook-note) > * { flex: none; }
body.book-open #stories .storybook-copy > .storybook-text:has(+ .storybook-note) { margin-bottom: 22px; }
body.book-open #stories .storybook-copy > .storybook-note { margin-top: auto; }
body.book-open #stories .storybook-controls {
  flex: none; display: flex; justify-content: center; align-items: center;
  height: 48px; min-height: 48px; gap: 16px; width: 100%; max-width: none;
  box-sizing: border-box; padding: 0 62px; margin: 0;
}
body.book-open #stories .book-side-control {
  top: 50%; bottom: auto; transform: translateY(-50%); margin: 0;
  width: 48px; height: 48px; min-height: 48px; scale: 1; animation: none;
}
body.book-open #stories .book-side-prev { left: -24px; }
body.book-open #stories .book-side-next { right: -24px; }
body.book-open #stories .book-dots { display: flex; flex-wrap: nowrap; min-width: 0; gap: 2px; }
body.book-open #stories .book-dot { width: 16px; height: 24px; background: transparent; box-shadow: none; }
body.book-open #stories .book-dot::before { width: 6px; height: 6px; }
body.book-open #stories .book-dot.active::before { width: 16px; }
body.book-open #stories .book-page-count { position: static; padding: 0; white-space: nowrap; font-size: 12px; }
body.book-open #reader-page-count { white-space: nowrap; font-size: 12px; color: #596f64; }
body.book-open #stories .flow-actions { flex: none; gap: 12px; margin: 0; padding: 0; flex-wrap: nowrap; }
body.book-open #stories .flow-actions .button { min-height: 44px; padding: 8px 14px; font-size: 13px; }
@media (max-width: 760px) {
  body.book-open #stories:not([hidden]) { padding-inline: 26px; gap: 6px; }
  body.book-open #stories .section-top { display: none; }
  body.book-open #stories .storybook-page { padding: 10px 26px; }
  body.book-open #stories .storybook-meta { font-size: 11px; padding-bottom: 6px; }
  body.book-open #stories .storybook-spread,
  body.book-open #stories .storybook-write-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: clamp(80px, 18dvh, 150px) minmax(0, 1fr);
    gap: 12px; padding-top: 10px;
  }
  body.book-open #stories .storybook-copy::before { display: none; }
  body.book-open #stories .storybook-copy h2 { font-size: 25px; }
  body.book-open #stories .storybook-intro,
  body.book-open #stories .storybook-text { font-size: 16px; }
  body.book-open #stories .book-dots { display: none; }
  body.book-open #stories .storybook-controls { flex-direction: column; gap: 0; line-height: 1.5; }
}
@media (max-height: 540px) {
  body.book-open #stories .section-top { display: none; }
  body.book-open #stories:not([hidden]) { padding-block: 4px; gap: 4px; }
  body.book-open #stories .storybook-page { padding-block: 8px; }
  body.book-open #stories .storybook-spread,
  body.book-open #stories .storybook-write-layout {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr);
    grid-template-rows: minmax(0, 1fr); --book-gap: 18px; gap: var(--book-gap); padding-top: 8px;
  }
  body.book-open #stories .storybook-copy h2 { font-size: 23px; }
  body.book-open #stories .storybook-meta { min-height: 20px; padding-bottom: 4px; }
}
@media (max-width: 600px) {
  body.book-open .campaign-header {
    flex-direction: column; align-items: center; gap: 4px; margin-inline: 10px; padding: 6px 0;
  }
  body.book-open .campaign-book-icon { width: 24px; height: 24px; }
  body.book-open .campaign-header .campaign-title { font-size: 16px; }
  body.book-open #stories .flow-actions .button { font-size: 12px; padding-inline: 10px; }
}
@media (max-width: 600px) and (max-height: 540px) {
  body.book-open #stories .storybook-spread,
  body.book-open #stories .storybook-write-layout { grid-template-columns: minmax(0, 1fr); }
  body.book-open #stories .storybook-visual,
  body.book-open #stories .storybook-write-visual { display: none; }
}
.reader-art-button { display: none; }
.reader-art-dialog { padding: 14px; width: min(1100px, 94vw); background: #fffdf8; border: 1px solid #e5e0d2; border-radius: 8px; }
.reader-art-dialog::backdrop { background: #102f41aa; }
.reader-art-dialog > button { display: block; margin: 0 0 10px auto; min-height: 44px; }
.reader-art-image { display: block; width: 100%; height: auto; max-height: calc(90dvh - 100px); object-fit: contain; }
@media (max-width: 600px) and (max-height: 540px) {
  body.book-open #stories .reader-art-button {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 44px; padding: 6px; margin-block: -8px;
    background: transparent; color: #183b4b; font-size: 12px; text-decoration: underline;
  }
}

/* The live submission form shares the book frame; only its fields scroll when
   their natural height exceeds the available space. Never shrink input text. */
body.book-open #stories .storybook-write-visual {
  display: flex; flex-direction: column; height: 100%; min-height: 0;
  inset: auto; margin: 0; padding: 0; gap: 0; overflow: hidden;
}
body.book-open #stories .storybook-write-visual img {
  display: block; flex: 1 1 0; min-height: 0; height: 0; width: 100%;
  aspect-ratio: auto; object-fit: cover; object-position: center 42%;
}
body.book-open #stories .storybook-write-visual figcaption {
  flex: none; padding: 10px 8px; font-size: 13px; line-height: 1.5;
}
body.book-open #stories .storybook-write-form {
  display: block; height: 100%; min-height: 0; max-height: 100%;
  overflow: auto; overscroll-behavior: contain; scrollbar-gutter: stable;
  padding: 0 10px 10px 0; scroll-padding-block: 12px;
}
body.book-open #stories .form-heading {
  margin-bottom: 10px; padding-bottom: 10px; gap: 4px 12px;
}
body.book-open #stories .write-form-intro h2 { font-size: clamp(18px, 1.4vw, 23px); }
body.book-open #stories .write-form-intro p { display: block; font-size: 13px; }
body.book-open #stories .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; }
body.book-open #stories #entry-fields input,
body.book-open #stories .source-language-label select {
  min-height: 44px; height: 44px; padding: 8px 10px; margin-top: 4px; font-size: 16px;
}
body.book-open #stories .form-divider { margin-block: 10px; }
body.book-open #stories .story-metadata {
  display: grid; grid-template-columns: minmax(0, .7fr) minmax(0, 1.3fr); gap: 16px;
}
body.book-open #stories .source-language-label { display: block !important; margin: 0; }
body.book-open #stories .source-language-label select { display: block; width: 100%; }
body.book-open #stories .story-label { margin-top: 10px; }
body.book-open #stories .story-label textarea {
  font-size: 16px; margin-top: 4px; resize: vertical;
  min-height: 120px !important; height: clamp(120px, 18dvh, 240px) !important;
}
body.book-open #stories .field-bottom { margin: 4px 0; }
body.book-open #stories .form-actions { margin-top: 8px; gap: 10px; }
body.book-open #stories .form-actions .button { min-height: 44px; height: auto; padding: 10px 14px; }
body.book-open #stories .form-message:empty { display: none; }
@media (max-width: 760px) {
  body.book-open #stories .storybook-write-visual { position: relative; }
  body.book-open #stories .storybook-write-visual figcaption {
    position: absolute; bottom: 0; left: 0; right: 0; padding: 6px 8px;
    background: #fffdf8e8; font-size: 11px;
  }
  body.book-open #stories .storybook-write-visual figcaption::before { display: none; }
  body.book-open #stories .storybook-write-form { padding-right: 6px; }
}
@media (max-width: 600px) {
  body.book-open #stories .form-grid,
  body.book-open #stories .story-metadata { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) and (max-height: 540px) {
  body.book-open #stories .storybook-write-visual { display: none; }
}
@media (min-width: 601px) and (max-height: 540px) {
  body.book-open #stories .storybook-copy::before { display: block; }
}

/* Every viewport keeps the art and controls fixed, with one complete article. */
body.book-open.reader-open #stories .storybook-copy {
  overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 0 10px 2px 0; box-sizing: border-box; scroll-padding-block: 12px;
  scrollbar-gutter: stable;
}
body.book-open.reader-open #stories .storybook-visual { background-size: contain; }
/* Draw the seam outside the scrolling column so overflow cannot clip it. */
body.book-open.reader-open #stories .storybook-copy::before { display: none; }
body.book-open.reader-open #stories .storybook-spread::before {
  display: block; position: absolute; top: 14px; bottom: 0;
  left: calc(55% - var(--book-gap) * .05); width: 1px; pointer-events: none;
  background: linear-gradient(transparent, #e8e2d4 10%, #e8e2d4 90%, transparent);
}
.storybook-mobile-image { display: none; }
.storybook-art-slot { display: contents; }
@media (max-width: 760px) {
  body.book-open .campaign-header { display: none; }
  body.book-open.reader-open #stories .storybook-page { padding-inline: 16px; }
  body.book-open.reader-open #stories .storybook-spread {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(36px, var(--reading-art-share)) minmax(0, 1fr); gap: 12px;
  }
  body.book-open.reader-open #stories .storybook-visual {
    display: block; width: 100%; height: 100%; min-height: 0; aspect-ratio: auto;
    background-image: none !important; background-color: transparent;
  }
  body.book-open.reader-open #stories .storybook-visual > svg { display: none; }
  body.book-open.reader-open #stories .storybook-mobile-image {
    display: block; width: 100%; height: 100%; min-height: 0; object-fit: contain;
  }
  body.book-open.reader-open #stories .storybook-copy {
    display: block;
    padding-right: 4px;
  }
  body.book-open.reader-open #stories .storybook-spread::before { display: none; }
  body.book-open.reader-open #stories .storybook-copy::before { display: none; }
  body.book-open.reader-open #stories .storybook-copy > .storybook-note { margin-top: 22px; }
  body.book-open.reader-open #stories .storybook-copy > .storybook-text:has(+ .storybook-note) { margin-bottom: 0; }
  body.book-open.reader-open #stories .reader-art-button { display: none; }
}

/* Fit the frame to the complete image, rather than letterboxing or cropping
   it inside a fixed 55/45 rectangle. The live reader adds the fitting slot;
   natural-flow editorial previews keep their existing frame. */
body.book-open.reader-open #stories .storybook-art-slot {
  display: flex; min-width: 0; min-height: 0; align-items: flex-start;
}
body.book-open.reader-open #stories .storybook-visual {
  display: block; flex: none;
  width: var(--reader-art-width, 100%); height: var(--reader-art-height, 100%);
  max-width: 100%; max-height: 100%; min-height: 0; aspect-ratio: auto;
  background-image: none !important; background-color: transparent;
}
body.book-open.reader-open #stories .storybook-visual > svg { display: none; }
body.book-open.reader-open #stories .storybook-mobile-image {
  display: block; width: 100%; height: 100%; min-height: 0; object-fit: contain;
}
body.book-open.reader-open #stories .storybook-spread[data-reader-layout="columns"] {
  grid-template-columns: minmax(0, var(--reader-art-width)) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}
body.book-open.reader-open #stories .storybook-page:has([data-reader-layout="columns"]) { padding-inline: 26px; }
body.book-open.reader-open #stories .storybook-spread[data-reader-layout="columns"]::before {
  display: block; left: calc(var(--reader-art-width) + var(--reader-gap) / 2);
}
body.book-open.reader-open #stories .storybook-spread[data-reader-layout="stacked"] {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: var(--reader-art-height) minmax(0, 1fr);
}
body.book-open.reader-open #stories .storybook-spread[data-reader-layout="stacked"]::before { display: none; }
body.book-open.reader-open #stories .storybook-spread[data-reader-layout="stacked"] .storybook-art-slot { justify-content: center; }
