/* =========================================================================
   AUTH GATE — full-screen login / guest screen.
   Shown once on first visit (no session AND no 'guest' localStorage flag).
   ========================================================================= */
.auth-gate {
  position: fixed; inset: 0; z-index: 210;
  background: radial-gradient(ellipse at top, #232836 0%, #0a0c11 85%);
  display: flex; align-items: center; justify-content: center;
  overflow-y: auto;
  transition: opacity 300ms ease, visibility 300ms;
  color: #e4e3de;
}
.auth-gate.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.auth-gate .ag-inner {
  max-width: 420px; width: 100%; padding: 2em 1.5em;
  text-align: center;
  display: flex; flex-direction: column; align-items: center;
}
.auth-gate .ag-wordmark {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 2.6em; font-weight: 500; margin: 0; letter-spacing: 0.02em;
  color: #e4e3de;
}
.auth-gate .ag-tag {
  color: #8089a0; font-style: italic; margin: 0.2em 0 2.2em;
  font-family: Georgia, serif; font-size: 1.05em;
}
.auth-gate .ag-options {
  display: flex; flex-direction: column; gap: 0.8em; width: 100%;
  align-items: stretch;
}
.auth-gate .ag-or {
  color: #8089a0; letter-spacing: 0.2em; font-size: 0.72em; text-transform: uppercase;
  margin: 0.2em 0;
}
.auth-gate .ag-card {
  background: #1b1f29; border: 1px solid #2a2f3c; border-radius: 8px;
  padding: 1.4em 1.4em; color: inherit; font: inherit;
  display: flex; flex-direction: column; gap: 0.5em; align-items: stretch;
  text-align: left; cursor: auto; width: 100%;
  box-sizing: border-box;
}
.auth-gate .ag-card-guest {
  text-align: center; cursor: pointer; align-items: center;
  justify-content: center;
  transition: border-color 180ms, transform 180ms;
  padding: 1em 1.2em; gap: 0.3em;
}
.auth-gate .ag-card-guest:hover { border-color: #6fb8ff; transform: translateY(-1px); }
.auth-gate .ag-card-guest .big {
  font-family: "Iowan Old Style", Palatino, serif; font-size: 1.05em; color: #e4e3de;
}
.auth-gate .ag-card-guest .muted { font-size: 0.78em; line-height: 1.4; color: #8089a0; max-width: 22em; }
.auth-gate .ag-card h2 {
  font-family: "Iowan Old Style", Palatino, serif; font-size: 1.2em; margin: 0; color: #e4e3de;
  font-weight: 500;
}
.auth-gate .ag-card .muted { color: #8089a0; font-size: 0.85em; margin: 0; }
.auth-gate .ag-card input {
  background: #0a0c11; color: #e4e3de; border: 1px solid #2a2f3c;
  border-radius: 4px; padding: 0.6em 0.8em; font: inherit;
}
.auth-gate .ag-card input:focus { outline: none; border-color: #6fb8ff; }
.auth-gate .ag-primary {
  background: #6fb8ff; color: #0a0c11; border: none; border-radius: 4px;
  padding: 0.7em 1em; cursor: pointer; font-weight: 600; font-size: 0.95em;
  font-family: inherit;
}
.auth-gate .ag-primary:hover { filter: brightness(1.1); }
.auth-gate .ag-secondary {
  background: transparent; color: #d8dce7; border: 1px solid #2a2f3c;
  padding: 0.6em 1em; border-radius: 4px; cursor: pointer; font: inherit;
}
.auth-gate .ag-secondary:hover { border-color: #6fb8ff; color: #6fb8ff; }
.auth-gate .error { color: #e46b6b; font-size: 0.85em; min-height: 1em; }

/* Step switcher: only the active card is visible. Smooth fade as the
   user moves email → code → totp. */
.auth-gate .ag-card.hidden { display: none; }
.auth-gate form[data-step] {
  animation: obFade 240ms ease;
}

/* Code / TOTP inputs — large, monospaced, well-spaced. Users paste
   6-digit codes here. */
.auth-gate .ag-code-input {
  font-family: "SF Mono", Menlo, "Courier New", monospace;
  font-size: 1.4em; letter-spacing: 0.4em; text-align: center;
  padding: 0.55em 0.6em;
}

/* "Use authenticator" / "Resend code" / "Use a different email"
   footer links. Visually-quiet text buttons; still 44px tap area on
   mobile. */
.auth-gate .ag-alt {
  display: flex; justify-content: center; align-items: center; gap: 0.5em;
  margin-top: 0.4em; font-size: 0.85em; color: #8089a0;
}
.auth-gate .ag-link {
  background: transparent; border: none; color: #8089a0;
  font: inherit; cursor: pointer; padding: 0.3em 0.2em;
  text-decoration: underline; text-decoration-color: rgba(128,137,160,0.4);
}
.auth-gate .ag-link:hover { color: #e4e3de; }

/* TOTP setup dialog styling — matches other dialogs, just surfaces
   otpauth-URI and the secret prominently. */
#totp-setup-dialog { max-width: 30em; }
#totp-setup-dialog h3 { margin-top: 0; }
#totp-setup-dialog textarea#totp-setup-uri {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.5em 0.7em; resize: none; word-break: break-all;
}
#totp-setup-dialog #totp-setup-secret {
  background: var(--bg); border: 1px solid var(--border); border-radius: 3px;
  padding: 0.6em 0.8em; margin-top: 0.3em;
}
#login-dialog form.hidden { display: none; }

/* Primary copy on Step 2: the magic link IS the happy path. Larger,
   lighter weight, sits above the fallback code input. */
.ag-primary-copy {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  color: #e4e3de; font-size: 1.05em; line-height: 1.55;
  margin: 0.2em 0 1em;
}
.ag-primary-copy span { color: #6fb8ff; font-style: italic; }

/* Divider between primary magic-link copy and the fallback code input. */
.ag-code-sep {
  position: relative; text-align: center;
  margin: 0.8em 0 0.6em; color: #8089a0; font-size: 0.78em;
  letter-spacing: 0.1em; text-transform: uppercase;
}
.ag-code-sep::before, .ag-code-sep::after {
  content: ""; position: absolute; top: 50%; width: 35%; height: 1px;
  background: #2a2f3c;
}
.ag-code-sep::before { left: 0; }
.ag-code-sep::after  { right: 0; }
.ag-code-sep span { background: #1b1f29; padding: 0 0.8em; position: relative; }

/* Dev-mode inline box: shown only when the server flagged dev_mode=true.
   Puts the code + magic link in front of the user instead of sending
   them to hunt logs/mail.log. */
.ag-dev-box {
  border: 1px dashed var(--warn); border-radius: 4px;
  background: rgba(225, 160, 74, 0.06);
  padding: 0.7em 0.9em; margin: 0.4em 0 0.6em;
  animation: obFade 260ms ease;
}
.ag-dev-box.hidden { display: none; }
.ag-dev-box .ag-dev-title {
  font-size: 0.78em; color: var(--warn); letter-spacing: 0.08em;
  text-transform: uppercase; margin-bottom: 0.4em;
}
.ag-dev-box .ag-dev-code {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 1.5em; letter-spacing: 0.35em; font-weight: 600;
  color: var(--text); text-align: center; padding: 0.25em 0;
}
.ag-dev-box .ag-dev-link {
  display: block; text-align: center; margin-top: 0.3em;
  color: var(--accent); font-size: 0.9em; text-decoration: none;
}
.ag-dev-box .ag-dev-link:hover { text-decoration: underline; }

/* In-flight submit: fade + disable pointer-events. Works for any form
   with .submitting (applied by _submitWithLoading). */
form.submitting { opacity: 0.8; pointer-events: none; }
form.submitting .ag-primary { position: relative; }

/* Soft TOTP-prompt dialog — smaller footprint, reads as an invitation
   rather than an interrupt. */
#totp-prompt-dialog.totp-prompt { max-width: 24em; padding: 1.4em 1.5em; }
#totp-prompt-dialog .totp-prompt-head {
  font-family: "Iowan Old Style", Palatino, serif;
  font-size: 1.15em; font-weight: 500; margin-bottom: 0.4em;
  color: var(--text);
}
#totp-prompt-dialog .totp-prompt-body {
  color: var(--muted); font-size: 0.92em; line-height: 1.5;
  margin: 0.2em 0 1em;
}
#totp-prompt-dialog .totp-prompt-actions {
  display: flex; justify-content: flex-end; align-items: center; gap: 0.5em;
}
#totp-prompt-dialog .totp-prompt-actions .ag-link {
  margin-right: auto;
  background: transparent; border: none; color: var(--muted);
  font: inherit; font-size: 0.9em; cursor: pointer;
}
#totp-prompt-dialog .totp-prompt-actions .ag-link:hover { color: var(--text); }
#totp-prompt-dialog .totp-prompt-actions .primary {
  background: var(--accent); color: var(--bg); border: none; border-radius: 3px;
  padding: 0.5em 1.1em; cursor: pointer; font-weight: 600;
}
#totp-prompt-dialog .totp-prompt-actions .primary:hover { filter: brightness(1.1); }

/* Settings drawer — account + security + this-device controls. Opens
   from the signed-in profile button. Shared drawer styling already
   handles positioning and transitions; only content styles here. */
#settings-drawer .settings-field {
  display: flex; flex-direction: column; gap: 0.3em;
  margin-bottom: 0.9em;
}
#settings-drawer .settings-label {
  font-size: 0.72em; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
}
#settings-drawer .settings-value {
  color: var(--text); font-size: 0.95em; word-break: break-word;
}
#settings-drawer .settings-desc {
  font-size: 0.85em; line-height: 1.5; margin: 0.2em 0 0.8em;
}
#settings-drawer .settings-inline-form {
  display: flex; gap: 0.4em; align-items: stretch;
}
#settings-drawer .settings-inline-form input {
  flex: 1; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.5em 0.7em; font: inherit;
}
#settings-drawer .settings-inline-form input:focus { outline: none; border-color: var(--accent); }
#settings-drawer .settings-inline-form .settings-save {
  background: var(--accent); color: var(--bg); border: none;
  border-radius: 3px; padding: 0.45em 0.9em; cursor: pointer;
  font-weight: 600;
}
#settings-drawer .settings-inline-form .settings-save:hover { filter: brightness(1.1); }
#settings-drawer #settings-name-status {
  font-size: 0.82em; align-self: center;
}
#settings-drawer .settings-actions {
  display: flex; gap: 0.5em; flex-wrap: wrap;
  margin-top: 0.4em;
}
#settings-drawer .settings-actions button {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.55em 1em; font: inherit; cursor: pointer;
}
#settings-drawer .settings-actions button:hover { border-color: var(--accent); color: var(--accent); }
#settings-drawer .settings-actions button.primary {
  background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600;
}
#settings-drawer .settings-actions button.primary:hover { color: var(--bg); filter: brightness(1.1); }
#settings-drawer .settings-totp-status {
  font-size: 0.88em; padding: 0.2em 0.7em; border-radius: 10px;
  border: 1px solid var(--border); color: var(--muted);
  font-family: "SF Mono", Menlo, monospace; letter-spacing: 0.04em;
  display: inline-block; margin-top: 0.2em;
}
#settings-drawer .settings-totp-status.enabled {
  color: var(--good); border-color: var(--good);
}
#settings-drawer .settings-totp-status.not-enabled {
  color: var(--warn); border-color: var(--warn);
}
#settings-drawer #settings-signout-btn {
  border-color: var(--bad); color: var(--bad);
}
#settings-drawer #settings-signout-btn:hover {
  border-color: var(--bad); color: #ffffff; background: var(--bad);
}

