/* Poetry section (feature 010-poetry-section-mvp).
   Reuses ../css/styles.css tokens (--bg, --surface, --ink, --soft, --accent,
   --line) — never modifies ../css/styles.css itself. Typography (feature
   020): every text element uses Newsreader, one face for the whole page —
   the sole intentional exception is the monospace "wordmark" box treatment
   (site mark in the topbar, "DA." mark in the footer), deliberately
   mirroring ../css/styles.css's own .nav-logo mark rather than reading in
   Newsreader, since that mark's whole identity is being a documentary
   monospace box distinct from body copy. */

.writing-page {
  background: var(--bg);
  color: var(--ink);
  font-family: "Newsreader", Georgia, "Times New Roman", serif;
  line-height: 1.6;
  min-height: 100vh;
}

.writing-wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.writing-topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(7, 10, 8, 0.96);
  backdrop-filter: saturate(140%) blur(6px);
  border-bottom: 4px solid var(--line);
}

.writing-topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.75rem;
}

/* Site mark (feature 020): a single-row topbar matching ../css/styles.css's
   .nav-inner pattern — boxed monospace wordmark, nav inline beside it,
   right-aligned item pushed to the far right via margin-left: auto below
   (three flex children here vs. .nav-inner's two, since the writing site's
   nav and language switcher are separate elements — space-between would
   spread all three apart evenly instead of grouping the mark with the nav
   on the left). */
.writing-site-mark {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0.3rem 0.55rem;
  white-space: nowrap;
  margin: 0;
  flex: 0 0 auto;
}

/* Nav toggle (feature 022): hidden here, shown only inside the
   @media (max-width: 720px) block below -- mirrors ../css/styles.css's
   .nav-toggle/.nav-toggle-bar exactly (values, not the class itself; same
   "mirror, don't share classes across the two files" precedent as the
   site-mark/footer-mark treatments from feature 020). */
.writing-nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  background: transparent;
  border: 1px solid var(--line);
  cursor: pointer;
  padding: 0;
  flex: 0 0 auto;
}

.writing-nav-toggle-bar {
  display: block;
  width: 20px;
  height: 2px;
  margin: 0 auto;
  background: var(--ink);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.writing-nav-toggle[aria-expanded="true"] .writing-nav-toggle-bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.writing-nav-toggle[aria-expanded="true"] .writing-nav-toggle-bar:nth-child(2) { opacity: 0; }
.writing-nav-toggle[aria-expanded="true"] .writing-nav-toggle-bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.writing-language-switcher-slot {
  margin-left: auto;
  flex: 0 0 auto;
}

.writing-language-switcher {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
}

.writing-language-current {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: "Newsreader", Georgia, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: 0.03em;
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
}

.writing-language-current:hover,
.writing-language-current:focus-visible {
  border-color: var(--accent);
}

.writing-language-menu {
  position: absolute;
  top: calc(100% + 0.25rem);
  right: 0;
  list-style: none;
  margin: 0;
  padding: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  min-width: 100%;
  z-index: 101;
}

.writing-language-menu button {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--soft);
  font-family: "Newsreader", Georgia, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: 0.03em;
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  text-align: left;
  cursor: pointer;
}

.writing-language-menu button:hover,
.writing-language-menu button:focus-visible {
  color: var(--ink);
  background: var(--bg);
}

.writing-section-nav {
  flex: 1 1 auto;
  /* A flex item's automatic minimum size defaults to a content-based
     minimum (its min-content size), not 0 -- without overriding it here,
     this item can't shrink below that floor no matter how narrow the row
     gets, so the .writing-section-nav ul's own flex-wrap never actually
     gets a chance to engage; the whole topbar row just grows wider than
     the viewport instead. Found 2026-08-20 verifying feature 020 at
     360px: scrollWidth 598px against a 360px viewport before this fix. */
  min-width: 0;
}

.writing-section-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
}

.writing-section-nav a {
  display: inline-block;
  padding: 0.5rem 0;
  color: var(--soft);
  text-decoration: none;
  font-family: "Newsreader", Georgia, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-size: 1rem;
  border-bottom: 2px solid transparent;
}

