#story-mode-dialog {
  /* Content-sized on desktop; never force nearly full viewport width. */
  width: fit-content;
  max-width: min(52rem, 75vw, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  box-sizing: border-box;
}
#story-mode-dialog .story-mode-sheet {
  width: 100%;
  max-width: 100%;
  max-height: calc(100dvh - 36px);
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
}
#story-mode-dialog [hidden] { display: none !important; }
#story-mode-dialog label, #story-mode-dialog .story-setting-grid > * { min-width: 0; }
#story-mode-dialog input, #story-mode-dialog select, #story-mode-dialog textarea {
  max-width: 100%;
  box-sizing: border-box;
}
#story-mode-dialog .story-choice-grid input { width: auto; }
#story-mode-dialog .story-shared-settings { order: 0; }
#story-mode-dialog .story-editor-extras {
  display: flex;
  justify-content: flex-start;
  margin: 12px 0 4px;
}
.story-existing-list {
  list-style: none;
  max-height: min(45vh, 26rem);
  overflow: auto;
  padding: 0;
  margin: .5rem 0;
}
.story-existing-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: .65rem;
  padding: .55rem .25rem;
  border-bottom: 1px solid var(--phantom-border, #444);
}
.story-existing-row > span { overflow-wrap: anywhere; }
.story-list-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
#story-setup-close, #story-editor .phantom-dialog-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding: .6rem 0 max(.6rem, env(safe-area-inset-bottom));
  background: var(--surface, #17131e);
  border-top: 1px solid var(--phantom-border, #444);
}
#story-setup-close { justify-content: flex-end; }
#story-mode-dialog .story-scene-delete[aria-disabled="true"],
#story-mode-dialog .story-scene-delete:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
#story-mode-dialog .story-scene-card {
  display: grid;
  grid-template-columns: minmax(9rem, 13rem) minmax(0, 1fr);
  gap: 0.75rem;
  align-items: start;
}
#story-mode-dialog .story-scene-preview-slot {
  grid-row: span 2;
  min-height: 9rem;
  border: 1px solid var(--phantom-border, currentColor);
  border-radius: 0.5rem;
  overflow: hidden;
}
#story-mode-dialog .story-scene-preview,
#story-mode-dialog .story-scene-preview-link { display: block; width: 100%; }
#story-mode-dialog .story-scene-preview { height: 9rem; object-fit: contain; }
#story-mode-dialog .story-scene-preview-empty { padding: 0.75rem; }
.story-collection-viewer {
  max-width: min(92vw, 70rem);
  width: 100%;
  max-height: calc(100dvh - 24px);
  overflow: hidden;
  background: var(--panel, #0D0D14);
  color: var(--text, #F6F4FF);
  border: 1px solid var(--border, #29283A);
  color-scheme: dark;
}
.story-collection-viewer::backdrop { background: rgba(0, 0, 0, .7); }
.story-viewer-sheet {
  display: grid;
  gap: .75rem;
  padding: 1rem;
  max-height: calc(100dvh - 24px);
  overflow: auto;
  background: var(--panel, #0D0D14);
  color: var(--text, #F6F4FF);
}
.story-viewer-sheet header, .story-viewer-controls { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.story-viewer-sheet h2,
.story-viewer-position { color: var(--text, #F6F4FF); }
.story-viewer-sheet h2 { margin: 0; }
.story-viewer-controls {
  position: sticky;
  bottom: 0;
  padding: .5rem 0 max(.5rem, env(safe-area-inset-bottom));
  background: var(--panel, #0D0D14);
}
.story-viewer-controls button {
  background: var(--panel-raised, #12121C);
  color: var(--text, #F6F4FF);
  border: 1px solid var(--border, #29283A);
}
.story-viewer-controls button:focus-visible {
  outline: 2px solid var(--accent-bright, #B59BFF);
  outline-offset: 2px;
}
.story-viewer-controls button:disabled { opacity: 0.55; }
.story-viewer-sheet img {
  display: block;
  width: 100%;
  max-height: 68vh;
  object-fit: contain;
  background: var(--panel-raised, #12121C);
}
.story-viewer-position { text-align: center; margin: 0; }
/* Stories source art is the full 1983×793 frame. Contain + right alignment
   keeps the hood, face and clasp inside the sheet; the heading stays HTML
   on the quiet left. The page notification mascot stays on the active top
   banner, not a second anchor in this sheet. */
#story-mode-dialog .story-heading-row {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  min-width: min(42rem, calc(100vw - 48px));
  aspect-ratio: 1983 / 793;
  margin: 0 0 12px;
  padding: 16px;
  border: 1px solid rgba(118, 82, 214, 0.65);
  border-radius: 12px;
  background-color: #090910;
  background-image: url("../assets/phantom-stories-banner-v1.webp?v=021230d20a35a7f6");
  background-repeat: no-repeat;
  background-position: right center;
  background-size: contain;
  overflow: visible;
  box-shadow: 0 0 24px rgba(139, 92, 246, 0.18);
}
#story-mode-dialog .story-heading-row > div {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  max-width: min(38%, 22rem);
  margin: 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(9, 9, 16, 0.78);
  border: 1px solid rgba(201, 167, 91, 0.45);
  color: var(--text, #F6F4FF);
}
#story-mode-dialog .story-heading-row h2 {
  margin: 0 0 4px;
  color: var(--text, #F6F4FF);
}
#story-mode-dialog .story-heading-row p {
  margin: 0;
  color: var(--secondary, #C8C5D2);
}
@media (max-width: 935px) {
  #story-mode-dialog .story-heading-row {
    aspect-ratio: 1983 / 793;
    background-image: url("../assets/phantom-stories-banner-v1-1280.webp?v=d44f86383c6ba55d");
    background-position: right center;
    background-size: contain;
  }
  #story-mode-dialog .story-heading-row > div { max-width: min(40%, 16rem); }
}
@media (max-width: 390px) {
  #story-mode-dialog .story-heading-row {
    aspect-ratio: 1983 / 793;
    background-image: url("../assets/phantom-stories-banner-v1-1280.webp?v=d44f86383c6ba55d");
    background-position: right center;
    background-size: contain;
  }
  #story-mode-dialog .story-heading-row > div { max-width: 34%; }
  #story-mode-dialog .story-heading-row p { font-size: 0.85rem; }
  #story-mode-dialog .story-heading-row h2 { font-size: 1.05rem; }
}
@media (max-width: 700px) {
  #story-mode-dialog {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
  }
  #story-mode-dialog .story-heading-row { align-items: flex-start; }
  #story-mode-dialog .story-mode-sheet { padding: 12px; }
  #story-mode-dialog .story-scene-card { grid-template-columns: minmax(0, 1fr); }
  #story-mode-dialog .story-scene-preview-slot { grid-row: auto; }
  .story-existing-row { grid-template-columns: auto minmax(0, 1fr); }
  .story-existing-row button { grid-column: 2; justify-self: start; }
  .story-list-actions button { flex: 1 1 7rem; }
  .story-collection-viewer,
  .story-viewer-sheet { max-height: calc(100dvh - 16px); }
  .story-viewer-controls { flex-wrap: wrap; justify-content: center; }
  .story-viewer-controls button { min-height: 44px; min-width: 44px; }
}