/* TOTP setup dialog — QR-first layout. The QR takes centre stage;
   manual entry (secret + URI) is tucked behind a <details> toggle
   for users whose app can't scan a camera QR. */
#totp-setup-dialog.totp-setup { max-width: 28em; padding: 1.5em 1.6em; }
#totp-setup-dialog .totp-setup-blurb {
  font-size: 0.9em; margin: 0.2em 0 1em;
}
#totp-setup-dialog .totp-setup-qr {
  display: flex; align-items: center; justify-content: center;
  background: #ffffff; padding: 1em; border-radius: 6px;
  margin: 0 auto 1.2em; width: fit-content;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
#totp-setup-dialog .totp-setup-qr svg { display: block; }
#totp-setup-dialog .totp-setup-manual {
  margin: 0 0 1em; font-size: 0.88em;
}
#totp-setup-dialog .totp-setup-manual summary {
  cursor: pointer; color: var(--muted); padding: 0.4em 0;
  list-style: none;
}
#totp-setup-dialog .totp-setup-manual summary::before { content: "› "; margin-right: 0.3em; }
#totp-setup-dialog .totp-setup-manual[open] summary::before { content: "▾ "; }
#totp-setup-dialog .totp-setup-manual summary:hover { color: var(--text); }
#totp-setup-dialog .totp-setup-manual-body { padding: 0.5em 0 0; }
#totp-setup-dialog .totp-setup-secret-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 0.5em;
  align-items: center; margin-bottom: 0.6em;
}
#totp-setup-dialog #totp-setup-secret {
  font-family: "SF Mono", Menlo, monospace; font-size: 1em;
  letter-spacing: 0.15em; color: var(--text);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 3px; padding: 0.4em 0.7em;
  word-break: keep-all;
}
#totp-setup-dialog .totp-setup-copy {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.35em 0.7em; cursor: pointer; font: inherit; font-size: 0.82em;
}
#totp-setup-dialog .totp-setup-copy:hover { border-color: var(--accent); color: var(--accent); }
#totp-setup-dialog .totp-setup-uri-wrap { margin-top: 0.4em; }
#totp-setup-dialog .totp-setup-uri-wrap summary {
  font-size: 0.85em; color: var(--muted); cursor: pointer;
  padding: 0.3em 0;
}
#totp-setup-dialog #totp-setup-uri {
  width: 100%; margin-top: 0.3em;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.5em 0.7em; resize: none;
  font-family: "SF Mono", Menlo, monospace; font-size: 0.8em;
  word-break: break-all;
}
#totp-setup-dialog .totp-setup-code-label {
  display: flex; flex-direction: column; gap: 0.3em; margin: 0.5em 0 0;
}
#totp-setup-dialog .totp-setup-code-label span {
  font-size: 0.85em;
}
#totp-setup-dialog .totp-setup-code-label input {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 1.2em; letter-spacing: 0.25em; text-align: center;
  padding: 0.5em 0.6em;
}

/* Signed-in-as label inside the overflow menu — subtle, unclickable. */
.overflow-menu .om-identity {
  padding: 0.5em 0.9em; margin-bottom: 0.2em;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 0.1em;
  font-size: 0.85em; color: var(--muted);
  line-height: 1.3;
}
.overflow-menu .om-identity.hidden { display: none; }
.overflow-menu .om-identity .om-id-label {
  font-size: 0.72em; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted);
}
.overflow-menu .om-identity .om-id-value {
  color: var(--text); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 22em;
}

@media (max-width: 480px) { .auth-gate .ag-wordmark { font-size: 2em; } }

/* =========================================================================
   EMPTY-STATE CARD — shown when a project has no scenes yet.
   ========================================================================= */
.story-empty-card {
  max-width: 560px; margin: 6em auto 2em; padding: 2em 2.2em;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  text-align: center;
}
.story-empty-card.hidden { display: none; }
.story-empty-card h2 {
  font-family: "Iowan Old Style", Palatino, serif; font-weight: 500;
  font-size: 1.4em; margin: 0 0 0.4em; color: var(--text);
}
.story-empty-card p { color: var(--muted); font-size: 0.95em; margin: 0 0 1.2em; line-height: 1.55; }
.story-empty-card button { display: block; width: 100%; margin-bottom: 0.5em; }
/* New mode-picker empty state: four tiles that launch onboarding with the
   clicked mode pre-selected. Sits in the same card; replaces the old
   "Your world is set" default. */
