/* WorldWeaver — base styles. Warm, readable, "old terminal meets paperback". */
:root {
  --ww-bg: #15130f;
  --ww-panel: #1f1c16;
  --ww-ink: #e8e2d4;
  --ww-muted: #9a9182;
  --ww-accent: #c9a14a;
  --ww-action: #8fb4c4;
  --ww-error: #d98b7a;
  --ww-border: #34302700;
}

/* Themes — override the palette on the body class (cascades to all content). */
body.ww-theme-midnight {
  --ww-bg: #0d1320; --ww-panel: #151f33; --ww-ink: #dce6f5; --ww-muted: #8595b3;
  --ww-accent: #5b8fd6; --ww-action: #8fb6e6; --ww-error: #e0917f; --ww-border: #20304d;
}
body.ww-theme-violet {
  --ww-bg: #1a1a2e; --ww-panel: #23233f; --ww-ink: #e0e0e0; --ww-muted: #8b8fa3;
  --ww-accent: #a78bfa; --ww-action: #c4b5fd; --ww-error: #f87171; --ww-border: #2e2e4d;
}
body.ww-theme-forest {
  --ww-bg: #0e1611; --ww-panel: #16221a; --ww-ink: #e2ece4; --ww-muted: #8aa093;
  --ww-accent: #5fb585; --ww-action: #8fd0a3; --ww-error: #d98b7a; --ww-border: #21372a;
}
body.ww-theme-slate {
  --ww-bg: #16181c; --ww-panel: #22262d; --ww-ink: #e4e7ec; --ww-muted: #969ca6;
  --ww-accent: #9fb3cc; --ww-action: #8fb4c4; --ww-error: #d98b7a; --ww-border: #2c313a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ww-bg);
  color: var(--ww-ink);
  font: 17px/1.65 Georgia, "Iowan Old Style", "Palatino Linotype", serif;
}

a { color: var(--ww-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.ww-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.7rem 1.2rem;
  background: var(--ww-panel);
  border-bottom: 1px solid #2b2820;
  font-family: system-ui, sans-serif; font-size: 0.95rem;
}
.ww-nav nav { display: flex; align-items: center; gap: 1rem; }
.ww-brand { font-weight: 700; letter-spacing: 0.5px; color: var(--ww-accent); font-size: 1.1rem; }
.ww-user { color: var(--ww-muted); }
/* Nav shows text by default; on narrow screens it swaps to icons to fit. */
.ww-nav-ico { display: none; }
@media (max-width: 560px) {
  .ww-nav { padding: 0.6rem 0.8rem; }
  .ww-nav nav { gap: 1.1rem; }
  /* Nav LINKS swap to icons; the brand keeps its full text. */
  .ww-nav nav .ww-nav-txt { display: none; }
  .ww-nav nav .ww-nav-ico { display: inline; font-size: 1.15rem; }
}
@media (max-width: 360px) {
  /* Only when truly cramped, shorten the brand to "WW". */
  .ww-brand .ww-nav-txt { display: none; }
  .ww-brand .ww-nav-ico { display: inline; font-weight: 700; }
}

.ww-main { max-width: 760px; margin: 0 auto; padding: 1.5rem 1.2rem 6rem; }

.ww-card {
  background: var(--ww-panel);
  border: 1px solid #2b2820; border-radius: 10px;
  padding: 1.2rem 1.4rem; margin-bottom: 1.4rem;
}
.ww-narrow { max-width: 420px; margin: 3rem auto; }
.ww-muted { color: var(--ww-muted); font-size: 0.92rem; }

h1, h2 { font-family: system-ui, sans-serif; font-weight: 650; }
h1 { margin-top: 0; }

label { display: block; margin: 0.8rem 0; font-family: system-ui, sans-serif; font-size: 0.9rem; color: var(--ww-muted); }
input, textarea, select {
  display: block; width: 100%; margin-top: 0.3rem;
  background: #100e0a; color: var(--ww-ink);
  border: 1px solid #3a352a; border-radius: 6px;
  padding: 0.6rem 0.7rem; font: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--ww-accent); box-shadow: 0 0 0 2px rgba(201,161,74,0.18); }
/* Radios/checkboxes are NOT full-width blocks (the rule above is for text fields). */
input[type="radio"], input[type="checkbox"] {
  display: inline-block; width: auto; margin: 0 0.5rem 0 0; padding: 0;
  vertical-align: middle; accent-color: var(--ww-accent); cursor: pointer;
}

