/* The story pages on phones (up to 600px): the Story Generator, the library,
   a story's page and the story sign-in prompt, whose <body> has .story-phone.
   Worlds shares those pages' desktop header but is not one of them.

   Loaded by templates/components/story_phone_head.html. Colours here are a
   source of the dark scheme (scripts/build_dark_css.py SOURCES): after any
   colour change run python scripts/build_dark_css.py.

   The header (owner, 2026-11-20): one row, as the phone chat has — a menu
   button, "Discipline Stories" (a link to the main stories page) and Support — and a
   menu panel with the pages' other links
   (templates/components/story_phone_header.html, static/story_menu.js).
   Above 600px the pages keep their own header and none of this shows. */

.story-bar,
.story-menu,
.story-menu-scrim,
.story-phone-only {
  display: none;
}

@media (max-width: 600px) {
  /* The desktop header: the account and Support links, the page title, the
     tagline and the pill links. The title and tagline stay in the page for
     screen readers and search engines (the bar's "Discipline Stories" is a link, not a
     heading); the links are in the menu panel. */
  body.story-phone .story-desk-only {
    display: none;
  }

  body.story-phone h1.story-desk-only,
  body.story-phone p.story-desk-only {
    display: block;
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  /* ---- The bar. <body> has 25px of padding (input.css); the bar spans the
     screen above it. It scrolls away with the page: a story gets the whole
     screen. No background of its own: iPhone Safari tints the strips around
     its status bar from the page's colour, and the bar sits on that. ---- */
  body.story-phone .story-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    height: 52px;
    margin: -25px -25px 0;
    padding: 0 14px 0 8px;
    border-bottom: 1px solid #e9e0f7;
  }

  /* The wrapper under the bar starts closer to it than to the screen's top. */
  body.story-phone .story-bar ~ .mx-auto {
    padding-top: 16px;
  }

  /* The menu button: three bars, no box, as the chat's. */
  body.story-phone .story-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    justify-self: start;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    box-shadow: none;
    color: #6b21a8;
    cursor: pointer;
  }

  body.story-phone .story-menu-toggle::before {
    content: "";
    width: 26px;
    height: 26px;
    background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M4 6h16M4 12h16M4 18h16'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M4 6h16M4 12h16M4 18h16'/%3E%3C/svg%3E") center / contain no-repeat;
  }

  /* "Discipline Stories" (owner, 2026-11-20; it was "Stories"): one line,
     centred between the menu button and Support, which are the same width
     as each other only by the grid. A size smaller under 375px, where the
     three would not fit at 18px (a donor's "Thank you" is the widest
     Support). */
  body.story-phone .story-bar-title {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 6px;
    color: #2a1a3a;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
    text-decoration: none;
    white-space: nowrap;
  }

  body.story-phone .story-bar-support {
    justify-self: end;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
  }

  /* ---- Visible shortcuts (owner, 2026-11-20): the two trips the menu
     would otherwise hide. The library's heading shares its row with "New
     story"; the generator's "Story Prompt" with "Library". ---- */
  body.story-phone .story-headrow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
  }

  body.story-phone .story-headrow > h1.title,
  body.story-phone .story-headrow > label {
    margin-bottom: 0;
    text-align: left;
  }

  body.story-phone .story-shortcut {
    display: inline-flex;
    flex: none;
    align-items: center;
    min-height: 38px;
    padding: 0 16px;
    border-radius: 999px;
    background: #f1e7fc;
    color: #6b21a8;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
  }

  body.story-phone .story-shortcut-primary {
    background: #8a3cc8;
    color: #ffffff;
  }

  /* ---- The menu panel: the chat menu's look (chat_phone.css). ---- */
  body.story-phone .story-menu-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgb(20 10 35 / 0.45);
  }

  body.story-phone .story-menu-scrim[hidden] {
    display: none;
  }

  body.story-phone .story-menu {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 2001;
    width: min(86vw, 320px);
    padding: calc(14px + env(safe-area-inset-top, 0px)) 14px 0;
    background: #fbf8ff;
    box-shadow: 4px 0 24px rgb(20 10 35 / 0.18);
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }

  body.story-phone.story-menu-open .story-menu {
    transform: none;
    visibility: visible;
    transition: transform 0.2s ease;
  }

  body.story-phone.story-menu-open {
    overflow: hidden;
  }

  body.story-phone .story-menu-brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
  }

  body.story-phone .story-menu-brand {
    color: #7e22ce;
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -0.01em;
  }

  body.story-phone .story-menu-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin: -4px -8px -4px 0;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    box-shadow: none;
    color: #6b7280;
    cursor: pointer;
  }

  body.story-phone .story-menu-nav {
    flex: 1;
    overflow-y: auto;
    /* A scroll that reaches the list's end does not move the page behind. */
    overscroll-behavior: contain;
  }

  body.story-phone .story-menu-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 0 8px;
    border-radius: 10px;
    color: #3b2a57;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
  }

  body.story-phone .story-menu-nav a[aria-current="page"] {
    background: #f1e7fc;
    color: #6b21a8;
  }

  body.story-phone .story-menu-nav svg {
    flex: none;
    color: #7e22ce;
  }

  body.story-phone .story-menu-foot {
    display: flex;
    flex: none;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0 10px;
    margin: 0 -14px;
    padding: 4px 12px calc(6px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #e9e0f7;
  }

  body.story-phone .story-menu-foot-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 10px;
    border: 0;
    background: transparent;
    color: #6b21a8;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
  }

  /* ---- A story's page (body.story-read; owner, 2026-11-20) ----
     The story is a sheet the width of the screen, as the phone chat's
     transcript is: the bar and the series strip sit on the page's colour,
     and the sheet starts under them with rounded top corners. The text
     column was 252px of a 390px screen (65%: 25px of page padding, 20px on
     the wrapper and 24px in the card, each side); it is 350px (90%). The
     title, the details and the actions line up on the left, each on one row
     where they fit. */
  body.story-phone.story-read,
  body.story-phone.story-gen,
  body.story-phone.story-wide {
    padding: 0;
  }

  body.story-phone.story-read .story-bar,
  body.story-phone.story-gen .story-bar,
  body.story-phone.story-wide .story-bar {
    margin: 0;
  }

  /* On a story's page and the generator the sheet starts right under the
     bar: no line under the bar, no strip of the page between them and no
     edge on the sheet (owner, 2026-11-20: the three read as a small
     separator band). The sheet's rounded corners are what part them. */
  body.story-phone.story-read .story-bar,
  body.story-phone.story-gen .story-bar {
    border-bottom: 0;
  }

  body.story-phone.story-read .story-bar ~ .mx-auto {
    padding: 0 0 40px;
  }

  body.story-phone.story-read .series-breadcrumb {
    margin: 4px 12px 12px;
    padding: 8px 14px;
  }

  body.story-phone.story-read .series-position {
    flex: none;
    white-space: nowrap;
  }

  body.story-phone.story-read .card {
    margin: 0;
    padding: 18px 20px 28px;
    border-radius: 18px 18px 0 0;
    box-shadow: none;
  }

  /* Previous and next story in a series: in the series strip, after
     "Part N of M" (owner, 2026-11-20; they were a row of their own above
     the title, under a strip that already said where you are). The card's
     corner links are the desktop's. */
  body.story-phone.story-read .series-corner-nav {
    display: none;
  }

  /* One row: a long series name gives way with "…" rather than pushing
     the links onto a second line; only where even that would leave the name
     under about 4em (the middle part of a series, both links, a 320px
     screen) do the links take a second line. */
  body.story-phone.story-read .series-breadcrumb {
    flex-wrap: wrap;
    gap: 4px 8px;
  }

  body.story-phone.story-read .series-breadcrumb > * {
    flex: none;
  }

  body.story-phone.story-read .series-breadcrumb > .series-breadcrumb-name {
    flex: 1 1 4em;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.story-phone.story-read .series-breadcrumb > .series-strip-nav {
    display: inline-flex;
    gap: 14px;
    margin-left: auto;
  }

  body.story-phone.story-read .series-strip-link {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    color: #6b21a8;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
  }

  body.story-phone.story-read .card > h1 {
    margin-bottom: 10px;
    padding: 0;
    font-size: 26px;
    line-height: 1.2;
    text-align: left;
  }

  /* Words, date and PDF; then Edit, Rewrite, History, audio. */
  body.story-phone.story-read .card > h1 + div,
  body.story-phone.story-read #story-actions {
    justify-content: flex-start;
    gap: 4px 16px;
    margin-bottom: 10px;
  }

  body.story-phone.story-read #story-actions {
    gap: 2px 20px;
    margin-bottom: 14px;
  }

  body.story-phone.story-read #story-actions .story-link-btn {
    min-height: 36px;
  }

  /* Edit mode's toolbar: the hint gets the row's spare width (it wrapped to
     five lines beside Cancel and Save). */
  body.story-phone.story-read .edit-toolbar {
    gap: 6px;
    padding: 8px 8px 8px 14px;
  }

  body.story-phone.story-read .edit-hint {
    font-size: 14px;
    line-height: 1.35;
  }

  body.story-phone.story-read .story-cancel-btn {
    padding-left: 10px;
    padding-right: 10px;
  }

  body.story-phone.story-read .story-save-btn {
    padding-left: 20px;
    padding-right: 20px;
  }

  /* The first heading of the text follows the actions, not a page top. */
  body.story-phone.story-read .story-content .story-page > :first-child {
    margin-top: 6px;
  }

  /* The page bar and the series links under the sheet: one row each. */
  body.story-phone.story-read #page-nav {
    margin: 16px 12px 0;
    padding: 8px;
  }

  body.story-phone.story-read .page-nav-btn {
    padding: 10px 14px;
    font-size: 15px;
    white-space: nowrap;
  }

  body.story-phone.story-read #page-indicator {
    font-size: 14px;
    white-space: nowrap;
  }

  body.story-phone.story-read .series-navigation {
    margin: 16px 12px 0;
    gap: 10px;
    padding: 0;
  }

  body.story-phone.story-read .series-nav-btn {
    padding: 12px 10px;
  }

  body.story-phone.story-read #prompt-details {
    margin: 24px 12px 0;
  }

  /* ---- The library and the story sign-in prompt (body.story-wide; owner,
     2026-11-20: "the width should be much higher there") ----
     The cards keep their own shape; the page gives them the screen less
     12px a side (they had 300px of a 390px screen, 45px a side). */
  body.story-phone.story-wide .story-bar ~ .mx-auto {
    padding: 14px 12px 40px;
  }

  /* The sign-in card's own 40px sides. */
  body.story-phone.story-wide .card {
    padding-left: 20px;
    padding-right: 20px;
  }

  /* ---- The Story Generator (body.story-gen) ----
     A sheet the width of the screen under the bar, as a story's page is,
     and at least as tall as the rest of the screen. */
  body.story-phone.story-gen .story-bar ~ .mx-auto {
    padding: 0;
  }

  body.story-phone.story-gen .error-box {
    margin: 4px 12px 12px;
  }

  body.story-phone.story-gen .card {
    margin: 0 0 12px;
    padding: 18px 20px 28px;
    border-radius: 18px 18px 0 0;
    box-shadow: none;
  }

  /* 52px: the bar. */
  body.story-phone.story-gen #story-form {
    margin-bottom: 0;
    min-height: calc(100vh - 52px);
    min-height: calc(100dvh - 52px);
  }

  /* The example prompt: its first two lines, until "Show more" (the whole
     text put Write Story two screens down). */
  body.story-phone.story-gen #example-prompt:not(.example-open) {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }

  body.story-phone.story-gen .story-example-toggle {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0;
    border: 0;
    background: transparent;
    color: #6b21a8;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
  }

  /* Hidden when the example fits in its two lines (stories.html
     updateExampleToggle); display above would otherwise beat [hidden]. */
  body.story-phone.story-gen .story-example-toggle[hidden] {
    display: none;
  }

  /* The length slider had a fixed 220px. */
  body.story-phone.story-gen #story-form div:has(> #story-length-slider) {
    width: 100% !important;
    max-width: 340px;
  }

  /* Write Story: one line, the sheet's width (96px of padding a side wrapped
     it to three lines); its template sets a 44px top margin inline. */
  body.story-phone.story-gen .generate-btn {
    width: 100%;
    margin-top: 28px !important;
    padding: 16px 20px;
  }

  /* "Writing Your Story": the same surface as the form it replaces (it was
     a pink card that stopped part-way down the page; owner, 2026-11-20).
     Its heading and progress bar are as they were. Inline background in
     the template, hence !important. */
  body.story-phone.story-gen #progress-container {
    min-height: calc(100vh - 52px);
    min-height: calc(100dvh - 52px);
    margin-bottom: 0;
    padding-top: 18px !important;
    background: inherit !important;
  }

  body.story-phone.story-gen #progress-container .video-player-container {
    border-radius: 14px;
  }

  body.story-phone.story-gen .story-result-btn {
    margin: 0 10px 10px 0;
  }

  /* ---- One surface on the story pages (owner, 2026-11-20: "having the
     separate color for the header is not good"; then the library's page
     aligned with the chat's, dark and light) ----
     The bar had the page's colour and the sheet under it another. The page
     is the sheet's colour, as the phone chat's is (chat_phone.css): white
     here, and the chat's near-black in dark (dark_extra.css). The library's
     pastel cards and the sign-in card sit on it. <html> too: iPhone Safari
     tints the strips around its status bar and toolbar from the page's
     background. */
  body.story-phone.story-read,
  body.story-phone.story-gen,
  body.story-phone.story-wide {
    background: #ffffff;
  }

  /* Separate: a browser without :has() drops only this rule. */
  html:has(> body.story-phone.story-read),
  html:has(> body.story-phone.story-gen),
  html:has(> body.story-phone.story-wide) {
    background: #ffffff;
  }

  /* The page bar and the series links under the story have the old page's
     colour as their own background: invisible on that page, pale panels on
     a white one. */
  body.story-phone.story-read #page-nav,
  body.story-phone.story-read .series-navigation {
    background: transparent;
  }

  /* Last in this block: scripts/build_dark_css.py reads no rule that
     follows a nested @media. */
  @media (prefers-reduced-motion: reduce) {
    body.story-phone .story-menu,
    body.story-phone.story-menu-open .story-menu {
      transition: none;
    }
  }
}

/* Narrow phones: the title a size smaller, so it keeps clear of Support. */
@media (max-width: 374px) {
  body.story-phone .story-bar-title {
    font-size: 16px;
  }
}

/* The menu panel's copy of Support exists for the narrow case below only. */
body.story-phone .story-menu-foot a.story-menu-support {
  display: none;
}

/* Below 320px (a large browser zoom) the title and Support cannot share the
   row with the menu button: Support moves into the menu panel, as it does in
   the chat at that width. */
@media (max-width: 319px) {
  body.story-phone .story-bar-support {
    display: none;
  }

  body.story-phone .story-menu-foot a.story-menu-support {
    display: inline-flex;
    /* .support-link's colour (output.css). */
    color: #c42a63;
  }
}