.story-empty-card .se-modes {
  display: grid; grid-template-columns: 1fr; gap: 0.6em;
  margin-top: 1em;
}
@media (min-width: 560px) { .story-empty-card .se-modes { grid-template-columns: 1fr 1fr; } }
.story-empty-card .se-mode {
  display: flex; flex-direction: column; align-items: flex-start;
  text-align: left; padding: 0.9em 1em; gap: 0.2em;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; font: inherit; width: auto; margin: 0;
  transition: border-color 150ms, background 150ms, transform 150ms;
}
.story-empty-card .se-mode:hover {
  border-color: var(--accent); background: rgba(111,184,255,0.05);
  transform: translateY(-1px);
}
.story-empty-card .se-mode-title {
  font-family: "Iowan Old Style", Palatino, serif; font-size: 1.02em; color: var(--text);
  font-weight: 600;
}
.story-empty-card .se-mode-desc { font-size: 0.85em; color: var(--muted); }
.story-empty-card .ag-primary { background: #6fb8ff; color: #0a0c11; border: none; border-radius: 4px; padding: 0.7em 1em; cursor: pointer; font-weight: 600; font-family: inherit; font-size: 1em; }
.story-empty-card .ag-secondary { background: transparent; color: var(--muted); border: 1px solid var(--border); padding: 0.6em 1em; border-radius: 4px; cursor: pointer; font-size: 0.9em; font-family: inherit; }
.story-empty-card .ag-secondary:hover { color: var(--accent); border-color: var(--accent); }
.story-empty-card .se-loading, .story-empty-card .se-error { display: flex; flex-direction: column; align-items: center; gap: 1em; }
.story-empty-card .se-loading.hidden, .story-empty-card .se-error.hidden, .story-empty-card .se-default.hidden, .story-empty-card .se-continue.hidden { display: none; }
.story-empty-card .se-continue p { margin: 0 0 1.2em; color: var(--muted); font-size: 0.95em; }
.story-empty-card .se-continue #story-empty-continue { max-width: 20em; margin: 0 auto; }
.story-empty-card .se-loading .ob-spinner { width: 2.4em; height: 2.4em; border-width: 2px; margin: 0.5em auto; }
.story-empty-card .se-loading-line { margin: 0; animation: obFade 400ms ease; }
.story-empty-card .se-error { color: var(--bad); }
.story-empty-card .se-error h2 { color: var(--bad); }

/* =========================================================================
   First-run onboarding — full-screen cover, three steps.
   ========================================================================= */
.onboarding {
  position: fixed; inset: 0; z-index: 200;
  background: radial-gradient(ellipse at top, #1b1f29 0%, #0a0c11 100%);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  transition: opacity 300ms ease, visibility 300ms;
}
.onboarding.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.onboarding .ob-inner { max-width: 880px; width: 100%; padding: 2em; }
.onboarding .ob-close {
  position: absolute; top: 1.2em; right: 1.2em;
  background: transparent; color: #8089a0; border: 1px solid #2a2f3c;
  padding: 0.45em 0.9em; border-radius: 4px; cursor: pointer;
  font-family: inherit; font-size: 0.88em;
  transition: color 150ms, border-color 150ms;
}
.onboarding .ob-close:hover { color: #e4e3de; border-color: #e4e3de; }
.onboarding .ob-close.hidden { display: none; }
.onboarding .ob-step { display: none; text-align: center; animation: obFade 260ms ease; }
.onboarding .ob-step.active { display: block; }
.onboarding h1 {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 2em; font-weight: 500; margin: 0 0 0.3em;
  color: #e4e3de; letter-spacing: 0.01em;
}
.onboarding .ob-sub {
  color: #8089a0; font-style: italic; margin: 0 0 2em;
  font-family: Georgia, serif;
}
.onboarding .ob-cards {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 1em;
}
@media (min-width: 960px) { .onboarding .ob-cards { grid-template-columns: repeat(4, 1fr); } }
.onboarding .ob-card {
  background: #1b1f29; border: 1px solid #2a2f3c; border-radius: 8px;
  padding: 1.8em 1.2em; cursor: pointer; color: inherit;
  text-align: left; font: inherit;
  transition: transform 180ms ease, border-color 180ms, background 180ms;
}
.onboarding .ob-card:hover {
  transform: translateY(-3px); border-color: #6fb8ff;
  background: #232836;
}
.onboarding .ob-card-icon { font-size: 2em; margin-bottom: 0.3em; }
.onboarding .ob-card-title {
  font-size: 1.1em; font-weight: 600; color: #e4e3de; margin-bottom: 0.4em;
  font-family: "Iowan Old Style", Palatino, serif;
}
.onboarding .ob-card-desc { font-size: 0.88em; color: #8089a0; line-height: 1.5; }
.onboarding #ob-seed-form input {
  width: 100%; max-width: 640px; padding: 0.8em 1em;
  background: #1b1f29; color: #e4e3de; border: 1px solid #2a2f3c;
  border-radius: 6px; font-family: "Iowan Old Style", Palatino, serif;
  font-size: 1.05em;
}
.onboarding #ob-seed-form input:focus { outline: none; border-color: #6fb8ff; }
.onboarding .ob-actions { display: flex; justify-content: center; gap: 0.8em; margin-top: 1.2em; }
.onboarding button {
  background: #1b1f29; color: #d8dce7; border: 1px solid #2a2f3c;
  border-radius: 4px; padding: 0.6em 1.4em; cursor: pointer;
  font-size: 0.95em; font-family: inherit;
  transition: filter 150ms;
}
.onboarding button.ob-primary { background: #6fb8ff; color: #0a0c11; border-color: #6fb8ff; font-weight: 600; }
.onboarding button:hover:not(:disabled) { filter: brightness(1.15); }
.onboarding button:disabled { opacity: 0.4; cursor: progress; }
.onboarding .ob-loading { display: flex; flex-direction: column; align-items: center; gap: 1.5em; }
.onboarding .ob-spinner {
  width: 3em; height: 3em; border-radius: 50%;
  border: 3px solid #2a2f3c; border-top-color: #6fb8ff;
  animation: obSpin 1.1s linear infinite;
}
.onboarding .ob-status {
  color: #d8dce7; font-family: "Iowan Old Style", Palatino, serif;
  font-size: 1.1em; font-style: italic;
  animation: obFade 400ms ease;
}

/* =========================================================================
   Coach-mark tour — post-onboarding walkthrough.
   ========================================================================= */
.tour-overlay {
  position: fixed; inset: 0; z-index: 180;
  pointer-events: auto;  /* catch clicks everywhere except the spotlight */
  background: transparent;
}
.tour-overlay.hidden { display: none; }
/* Dim backdrop via a four-rect mask so the spotlight stays clickable.
   Implemented as four absolutely-positioned dividers around the target. */
.tour-dim {
  position: fixed; background: rgba(0,0,0,0.62);
  transition: all 220ms ease;
}
.tour-spotlight {
  position: fixed; pointer-events: none;
  border: 2px solid #6fb8ff; border-radius: 6px;
  box-shadow: 0 0 0 4px rgba(111,184,255,0.25), 0 0 32px rgba(111,184,255,0.4);
  transition: all 220ms ease;
}
.tour-bubble {
  position: fixed; z-index: 181;
  background: #1b1f29; color: #e4e3de;
  border: 1px solid #6fb8ff; border-radius: 6px;
  padding: 1em 1.1em; max-width: 22em;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  font-size: 0.9em; line-height: 1.5;
  transition: all 220ms ease;
}
.tour-bubble::after {
  content: ""; position: absolute;
  border-left: 8px solid transparent; border-right: 8px solid transparent;
}
.tour-bubble.arrow-up::after    { top: -8px; left: 28px; border-bottom: 8px solid #6fb8ff; }
.tour-bubble.arrow-down::after  { bottom: -8px; left: 28px; border-top: 8px solid #6fb8ff; }
.tour-bubble.arrow-left::after  { top: 20px; left: -8px;
  border-top: 8px solid transparent; border-bottom: 8px solid transparent;
  border-left: none; border-right: 8px solid #6fb8ff; }
.tour-bubble.arrow-right::after { top: 20px; right: -8px;
  border-top: 8px solid transparent; border-bottom: 8px solid transparent;
  border-left: 8px solid #6fb8ff; border-right: none; }
.tour-bubble .tour-step-num {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 0.72em; letter-spacing: 0.15em; text-transform: uppercase;
  color: #8089a0; margin-bottom: 0.4em;
}
.tour-bubble .tour-title {
  font-family: "Iowan Old Style", Palatino, serif;
  font-size: 1.05em; color: #f0eee6; margin-bottom: 0.4em; font-weight: 500;
}
.tour-bubble .tour-body { color: #d8dce7; }
.tour-bubble .tour-actions {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.6em; margin-top: 0.9em;
}
.tour-bubble .tour-skip {
  background: transparent; color: #8089a0; border: 1px solid #2a2f3c;
  border-radius: 4px; padding: 0.35em 0.7em; cursor: pointer; font-size: 0.82em;
}
.tour-bubble .tour-skip:hover { color: #e4e3de; border-color: #e4e3de; }
.tour-bubble .tour-next {
  background: #6fb8ff; color: #0a0c11; border: none;
  border-radius: 4px; padding: 0.4em 1em; cursor: pointer; font-weight: 600;
  font-size: 0.88em;
}
.tour-bubble .tour-next:hover { filter: brightness(1.1); }

#restart-tour {
  background: transparent; color: var(--text); border: 1px solid var(--border);
  padding: 0.4em 0.9em; border-radius: 4px; cursor: pointer; font-size: 0.88em;
  font-family: inherit;
}
#restart-tour:hover { border-color: var(--accent); color: var(--accent); }

/* First-run tooltip bubble — one at a time, positioned in JS. */
.ob-tooltip {
  position: fixed; z-index: 150;
  background: #6fb8ff; color: #0a0c11;
  border-radius: 6px; padding: 0.7em 1em;
  max-width: 22em; font-size: 0.9em; font-family: inherit;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  transition: opacity 200ms, transform 200ms;
  opacity: 1; transform: translateY(0);
}
.ob-tooltip.hidden { opacity: 0; transform: translateY(6px); pointer-events: none; }
.ob-tooltip::after {
  content: ""; position: absolute; top: -8px; left: 24px;
  border-left: 8px solid transparent; border-right: 8px solid transparent;
  border-bottom: 8px solid #6fb8ff;
}
.ob-tooltip.arrow-bottom::after { top: auto; bottom: -8px; border-bottom: none; border-top: 8px solid #6fb8ff; }
.ob-tooltip .ob-tt-body { margin-bottom: 0.4em; line-height: 1.4; }
.ob-tooltip .ob-tt-close {
  background: rgba(0,0,0,0.25); color: #0a0c11; border: none;
  padding: 0.2em 0.7em; border-radius: 3px; cursor: pointer; font-size: 0.85em;
  font-weight: 600;
}
.ob-tooltip .ob-tt-close:hover { filter: brightness(1.15); }

@keyframes obFade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes obSpin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .onboarding .ob-cards { grid-template-columns: 1fr; }
  .onboarding h1 { font-size: 1.5em; }
}

:root {
  --bg: #10131a;
  --panel: #1b1f29;
  --border: #2a2f3c;
  --text: #d8dce7;
  --muted: #9ba3b8;   /* bumped from #8089a0 for WCAG AA on --bg */
  --accent: #6fb8ff;
  --warn: #e1a04a;
  --good: #6fd49a;
  --bad: #e46b6b;
  --reader-bg: #10131a;
  --reader-text: #e4e3de;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;  /* never let anything push a horizontal scrollbar */
  overflow-y: scroll;
}
/* Small-text readability: anything under 14px promoted to --text so the
   muted-by-default hierarchy doesn't cost legibility at smaller sizes. */
.badge, .autorun-indicator, #turn-status { color: var(--text); }

/* =========================================================================
   Top bar — minimal identity + drawer toggles. No forms, no inputs.
   ========================================================================= */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 0.5em;
  padding: 0.55em 1em;
  background: rgba(16, 19, 26, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  font-size: 0.9em;
}
/* Interactive targets (picker + buttons) get real touch heights. Informational
   pills (.badge) stay small/muted so they read as status, not controls. */
.topbar select, .topbar .tb-btn {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.6em 1em; font-size: 0.95em; cursor: pointer;
  min-height: 36px;
}
.topbar select { max-width: 22em; color: var(--text); }
.topbar .tb-btn {
  font-family: inherit; line-height: 1.2;
  transition: color 150ms, border-color 150ms, background 150ms;
  white-space: nowrap;
  min-width: 2.5em;   /* ⋯ and + N shouldn't squeeze below a comfortable target */
}
.topbar .tb-btn:hover { color: var(--text); border-color: var(--accent); background: rgba(111,184,255,0.05); }
.topbar .tb-btn.user-btn.logged-in { color: var(--accent); border-color: var(--accent); }
/* User button: glyph + label side by side on desktop; label hides on mobile
   via the @media (max-width: 720px) block. display:inline-flex lets both
   spans live on one baseline with a clean gap. */
.topbar #user-btn { display: inline-flex; align-items: center; gap: 0.4em; }
.topbar .spacer { flex: 1; }
.topbar .badge {
  font-size: 0.7em; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text); background: var(--panel); cursor: default;
  border: 1px solid var(--border); border-radius: 10px;
  padding: 0.25em 0.7em; line-height: 1.2;
  /* explicit: not a control, don't inherit the .tb-btn touch height */
  min-height: 0;
}

/* Mode chip — clickable variant of .badge, opens #mode-popover. Elevated
   to first-class topbar citizen: present on every viewport. Collapses to
   the mode's initial on very narrow screens via the @media block below. */
.topbar .tb-badge {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 0.5em 0.9em; font: inherit; font-size: 0.85em;
  letter-spacing: 0.04em; text-transform: uppercase; cursor: pointer;
  font-family: inherit; font-weight: 500;
  transition: color 150ms, border-color 150ms;
  min-height: 36px;
}
.topbar .tb-badge:hover { border-color: var(--accent); color: var(--accent); }
.topbar .tb-badge::after { content: "  ▾"; font-size: 0.8em; opacity: 0.7; }

/* Topbar Unfold button — the session-level "let the story run on its
   own" control. Styled like other .tb-btn with a slight accent when
   running (handled by JS adding the .running class). */
.topbar .tb-unfold { font-weight: 500; }
.topbar .tb-unfold.running {
  border-color: var(--accent); color: var(--accent);
  background: rgba(111, 184, 255, 0.08);
}
.autorun-indicator {
  font-size: 0.75em; color: var(--accent); padding: 0.2em 0.6em;
  background: rgba(111, 184, 255, 0.08); border: 1px solid var(--accent);
  border-radius: 10px; letter-spacing: 0.05em;
}
.autorun-indicator::before { content: "● "; animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 0.4 } 50% { opacity: 1 } }
.hidden { display: none !important; }

/* =========================================================================
   Overflow menu — everything that used to be a topbar button. Opens under
   the ⋯ control, click-outside / Esc closes it.
   ========================================================================= */
.overflow-menu {
  position: fixed; top: 3em; right: 0.8em; z-index: 50;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.35em;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  min-width: 14em;
  display: flex; flex-direction: column; gap: 0.1em;
}
.overflow-menu .om-item {
  background: transparent; border: none; color: var(--text);
  padding: 0.7em 0.9em; text-align: left; border-radius: 4px;
  font: inherit; font-size: 0.95em; cursor: pointer; white-space: nowrap;
  min-height: 36px;
}
.overflow-menu .om-item:hover { background: rgba(111,184,255,0.09); color: var(--accent); }
.overflow-menu .om-sep {
  height: 1px; background: var(--border); margin: 0.25em 0.35em;
}
.overflow-menu .om-check { display: flex; align-items: center; gap: 0.5em; }
.overflow-menu .om-check input { margin: 0; }
/* Mobile-only overflow items (e.g. "+ New" mirror). Hidden by default
   so desktop doesn't duplicate the topbar button inside the menu. */
.overflow-menu .om-item-mobile { display: none; }

/* Signed-in user button: replace the person-icon with a small round chip
   showing user initials. Colors match .logged-in state (accent). */
.topbar #user-btn.user-btn-initials {
  padding: 0.3em; min-width: 36px; width: 36px; height: 36px;
  border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
}
.topbar #user-btn.user-btn-initials .u-initials {
  font-size: 0.85em; font-weight: 600; color: var(--accent); letter-spacing: 0;
}

/* Mode popover — inline list anchored under #mode-badge. */
.mode-popover {
  position: fixed; z-index: 55;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  padding: 0.35em; min-width: 17em; max-width: calc(100vw - 16px);
  display: flex; flex-direction: column; gap: 0.1em;
}
.mode-popover .mp-item {
  background: transparent; color: var(--text); border: none;
  padding: 0.55em 0.7em; text-align: left; border-radius: 4px;
  font: inherit; cursor: pointer; white-space: nowrap;
}
.mode-popover .mp-item:hover { background: rgba(111,184,255,0.09); color: var(--accent); }
.mode-popover .mp-item.selected { color: var(--accent); font-weight: 600; }
.mode-popover .mp-item.selected::before { content: "✓  "; color: var(--accent); }

.topbar #mode-badge { cursor: pointer; user-select: none; }
.topbar #mode-badge:hover { border-color: var(--accent); color: var(--accent); }
.topbar #mode-badge::after { content: "  ▾"; font-size: 0.7em; opacity: 0.7; }

/* Autorun popover — anchored above the ▶ Auto button in the action dock. */
.autorun-popover {
  position: fixed; z-index: 55;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 -6px 30px rgba(0,0,0,0.5);
  padding: 0.9em 1em; min-width: 22em; max-width: calc(100vw - 16px);
  color: var(--text);
}
.autorun-popover .ap-head { display: flex; align-items: center; gap: 0.6em; margin-bottom: 0.4em; }
.autorun-popover .ap-desc { font-size: 0.85em; margin: 0 0 0.8em; }
.autorun-popover .ap-speed { display: flex; align-items: center; gap: 0.5em; margin-bottom: 0.8em; }
.autorun-popover .ap-speed input[type=range] { flex: 1; }
.autorun-popover .ap-actions { display: flex; gap: 0.5em; }
.autorun-popover .ap-actions .primary {
  background: var(--accent); color: var(--bg); border: none; border-radius: 3px;
  padding: 0.55em 1em; font-weight: 600; cursor: pointer;
}

/* Action-dock buttons — the new autorun entry. */
.action-dock .action-bar #autorun-btn {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.55em 0.9em; cursor: pointer; font-weight: 600;
  white-space: nowrap;
}
.action-dock .action-bar #autorun-btn:hover { border-color: var(--accent); color: var(--accent); }
.action-dock .action-bar #autorun-btn.running {
  border-color: var(--accent); color: var(--accent); background: rgba(111,184,255,0.08);
}
.action-dock .action-bar.writing > #autorun-btn { display: none; }

/* #turn-status can now carry an error — mark it visually distinct. */
#turn-status.error-text { color: var(--bad); }

/* =========================================================================
   Mobile breakpoint — only the four essentials in the topbar, no
   horizontal overflow, action dock respects safe-area-inset-bottom.
   ========================================================================= */
@media (max-width: 720px) {
  .topbar { gap: 0.4em; padding: 0.55em 0.7em; flex-wrap: nowrap; min-width: 0; }
  .topbar #project-picker { flex: 1; min-width: 0; max-width: none; }
  /* Hide read-only status pills on narrow screens; the info lives in the
     ⋯ menu (Mode via System & Mode) and the autorun indicator remains
     accessible from System drawer. */
  .topbar #mode-badge,
  .topbar #role-badge,
  .topbar #autorun-indicator { display: none; }
  /* iOS/Android touch-target minimum 44×44. */
  .topbar select,
  .topbar .tb-btn { padding: 0.7em 0.8em; font-size: 0.95em; min-height: 44px; }
  /* Mode chip stays visible on mobile (no longer hidden) but compresses
     to a single-letter badge so it fits. Drops the ▾ arrow too — the
     chevron wouldn't fit, and the chip itself telegraphs "tappable". */
  .topbar .tb-badge { padding: 0.7em 0.65em; font-size: 0.95em; min-height: 44px; min-width: 44px; }
  .topbar .tb-badge::after { display: none; }
  /* Unfold button — tight square-ish footprint on mobile. We keep the
     glyph + short word ("▶ Unfold" / "■ Unfolding") on ≤720px because
     "▶" alone is too cryptic; the bar is wide enough. At the narrowest
     (≤380px) the button collapses to the glyph only via the nested
     rule below. */
  .topbar .tb-unfold { padding: 0.7em 0.7em; min-width: 44px; }
  /* "+ New" stays visible on mobile — users asked for it not to move into
     the overflow menu. It compresses to "+" on very narrow screens via
     the CSS below. */
  .topbar #new-project-btn { padding: 0.7em 0.6em; min-width: 44px; }
  /* The mobile overflow-menu "+ New project" mirror is now redundant —
     the topbar button is always visible. Hide it. */
  .overflow-menu .om-item-mobile { display: none; }
  /* ⋯ stays a 44×44 square icon. */
  .topbar #overflow-btn { padding: 0.7em; min-width: 44px; width: 44px; }
  /* Signed-out user button must show "Sign in" text — icon alone is
     unlabeled ambiguity. Signed-in user button remains the initials chip
     defined above (36px round). */
  .topbar #user-btn:not(.user-btn-initials) {
    padding: 0.7em 0.9em; white-space: nowrap; min-width: 0; width: auto;
  }
  .topbar #user-btn.user-btn-initials {
    padding: 0.3em; min-width: 40px; width: 40px; height: 40px;
  }

  /* No horizontal overflow: every topbar child must be shrinkable. The
     <select>'s default min-width:auto can otherwise push buttons past
     the viewport. */
  .topbar > * { min-width: 0; }
  .topbar #project-picker { flex: 1 1 0; min-width: 0; }

  /* Extra-tight screens (≤380px): collapse "+ New" text to just "+",
     Unfold to just the glyph, and Mode to the first letter of the
     current mode value (driven by JS — see #mode-badge population). */
  @media (max-width: 380px) {
    .topbar #new-project-btn { font-size: 0; padding: 0.7em; min-width: 40px; width: 40px; }
    .topbar #new-project-btn::before {
      content: "+"; font-size: 1.3rem; line-height: 1; color: inherit;
    }
    /* Unfold: keep the glyph, drop the word. JS still sets the full
     text; we clip via a smaller font-family override isn't viable, so
     instead we rely on a subtler max-width + overflow trick. */
    .topbar .tb-unfold {
      max-width: 44px; overflow: hidden; white-space: nowrap; padding: 0.7em 0;
      text-indent: 0;
    }
  }
  /* Overflow-menu items become full-width rows, tappable with a thumb. */
  .overflow-menu .om-item { padding: 0.85em 1em; font-size: 1em; min-height: 44px; }
  .overflow-menu { top: 3.2em; left: 0.6em; right: 0.6em; min-width: 0; }

  /* Scene control rows: stop relying on :hover (no hover on touch) and
     keep controls at full opacity so they're always discoverable. */
  .scene-block .ctrls { opacity: 1; flex-wrap: wrap; }

  /* Action dock takes the whole width, no side margin fiddling. */
  .action-dock .action-bar { width: calc(100% - 0.8em); padding: 0.6em 0.8em; }
  .action-dock .action-bar input#intent { min-width: 0; }
}