/* Custom-styled select with a drawn caret (native dark selects look rough). */
select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  cursor: pointer; padding-right: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23c9a14a' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.85rem center; background-size: 11px;
}
select:hover { border-color: #4a4436; }
select option { background: #1a1610; color: var(--ww-ink); }
.ww-btn-danger { background: transparent; color: var(--ww-error); border: 1px solid #5a2e26; }
.ww-btn-danger:hover { background: var(--ww-error); color: #1a1710; }

.ww-btn {
  font-family: system-ui, sans-serif; font-size: 0.95rem; cursor: pointer;
  background: var(--ww-accent); color: #1a1710; border: 0; border-radius: 6px;
  padding: 0.55rem 1.2rem; font-weight: 600;
}
.ww-btn:disabled { opacity: 0.5; cursor: default; }

.ww-flash { background: #2a2a18; border-left: 3px solid var(--ww-accent); padding: 0.6rem 0.9rem; margin-bottom: 1rem; border-radius: 4px; }
.ww-flash-error { background: #2e1c18; border-left-color: var(--ww-error); }

/* Home top: the two creation cards side by side, stacking on narrow screens.
   On desktop the pair breaks out of the 760px .ww-main column to use the full
   screen width (centered on the viewport via the 50% + translate trick). */
.ww-home-top { display: grid; gap: 1.4rem; align-items: start; margin-bottom: 1.4rem; }
.ww-home-top .ww-card { margin-bottom: 0; }
@media (min-width: 52rem) {
  .ww-home-top {
    grid-template-columns: 1fr 1fr;
    width: min(1400px, calc(100vw - 3rem));
    margin-left: 50%; transform: translateX(-50%);
  }
}

/* The two creation cards collapse to just their headings for returning players
   (expanded automatically when the account has no stories yet). The heading is
   the click target; the triangle shows the state. */
.ww-home-fold summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 0.55rem; }
.ww-home-fold summary::-webkit-details-marker { display: none; }
.ww-home-fold summary::before { content: '▸'; color: var(--ww-accent); font-size: 1.1rem; line-height: 1; }
.ww-home-fold[open] summary::before { content: '▾'; }
.ww-home-fold summary h1 { margin: 0; display: inline; }
.ww-home-fold summary:hover h1 { color: var(--ww-accent); }
.ww-home-fold[open] summary { margin-bottom: 0.6rem; }

.ww-story-list { list-style: none; padding: 0; margin: 0; }
/* Each story is its own sub-card: title/actions row, then an optional body row
   (featured thumbnail + expandable summary snippet). */
.ww-story-list li {
  background: rgba(0, 0, 0, 0.14); border: 1px solid #2b2820; border-radius: 8px;
  padding: 0.6rem 0.9rem; margin-bottom: 0.7rem;
}
.ww-story-row {
  position: relative;
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem 1rem; flex-wrap: wrap;
}
/* Body row: drops to its own full-width line under the title/actions (same
   flex-basis trick as the rename form). The thumbnail floats so the summary
   text wraps around it. */
.ww-story-body { flex-basis: 100%; margin-top: 0.45rem; }
.ww-story-body::after { content: ''; display: block; clear: both; }
/* Featured thumbnail: gallery-tile sized. Desktop floats it right with the
   summary wrapping around; mobile shows it full-width above the text (the
   same size a mobile gallery tile renders at). */
.ww-story-thumb {
  float: right; width: 150px; height: 150px; object-fit: cover;
  margin: 0.1rem 0 0.4rem 0.9rem;
  border-radius: 6px; border: 1px solid #2b2820;
}
@media (max-width: 560px) {
  .ww-story-thumb { float: none; display: block; width: 100%; height: auto; margin: 0 0 0.5rem; }
}
.ww-story-summary { min-width: 0; font-size: 0.88rem; color: var(--ww-muted); }
.ww-story-summary summary { cursor: pointer; list-style: none; }
.ww-story-summary summary::-webkit-details-marker { display: none; }
.ww-story-summary summary:hover { color: var(--ww-ink); }
/* Open: the snippet is replaced by the full text; the summary line becomes a
   small "less" affordance to collapse again. */
.ww-story-summary[open] .ww-snip { display: none; }
.ww-story-summary[open] summary::after { content: '▴ less'; font-size: 0.78rem; }
.ww-story-full p { margin: 0 0 0.55em; }
.ww-story-full p:last-child { margin-bottom: 0.2em; }
/* The title span keeps clear of the pinned ☰ button so long titles wrap under it. */
.ww-story-main { min-width: 0; padding-right: 2.4rem; }
/* Story-actions hamburger: one ☰ button firmly affixed to the card's top-right;
   clicking drops the former action buttons down as a vertical menu. */
.ww-story-menu { position: absolute; top: 0.45rem; right: 0.55rem; }
.ww-story-menu-btn { line-height: 1.1; }
.ww-story-menu-items {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 40;
  display: flex; flex-direction: column; gap: 0.3rem; min-width: 8.5rem;
  background: var(--ww-panel); border: 1px solid #2b2820; border-radius: 8px;
  padding: 0.4rem; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
.ww-story-menu-items[hidden] { display: none; }
.ww-story-menu-items .ww-btn { width: 100%; justify-content: flex-start; text-align: left; }
.ww-story-menu-items button.ww-btn { display: flex; align-items: center; }
.ww-story-menu-items form { display: flex; }
.ww-story-menu-items form .ww-btn { flex: 1; }
.ww-inline { margin: 0; }
.ww-story-row .ww-btn-danger { opacity: 0.55; }
.ww-story-row:hover .ww-btn-danger { opacity: 1; }
/* Inline rename: hidden until the Rename button reveals it (the [hidden] attribute
   must win, so only style display when it's NOT hidden), then drops to its own
   full-width line under the story row. */
.ww-rename-form { flex-basis: 100%; gap: 0.4rem; align-items: center; margin: 0.4rem 0 0; }
.ww-rename-form:not([hidden]) { display: flex; }
.ww-rename-form input[name=title] { margin: 0; flex: 1; min-width: 0; }
/* Inline "Share" panel (mirrors the rename form: full-width, revealed on toggle). */
.ww-share-form { flex-basis: 100%; margin: 0.4rem 0 0; }
.ww-share-form[hidden] { display: none; }
.ww-share-scope { border: 1px solid var(--ww-line, rgba(0,0,0,.15)); border-radius: 6px; padding: 0.5rem 0.7rem; margin: 0 0 0.5rem; }
.ww-share-scope legend { font-size: 0.85rem; padding: 0 0.3rem; color: var(--ww-muted); }
.ww-share-users { margin: 0.2rem 0 0.5rem 1.6rem; display: flex; flex-direction: column; gap: 0.25rem; max-height: 12rem; overflow-y: auto; }
.ww-share-users[hidden] { display: none; }
.ww-checkline { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; color: var(--ww-ink); }
.ww-checkline input { flex: 0 0 auto; }
/* (Story-row stacking is no longer breakpoint-specific: the actions row is
   always full-width and wrapping — see .ww-story-actions above.) */

/* Image gallery: responsive grid of square thumbnails, each linking to its segment. */
.ww-gallery {
  list-style: none; padding: 0; margin: 1rem 0 0;
  display: grid; gap: 0.7rem;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.ww-gallery-item { margin: 0; }
.ww-gallery-link {
  display: block; position: relative; border-radius: 8px; overflow: hidden;
  border: 1px solid #2b2820; background: var(--ww-panel);
}
.ww-gallery-img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover; }
.ww-gallery-cap {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column; gap: 0.05rem;
  padding: 1.1rem 0.55rem 0.45rem; color: #fff;
  font-family: system-ui, sans-serif;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
}
.ww-gallery-title { font-size: 0.8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ww-gallery-seq { font-size: 0.7rem; opacity: 0.85; }
.ww-gallery-link:hover { border-color: var(--ww-accent); }
.ww-gallery-link:hover .ww-gallery-img { filter: brightness(1.06); }
@media (max-width: 560px) {
  /* Single column on mobile, so each illustration shows large. */
  .ww-gallery { grid-template-columns: 1fr; gap: 0.7rem; }
}

/* Play view */
.ww-title { font-size: 1.4rem; margin-bottom: 1rem; color: var(--ww-accent); }
.ww-transcript { }
.ww-turn { margin-bottom: 1.4rem; }
/* Briefly highlight the segment a Gallery deep-link (#seg-N) lands on. */
.ww-turn.ww-seg-target { animation: ww-seg-pulse 2.2s ease-out both; border-radius: 6px; }
@keyframes ww-seg-pulse {
  0%, 12% { background: rgba(201, 161, 74, 0.22); }
  100% { background: transparent; }
}
.ww-action {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--ww-action); margin: 1.2rem 0 0.6rem;
  font-size: 0.95rem;
}
.ww-para { margin: 0 0 0.9rem; }

/* Admin debug overlay: the turn's clock + place, small and out of the way. */
.ww-turn-meta {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--ww-muted);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  margin: 1.1rem 0 -0.8rem;
  opacity: 0.75;
}

.ww-error { color: var(--ww-error); }

/* Edit segment text */
.ww-edit {
  font-family: system-ui, sans-serif; font-size: 0.76rem; cursor: pointer;
  background: transparent; color: var(--ww-muted); border: 1px solid #2f2b23;
  border-radius: 5px; padding: 0.15rem 0.55rem; margin-top: 0.2rem; opacity: 0.65;
}
.ww-edit:hover { color: var(--ww-accent); border-color: var(--ww-accent); opacity: 1; }
.ww-editing > .ww-edit, .ww-editing .ww-prose { display: none; }
.ww-editor { margin: 0.4rem 0; }
.ww-edit-area { width: 100%; min-height: 9rem; font: inherit; line-height: 1.55; resize: vertical; }
.ww-edit-bar { display: flex; gap: 0.5rem; margin-top: 0.4rem; }

/* Admin player-traits editor */
.ww-trait-row { display: flex; align-items: center; gap: 0.5rem; margin: 0.3rem 0; flex-wrap: wrap; }
.ww-trait-edit { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 0; }
.ww-trait-key { font-family: system-ui, sans-serif; font-size: 0.85rem; color: var(--ww-muted); min-width: 6rem; }
.ww-trait-edit input { margin-top: 0; flex: 1; }
.ww-trait-add { display: flex; align-items: end; gap: 0.5rem; margin-top: 0.6rem; flex-wrap: wrap; }
.ww-trait-add label { margin: 0; }

.ww-trait-rescan { margin-top: 0.8rem; padding-top: 0.6rem; border-top: 1px solid var(--ww-border, #4444); }
.ww-rescan-debug {
  margin-top: 0.5rem; padding: 0.5rem 0.6rem; max-height: 16rem; overflow: auto;
  font-size: 0.8rem; line-height: 1.35; white-space: pre-wrap; word-break: break-word;
  background: rgba(0,0,0,0.18); border-radius: 4px;
}

/* Turn-in-progress: a fill sweeps across the action input (over the typed text)
   while the turn generates — same visual language as the Illustrate button,
   with no layout shift. The fill is a hard-stop gradient at --ww-progress. */
.ww-prompt input.ww-busy, .ww-prompt textarea.ww-busy {
  background-image:
    linear-gradient(90deg,
      rgba(201,161,74,0.30) 0,
      rgba(201,161,74,0.30) var(--ww-progress, 4%),
      transparent var(--ww-progress, 4%));
  background-repeat: no-repeat;
  transition: background 0.15s linear;
  cursor: progress;
}
/* Brand-new story: the opening narration is still generating — the placeholder
   pulses and the prompt is disabled until the first story text appears. */
.ww-opening-pending .ww-para { animation: ww-pulse 1.5s ease-in-out infinite; }
@keyframes ww-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
.ww-prompt textarea:disabled { opacity: 0.5; cursor: progress; }

/* Bottom margin leaves room for the feature star, which hangs just below the
   image's bottom-right corner. */
.ww-image-wrap { position: relative; margin: 0.6rem 0 1.7rem; display: inline-block; }
.ww-illus { display: block; max-width: 100%; border-radius: 8px; border: 1px solid #2b2820; }
.ww-image-del {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; line-height: 22px;
  border-radius: 50%; border: 0; cursor: pointer; font-size: 16px;
  background: rgba(20,18,14,0.7); color: #e8e2d4;
}
.ww-image-del:hover { background: var(--ww-error); color: #1a1710; }
/* Feature star: sits just below the bottom-right corner of the illustration.
   Starring makes this image the story's home-card thumbnail; starring the
   featured one again clears it. */
.ww-image-star {
  position: absolute; right: 2px; bottom: -1.6rem;
  background: none; border: 0; cursor: pointer; padding: 0 0.2rem;
  font-size: 1.05rem; line-height: 1.4; color: var(--ww-muted); opacity: 0.55;
}
.ww-image-star::before { content: '☆'; }                        /* outline until featured */
.ww-image-star.is-featured::before { content: '★'; }
.ww-image-star:hover { opacity: 1; color: var(--ww-accent); }
.ww-image-star.is-featured { opacity: 1; color: var(--ww-accent); text-shadow: 0 0 6px rgba(201,161,74,0.55); }
.ww-image-star:disabled { cursor: default; opacity: 0.3; }
.ww-illustrate {
  position: relative; overflow: hidden;
  font-family: system-ui, sans-serif; font-size: 0.8rem; cursor: pointer;
  background: transparent; color: var(--ww-muted); border: 1px solid #3a352a;
  border-radius: 5px; padding: 0.25rem 0.7rem; margin-top: 0.3rem;
}
.ww-illustrate:hover { color: var(--ww-accent); border-color: var(--ww-accent); }
.ww-illustrate:disabled { cursor: default; }
/* Faux progress fill driven by --ww-progress (set from JS). */
.ww-illustrate.ww-progress { color: var(--ww-ink); border-color: var(--ww-accent); }
.ww-illustrate.ww-progress::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: var(--ww-progress, 0%);
  background: rgba(201,161,74,0.28); transition: width 0.15s linear; z-index: 0;
}
.ww-illustrate .ww-illustrate-label { position: relative; z-index: 1; }
/* Illustrate split button: main action + caret that opens a perspective menu;
   picking one starts generation in that perspective immediately. */
.ww-illus-controls { position: relative; display: inline-block; margin-top: 0.3rem; }
.ww-illus-split { display: inline-flex; }
.ww-illus-controls .ww-illustrate { margin-top: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.ww-illus-caret {
  font-family: system-ui, sans-serif; font-size: 0.8rem; cursor: pointer; line-height: 1;
  background: transparent; color: var(--ww-muted);
  border: 1px solid #3a352a; border-left: 0;
  border-top-right-radius: 5px; border-bottom-right-radius: 5px; padding: 0.25rem 0.45rem;
}
.ww-illus-caret:hover { color: var(--ww-accent); border-color: var(--ww-accent); }
.ww-illus-caret:disabled { cursor: default; opacity: 0.6; }
.ww-illus-menu {
  position: absolute; left: 0; bottom: 100%; margin-bottom: 4px; z-index: 20;
  min-width: 100%; white-space: nowrap;
  background: #161310; border: 1px solid #3a352a; border-radius: 6px; padding: 0.25rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.ww-illus-opt {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: transparent; color: var(--ww-ink); border: 0; border-radius: 4px;
  font-size: 0.8rem; padding: 0.4rem 0.6rem;
}
.ww-illus-opt:hover { background: rgba(201,161,74,0.16); color: var(--ww-accent); }

/* Clone control: the per-turn "Clone from here" button (beside Illustrate / after an
   image). Hidden until the player taps that segment (article gets .ww-tap-open), so it
   stays out of the way until deliberately summoned. */
.ww-turn-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem 0.6rem; }
.ww-fork-ico { vertical-align: -2px; }
.ww-clone-btn {
  display: none; align-items: center; gap: 0.35rem; cursor: pointer;
  font-family: system-ui, sans-serif; font-size: 0.76rem; line-height: 1;
  background: transparent; color: var(--ww-muted); border: 1px solid #3a352a;
  border-radius: 5px; padding: 0.3rem 0.55rem; margin-top: 0.3rem; align-self: center;
}
.ww-turn.ww-tap-open .ww-clone-btn { display: inline-flex; }
.ww-clone-btn:hover { color: var(--ww-accent); border-color: var(--ww-accent); }
.ww-clone-btn:disabled { cursor: default; opacity: 0.6; }
.ww-clone-busy { color: var(--ww-accent); border-color: var(--ww-accent); }
/* Subtle cue that the open segment is the one whose clone control is showing. */
.ww-turn.ww-tap-open { border-left: 2px solid var(--ww-border, #3a352a); margin-left: -0.6rem; padding-left: 0.6rem; }

/* Settings: key forms */
.ww-key-form .ww-key-actions { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.5rem; }
.ww-key-form .ww-provider, .ww-key-form select { width: 100%; }

.ww-prompt {
  position: sticky; bottom: 0;
  display: flex; align-items: flex-end; gap: 0.5rem;
  background: linear-gradient(transparent, var(--ww-bg) 22%);
  padding: 1rem 0 0.6rem; margin-top: 1rem;
}
.ww-prompt .ww-caret {
  font-family: ui-monospace, monospace; color: var(--ww-accent); font-size: 1.1rem;
  line-height: 1.45; padding-bottom: 0.55rem;
}
.ww-prompt input, .ww-prompt textarea { margin-top: 0; flex: 1;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
/* Auto-growing action box: one line by default, grows with wrapped input (JS sets
   the height), then scrolls past a cap so the prompt never eats the screen. */
.ww-prompt textarea {
  resize: none; overflow-y: auto; line-height: 1.45;
  min-height: 2.6rem; max-height: 40vh; box-sizing: border-box;
  white-space: pre-wrap; word-break: break-word;
}
.ww-prompt .ww-btn { flex: 0 0 auto; }
/* The Do button as a progress bar: SAME size/shape/text, but the solid themed fill is
   swapped for the same OUTLINE/wireframe look as the Illustrate and input progress bars
   — a transparent body with an accent outline and a translucent accent fill that grows
   to full. Reverts to the normal solid themed button when done (the class is removed).
   box-sizing:border-box (global) keeps the 1px outline from changing the button size. */
.ww-prompt .ww-btn.ww-do-progress {
  position: relative; overflow: hidden; cursor: progress;
  background: transparent; color: var(--ww-ink); border: 1px solid var(--ww-accent);
}
.ww-prompt .ww-btn.ww-do-progress::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: var(--ww-progress, 0%); background: rgba(201,161,74,0.28);
  transition: width 0.15s linear; z-index: 0;
}
.ww-prompt .ww-btn.ww-do-progress .ww-pl { position: relative; z-index: 1; }
.ww-prompt .ww-btn.ww-do-progress:disabled { opacity: 1; }

/* Floating "jump to latest segment" arrow (shown only when not on the last one) */
.ww-jump-end {
  position: fixed; right: 18px; bottom: 84px; z-index: 20;
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--ww-accent); background: var(--ww-panel); color: var(--ww-accent);
  font-size: 1.3rem; line-height: 1; box-shadow: 0 2px 10px rgba(0,0,0,0.4);
  transition: opacity 0.15s, transform 0.15s;
}
.ww-jump-end:hover { background: var(--ww-accent); color: #1a1710; transform: translateY(-1px); }
.ww-jump-end[hidden] { display: none; }
.ww-jump-top { bottom: 136px; }

/* Undo / Regenerate controls */
.ww-controls { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.8rem; }
.ww-controls .ww-btn { background: transparent; color: var(--ww-muted); border: 1px solid #3a352a; }
.ww-controls .ww-btn:hover:not(:disabled) { color: var(--ww-accent); border-color: var(--ww-accent); }
.ww-controls .ww-btn:disabled { opacity: 0.4; cursor: default; }
/* Generic faux-progress fill for any button (regenerate). */
.ww-btn.ww-progress { position: relative; overflow: hidden; color: var(--ww-ink); border-color: var(--ww-accent); }
.ww-btn.ww-progress::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: var(--ww-progress, 0%);
  background: rgba(201,161,74,0.26); transition: width 0.15s linear; z-index: 0;
}
.ww-btn.ww-progress .ww-pl { position: relative; z-index: 1; }

/* Admin diagnostics */
.ww-btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.ww-trace { border: 1px solid #2b2820; border-radius: 6px; margin: 0.4rem 0; padding: 0.3rem 0.6rem; background: #181610; }
.ww-trace summary { cursor: pointer; font-family: system-ui, sans-serif; font-size: 0.9rem; }
.ww-trace pre, .ww-card pre {
  white-space: pre-wrap; word-break: break-word; background: #100e0a;
  border: 1px solid #2b2820; border-radius: 5px; padding: 0.6rem; font-size: 0.82rem;
  max-height: 320px; overflow: auto; color: #cfc8b8;
}
.ww-trace h4, .ww-card h4 { margin: 0.7rem 0 0.2rem; font-size: 0.82rem; color: var(--ww-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.ww-badge { display: inline-block; font-family: ui-monospace, monospace; font-size: 0.72rem;
  padding: 0.1rem 0.4rem; border-radius: 4px; background: #333; color: #ddd; }
.ww-badge-mcdm { background: #3a2f12; color: var(--ww-accent); }
.ww-badge-worlddm { background: #16313a; color: #8fc4d0; }
.ww-badge-idm { background: #2a163a; color: #c79fd0; }
.ww-badge-npcdm { background: #163a23; color: #8fd0a3; }
.ok { color: #8fd0a3; } .fail { color: var(--ww-error); }
.ww-mini { font-size: 0.85rem; padding-left: 1.1rem; margin: 0.3rem 0; }
.ww-mini li { margin: 0.15rem 0; }
.ww-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.ww-table th, .ww-table td { text-align: left; padding: 0.3rem 0.5rem; border-bottom: 1px solid #2b2820; vertical-align: top; }

/* --- Link buttons ---------------------------------------------------------
   Anchors styled as buttons (Wiki, Export, Save, Enter…) would otherwise
   inherit the body's line-height (1.65) and render taller than real
   <button>s, which get the UA's `normal`. Normalize everywhere. */
a.ww-btn { display: inline-flex; align-items: center; text-decoration: none; line-height: 1.2; }

/* --- Summary modal --------------------------------------------------------- */
.ww-modal-overlay {
  position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 1.2rem;
}
.ww-modal {
  background: var(--ww-panel); color: var(--ww-ink); border: 1px solid var(--ww-border);
  border-radius: 10px; max-width: 44rem; width: 100%; max-height: 80vh;
  display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.ww-modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.8rem;
  padding: 0.8rem 1.1rem; border-bottom: 1px solid #2b2820;
}
.ww-modal-close { padding: 0.2rem 0.6rem; }
.ww-modal-body { overflow-y: auto; padding: 0.9rem 1.2rem 1.2rem; line-height: 1.55; }
.ww-modal-body p { margin: 0 0 0.8em; }

/* --- Story wiki ------------------------------------------------------------ */
.wiki { display: flex; gap: 1.6rem; max-width: 72rem; margin: 0 auto; padding: 1rem 1.2rem 3rem; align-items: flex-start; }
.wiki-nav {
  flex: 0 0 15rem; position: sticky; top: 1rem;
  background: var(--ww-panel); border: 1px solid #2b2820; border-radius: 8px; padding: 0.9rem 1rem;
  font-size: 0.9rem;
}
.wiki-nav-title { font-weight: 700; margin: 0 0 0.1rem; }
.wiki-nav-sub { margin: 0 0 0.7rem; font-size: 0.8rem; }
.wiki-nav nav { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.8rem; }
.wiki-nav nav a { text-decoration: none; }
.wiki-note { font-size: 0.78rem; line-height: 1.4; }
.wiki-main { flex: 1 1 auto; min-width: 0; }
.wiki-h1 { font-size: 1.5rem; margin: 0.2rem 0 1rem; }
.wiki-main section > h2 {
  font-size: 1.2rem; margin: 1.8rem 0 0.7rem; padding-bottom: 0.25rem;
  border-bottom: 2px solid var(--ww-accent);
}
.wiki-entry {
  background: var(--ww-panel); border: 1px solid #2b2820; border-radius: 8px;
  padding: 0.8rem 1rem; margin: 0 0 0.8rem;
}
.wiki-entry h3 { margin: 0 0 0.4rem; font-size: 1.05rem; }
.wiki-entry h4 { margin: 0.7rem 0 0.25rem; font-size: 0.88rem; color: var(--ww-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.wiki-entry p { margin: 0.3rem 0; line-height: 1.5; }
.wiki-infobox { display: grid; grid-template-columns: max-content 1fr; gap: 0.15rem 0.9rem; margin: 0.4rem 0 0; font-size: 0.92rem; }
.wiki-infobox dt { color: var(--ww-muted); }
.wiki-infobox dd { margin: 0; min-width: 0; }
.wiki-list { margin: 0.2rem 0 0.4rem; padding-left: 1.2rem; font-size: 0.92rem; line-height: 1.5; }
.wiki-list li { margin: 0.15rem 0; }
.wiki-history { margin-top: 0.5rem; }
.wiki-history summary { cursor: pointer; color: var(--ww-muted); font-size: 0.9rem; }
.wiki-event { padding: 0.55rem 1rem; }
.wiki-event-head { margin: 0; }
.wiki-witnesses { font-size: 0.85rem; }
.wiki-entry:target { outline: 2px solid var(--ww-accent); scroll-margin-top: 1rem; }
@media (max-width: 52rem) {
  .wiki { flex-direction: column; }
  .wiki-nav { position: static; flex: none; width: auto; }
}

/* --- Story ingestion setup ------------------------------------------------- */
.ww-setup { max-width: 44rem; margin: 0 auto; padding: 1rem 1.2rem 3rem; }
.ww-ingest > summary { cursor: pointer; font-weight: 600; margin: 0.4rem 0; }
.ww-ingest { margin: 0.6rem 0; }
.ww-progressbar { height: 0.7rem; background: #2b2820; border-radius: 999px; overflow: hidden; margin: 0.8rem 0 0.4rem; }
.ww-progressbar-fill { height: 100%; width: 0; background: var(--ww-accent); transition: width 0.3s ease; }
.ww-ing-status { font-weight: 600; margin: 0.2rem 0; }
.ww-ing-counts { margin: 0.1rem 0 0; font-size: 0.9rem; }
.ww-ing-error { margin-top: 0.8rem; padding: 0.6rem 0.8rem; background: #2e1c18; border-left: 3px solid var(--ww-error); border-radius: 4px; }
.ww-error-text { color: var(--ww-error); margin: 0 0 0.4rem; }
.ww-setup-fieldset { border: 1px solid #2b2820; border-radius: 8px; padding: 0.8rem 1rem; margin: 0 0 1rem; }
.ww-setup-fieldset legend { font-weight: 600; padding: 0 0.4rem; }
.ww-radio { display: flex; align-items: center; gap: 0.5rem; margin: 0.45rem 0; cursor: pointer; color: var(--ww-ink); }
.ww-radio input { flex: 0 0 auto; }
.ww-setup-sub { margin: 0.2rem 0 0.8rem 1.6rem; display: flex; flex-direction: column; gap: 0.4rem; }
.ww-setup-new-char { margin: 0.4rem 0 0.2rem; display: flex; flex-direction: column; gap: 0.4rem; }
.ww-setup-fieldset select,
.ww-setup-fieldset input[type="text"],
.ww-setup-new-char textarea { width: 100%; margin: 0.2rem 0 0.4rem; }
.ww-setup-actions { display: flex; align-items: center; gap: 0.8rem; }

/* --- Monetization admin (monetize.php) --- */
.ww-tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; margin: 0.6rem 0 1rem; border-bottom: 1px solid var(--ww-border); }
.ww-tabs a { padding: 0.35rem 0.8rem; color: var(--ww-muted); text-decoration: none; border: 1px solid transparent; border-bottom: none; border-radius: 6px 6px 0 0; }
.ww-tabs a:hover { color: var(--ww-ink); }
.ww-tabs a.ww-tab-active { color: var(--ww-accent); border-color: var(--ww-border); background: var(--ww-panel); }
.ww-tier-head { display: flex; flex-wrap: wrap; gap: 0.8rem; align-items: end; margin-bottom: 0.5rem; }
.ww-tier-form label, .ww-price-form label { display: inline-block; margin: 0.25rem 0.6rem 0.25rem 0; }
.ww-tier-form fieldset { margin: 0.6rem 0; border: 1px solid var(--ww-border); border-radius: 6px; padding: 0.5rem 0.8rem; }
.ww-quota-grid { max-width: 34rem; margin-top: 0.5rem; }
.ww-price-form input[type="number"] { width: 7em; }
.ww-pnl-pos { color: #7fb47f; }
.ww-pnl-neg { color: var(--ww-error); }
.ww-meter { display: block; height: 0.5rem; border-radius: 4px; background: var(--ww-panel); overflow: hidden; max-width: 16rem; }
.ww-meter > span { display: block; height: 100%; background: var(--ww-accent); }
.ww-meter-over > span { background: var(--ww-error); }
.ww-upgrade-out { background: var(--ww-bg); border: 1px solid var(--ww-border); border-radius: 6px; padding: 0.6rem 0.8rem; font-size: 0.8rem; overflow-x: auto; white-space: pre-wrap; }