.writing-section-nav a:hover,
.writing-section-nav a:focus-visible {
  color: var(--ink);
}

.writing-section-nav li[aria-current="true"] a {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.writing-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 2rem;
  align-items: start;
}

.writing-sidebar {
  border-right: 1px solid var(--line);
  padding-right: 1.5rem;
  position: sticky;
  top: 2rem;
}

.writing-sidebar h2 {
  font-family: "Newsreader", Georgia, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.95rem;
  color: var(--soft);
  margin: 0 0 1rem;
}

.writing-theme-accordion {
  list-style: none;
  margin: 0;
  padding: 0;
}

.writing-theme-group {
  margin: 0 0 0.75rem;
}

.writing-theme-toggle {
  display: block;
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  font-family: "Newsreader", Georgia, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-size: 0.9rem;
  color: var(--soft);
  padding: 0.3rem 0;
}

.writing-theme-toggle::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  color: var(--line);
}

.writing-theme-toggle:hover,
.writing-theme-toggle:focus-visible {
  color: var(--ink);
}

.writing-theme-group[data-expanded="true"] .writing-theme-toggle {
  color: var(--accent);
}

.writing-theme-group[data-expanded="true"] .writing-theme-toggle::before {
  content: "▾";
  color: var(--accent);
}

.writing-theme-group .writing-glossary {
  display: none;
  margin: 0.4rem 0 0 1.4rem;
}

.writing-theme-group[data-expanded="true"] .writing-glossary {
  display: block;
}

.writing-glossary {
  list-style: none;
  margin: 0;
  padding: 0;
}

.writing-glossary li {
  margin: 0 0 0.5rem;
}

.writing-glossary button {
  background: none;
  border: none;
  color: var(--soft);
  font: inherit;
  text-align: left;
  cursor: pointer;
  padding: 0.15rem 0;
}

.writing-glossary button:hover,
.writing-glossary button:focus-visible {
  color: var(--accent);
}

.writing-glossary li[aria-current="true"] button {
  color: var(--ink);
  font-weight: 600;
  border-bottom: 2px solid var(--accent);
}

.writing-reading-pane h1 {
  font-family: "Newsreader", Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  margin: 0 0 0.5rem;
}

.writing-original-language {
  color: var(--soft);
  font-size: 0.85rem;
  margin: 0 0 1.5rem;
}

.writing-original-language[hidden] {
  display: none;
}

.writing-poem-body {
  white-space: pre-wrap;
  font-size: 1.05rem;
  max-width: 42em;
  margin: 0 0 2rem;
}

.writing-poem-body--columns {
  column-width: 20em;
  column-gap: 2rem;
  max-width: none;
}

/* Clepsidra/hourglass shape (feature 021), "Clipa" only (@shape: hourglass).
   Alignment only -- the taper itself comes entirely from the poem's own
   already-varying line lengths, preserved across its translations. */
.writing-poem-body--hourglass {
  text-align: center;
}

.writing-quote-stack {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.writing-quote-entry {
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--line);
}

.writing-quote-entry:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.writing-quote-entry h2 {
  font-family: "Newsreader", Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: clamp(1.4rem, 3vw, 1.9rem);
  margin: 0 0 0.4rem;
}

.writing-quote-entry .writing-original-language {
  margin: 0 0 0.75rem;
}

.writing-quote-entry .writing-poem-body {
  margin: 0;
}

/* Feature 028: a lighter secondary treatment than .writing-controls
   button's filled accent style, since this sits inline after a quote's
   body rather than as a primary reading-navigation action. */
.writing-quote-entry .writing-copy-link {
  display: inline-block;
  margin-top: 0.75rem;
  background: none;
  border: 1px solid var(--line);
  color: var(--soft);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
}

.writing-quote-entry .writing-copy-link:hover,
.writing-quote-entry .writing-copy-link:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
}

.writing-controls {
  display: flex;
  gap: 0.75rem;
}

.writing-controls button {
  background: var(--accent);
  color: var(--bg);
  border: none;
  font-family: inherit;
  font-weight: 700;
  padding: 0.6rem 1.1rem;
  cursor: pointer;
}