/* SCENE COLLAPSE DISCIPLINE — reading view is quiet by default.
   The collapsed state shows: chevron, location, POV, prose, and the
   single "Share this moment" primary action. Everything else —
   sequence number, tension, score badge, edited chip, version toggle,
   Rewrite/Regenerate/Lock/Go back controls, purpose subtitle — is
   hidden until the user taps the chevron to enter "edit/explore
   mode". This is the "reading first, controlling second" contract. */
.scene-block:not(.expanded) .head-expanded,
.scene-block:not(.expanded) .purpose,
.scene-block:not(.expanded) .version-toggle,
.scene-block:not(.expanded) .ctrls { display: none !important; }
/* Expanded state: reveal everything. .ctrls is a flex row, others are
   block. opacity:1 to override any legacy dimming. */
.scene-block.expanded .head-expanded { display: inline; opacity: 1; color: var(--muted); }
.scene-block.expanded .purpose { display: block; opacity: 1; }
.scene-block.expanded .version-toggle { display: inline-flex; opacity: 1; }
.scene-block.expanded .ctrls {
  display: flex; gap: 0.4em; margin-top: 0.8em;
  padding-top: 0.6em; border-top: 1px dotted var(--border);
  align-items: center; font-size: 0.85em; flex-wrap: wrap;
}

/* Primary "Share this moment" text-link — always visible beneath the
   prose. Styled as a muted, quiet button so it doesn't dominate the
   reading view, but always one tap away for the sender. */
.scene-block .share-row {
  margin-top: 0.8em; padding-top: 0.6em;
  border-top: 1px dotted var(--border);
}
.scene-block .share-moment-btn {
  background: transparent; color: var(--muted);
  border: none; padding: 0.25em 0;
  font: inherit; font-size: 0.88em;
  font-style: italic; cursor: pointer;
  letter-spacing: 0.02em;
  transition: color 140ms;
}
.scene-block .share-moment-btn::before {
  content: "› "; font-style: normal; opacity: 0.6;
}
.scene-block .share-moment-btn:hover { color: var(--accent); }

/* =========================================================================
   Story feed — the application.
   ========================================================================= */
#story-main {
  max-width: 760px;
  margin: 0 auto;
  padding: 3em 1.5em 8em;
  min-height: calc(100vh - 60px);
}
.autorun-banner {
  position: sticky; top: 48px; z-index: 9;
  background: rgba(111, 184, 255, 0.08);
  border: 1px solid var(--accent); border-radius: 4px;
  padding: 0.5em 0.9em; margin-bottom: 1em;
  font-size: 0.85em; color: var(--accent);
  display: flex; align-items: center; gap: 0.8em;
}
.story-empty { text-align: center; padding: 6em 2em; font-size: 0.95em; }
.scenes-feed { display: flex; flex-direction: column; gap: 2em; }

