/* PWA-only Story Reel shell v1.8.240.
   Local Chat remains the source of truth; this file gives the published PWA
   its own layout owner so the mobile composer cannot be split across two
   overlapping grid children. */

/* Keep terminal network errors readable in the narrow mobile image rail. */
@media (max-width: 760px) {
  .chat-image-placeholder-meta { display: grid; gap: 6px; }
  .chat-image-placeholder-stage { white-space: nowrap; }
  .chat-image-placeholder-data { justify-content: space-between; gap: 4px; }
  .chat-image-placeholder-error-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .chat-image-placeholder-error { white-space: normal; overflow: visible; overflow-wrap: anywhere; font-size: 12px; line-height: 1.5; }
  .chat-image-placeholder-retry { width: 100%; white-space: nowrap; padding: 4px 3px; }
  #archive-dlg .archive-restore-btn { flex: 0 0 72px !important; width: 72px !important; min-width: 72px !important; max-width: 72px !important; white-space: nowrap; }
}

:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) {
  --pwa-story-gutter: 7px;
  --pwa-story-composer-gap: 6px;
  --pwa-story-send: 42px;
}

:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer {
  display: grid;
  grid-column: 1;
  grid-row: 3;
  grid-template-columns: minmax(96px, auto) minmax(280px, 1fr) 70px var(--pwa-story-send);
  grid-template-areas: "modes text actions send";
  align-items: center;
  gap: 8px;
  width: min(1060px, calc(100% - 36px));
  height: 62px;
  align-self: center;
  justify-self: center;
  min-width: 0;
  padding: 7px;
  border: 1px solid var(--story-line);
  border-radius: 15px;
  background: var(--story-panel);
  box-shadow: 0 0 0 1px rgba(66, 53, 44, .07), 0 8px 24px rgba(66, 53, 44, .07);
}

:root[data-theme="story-dark"] #tab-chat > .pwa-story-composer {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .075);
}

@media (min-width: 1200px) {
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer {
    width: min(1060px, calc(100% - 36px)) !important;
    max-width: none !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }
}

@media (min-width: 761px) and (max-width: 1199px) {
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer {
    width: min(1060px, calc(100% - 36px)) !important;
    max-width: none !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }
}

:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer > .input-toolbar,
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer > .chat-input {
  display: contents;
}

:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer .imode-seg {
  grid-area: modes;
  min-width: 0;
  height: 48px;
}

:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer #chat-text {
  grid-area: text;
  width: 100%;
  min-width: 0;
  height: 48px;
  min-height: 48px;
  margin: 0;
  padding: 13px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--story-soft);
  color: var(--label);
  font-size: 16px;
  line-height: 1.45;
  resize: none;
}

:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer .io-actions {
  grid-area: actions;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  min-width: 0;
  height: 48px;
  margin: 0;
}

:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer .io-actions > button {
  flex: 0 0 33px;
  width: 33px;
  min-width: 33px;
  height: 40px !important;
  min-height: 40px;
  padding: 0 !important;
  border: 1px solid var(--story-line) !important;
  border-radius: 10px !important;
  background: var(--story-soft) !important;
  color: var(--label-2) !important;
  box-shadow: none !important;
  font-size: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer #cc-expand-input::before { content: "✦"; color: var(--accent); font-size: 18px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer #cc-undo-input::before { content: "↶"; color: var(--label-2); font-size: 18px; }

:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer #chat-send {
  grid-area: send;
  width: var(--pwa-story-send);
  min-width: var(--pwa-story-send);
  height: 42px;
  margin: 0;
  border-radius: 11px;
}

@media (max-width: 760px) {
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat.active {
    padding-inline: 0;
    grid-template-rows: 58px minmax(0, 1fr) 70px;
  }

  /* The character rail is a separate thumb-side affordance, not an input
     control. Keep it out of the right-side action lane. */
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat.active > .scene-roster-panel {
    left: 0;
    right: auto;
    border-radius: 0 15px 15px 0;
    box-shadow: 8px 10px 28px rgba(0, 0, 0, .14);
  }

  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat.active > .scene-roster-panel[open] {
    left: 0;
    right: auto;
    border-radius: 0 18px 18px 0;
  }

  /* One component, one row, four explicit slots: mode / text / utilities /
     send. No negative margins or textarea-reserve hacks are needed. */
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer {
    grid-template-columns: clamp(84px, 22vw, 92px) minmax(0, 1fr) 70px var(--pwa-story-send);
    grid-template-areas: "modes text actions send";
    align-items: center;
    gap: var(--pwa-story-composer-gap);
    width: calc(100% - 14px);
    height: 70px;
    align-self: stretch;
    min-width: 0;
    margin: 0 7px;
    padding: 5px;
    border: 1px solid var(--story-line);
    border-radius: 12px;
    background: var(--story-panel);
    box-shadow: 0 0 0 1px rgba(66, 53, 44, .07), 0 8px 24px rgba(66, 53, 44, .07);
  }

  :root[data-theme="story-dark"] #tab-chat > .pwa-story-composer {
    box-shadow: 0 0 0 1px rgba(255, 255, 255, .075);
  }

  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer .imode-seg {
    grid-area: modes;
    display: inline-grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    width: 100%;
    height: 46px;
    min-width: 0;
    padding: 3px;
    gap: 1px;
    border-radius: 10px;
    background: var(--story-soft);
  }

  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer .imode-btn {
    min-width: 0;
    height: 40px;
    padding: 0 4px;
    border-radius: 8px;
    font-size: 0;
  }
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer .imode-btn::after {
    font-size: 12px;
    font-weight: 700;
  }
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer .imode-btn[data-imode="say"]::after { content: "说"; }
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer .imode-btn[data-imode="do"]::after { content: "做"; }
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer .imode-btn[data-imode="story"]::after { content: "旁白"; }

  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer #chat-text {
    grid-area: text;
    width: 100%;
    min-width: 0;
    height: 46px;
    min-height: 46px;
    max-height: 46px;
    margin: 0;
    padding: 12px 10px;
    border: 0;
    border-radius: 10px;
    background: var(--story-soft);
    color: var(--label);
    font-size: 15px;
    line-height: 1.45;
    resize: none;
    overflow: hidden;
  }

  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer .io-actions {
    grid-area: actions;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 3px;
    min-width: 0;
    height: 46px;
    margin: 0;
  }

  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer .io-actions > button {
    flex: 0 0 33px;
    width: 33px;
    min-width: 33px;
    height: 36px !important;
    min-height: 36px;
    padding: 0 !important;
    border: 1px solid var(--story-line) !important;
    border-radius: 10px !important;
    background: var(--story-soft) !important;
    color: var(--label-2) !important;
    box-shadow: none !important;
    font-size: 0 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer #cc-expand-input::before { content: "✦"; color: var(--accent); font-size: 17px; }
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer #cc-undo-input::before { content: "↶"; color: var(--label-2); font-size: 17px; }

  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer #chat-send {
    grid-area: send;
    width: var(--pwa-story-send);
    min-width: var(--pwa-story-send);
    height: 42px;
    margin: 0;
    border-radius: 11px;
  }
}