.writing-controls button:hover,
.writing-controls button:focus-visible {
  background: var(--ink);
}

.writing-empty {
  color: var(--soft);
  font-style: italic;
}

.writing-search-input {
  display: block;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  margin: 0 0 1rem;
  box-sizing: border-box;
}

.writing-search-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.writing-search-empty {
  color: var(--soft);
  font-style: italic;
  font-size: 0.9rem;
  margin: 0.5rem 0;
}

/* Search dropdown (feature 027): a normal block element in the document
   flow, not position:absolute -- it pushes the accordion/chip content
   below it down while open, rather than overlaying it. Simpler and safer
   than an overlay given feature 025's overflow-clipping lesson (an
   absolutely-positioned dropdown would need its own careful positioning
   context to avoid the exact "wide/tall content forces an ancestor to
   grow, or gets clipped by one" trap that shipped as a bug then). The
   trade-off -- content shifting down briefly while browsing -- is a
   reasonable one for a no-build-step static site. */
.writing-search-dropdown {
  list-style: none;
  margin: -0.75rem 0 1rem;
  padding: 0;
  max-height: 16rem;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
}

.writing-search-dropdown li[role="option"] {
  padding: 0.5rem 0.75rem;
  color: var(--soft);
  cursor: pointer;
  font-size: 0.9rem;
}

.writing-search-dropdown li[role="option"]:hover,
.writing-search-dropdown li[role="option"].writing-search-dropdown-option--active {
  background: var(--bg);
  color: var(--accent);
}

.writing-search-dropdown li.writing-search-empty {
  cursor: default;
  padding: 0.5rem 0.75rem;
  margin: 0;
}

.writing-search-dropdown li.writing-search-empty:hover {
  background: none;
  color: var(--soft);
}

.writing-interpretation-toggle {
  display: inline-block;
  background: none;
  border: 1px solid var(--line);
  color: var(--soft);
  font-family: inherit;
  font-weight: 700;
  padding: 0.5rem 1rem;
  margin: 0 0 1rem;
  cursor: pointer;
}

.writing-interpretation-toggle:hover,
.writing-interpretation-toggle:focus-visible {
  color: var(--ink);
  border-color: var(--accent);
}

.writing-interpretation-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  white-space: pre-wrap;
  font-size: 0.9rem;
  font-style: italic;
  padding: 1rem 1.25rem;
  margin: 0 0 1.5rem;
}

.writing-footer {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 2.5rem;
  color: var(--soft);
  font-size: 0.85rem;
  border-top: 1px solid var(--line);
}

/* Owner unlock (feature 019): the footer mark itself is the only
   affordance -- no icon, no label, nothing that hints a control lives
   here, per FR-005 (unlisted). Clicking it reveals a minimal inline
   passphrase field in place of the plain mark. Styled as the "DA." wordmark
   (feature 020), mirroring ../css/styles.css's .nav-logo exactly: box,
   monospace, accent-colored period, matching hover. */
.writing-footer-name {
  cursor: pointer;
  display: inline-block;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0.3rem 0.55rem;
}

.writing-footer-name:hover,
.writing-footer-name:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
}

.writing-footer-mark-dot {
  color: var(--accent);
}

.writing-footer-name:hover .writing-footer-mark-dot,
.writing-footer-name:focus-visible .writing-footer-mark-dot {
  color: inherit;
}

/* :not([hidden]) is required here, not just .writing-owner-unlock -- an
   author stylesheet's own `display` declaration always wins over the
   browser's UA-stylesheet `[hidden] { display: none }` default, so a bare
   `display: flex` on this class silently defeated the `hidden` attribute
   entirely: the passphrase field was visibly showing to every visitor by
   default in production, not actually hidden until clicked as FR-005
   (feature 019) requires. Found 2026-08-20 while verifying feature 020. */
.writing-owner-unlock:not([hidden]) {
  display: flex;
  gap: 0.5rem;
  max-width: 16rem;
  margin: 0.5rem 0 0;
}

.writing-owner-unlock-input {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.6rem;
  box-sizing: border-box;
}