.scene-block {
  border-radius: 6px;
  padding: 0.4em 0 1.2em;
  border-bottom: 1px dotted var(--border);
  cursor: pointer;
  position: relative;
  transition: background 120ms;
}
.scene-block:last-child { border-bottom: none; }
/* No cursor:pointer on the whole block — only the chevron toggles expand,
   so the prose remains normally-selectable for copy-paste. */
.scene-block { cursor: default; }
.scene-block:hover { background: rgba(111, 184, 255, 0.02); }
.scene-block.expanded { background: rgba(111, 184, 255, 0.04); }
/* Scene expand toggle — needs to visibly read as a button, not a
   stray character. At rest, it looks like a quiet pill; on hover/tap,
   it lights up with the accent. Sized for real fingers (36px desktop,
   44px mobile) with a subtle label on wider screens so the affordance
   is unambiguous. */
.scene-block .head .expand-btn {
  display: inline-flex; align-items: center; gap: 0.35em;
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 0.3em 0.7em;
  font: inherit; font-size: 0.82em; cursor: pointer;
  letter-spacing: 0.04em; text-transform: uppercase; font-weight: 600;
  min-height: 30px;
  transition: color 140ms, border-color 140ms, background 140ms;
  margin-right: 0.6em;
}
.scene-block .head .expand-btn::after {
  content: "Details";
  display: inline-block;
}
.scene-block.expanded .head .expand-btn::after { content: "Hide"; }
.scene-block .head .expand-btn:hover {
  color: var(--accent); border-color: var(--accent);
  background: rgba(111,184,255,0.06);
}
.scene-block .head .expand-btn .chev {
  display: inline-block; transition: transform 150ms;
  font-size: 1.1em; line-height: 1;
}
.scene-block.expanded .head .expand-btn .chev { transform: rotate(90deg); }
@media (max-width: 720px) {
  .scene-block .head .expand-btn { min-height: 40px; padding: 0.45em 0.8em; font-size: 0.88em; }
}
.scene-block.flagged::before {
  content: ""; position: absolute; left: -1em; top: 0.6em; bottom: 0.6em;
  width: 2px; background: var(--warn); border-radius: 1px;
}
.scene-block.locked::before {
  content: ""; position: absolute; left: -1em; top: 0.6em; bottom: 0.6em;
  width: 2px; background: var(--accent); border-radius: 1px;
}
.scene-block .head {
  display: flex; align-items: baseline; gap: 0.6em;
  color: var(--muted); font-size: 0.72em; margin-bottom: 0.5em;
  letter-spacing: 0.05em;
}
.scene-block .head .seq { font-family: "SF Mono", Menlo, monospace; }
.scene-block .head .loc { color: var(--accent); font-style: italic; letter-spacing: 0.02em; }
.scene-block .head .pov { color: var(--muted); font-style: italic; }
.scene-block .head .sep { opacity: 0.4; }
.scene-block .head .score-badge {
  margin-left: auto; font-family: "SF Mono", Menlo, monospace;
  padding: 0.05em 0.5em; border-radius: 10px; font-size: 0.75em;
  border: 1px solid transparent;
}
.scene-block .head .score-badge.accept { color: var(--good); border-color: var(--good); }
.scene-block .head .score-badge.weak   { color: var(--warn); border-color: var(--warn); }
.scene-block .head .score-badge.reject { color: var(--bad);  border-color: var(--bad); }
.scene-block .head .score-badge.none   { color: var(--muted); border-color: var(--border); }

/* "Edited" badge — warm amber chip. Quietly indicates "you've reshaped
   this part of the story". Score badges follow the same sizing. */
.scene-block .head .edited-badge {
  margin-left: 0.4em; font-family: "SF Mono", Menlo, monospace;
  padding: 0.05em 0.5em; border-radius: 10px; font-size: 0.75em;
  border: 1px solid var(--warn); color: var(--warn);
  letter-spacing: 0.03em;
}

/* Version toggle — segmented pair. Sits between the scene head and prose;
   flips which version the reader sees (your rewrite ↔ the original).
   Pure client-side; no server calls. */
.scene-block .version-toggle {
  display: inline-flex; gap: 0; margin: 0.4em 0 0.8em;
  border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
  font-size: 0.78em; user-select: none;
}
.scene-block .version-toggle .vt-btn {
  background: transparent; color: var(--muted);
  border: none; padding: 0.3em 0.9em; cursor: pointer;
  font: inherit; letter-spacing: 0.03em;
  transition: background 140ms, color 140ms;
}
.scene-block .version-toggle .vt-btn + .vt-btn { border-left: 1px solid var(--border); }
.scene-block .version-toggle .vt-btn:hover:not(.active) { color: var(--text); }
.scene-block .version-toggle .vt-btn.active {
  background: rgba(111, 184, 255, 0.15); color: var(--accent); font-weight: 600;
}

/* Fade transition for prose swap — used by version-toggle and by the
   right-column variant swap when "Try again" drafts another take. */
.scene-block .prose-body.fading { opacity: 0.25; transition: opacity 140ms ease; }
.scene-block .prose-body { transition: opacity 140ms ease; }
.variant-prose.fading { opacity: 0.25; transition: opacity 140ms ease; }

/* Seamless rewrite mode: the prose itself becomes editable. Same Iowan
   typography as display mode; only a soft left-border + focus ring +
   a small header tell the user they're in edit state. No form chrome,
   no contrasting background — it reads as "shaping the story", not
   "filling in a form". */
.scene-block .prose-body[data-mode="edit"] {
  display: flex; flex-direction: column; gap: 0.9em;
}
.scene-block .reshape-header {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-style: italic; color: var(--muted); font-size: 0.85em;
  letter-spacing: 0.02em;
}
.scene-block .reshape-prose {
  outline: none;
  padding: 0.6em 0.9em;
  border-left: 2px solid var(--accent);
  background: rgba(111, 184, 255, 0.03);
  border-radius: 3px;
  /* Typography parity with .prose-body: */
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 1.05em; line-height: 1.72; color: var(--reader-text);
  min-height: 4em;
}
.scene-block .reshape-prose p { margin: 0 0 0.9em; text-indent: 1.4em; }
.scene-block .reshape-prose p:first-child { text-indent: 0; }
.scene-block .reshape-actions {
  display: flex; gap: 0.5em; align-items: center; flex-wrap: wrap;
}
.scene-block .reshape-actions button {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.4em 0.9em; cursor: pointer; font: inherit;
}
.scene-block .reshape-actions .reshape-keep {
  background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600;
}
.scene-block .reshape-actions .reshape-keep:hover { filter: brightness(1.1); }
.scene-block .reshape-actions .reshape-cancel:hover { border-color: var(--accent); color: var(--accent); }
.scene-block .reshape-actions .reshape-status.error-text { color: var(--bad); }
.scene-block.is-reshaping { background: rgba(111, 184, 255, 0.02); }

/* Variants side-by-side — a two-column comparison that opens inside the
   scene block when the user clicks "Try another version". Left is the
   snapshot of what they were reading; right is a freshly-drafted take.
   Both columns are equally selectable — user picks which to keep. */
.scene-block .prose-body[data-mode="variants"] {
  display: flex; flex-direction: column; gap: 0.8em;
}
.scene-block .variants-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.2em;
}
@media (max-width: 720px) {
  .scene-block .variants-grid { grid-template-columns: 1fr; gap: 0.8em; }
  /* Ensure the Keep buttons remain visible without scrolling on mobile —
     truncated prose is ~4 sentences (via JS _proseHtml on mobile) and
     the Keep button follows in the same column. */
  .scene-block .variant-col { padding: 0.4em 0 0.6em; }
}
/* "Read more" toggle inside a truncated variant column. Quiet text-link
   styling so it doesn't compete with the Keep buttons below. */
.scene-block .variant-readmore {
  background: transparent; color: var(--muted);
  border: none; padding: 0.3em 0 0; font: inherit; font-size: 0.88em;
  font-style: italic; cursor: pointer; letter-spacing: 0.02em;
  align-self: flex-start;
}
.scene-block .variant-readmore::before { content: "› "; font-style: normal; opacity: 0.6; }
.scene-block .variant-readmore:hover { color: var(--accent); }
.scene-block .variant-col {
  border-left: 2px solid var(--border);
  padding: 0.4em 0.9em 0.8em;
  display: flex; flex-direction: column; gap: 0.6em;
  transition: border-color 180ms, background 180ms;
}
.scene-block .variant-col.variant-right { border-left-color: var(--accent); }
.scene-block .variant-col .variant-label {
  font-size: 0.75em; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
}
.scene-block .variant-col.variant-right .variant-label { color: var(--accent); }
.scene-block .variant-prose {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 1em; line-height: 1.7; color: var(--reader-text);
}
.scene-block .variant-prose p { margin: 0 0 0.7em; text-indent: 1.2em; }
.scene-block .variant-prose p:first-child { text-indent: 0; }
.scene-block .variant-prose.variant-loading {
  display: flex; align-items: center; gap: 0.7em; color: var(--muted); font-style: italic;
  min-height: 3em;
}
.scene-block .variant-keep {
  align-self: flex-start;
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.35em 0.9em; cursor: pointer; font: inherit; font-size: 0.9em;
}
.scene-block .variant-keep:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.scene-block .variant-keep:disabled { opacity: 0.4; cursor: not-allowed; }
.scene-block .variant-col.variant-right .variant-keep {
  background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600;
}
.scene-block .variant-col.variant-right .variant-keep:hover:not(:disabled) { color: var(--bg); filter: brightness(1.1); }
/* Variant controls row: "Never mind" lives on the LEFT as a quiet
   text-link (escape hatch, not a sibling action). "Try again" is
   right-aligned as the primary action — it's the one users reach
   for after reading both takes. */
.scene-block .variant-controls {
  display: flex; gap: 0.5em; justify-content: space-between; align-items: center;
  padding-top: 0.5em; border-top: 1px dotted var(--border);
}
.scene-block .variant-controls .variant-cancel {
  background: transparent; color: var(--muted);
  border: none; padding: 0.35em 0.2em;
  cursor: pointer; font: inherit; font-size: 0.88em; font-style: italic;
  letter-spacing: 0.02em;
}
.scene-block .variant-controls .variant-cancel:hover { color: var(--text); }
.scene-block .variant-controls .variant-again {
  background: var(--accent); color: var(--bg);
  border: none; border-radius: 3px;
  padding: 0.45em 1em; cursor: pointer; font: inherit; font-size: 0.9em;
  font-weight: 600; letter-spacing: 0.02em;
}
.scene-block .variant-controls .variant-again:hover:not(:disabled) { filter: brightness(1.1); }
.scene-block .variant-controls .variant-again:disabled { opacity: 0.4; cursor: not-allowed; }
.scene-block.is-exploring { background: rgba(111, 184, 255, 0.02); }