@media (max-width: 360px) {
  :root[data-theme="story-warm"], :root[data-theme="story-dark"] {
    --pwa-story-send: 38px;
    --pwa-story-composer-gap: 4px;
  }

  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer {
    grid-template-columns: 84px minmax(0, 1fr) 62px var(--pwa-story-send);
  }

  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #tab-chat > .pwa-story-composer .io-actions > button {
    flex-basis: 29px;
    width: 29px;
    min-width: 29px;
  }
}

/* Compact role-editor inventory. The special-tag library is a utility, not
   the primary editor surface: keep it dense and bounded so long inventories
   do not push the save/generate actions below the fold. */
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-lib {
  margin: 4px 0 6px;
  border-radius: 9px;
}
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-lib > summary {
  padding: 7px 9px;
  gap: 6px;
}
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-lib > summary strong { font-size: 11px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-hint { font-size: 9px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-body { padding: 0 9px 8px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-pinned-head { margin-bottom: 4px; font-size: 9px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-manage { padding: 2px 5px; font-size: 9px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-pinned { gap: 4px; min-height: 24px; margin-bottom: 6px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-pin {
  min-height: 24px;
  padding: 3px 6px;
  gap: 4px;
  border-radius: 7px;
}
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-pin > span:nth-child(2) { font-size: 10px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-pin small { font-size: 7.5px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-addrow { gap: 5px; margin-bottom: 6px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-addrow input { padding: 6px 8px; font-size: 11px; border-radius: 8px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-addrow button { padding: 6px 9px; font-size: 11px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-toolbar { gap: 5px; margin: 2px 0 6px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-pool {
  max-height: 132px;
  overflow-y: auto;
  gap: 4px;
  padding: 2px 1px 1px;
  scrollbar-width: thin;
}
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-empty,
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-empty-pinned {
  font-size: 10px;
  line-height: 1.35;
}
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-empty-pinned { padding: 4px 6px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-toolbar .cc-stag-hint { font-size: 9px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-chip {
  min-height: 25px;
  padding: 4px 20px 4px 8px;
  border-radius: 7px;
  font-size: 10px;
}
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-chip small { font-size: 8px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-check { width: 13px; height: 13px; font-size: 9px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-chip-del { right: 4px; font-size: 9px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-syncrow { gap: 6px; margin-top: 7px; padding-top: 7px; }
:where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .cc-stag-sync { font-size: 9.5px; }

/* Works browser mobile repair: the desktop decision shelf used four fixed
   128px columns, which made a 366px phone canvas 648px wide and clipped the
   left side of the dialog. */
@media (max-width: 560px) {
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #cp-work-view {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    padding-inline: 12px;
  }
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) #cp-work-view > * {
    min-width: 0;
    max-width: 100%;
  }
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .wb-decision-chip-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-width: 0;
  }
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .wb-decision-chip-grid .wb-featured-work,
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .wb-featured-work.is-qualified {
    min-width: 0;
    width: 100%;
  }
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .wb-featured-grid,
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .wb-work-chip-grid,
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .wb-work-chip-grid-popular {
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
  }
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .wb-section-heading h4 {
    font-size: 22px;
    overflow-wrap: anywhere;
  }
  /* Popular works: show three compact chips per phone row. */
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .wb-work-chip-grid-popular {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    max-height: 190px;
    overflow-y: auto;
  }
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .wb-work-chip-grid-popular .wb-featured-work {
    width: 100%;
    min-width: 0;
    min-height: 38px;
    padding: 4px 5px;
  }
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .wb-work-chip-grid-popular .wb-featured-copy strong {
    font-size: 9.5px;
    line-height: 1.15;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .wb-work-chip-grid-popular .wb-featured-copy small {
    font-size: 7.5px;
    white-space: nowrap;
  }
  /* Character cards: the four decision labels need readable touch targets;
     use a 2×2 action grid instead of squeezing text into one line. */
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .wb-card-quick-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }
  :where(:root[data-theme="story-warm"], :root[data-theme="story-dark"]) .wb-card-action {
    min-width: 0;
    min-height: 30px;
    padding-inline: 3px;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    font-size: 10px;
  }
}