.writing-owner-unlock-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.writing-owner-unlock-submit {
  background: var(--accent);
  color: var(--bg);
  border: none;
  font-family: inherit;
  font-weight: 700;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
}

.writing-owner-unlock-submit:hover,
.writing-owner-unlock-submit:focus-visible {
  background: var(--ink);
}

.writing-owner-unlock-status {
  font-size: 0.8rem;
  font-style: italic;
  margin: 0.5rem 0 0;
}

@media (max-width: 375px) {
  .writing-owner-unlock {
    max-width: 100%;
  }
}

@media (max-width: 720px) {
  .writing-layout {
    grid-template-columns: 1fr;
  }

  .writing-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding-right: 0;
    padding-bottom: 1.5rem;
    position: static;
    /* Feature 026: a grid item's default min-width is content-based
       (auto), so without this the wide, unwrapped .writing-theme-chips
       row (feature 025) forces the whole sidebar column -- and the page
       along with it -- to grow instead of scrolling within its own box. */
    min-width: 0;
  }

  .writing-topbar-inner {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
    row-gap: 0.6rem;
  }

  .writing-section-nav ul {
    gap: 0.2rem 0.9rem;
  }

  /* Nav toggle (feature 022): the hamburger only exists at this
     breakpoint; above it .writing-nav-toggle stays display:none from its
     base rule and the two selectors below never apply, so desktop is
     untouched by construction (FR-003). */
  .writing-nav-toggle {
    display: flex;
  }

  .writing-section-nav ul {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 0;
  }

  /* The nav itself (not just its <ul>) needs to drop to its own full-width
     row once open, mirroring ../css/styles.css's .nav-menu
     { width:100%; order:3 }. Scoped to --open only, not the base
     .writing-section-nav rule: forcing flex-basis:100% unconditionally
     would reserve a full empty row (and its row-gap) even while collapsed,
     since the nav element itself has no visible height once its <ul> is
     display:none. Without this rule at all, the opened list gets squeezed
     into whatever space is left beside the toggle/language-switcher on
     .writing-topbar-inner's wrapped flex row instead of its own row (found
     via pre-merge review, 2026-08-20: the language switcher badge visibly
     shared a row with the first couple of nav links). order: 5 keeps it
     last regardless of exact DOM position among the row's other children. */
  .writing-section-nav--open {
    flex: 1 1 100%;
    order: 5;
  }

  .writing-section-nav--open ul {
    display: flex;
  }

  /* Sidebar collapse (feature 022): same reasoning -- only reachable at
     this breakpoint, so the [data-expanded] attribute the JS always sets
     (regardless of viewport) is simply never read outside it. */
  .writing-sidebar-body {
    display: none;
  }

  .writing-sidebar[data-expanded="true"] .writing-sidebar-body {
    display: block;
  }

  .writing-sidebar h2 {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .writing-sidebar h2::after {
    content: "▸";
    color: var(--line);
    margin-left: 0.5rem;
  }

  .writing-sidebar[data-expanded="true"] h2::after {
    content: "▾";
    color: var(--accent);
  }

  /* Theme chips (feature 025): only reachable at this breakpoint, since
     renderThemedAccordionCollection's buildMobileNav() (writing.js) is
     itself gated on the same 720px matchMedia query — the desktop
     .writing-theme-accordion/.writing-theme-group rules above are
     untouched and never see this markup. */
  .writing-theme-nav {
    margin-top: 0.25rem;
  }

  .writing-theme-chips {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.5rem;
    list-style: none;
    margin: 0 0 0.75rem;
    padding: 0 0 0.5rem;
  }

  .writing-theme-chip {
    flex: 0 0 auto;
    margin: 0;
  }

  .writing-theme-chip .writing-theme-toggle {
    display: inline-block;
    width: auto;
    white-space: nowrap;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.35rem 0.9rem;
    font-size: 0.8rem;
  }

  .writing-theme-chip .writing-theme-toggle::before {
    content: none;
  }

  .writing-theme-chip[data-active="true"] .writing-theme-toggle {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
  }

  .writing-theme-panels {
    margin-top: 0.5rem;
  }
}