/* Scene is currently showing the generated original instead of the edit —
   warm amber left border so it's obvious you're looking at the pre-edit
   version. */
.scene-block.viewing-original { border-left: 3px solid var(--warn); }

/* Share dialog: preview + note + result layout. Built around the idea
   that sharing is "passing along a story moment", not "exporting data". */
#share-dialog .share-preview {
  margin: 0.2em 0 0.9em; padding: 0.7em 0.9em;
  border-left: 2px solid var(--accent); border-radius: 3px;
  background: rgba(111, 184, 255, 0.04);
}
#share-dialog .share-preview:not(.show) { display: none; }
#share-dialog .share-preview-label {
  font-size: 0.72em; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 0.35em; font-weight: 600;
}
#share-dialog .share-preview-excerpt {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  color: var(--reader-text); font-size: 0.95em; line-height: 1.55;
  font-style: italic;
}
#share-dialog .share-note-label,
#share-dialog .share-visibility-label {
  display: flex; flex-direction: column; gap: 0.3em; margin: 0.6em 0;
}
#share-dialog .share-note-label > span:first-child,
#share-dialog .share-visibility-label > span:first-child {
  font-size: 0.85em; color: var(--text);
}
#share-dialog #share-note {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.55em 0.7em; font: inherit; font-family: inherit;
  resize: vertical; min-height: 3em;
}
#share-dialog #share-note:focus { outline: none; border-color: var(--accent); }
#share-dialog .share-actions { margin-top: 0.9em; justify-content: flex-end; gap: 0.5em; }
#share-dialog .share-actions button { font: inherit; cursor: pointer; }
#share-dialog .share-actions #share-copy-link-btn {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.55em 1em;
}
#share-dialog .share-actions #share-copy-link-btn:hover { border-color: var(--accent); color: var(--accent); }

#share-result { margin-top: 0.8em; }
#share-result .share-result-success {
  color: var(--good); font-size: 0.92em; margin: 0 0 0.5em;
}
#share-result .share-link-row {
  display: flex; gap: 0.5em; align-items: stretch;
}
#share-result .share-link-row input {
  flex: 1; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.5em 0.7em; font-family: "SF Mono", Menlo, monospace; font-size: 0.85em;
}
#share-result .share-bundle {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.6em 0.8em; font: inherit;
  font-family: -apple-system, system-ui, sans-serif; font-size: 0.9em;
  line-height: 1.45; resize: vertical;
}
#share-result .error { color: var(--bad); font-size: 0.9em; }
#share-result.show { animation: obFade 260ms ease; }

/* (Inline "That was a moment…" share prompt card removed — replaced by
   the quieter, always-visible .share-moment-btn inside each .scene-block.
   Dead CSS was here; now there's a single share affordance per scene,
   not an interruptive card.) */

.scene-block .purpose {
  font-size: 0.8em; color: var(--muted); font-style: italic; margin-bottom: 0.4em;
}
.scene-block .prose-body {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 1.05em; line-height: 1.72;
  color: var(--reader-text);
}
.scene-block .prose-body p { margin: 0 0 0.9em; text-indent: 1.4em; }
.scene-block .prose-body p:first-child { text-indent: 0; }
/* Drop cap: ONLY on the first scene in the feed — previously it rendered
   on every scene, giving the page ten giant blue letters. And it uses
   reader text color (warm off-white), not the accent blue, so it reads
   as typography, not as decoration. */
.scenes-feed > .scene-block:first-child .prose-body p:first-child::first-letter {
  font-size: 2.6em; float: left; line-height: 0.85;
  padding: 0.08em 0.12em 0 0; color: var(--reader-text);
}

/* Scene controls — always visible but subdued; full opacity on hover/focus
   or when the user has explicitly expanded the block. */
.scene-block .ctrls {
  display: flex; gap: 0.4em; margin-top: 0.8em;
  padding-top: 0.6em; border-top: 1px dotted var(--border);
  align-items: center; font-size: 0.85em;
  opacity: 0.55; transition: opacity 150ms ease;
}
.scene-block:hover .ctrls,
.scene-block:focus-within .ctrls,
.scene-block.expanded .ctrls { opacity: 1; }
.scene-block .ctrls button {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  font-size: 0.85em; padding: 0.45em 0.9em; border-radius: 3px; cursor: pointer;
  min-height: 36px;
}
@media (max-width: 720px) {
  .scene-block .ctrls button { font-size: 0.95em; padding: 0.6em 1em; min-height: 44px; }
}
.scene-block .ctrls button:hover { color: var(--text); border-color: var(--accent); }
.scene-block .ctrls button.locked { color: var(--accent); border-color: var(--accent); }
.scene-block .ctrls .reason { flex: 1; text-align: right; color: var(--muted); font-size: 0.75em; font-style: italic; }
.scene-block.regenerating { opacity: 0.55; }
.scene-block.regenerating::after {
  content: "regenerating…"; position: absolute; top: 0.6em; right: 0;
  font-size: 0.75em; color: var(--accent);
  padding: 0.2em 0.5em; border-radius: 3px; border: 1px solid var(--accent);
  background: var(--bg);
}

/* Interactive reader card (when mode includes 'interactive') — hosts choice buttons */
#interactive-output.interactive { margin-bottom: 2em; padding: 1.2em 0.2em; }
#interactive-output.interactive .chapter {
  font-size: 0.75em; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--muted); text-align: center; margin-bottom: 0.8em;
}
#interactive-output.interactive .scene {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 1.1em; line-height: 1.72; white-space: pre-wrap;
  margin-bottom: 1em;
}
#interactive-output.interactive .choices { display: flex; flex-direction: column; gap: 0.5em; margin: 0.8em 0; }
#interactive-output.interactive .choice-btn {
  text-align: left; padding: 0.65em 0.95em;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  font-family: Georgia, serif; font-size: 0.95em; cursor: pointer;
}
#interactive-output.interactive .choice-btn:hover:not(:disabled) {
  border-color: var(--accent); color: var(--accent);
}
#interactive-output.interactive .choice-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#interactive-output.interactive .free-action-prompt { font-style: italic; margin-top: 0.6em; color: var(--muted); }
#interactive-output.interactive .free-action-row { display: flex; gap: 0.5em; margin-top: 0.4em; }
#interactive-output.interactive .free-action-row input {
  flex: 1; background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.5em 0.7em; font-family: Georgia, serif;
}
#interactive-output.interactive .free-action-row button {
  background: var(--accent); color: var(--bg); border: none; border-radius: 4px;
  padding: 0.5em 1em; cursor: pointer; font-weight: 600;
}

.scene-choices {
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 4px; padding: 0.8em 1em; margin: 1em 0 2em;
}
.scene-choices h4 {
  margin: 0 0 0.6em; font-size: 0.75em; letter-spacing: 0.1em;
  color: var(--muted); text-transform: uppercase; font-weight: 600;
}
.scene-choices .choices-list { display: flex; flex-direction: column; gap: 0.4em; margin-bottom: 0.5em; }
.scene-choices button.choice-btn {
  text-align: left; padding: 0.5em 0.8em;
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 3px; font-family: Georgia, serif; font-size: 0.9em; cursor: pointer;
}
.scene-choices button.choice-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.scene-choices button.choice-btn:disabled { opacity: 0.4; cursor: not-allowed; }
/* "explored" = a child node of the current turn already exists for this
   choice, so clicking REPLAYS the saved branch instead of regenerating. The
   ↪ prefix in the label plus a quieter, dashed-left border distinguishes it
   from the fresh-generation buttons. */
.scene-choices button.choice-btn.explored {
  border-left-style: dashed; border-left-color: var(--accent); color: var(--muted); font-style: italic;
}
.scene-choices button.choice-btn.explored:hover:not(:disabled) { color: var(--accent); }
.scene-choices.autorun-held { opacity: 0.55; pointer-events: none; }
.scene-choices .free-row { display: flex; gap: 0.4em; }
.scene-choices .free-row input { flex: 1; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 3px; padding: 0.4em; font-family: Georgia, serif; }
.scene-choices .free-row button { background: var(--accent); color: var(--bg); border: none; border-radius: 3px; padding: 0.4em 0.8em; cursor: pointer; font-weight: 600; }

/* Checkpoint strip: Undo button + sibling branch chips above the choices.
   Lives inside .scene-choices and only appears when the project has branch
   tree data (migration 010+). Styled quiet so it doesn't compete with the
   primary choice buttons. */
.scene-choices .checkpoint-strip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.35em;
  margin-bottom: 0.6em; font-size: 0.8em; color: var(--muted);
}
.scene-choices .checkpoint-strip:empty { display: none; }
.scene-choices .undo-btn {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.2em 0.6em; cursor: pointer; font-family: inherit;
}
.scene-choices .undo-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.scene-choices .undo-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.scene-choices .checkpoint-sep { color: var(--border); margin: 0 0.2em; }
.scene-choices .checkpoint-label { color: var(--muted); font-style: italic; }
.scene-choices .sibling-chip {
  background: transparent; color: var(--muted);
  border: 1px dashed var(--border); border-radius: 3px;
  padding: 0.15em 0.5em; font-size: 0.9em; cursor: pointer;
  font-family: inherit;
}
.scene-choices .sibling-chip:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); border-style: solid; }
.scene-choices .sibling-chip:disabled { opacity: 0.35; cursor: not-allowed; }
/* Inline autorun button inside the checkpoint-strip — mirrors the dock's
   ▶ Auto so interactive mode (which hides the dock) still surfaces it. */
.scene-choices .autorun-inline-btn {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.2em 0.6em; cursor: pointer; font-family: inherit;
  margin-left: auto;
}
.scene-choices .autorun-inline-btn:hover { border-color: var(--accent); color: var(--accent); }
.scene-choices .autorun-inline-btn.running { border-color: var(--accent); color: var(--accent); background: rgba(111,184,255,0.08); }

/* =========================================================================
   Bottom action dock — always visible when a project is loaded (no more
   floating "+" button; the bar itself is the affordance).
   ========================================================================= */
.action-dock {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: center; pointer-events: none;
}
.action-dock.onboarding-hidden { display: none; }  /* hide during auth gate / onboarding / empty-state */
.action-dock .action-bar {
  display: flex;
  width: min(760px, calc(100% - 2em));
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px 6px 0 0; border-bottom: none;
  padding: 0.7em 1em;
  gap: 0.5em; align-items: center;
  pointer-events: auto;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.45);
}
.action-dock .action-bar select,
.action-dock .action-bar input {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 0.5em 0.7em; font-size: 0.95em;
}
.action-dock .action-bar input#intent {
  flex: 1; font-family: Georgia, serif;
}
.action-dock .action-bar button {
  background: var(--accent); color: var(--bg); border: none;
  border-radius: 3px; padding: 0.55em 0.9em; cursor: pointer;
  font-weight: 600;
}
.action-dock .action-bar #run-turn { padding: 0.55em 1.1em; font-weight: 600; }
.action-dock .action-bar #run-turn:disabled { opacity: 0.4; cursor: not-allowed; }
#turn-status { font-size: 0.75em; min-width: 6em; color: var(--text); }

