.story-lab {
  color: var(--ink, #f4eddc);
  padding-bottom: 88px;
}

.story-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(310px, .8fr);
  align-items: start;
  gap: clamp(24px, 3.5vw, 50px);
}

.story-preview {
  position: sticky;
  top: 104px;
  min-width: 0;
}

.story-preview-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin: 3px 0 16px;
}

.story-preview-heading > :last-child {
  flex-shrink: 0;
  color: var(--muted, #bdb5cf);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.story-canvas-stage {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 250px;
  padding: clamp(14px, 2.5vw, 32px);
  border: 1px solid var(--line, #40364e);
  border-radius: var(--radius, 24px);
  background: radial-gradient(ellipse at 15% 0, rgba(170, 133, 235, .1), transparent 70%), #1b1728;
}

.story-canvas {
  display: block;
  width: 100%;
  max-height: 760px;
  height: auto;
  object-fit: contain;
  box-shadow: 0 16px 42px rgba(0, 0, 0, .22);
}

.story-canvas[hidden],
.story-preview-message[hidden],
.story-lab [hidden] {
  display: none;
}

.story-preview-message {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 100%;
  max-height: 760px;
  aspect-ratio: var(--story-preview-ratio, 1.8);
  margin: 0;
  padding: 24px;
  color: var(--muted, #bdb5cf);
  font-size: 14px;
  line-height: 1.65;
  text-align: center;
}

.story-preview-note {
  margin: 15px 0 0;
  color: var(--muted, #bdb5cf);
  font-size: 12px;
  line-height: 1.65;
}

.story-settings,
.story-panel {
  min-width: 0;
  box-sizing: border-box;
  padding: clamp(22px, 2.6vw, 32px);
  border: 1px solid var(--line, #40364e);
  border-radius: var(--radius, 24px);
  background: var(--panel, #211b31);
}

.story-settings h2 {
  margin: 12px 0 18px;
  font: 400 clamp(32px, 3vw, 46px) / 1.05 Georgia, serif;
  letter-spacing: -.04em;
}

.story-intro-copy {
  margin: 0 0 26px;
  color: var(--muted, #bdb5cf);
  font-size: 14px;
  line-height: 1.7;
}

.story-field {
  min-width: 0;
  margin: 0 0 24px;
  padding: 0;
  border: 0;
}

.story-field > label,
.story-field legend,
.story-label-row label {
  display: block;
  margin: 0 0 10px;
  padding: 0;
  color: var(--ink, #f4eddc);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.5;
}

.story-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.story-label-row label span {
  color: var(--muted, #bdb5cf);
  font-size: 11px;
  font-weight: 400;
}

.story-label-row output {
  flex-shrink: 0;
  color: var(--muted, #bdb5cf);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.story-field input[type="text"],
.story-field select,
.story-field textarea {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line, #40364e);
  border-radius: 11px;
  background: var(--bg, #161322);
  color: var(--ink, #f4eddc);
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
  color-scheme: dark;
}

.story-field select {
  padding-right: 26px;
}

.story-field textarea {
  min-height: 124px;
  resize: vertical;
}

.story-field input::placeholder,
.story-field textarea::placeholder {
  color: var(--muted, #bdb5cf);
  opacity: .75;
}

.story-lab input:focus-visible,
.story-lab select:focus-visible,
.story-lab textarea:focus-visible,
.story-lab button:focus-visible {
  outline: 2px solid var(--accent, #d7f57b);
  outline-offset: 4px;
}

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

.story-layout-options label,
.story-theme-options label {
  position: relative;
  cursor: pointer;
}

.story-layout-options input,
.story-theme-options input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.story-layout-options label > span {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 9px;
  min-height: 86px;
  box-sizing: border-box;
  padding: 13px 16px;
  border: 1px solid var(--line, #40364e);
  border-radius: 12px;
  color: var(--muted, #bdb5cf);
  font-size: 12px;
  font-weight: 600;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}

.story-layout-options b {
  font-size: 19px;
  line-height: 1.2;
  font-weight: 500;
}

.story-layout-options input:checked + span {
  border-color: var(--accent, #d7f57b);
  background: rgba(215, 245, 123, .09);
  color: var(--accent, #d7f57b);
}

.story-layout-options input:focus-visible + span,
.story-theme-options input:focus-visible + span {
  outline: 2px solid var(--ink, #f4eddc);
  outline-offset: 4px;
}

.story-theme-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.story-theme-options label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  min-height: 78px;
  padding: 5px 3px;
  color: var(--muted, #bdb5cf);
  font-size: 11px;
  line-height: 1.4;
}

.story-theme-swatch {
  display: block;
  width: 38px;
  height: 38px;
  box-sizing: border-box;
  border: 3px solid transparent;
  border-radius: 50%;
  background-clip: padding-box;
}

.story-theme-midnight { background-color: #433354; }
.story-theme-paper { background-color: #eee4cf; }
.story-theme-lilac { background-color: #c9ade7; }

.story-theme-options input:checked + .story-theme-swatch {
  box-shadow: 0 0 0 2px var(--panel, #211b31), 0 0 0 4px var(--accent, #d7f57b);
}

.story-theme-options input:checked ~ span:last-child {
  color: var(--ink, #f4eddc);
}

.story-prompt-box {
  margin-top: 4px;
  padding: 22px;
  border: 1px dashed #6a527f;
  border-radius: 16px;
  background: rgba(170, 133, 235, .055);
}

.story-prompt-box > .eyebrow {
  color: var(--purple, #aa85eb);
  font-size: 10px;
}

.story-prompt-box p {
  margin: 12px 0 11px;
  color: var(--ink, #f4eddc);
  font: 400 19px / 1.5 Georgia, serif;
}

.story-prompt-button {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--accent, #d7f57b);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.story-prompt-button span {
  font-size: 20px;
}

.story-prompt-box small {
  display: block;
  margin-top: 9px;
  color: var(--muted, #bdb5cf);
  font-size: 11px;
  line-height: 1.6;
}

.story-scenes-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 30px;
  margin: 58px 0 24px;
}

.story-scenes-heading h3 {
  margin: 12px 0 0;
  font: 400 clamp(28px, 3.2vw, 42px) / 1.1 Georgia, serif;
  letter-spacing: -.035em;
}

.story-scenes-heading p {
  max-width: 330px;
  margin: 0 0 1px;
  color: var(--muted, #bdb5cf);
  font-size: 13px;
  line-height: 1.7;
}

.story-panel-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 22px;
}

.story-panel {
  margin: 0;
  padding: 23px;
}

.story-panel-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 20px;
}

.story-panel-heading > .eyebrow {
  color: var(--peach, #ffbb84);
  font-size: 10px;
}

.story-move-buttons {
  display: flex;
  gap: 5px;
}

.story-move-buttons button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 44px;
  padding: 6px 9px;
  border: 1px solid var(--line, #40364e);
  border-radius: 8px;
  background: var(--bg, #161322);
  color: var(--ink, #f4eddc);
  font-size: 10px;
  cursor: pointer;
}

.story-move-buttons button:hover:not(:disabled) {
  border-color: var(--purple, #aa85eb);
}

.story-move-buttons button:disabled {
  opacity: .4;
  cursor: default;
}

.story-panel-picture {
  margin: 0 0 22px;
}

.story-panel-picture img {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 230px;
  padding: 12px;
  border: 1px solid var(--line, #40364e);
  border-radius: 12px;
  background: var(--bg, #161322);
  object-fit: contain;
}

.story-panel-picture figcaption {
  margin-top: 10px;
  color: var(--muted, #bdb5cf);
  font-size: 11px;
  line-height: 1.6;
}

.story-caption-field {
  margin-bottom: 0;
}

.story-finish-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 22px 35px;
  margin-top: 30px;
  padding-top: 30px;
  border-top: 1px solid var(--line, #40364e);
}

.story-actions {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 10px;
}

.story-actions .button {
  min-height: 48px;
}

.story-actions .button:disabled {
  opacity: .5;
  cursor: wait;
  transform: none;
}

.story-finish-notes {
  max-width: 350px;
}

.story-storage,
.story-result {
  margin: 0;
  color: var(--muted, #bdb5cf);
  font-size: 11px;
  line-height: 1.7;
}

.story-storage-warning {
  color: var(--peach, #ffbb84);
}

.story-result {
  margin-top: 8px;
  color: var(--accent, #d7f57b);
}

.story-result:empty {
  display: none;
}

.story-empty {
  padding: 32px;
  border: 1px solid var(--line, #40364e);
  border-radius: var(--radius, 24px);
  background: var(--panel, #211b31);
}

.story-empty h2 {
  font-size: 32px;
}

.story-empty p {
  line-height: 1.7;
}

.story-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (max-width: 1050px) {
  .story-workspace { grid-template-columns: minmax(0, 1fr) minmax(300px, .85fr); gap: 24px; }
  .story-panel-grid { gap: 14px; }
  .story-panel { padding: 18px; }
  .story-panel-picture img { height: 200px; }
  .story-panel-heading { align-items: flex-start; }
  .story-label-row { flex-wrap: wrap; gap: 0 10px; }
  .story-label-row output { margin-bottom: 10px; }
}

@media (max-width: 800px) {
  .story-workspace { grid-template-columns: 1fr; gap: 30px; }
  .story-preview { position: static; }
  .story-settings { padding: 25px; }
  .story-settings h2 br { display: none; }
  .story-settings h2 { font-size: 34px; }
  .story-panel-grid { grid-template-columns: 1fr; gap: 20px; }
  .story-panel { padding: 24px; }
  .story-panel-picture img { height: 280px; }
  .story-panel-heading { align-items: center; }
  .story-scenes-heading { margin-top: 42px; }
  .story-scenes-heading p { max-width: 260px; }
  .story-finish-notes { max-width: none; }
  .story-lab { padding-bottom: 56px; }
}

@media (max-width: 540px) {
  .story-preview-heading { align-items: flex-start; gap: 10px; }
  .story-preview-heading .eyebrow { max-width: 150px; font-size: 9px; }
  .story-preview-heading > :last-child { font-size: 10px; }
  .story-canvas-stage { padding: 12px; min-height: 190px; border-radius: 16px; }
  .story-canvas, .story-preview-message { max-height: 650px; }
  .story-preview-note { font-size: 11px; }
  .story-settings { padding: 22px; }
  .story-settings h2 { font-size: 32px; }
  .story-prompt-box { padding: 18px; }
  .story-prompt-box p { font-size: 18px; }
  .story-scenes-heading { flex-direction: column; align-items: flex-start; gap: 15px; }
  .story-scenes-heading p { max-width: none; }
  .story-panel { padding: 21px; }
  .story-panel-picture img { height: 250px; }
  .story-actions { width: 100%; }
  .story-actions .button-primary { width: 100%; }
  .story-finish-bar { gap: 20px; margin-top: 24px; padding-top: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .story-layout-options label > span { transition: none; }
}