/* Respect the iPhone home-indicator / Android nav area so the dock never
   sits under the system overlay. */
.action-dock .action-bar { padding-bottom: calc(0.7em + env(safe-area-inset-bottom, 0px)); }

/* In-dock writing-state takeover: when a turn is running, the input disappears
   and an inline spinner + message fills the bar. No job IDs, no rc= codes. */
.action-dock .action-bar.writing > #intent,
.action-dock .action-bar.writing > #run-turn,
.action-dock .action-bar.writing > #action-actor,
.action-dock .action-bar.writing > #turn-status { display: none; }
.action-dock .action-bar .writing-line {
  display: none; align-items: center; gap: 0.7em; flex: 1;
  color: var(--text); font-style: italic;
}
.action-dock .action-bar.writing .writing-line { display: flex; }
.writing-line .writing-dot {
  width: 0.7em; height: 0.7em; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: obSpin 1s linear infinite;
}
.writing-line .writing-elapsed {
  color: var(--muted); font-style: normal; font-variant-numeric: tabular-nums;
}
/* Centered writing-line for the scene-choices surface (interactive mode) */
.scene-choices .writing-line {
  padding: 0.8em 1em; border-radius: 4px;
}

/* =========================================================================
   Dual-input discipline: interactive mode uses .scene-choices as the only
   action surface; non-interactive modes use the bottom action-dock as the
   only action surface. Body gets a `mode-interactive` class from JS when
   state.mode includes 'interactive'.
   ========================================================================= */
body.mode-interactive .action-dock { display: none !important; }
body:not(.mode-interactive) .scene-choices { display: none !important; }

/* Make prose slightly brighter than chrome — main content is the point. */
.scene-block .prose-body { color: #f0eee6; }

/* =========================================================================
   Drawers (left = World/Author/Campaign, right = System)
   ========================================================================= */
.drawer {
  position: fixed; top: 0; bottom: 0; width: min(420px, 88vw);
  background: var(--panel);
  border-right: 1px solid var(--border);
  box-shadow: 6px 0 24px rgba(0,0,0,0.3);
  z-index: 40; overflow-y: auto;
  transition: transform 220ms ease;
  font-size: 0.88em;
}
.drawer.drawer-left  { left: 0;  transform: translateX(-100%); }
.drawer.drawer-right { right: 0; left: auto; border-right: none; border-left: 1px solid var(--border); box-shadow: -6px 0 24px rgba(0,0,0,0.3); transform: translateX(100%); }
.drawer:not(.hidden).drawer-left  { transform: translateX(0); }
.drawer:not(.hidden).drawer-right { transform: translateX(0); }
.drawer-head {
  position: sticky; top: 0; z-index: 2;
  background: var(--panel);
  display: flex; align-items: center; gap: 0.5em;
  padding: 0.7em 1em; border-bottom: 1px solid var(--border);
}
.drawer-head h3 { margin: 0; font-size: 0.85em; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); font-weight: 600; flex: 1; }
.drawer-close {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  padding: 0.2em 0.55em; border-radius: 3px; cursor: pointer; font-size: 1em;
}
.drawer-close:hover { color: var(--text); border-color: var(--bad); }
.drawer-body { padding: 1em 1.2em 2em; }

/* Author tab: three grouped sections instead of a flat accordion list.
   Each group is separated by a subtle divider + a small uppercase header
   so users can scan "Story shape" vs "People & Places" vs "Structure"
   instead of hunting through seven identical <h3>s. */
.tab-panel[data-tab="author"] .author-group {
  margin-bottom: 1.6em;
  padding-bottom: 1em;
  border-bottom: 1px solid var(--border);
}
.tab-panel[data-tab="author"] .author-group:last-child { border-bottom: none; margin-bottom: 0; }
.tab-panel[data-tab="author"] .author-group-head {
  font-size: 0.72em; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; margin: 0 0 0.6em;
  padding-left: 0.2em;
}
.tab-panel[data-tab="author"] .author-group details { margin-bottom: 0.4em; }

.tabs { display: flex; gap: 0.3em; flex: 1; }
.tabs .tab {
  background: transparent; color: var(--muted); border: none; border-bottom: 2px solid transparent;
  padding: 0.4em 0.7em; font-size: 0.8em; letter-spacing: 0.08em; text-transform: uppercase;
  cursor: pointer; font-weight: 600;
}
.tabs .tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .tab:hover:not(.active) { color: var(--text); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Drawer forms — tight, consistent */
.drawer details { border-bottom: 1px dotted var(--border); padding: 0.3em 0; }
.drawer details[open] { padding-bottom: 0.8em; }
.drawer details > summary { cursor: pointer; padding: 0.4em 0; list-style: none; }
.drawer details > summary::-webkit-details-marker { display: none; }
.drawer details > summary::before { content: "▸"; display: inline-block; width: 1em; color: var(--muted); transition: transform 120ms; }
.drawer details[open] > summary::before { transform: rotate(90deg); }
.drawer details > summary h3 {
  display: inline; font-size: 0.8em; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; margin: 0;
}
.drawer h3 { font-size: 0.8em; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 1em 0 0.4em; }
.drawer h4 { font-size: 0.8em; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 0 0 0.5em; }
.drawer form { margin-bottom: 0.3em; }
.drawer form.stacked > input,
.drawer form.stacked > select,
.drawer form.stacked > textarea,
.drawer form > input,
.drawer form > select,
.drawer form > textarea {
  display: block; width: 100%; margin-bottom: 0.35em;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 3px; padding: 0.35em 0.5em; font-size: 0.88em; font-family: inherit;
}
.drawer form textarea { resize: vertical; min-height: 3em; }
.drawer form button {
  background: var(--accent); color: var(--bg); border: none; border-radius: 3px;
  padding: 0.4em 0.9em; cursor: pointer; font-size: 0.85em; font-weight: 600;
}
.drawer form button:hover { filter: brightness(1.1); }
.drawer form label { font-size: 0.85em; display: inline-block; margin-right: 0.4em; }
.drawer .scroll { max-height: 40vh; overflow-y: auto; margin-top: 0.4em; padding-right: 0.2em; }

/* Right drawer sections */
.sys-block { margin-bottom: 1.2em; padding-bottom: 1em; border-bottom: 1px dotted var(--border); }
.sys-block:last-child { border: none; }
.sys-block h4 { margin: 0 0 0.5em; }
.sys-block select, .sys-block input[type=range] { width: 100%; }
.sys-block select { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 3px; padding: 0.35em 0.5em; }
.sys-block label { display: block; margin-bottom: 0.3em; font-size: 0.88em; }
.sys-block .autorun-controls { display: flex; align-items: center; gap: 0.5em; margin-bottom: 0.5em; }
.sys-block button#autorun-toggle {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  padding: 0.35em 0.8em; border-radius: 3px; cursor: pointer; font-size: 0.88em;
}
.sys-block button#autorun-toggle.running { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
.sys-block button#autorun-toggle:hover:not(.running) { border-color: var(--accent); color: var(--accent); }
#autorun-speed-label { margin-left: 0.4em; font-size: 0.8em; color: var(--muted); }
#autorun-status.tension-low  { color: var(--muted); }
#autorun-status.tension-mid  { color: var(--warn); }
#autorun-status.tension-high { color: var(--bad); }

/* Drawer backdrop */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 35;
  opacity: 0; pointer-events: none; transition: opacity 180ms;
}
.drawer-backdrop.show { opacity: 1; pointer-events: auto; }

/* =========================================================================
   Drawer content rendering (characters, threads, canon, sheets, events)
   ========================================================================= */
#project-meta { padding: 0.4em 0 0.8em; border-bottom: 1px dotted var(--border); margin-bottom: 0.6em; font-size: 0.88em; }
.thread { padding: 0.4em 0; border-bottom: 1px dotted var(--border); font-size: 0.85em; }
.thread:last-child { border: none; }
.thread .id { color: var(--accent); font-family: "SF Mono", Menlo, monospace; font-size: 0.85em; }
.thread .status { font-size: 0.72em; padding: 0.1em 0.4em; border-radius: 3px; margin-left: 0.4em; letter-spacing: 0.05em; }
.status.open        { background: var(--border); color: var(--muted); }
.status.escalating  { background: #403224; color: var(--warn); }
.status.resolved    { background: #254532; color: var(--good); }
.thread .setup { color: var(--text); margin-top: 0.2em; }
.thread .payoffs { color: var(--muted); font-size: 0.8em; margin-top: 0.2em; }
.thread .payoffs li { margin-left: 1em; }

.char { padding: 0.5em 0; border-bottom: 1px dotted var(--border); font-size: 0.85em; }
.char:last-child { border: none; }
.char .name { font-weight: 600; }
.char .arc { display: inline-block; font-size: 0.8em; color: var(--warn); margin-left: 0.5em; }
.char .beliefs { display: flex; flex-wrap: wrap; gap: 0.3em; margin-top: 0.3em; }
.char .belief { font-size: 0.72em; padding: 0.1em 0.45em; border-radius: 3px; background: var(--bg); font-family: "SF Mono", Menlo, monospace; }
.char .belief .v { color: var(--accent); margin-left: 0.3em; }
.char details { margin-top: 0.4em; border: none; padding: 0; }
.char details summary { font-size: 0.78em; color: var(--muted); padding: 0; }
.char details summary::before { content: "▸"; }
.char details ul { margin: 0.3em 0 0 1em; padding: 0; font-size: 0.8em; }

.fact { padding: 0.3em 0; border-bottom: 1px dotted var(--border); display: flex; gap: 0.5em; align-items: flex-start; font-size: 0.82em; }
.fact:last-child { border: none; }
.fact .locked { color: var(--warn); }
.fact .unlocked { color: var(--muted); }
.fact .vis { font-size: 0.68em; padding: 0.05em 0.35em; border-radius: 2px; background: var(--border); color: var(--muted); }
.fact .vis.dm_only { background: #4a2c2c; color: var(--bad); }
.fact .vis.party_only { background: #2c3f4a; color: var(--accent); }
.fact .triple { flex: 1; }
.fact .triple .s { color: var(--accent); }
.fact .triple .p { color: var(--muted); margin: 0 0.3em; }
.fact .triple .o { color: var(--text); }
.fact button { background: transparent; border: 1px solid var(--border); color: var(--muted); font-size: 0.7em; padding: 0.1em 0.3em; border-radius: 3px; cursor: pointer; }
.fact button:hover { color: var(--text); border-color: var(--accent); }

.sheet { padding: 0.5em 0; border-bottom: 1px dotted var(--border); font-size: 0.85em; }
.sheet:last-child { border: none; }
.sheet-head { display: flex; align-items: center; gap: 0.5em; flex-wrap: wrap; }
.sheet-head .name { font-weight: 600; }
.sheet-head .tag { font-size: 0.7em; padding: 0.1em 0.4em; border-radius: 3px; background: var(--border); color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.sheet-head .tag.pc { background: #2c3f4a; color: var(--accent); }
.sheet-head .role { color: var(--muted); font-size: 0.8em; }
.sheet-hp { display: flex; align-items: center; gap: 0.4em; margin: 0.3em 0; font-size: 0.85em; }
.sheet-hp .bar { flex: 1; height: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 5px; overflow: hidden; }
.sheet-hp .bar .fill { height: 100%; background: var(--good); transition: width 200ms; }
.sheet-hp .bar .fill.low { background: var(--warn); }
.sheet-hp .bar .fill.crit { background: var(--bad); }
.sheet-hp input[type="number"] { width: 3em; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 3px; padding: 0.1em 0.3em; font-size: 0.85em; }
.sheet-hp button { background: transparent; border: 1px solid var(--border); color: var(--muted); font-size: 0.72em; padding: 0.1em 0.4em; border-radius: 3px; cursor: pointer; }
.sheet .conditions { display: flex; gap: 0.25em; flex-wrap: wrap; margin-top: 0.3em; }
.sheet .cond { font-size: 0.7em; padding: 0.1em 0.4em; border-radius: 3px; background: var(--bg); color: var(--warn); border: 1px solid var(--warn); cursor: pointer; }
.sheet .add-cond { background: transparent; border: 1px dashed var(--border); color: var(--muted); font-size: 0.7em; padding: 0.1em 0.4em; border-radius: 3px; cursor: pointer; }

.dice-row, .play-row, .init-form { display: flex; flex-wrap: wrap; gap: 0.3em; align-items: center; }
.dice-row input, .dice-row select, .play-row input, .play-row select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 3px; padding: 0.3em 0.4em; font-size: 0.85em;
}
.dice-row button, .play-row button, .init-form button {
  background: var(--accent); color: var(--bg); border: none; border-radius: 3px;
  padding: 0.3em 0.7em; cursor: pointer; font-size: 0.85em; font-weight: 600;
}
.init-form button.muted { background: var(--border); color: var(--muted); }
.dice-result { font-size: 0.9em; margin-top: 0.3em; padding: 0.4em 0.6em; background: var(--bg); border-radius: 3px; min-height: 1.5em; font-family: "SF Mono", Menlo, monospace; }
.dice-result.success { border-left: 3px solid var(--good); }
.dice-result.fail { border-left: 3px solid var(--bad); }
.dice-result.crit { border-left: 3px solid var(--accent); font-weight: 600; }
#rolls-list { font-size: 0.75em; max-height: 10em; overflow-y: auto; color: var(--muted); }

#events-list .event { padding: 0.35em 0; border-bottom: 1px dotted var(--border); font-size: 0.85em; }
#events-list .event:last-child { border: none; }
#events-list .event .status { font-size: 0.68em; padding: 0.1em 0.35em; border-radius: 2px; letter-spacing: 0.05em; text-transform: uppercase; }
#events-list .event .when { color: var(--muted); font-size: 0.75em; font-family: "SF Mono", Menlo, monospace; }

.init-list { margin-bottom: 0.4em; }
.init-row { display: flex; align-items: center; gap: 0.5em; padding: 0.25em 0; font-size: 0.85em; }
.init-row.current { background: var(--border); border-radius: 3px; padding-left: 0.4em; }
.init-row .rank { color: var(--muted); font-family: "SF Mono", monospace; font-size: 0.8em; width: 1.5em; }
.init-row .init { color: var(--accent); font-family: "SF Mono", monospace; font-size: 0.8em; margin-left: auto; }

#char-list .char-item { padding: 0.4em 0; border-bottom: 1px dotted var(--border); font-size: 0.85em; }
#char-list .char-item:last-child { border: none; }
#char-list .char-item .name { font-weight: 600; }
#char-list .char-item .role { color: var(--muted); font-size: 0.75em; margin-left: 0.4em; }
#char-list .char-item .actions { margin-top: 0.3em; display: flex; gap: 0.4em; }
#char-list .char-item button { background: transparent; border: 1px solid var(--border); color: var(--muted); font-size: 0.75em; padding: 0.15em 0.5em; border-radius: 3px; cursor: pointer; }
#char-list .char-item .backstory { color: var(--muted); font-size: 0.85em; margin-top: 0.3em; padding: 0.3em; background: var(--bg); border-radius: 3px; line-height: 1.4; white-space: pre-wrap; }

#locations-list > div { padding: 0.25em 0; border-bottom: 1px dotted var(--border); font-size: 0.85em; color: var(--text); }

#planned-list .plan-item { padding: 0.35em 0; border-bottom: 1px dotted var(--border); font-size: 0.85em; }
#planned-list .plan-item:last-child { border: none; }
#planned-list .plan-item .title { font-weight: 600; }
#planned-list .plan-item .at { color: var(--accent); font-size: 0.8em; }

.asset { padding: 0.5em 0; border-bottom: 1px dotted var(--border); }
.asset:last-child { border: none; }
.asset img { max-width: 100%; max-height: 160px; border-radius: 4px; margin-bottom: 0.3em; }
.asset .id { font-family: "SF Mono", Menlo, monospace; font-size: 0.75em; color: var(--muted); }
.asset details pre { font-size: 0.72em; background: var(--bg); padding: 0.4em; border-radius: 3px; max-height: 160px; overflow-y: auto; }

/* =========================================================================
   Modals (native <dialog>)
   ========================================================================= */
dialog {
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); color: var(--text);
  padding: 1.4em 1.6em; box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  max-width: 28em; width: 92%;
}
dialog::backdrop { background: rgba(8, 10, 14, 0.6); backdrop-filter: blur(2px); }
dialog h3 { margin: 0 0 0.8em; color: var(--accent); font-size: 1em; }
dialog label { display: block; margin-bottom: 0.6em; font-size: 0.9em; }
dialog label > span.muted { margin-left: 0.5em; font-size: 0.8em; }
dialog input, dialog select {
  display: block; width: 100%; margin-top: 0.2em;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.4em 0.6em; font-size: 0.95em; font-family: inherit;
}
dialog fieldset { border: 1px solid var(--border); border-radius: 5px; padding: 0.6em 0.8em 0.3em; margin: 0.6em 0 1em; }
dialog fieldset legend { padding: 0 0.4em; font-size: 0.85em; }
dialog fieldset label { display: inline-block; width: 47%; margin-right: 0.5em; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5em; margin-top: 0.8em; }
.dialog-actions button {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.45em 1em; cursor: pointer; font-weight: 500;
}
.dialog-actions button.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.dialog-actions button:hover { filter: brightness(1.1); }
.error { color: var(--bad); font-size: 0.85em; margin-top: 0.6em; min-height: 1em; }

/* Role badge in top bar */
#role-badge {
  font-size: 0.7em; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 0.15em 0.5em; border-radius: 3px;
  background: var(--border); color: var(--muted);
}
#role-badge.role-owner  { background: #4a3c1f; color: var(--accent); border: 1px solid var(--accent); }
#role-badge.role-editor { background: #2c3f4a; color: var(--accent); }
#role-badge.role-player { background: #253f32; color: var(--good); }
#role-badge.role-viewer { background: var(--border); color: var(--muted); }
.user-btn.logged-in { color: var(--accent); border-color: var(--accent); }

/* Members list inside People drawer */
#members-list .member { display: flex; align-items: center; gap: 0.5em; padding: 0.35em 0; border-bottom: 1px dotted var(--border); font-size: 0.88em; }
#members-list .member:last-child { border: none; }
#members-list .member .name { flex: 1; }
#members-list .member .email { color: var(--muted); font-size: 0.78em; }
#members-list .member .role-tag { font-size: 0.7em; letter-spacing: 0.05em; text-transform: uppercase; padding: 0.1em 0.4em; border-radius: 3px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
#members-list .member .role-tag.owner { background: #4a3c1f; color: var(--accent); border-color: var(--accent); }
#members-list .member button { background: transparent; border: 1px solid var(--border); color: var(--muted); font-size: 0.75em; padding: 0.15em 0.4em; border-radius: 3px; cursor: pointer; }
#members-list .member button:hover { color: var(--bad); border-color: var(--bad); }

#current-user-card { padding: 0.4em 0; border-bottom: 1px dotted var(--border); margin-bottom: 0.5em; }
#current-user-card .name { font-weight: 600; }
#current-user-card .email { color: var(--muted); font-size: 0.82em; }

#invite-result { margin-top: 0.8em; padding: 0.6em; background: var(--bg); border-radius: 4px; font-size: 0.85em; word-break: break-all; display: none; }
#invite-result.show { display: block; }
#invite-result .url { font-family: "SF Mono", Menlo, monospace; color: var(--accent); user-select: all; }
#invite-result .copy-btn { margin-top: 0.5em; background: var(--accent); color: var(--bg); border: none; padding: 0.3em 0.7em; border-radius: 3px; cursor: pointer; font-size: 0.8em; }

/* Role-gated UI affordances */
.role-hidden { display: none !important; }       /* hide from non-editors/owners */
.role-disabled { opacity: 0.4; pointer-events: none; }

/* =========================================================================
   Toast (status + errors)
   ========================================================================= */
.toast {
  position: fixed; top: 1em; right: 1em; z-index: 100;
  padding: 0.7em 1em; border-radius: 4px; max-width: 32em;
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4); font-size: 0.85em;
  transition: opacity 150ms, transform 150ms;
}
.toast.hidden { opacity: 0; transform: translateX(1em); pointer-events: none; }
.toast.error { border-color: var(--bad); border-left-width: 3px; }
.toast.info  { border-color: var(--accent); border-left-width: 3px; }

/* Debug log when toggled */
#turn-log {
  font-family: "SF Mono", Menlo, monospace; font-size: 0.72em;
  white-space: pre-wrap; color: var(--muted);
  background: var(--panel); border: 1px solid var(--border); border-radius: 4px;
  padding: 0.8em; margin: 1em 0;
  max-height: 40vh; overflow-y: auto;
}
