:root {
    color-scheme: light;
    --paper: #f5f7fb;
    --surface: #ffffff;
    --surface-strong: #ffffff;
    --ink: #111827;
    --muted: #64748b;
    --line: #d8dee8;
    --charcoal: #111827;
    --charcoal-2: #ffffff;
    --accent: #d23b45;
    --accent-dark: #b82734;
    --blue: #2563eb;
    --green: #047857;
    --amber: #b45309;
    --danger: #b91c1c;
    --shadow: 0 18px 50px rgba(23, 23, 23, 0.12);
    --radius: 8px;
    /* Tier colors — used in Story Bible, Prompt Builder, Panels, Pages */
    --tier-main-bg: #fde2e4;
    --tier-main-fg: #9f1239;
    --tier-main-ring: #f43f5e;
    --tier-secondary-bg: #dbeafe;
    --tier-secondary-fg: #1e3a8a;
    --tier-secondary-ring: #3b82f6;
    --tier-recurring_minor-bg: #ede9fe;
    --tier-recurring_minor-fg: #5b21b6;
    --tier-recurring_minor-ring: #8b5cf6;
    --tier-one_scene_extra-bg: #fef3c7;
    --tier-one_scene_extra-fg: #92400e;
    --tier-one_scene_extra-ring: #f59e0b;
    --tier-crowd_type-bg: #e2e8f0;
    --tier-crowd_type-fg: #334155;
    --tier-crowd_type-ring: #64748b;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--paper);
    /* Reserve a stable gutter so layout doesn't shift when scrollbar appears/disappears. */
    scrollbar-gutter: stable;
    /* Firefox scrollbar styling. */
    scrollbar-width: thin;
    scrollbar-color: rgba(15, 23, 42, 0.28) transparent;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background: var(--paper);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* === Global sleek scrollbars (WebKit/Blink) ============================
   Applied to every scroll container so the visual is consistent across
   the app. Theme-aware via the `body.narrorift-mode` override below. */
*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: rgba(15, 23, 42, 0.22);
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
    background: rgba(15, 23, 42, 0.38);
    background-clip: padding-box;
    border: 2px solid transparent;
}

*::-webkit-scrollbar-thumb:active {
    background: rgba(15, 23, 42, 0.52);
    background-clip: padding-box;
    border: 2px solid transparent;
}

*::-webkit-scrollbar-corner {
    background: transparent;
}

/* Dark theme scrollbars — matches narrorift-mode palette. */
body.narrorift-mode,
body.is-launch-view {
    scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}

body.narrorift-mode *::-webkit-scrollbar-thumb,
body.is-launch-view *::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.28);
    background-clip: padding-box;
}

body.narrorift-mode *::-webkit-scrollbar-thumb:hover,
body.is-launch-view *::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.5);
    background-clip: padding-box;
}

body.narrorift-mode *::-webkit-scrollbar-thumb:active,
body.is-launch-view *::-webkit-scrollbar-thumb:active {
    background: rgba(148, 163, 184, 0.7);
    background-clip: padding-box;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: wait;
    opacity: 0.64;
}

a {
    color: inherit;
}

.app-root {
    min-height: 100vh;
}

.auth-view {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 430px);
    gap: 40px;
    align-items: center;
    padding: 56px clamp(20px, 5vw, 72px);
}

/* === Narrorift launch screen ============================================
   When auth.js sets `body.is-launch-view`, the standard auth layout is
   restyled into a dedicated "connecting" interstitial: dark theme matching
   narrorift-mode, centered single column, glass card with a spinner. This
   only applies while the launch is in progress — once the user lands in
   the studio (showAuthed) the class is removed.
*/
body.is-launch-view {
    color-scheme: dark;
    --paper: #090b12;
    --surface: #11151f;
    --surface-strong: #151b27;
    --ink: #eef2f7;
    --muted: #9ca3af;
    --line: #293244;
    --accent: #38bdf8;
    --accent-dark: #0ea5e9;
    --green: #22c55e;
    --danger: #f87171;
    --shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
    background:
        radial-gradient(1100px 540px at 18% 12%, rgba(56, 189, 248, 0.10), transparent 70%),
        radial-gradient(900px 480px at 82% 88%, rgba(190, 18, 60, 0.08), transparent 72%),
        linear-gradient(90deg, rgba(148, 163, 184, 0.05) 1px, transparent 1px),
        linear-gradient(180deg, rgba(148, 163, 184, 0.05) 1px, transparent 1px),
        var(--paper);
    background-size: auto, auto, 34px 34px, 34px 34px, auto;
}

body.is-launch-view .auth-view {
    grid-template-columns: minmax(0, 1fr);
    place-items: center;
    text-align: center;
    padding: 56px clamp(20px, 5vw, 72px);
}

body.is-launch-view .auth-copy {
    max-width: 720px;
    display: grid;
    gap: 18px;
    justify-items: center;
}

body.is-launch-view .auth-copy .eyebrow {
    color: var(--accent);
    letter-spacing: 0.18em;
}

body.is-launch-view .auth-copy h1 {
    max-width: none;
    font-size: clamp(2.4rem, 6.4vw, 4.6rem);
    line-height: 1.02;
    background: linear-gradient(120deg, #f8fafc 0%, #cbd5e1 60%, #94a3b8 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 12px 36px rgba(56, 189, 248, 0.10);
}

body.is-launch-view .auth-copy p:not(.eyebrow) {
    max-width: 480px;
    margin: 0;
    color: var(--muted);
    font-size: 1.04rem;
    line-height: 1.6;
}

body.is-launch-view .auth-panel {
    margin-top: 8px;
    padding: 0;
    border: 0;
    box-shadow: none;
    background: transparent;
    width: min(440px, 100%);
}

/* All the auth-panel children except the message are hidden in launch
   mode by auth.js, so we only need to style the message itself. */
body.is-launch-view #auth-message {
    position: relative;
    margin: 0;
    padding: 18px 22px 18px 56px;
    min-height: 56px;
    border-radius: 14px;
    border: 1px solid rgba(56, 189, 248, 0.22);
    background:
        linear-gradient(135deg, rgba(21, 27, 39, 0.92), rgba(13, 17, 26, 0.92));
    box-shadow:
        0 18px 48px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(148, 163, 184, 0.06);
    backdrop-filter: blur(10px);
    color: #e2e8f0;
    font-size: 0.98rem;
    line-height: 1.5;
    text-align: left;
    display: flex;
    align-items: center;
}

body.is-launch-view #auth-message::before {
    content: "";
    position: absolute;
    left: 20px;
    top: 50%;
    width: 22px;
    height: 22px;
    margin-top: -11px;
    border-radius: 50%;
    border: 2px solid rgba(56, 189, 248, 0.25);
    border-top-color: var(--accent);
    animation: launchSpin 0.9s linear infinite;
}

body.is-launch-view #auth-message.error {
    border-color: rgba(248, 113, 113, 0.45);
    color: #fecaca;
}

body.is-launch-view #auth-message.error::before {
    border-color: rgba(248, 113, 113, 0.25);
    border-top-color: var(--danger);
    animation: none;
    /* Render an "!" instead of a spinner on error states. */
    content: "!";
    display: grid;
    place-items: center;
    color: var(--danger);
    font-weight: 900;
    font-size: 14px;
    background: rgba(248, 113, 113, 0.08);
}

@keyframes launchSpin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    body.is-launch-view #auth-message::before {
        animation: none;
    }
}

@media (max-width: 720px) {
    body.is-launch-view .auth-view {
        padding: 40px 20px;
        gap: 28px;
    }
    body.is-launch-view .auth-copy h1 {
        font-size: clamp(2rem, 9vw, 3rem);
    }
}
/* === end launch screen =================================================== */

.auth-copy {
    max-width: 680px;
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--accent);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.auth-copy h1 {
    margin: 0;
    max-width: 620px;
    font-size: clamp(2.6rem, 7vw, 5.8rem);
    line-height: 0.96;
    letter-spacing: 0;
}

.auth-copy p:not(.eyebrow) {
    max-width: 560px;
    margin: 22px 0 0;
    color: #4b4540;
    font-size: 1.08rem;
    line-height: 1.7;
}

.auth-panel,
.tool-panel,
.result-panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 253, 250, 0.95);
    box-shadow: var(--shadow);
}

.auth-panel {
    padding: 22px;
}

.auth-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 18px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #eee7db;
}

.auth-tab {
    min-height: 42px;
    border: 0;
    border-radius: 6px;
    color: var(--muted);
    background: transparent;
    font-weight: 750;
}

.auth-tab.active {
    color: var(--ink);
    background: var(--surface-strong);
    box-shadow: 0 8px 22px rgba(23, 23, 23, 0.08);
}

.auth-form,
.wide-form {
    display: grid;
    gap: 15px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 760;
}

input,
textarea,
select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--ink);
    background: var(--surface-strong);
    padding: 10px 12px;
    outline: none;
}

textarea {
    resize: vertical;
    line-height: 1.5;
}

select[multiple] {
    min-height: 136px;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.primary-action,
.secondary-action {
    min-height: 44px;
    border-radius: 7px;
    padding: 0 16px;
    font-weight: 820;
}

.primary-action {
    border: 1px solid var(--accent-dark);
    color: #fff;
    background: var(--accent);
}

.primary-action:hover {
    background: var(--accent-dark);
}

.secondary-action {
    border: 1px solid var(--line);
    color: var(--ink);
    background: var(--surface-strong);
}

.secondary-action:hover {
    border-color: #b6ab9e;
    background: #f8f4ed;
}

.divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 18px 0;
    color: var(--muted);
    font-size: 0.8rem;
}

.divider::before,
.divider::after {
    content: "";
    height: 1px;
    flex: 1;
    background: var(--line);
}

.form-message {
    min-height: 20px;
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.4;
}

.form-message.error {
    color: var(--danger);
}

.form-message.success {
    color: var(--green);
}

.form-message.warning {
    color: var(--amber);
}

/* Toast-style transient messages set by setStudioMessage(). Pops up from
   the bottom-center of the viewport, then slides back down and fades when
   `is-fading` is added by the auto-dismiss timer. Non-toast (sticky)
   messages render inline in their original location, exactly as before. */
.form-message.is-toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    z-index: 9000;
    max-width: min(540px, calc(100vw - 32px));
    margin: 0;
    padding: 12px 18px;
    border-radius: 12px;
    background: rgba(20, 24, 33, 0.94);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    text-align: center;
    pointer-events: none;
    transform: translate(-50%, 0);
    opacity: 1;
    animation: studioMessageSlideUp 260ms cubic-bezier(0.16, 0.84, 0.44, 1);
    transition: opacity 320ms ease, transform 320ms ease;
    will-change: opacity, transform;
}

.form-message.is-toast.error {
    border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}

.form-message.is-toast.success {
    border-color: color-mix(in srgb, var(--green) 45%, transparent);
}

.form-message.is-toast.is-fading {
    opacity: 0;
    transform: translate(-50%, 24px);
}

@keyframes studioMessageSlideUp {
    from {
        opacity: 0;
        transform: translate(-50%, 32px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .form-message.is-toast {
        animation: none;
        transition: opacity 200ms linear;
    }
    .form-message.is-toast.is-fading {
        transform: translate(-50%, 0);
    }
}

.studio-view {
    min-height: 100vh;
    display: grid;
    grid-template-rows: 68px 1fr;
}

.studio-topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 0 clamp(18px, 4vw, 36px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
    background: var(--charcoal);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    text-decoration: none;
}

.brand-mark {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 8px;
    background: var(--accent);
    font-weight: 900;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: #cfc7bd;
    font-size: 0.78rem;
}

.topbar-actions {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.mode-badge,
.return-link {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 7px;
    color: #f8fafc;
    background: rgba(255, 255, 255, 0.08);
    padding: 0 10px;
    font-size: 0.78rem;
    font-weight: 820;
    white-space: nowrap;
}

.return-link {
    border-color: rgba(34, 197, 94, 0.45);
    color: #bbf7d0;
    text-decoration: none;
}

.return-link:hover {
    background: rgba(34, 197, 94, 0.14);
}

.user-email {
    max-width: 270px;
    overflow: hidden;
    color: #e8ded3;
    font-size: 0.9rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-button {
    display: inline-grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--ink);
    background: var(--surface-strong);
}

.studio-topbar .icon-button {
    border-color: rgba(255, 255, 255, 0.22);
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.icon-button svg {
    width: 18px;
    height: 18px;
}

.studio-layout {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    min-height: 0;
}

.studio-sidebar {
    position: sticky;
    top: 68px;
    height: calc(100vh - 68px);
    padding: 16px 12px;
    border-right: 1px solid rgba(255, 255, 255, 0.12);
    background: var(--charcoal-2);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    margin-bottom: 5px;
    border: 1px solid transparent;
    border-radius: 7px;
    color: #e9e0d6;
    background: transparent;
    padding: 0 12px;
    text-align: left;
    font-weight: 760;
}

.nav-item svg {
    width: 18px;
    height: 18px;
}

.nav-item:hover,
.nav-item.active {
    border-color: rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.09);
}

.studio-main {
    min-width: 0;
    padding: 28px clamp(18px, 4vw, 40px) 56px;
}

.studio-status {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.studio-status h2 {
    margin: 0;
    font-size: clamp(1.65rem, 3vw, 2.3rem);
    letter-spacing: 0;
}

.studio-status .form-message {
    max-width: 520px;
    text-align: right;
}

.studio-section {
    display: none;
}

.studio-section.active {
    display: block;
}

.workspace-grid {
    display: grid;
    grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.tool-panel,
.result-panel {
    padding: 18px;
}

.tool-panel h3,
.result-panel h3 {
    margin: 0 0 16px;
    font-size: 1.05rem;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.panel-heading h3 {
    margin: 0;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.form-grid .span-2 {
    grid-column: span 2;
}

.form-section {
    display: grid;
    gap: 12px;
    padding-top: 2px;
}

.form-section h4 {
    margin: 0;
    color: var(--ink);
    font-size: 0.96rem;
}

.form-section p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.83rem;
    line-height: 1.45;
}

.cast-detail-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.cast-detail-grid .span-2 {
    grid-column: span 2;
}

.trait-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.panel-generator-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.item-list {
    display: grid;
    gap: 10px;
}

.content-list {
    margin-top: 18px;
}

.forge-panel {
    margin-bottom: 18px;
}

.draft-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 12px;
    margin-top: 14px;
}

.draft-card {
    display: grid;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-strong);
    padding: 14px;
}

.draft-card-header {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 12px;
}

.draft-card h4 {
    margin: 0 0 6px;
    font-size: 1rem;
}

.draft-card p {
    margin: 0;
    color: #4f4943;
    line-height: 1.5;
}

.draft-card .muted-copy {
    color: var(--muted);
}

.empty-state {
    min-height: 96px;
    place-items: center;
    border: 1px dashed #c6baac;
    border-radius: var(--radius);
    color: var(--muted);
    background: rgba(255, 255, 255, 0.48);
    padding: 20px;
    text-align: center;
}

.list-item {
    display: grid;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-strong);
    padding: 14px;
}

.list-item.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(190, 18, 60, 0.12);
}

.list-item.project-locked {
    border-style: dashed;
    cursor: not-allowed;
}

.list-item h4 {
    margin: 0;
    font-size: 1rem;
}

.list-item p {
    margin: 0;
    color: #4f4943;
    line-height: 1.5;
}

.list-item .muted-copy {
    color: var(--muted);
}

.chapter-list {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.chapter-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.4);
    padding: 0 9px;
    font-size: 0.75rem;
    font-weight: 760;
}

.chapter-pill.current {
    border-color: rgba(34, 197, 94, 0.42);
    color: #064e3b;
    background: #d1fae5;
}

.detail-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px 12px;
    margin: 0;
}

.detail-list div {
    min-width: 0;
}

.detail-list dt {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 820;
}

.detail-list dd {
    margin: 2px 0 0;
    color: var(--ink);
    font-size: 0.88rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    background: #eee7db;
    color: #514a43;
    padding: 0 9px;
    font-size: 0.76rem;
    font-weight: 760;
}

.pill.success {
    color: #064e3b;
    background: #d1fae5;
}

.pill.warning {
    color: #7c2d12;
    background: #ffedd5;
}

.pill.danger {
    color: #7f1d1d;
    background: #fee2e2;
}

.result-panel {
    margin-top: 18px;
}

.embedded-panel {
    margin-top: 0;
    box-shadow: none;
}

.result-panel pre {
    overflow: auto;
    max-height: 520px;
    margin: 0;
    border-radius: 7px;
    background: #1f1f1f;
    color: #fff7ed;
    padding: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
}

.result-panel .prompt-block {
    display: grid;
    gap: 10px;
}

.prompt-block h4 {
    margin: 0;
}

.prompt-block p {
    margin: 0;
    color: #3f3a34;
    line-height: 1.65;
}

.generated-panel-frame {
    display: grid;
    gap: 12px;
}

.generated-panel-frame img {
    width: min(100%, 1024px);
    max-height: 72vh;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-strong);
    object-fit: contain;
}

.asset-link {
    color: var(--accent);
    font-weight: 820;
    text-decoration: none;
}

.not-found {
    display: grid;
    min-height: 100vh;
    place-content: center;
    padding: 28px;
    text-align: center;
}

.text-link {
    color: var(--accent);
    font-weight: 820;
}

body.narrorift-mode {
    color-scheme: dark;
    --paper: #090b12;
    --surface: #11151f;
    --surface-strong: #151b27;
    --ink: #eef2f7;
    --muted: #9ca3af;
    --line: #293244;
    --charcoal: #070a11;
    --charcoal-2: #0d111a;
    --accent: #38bdf8;
    --accent-dark: #0ea5e9;
    --blue: #60a5fa;
    --green: #22c55e;
    --amber: #f59e0b;
    --danger: #f87171;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.38);
    background:
        linear-gradient(90deg, rgba(148, 163, 184, 0.06) 1px, transparent 1px),
        linear-gradient(180deg, rgba(148, 163, 184, 0.05) 1px, transparent 1px),
        var(--paper);
    background-size: 34px 34px;
}

.narrorift-mode .studio-topbar {
    border-bottom-color: #1f2937;
    background: #070a11;
}

.narrorift-mode .studio-sidebar {
    border-right-color: #1f2937;
    background: rgba(13, 17, 26, 0.96);
}

.narrorift-mode .brand-mark {
    border-color: rgba(96, 165, 250, 0.42);
    background: #ef4444;
}

.narrorift-mode .brand small,
.narrorift-mode .user-email {
    color: #cbd5e1;
}

.narrorift-mode .eyebrow {
    color: #38bdf8;
}

.narrorift-mode .nav-item {
    color: #dbeafe;
}

.narrorift-mode .nav-item:hover,
.narrorift-mode .nav-item.active {
    border-color: rgba(96, 165, 250, 0.35);
    background: rgba(96, 165, 250, 0.12);
}

.narrorift-mode .tool-panel,
.narrorift-mode .result-panel,
.narrorift-mode .list-item {
    border-color: var(--line);
    background: rgba(17, 21, 31, 0.94);
}

.narrorift-mode .empty-state {
    border-color: #334155;
    color: #94a3b8;
    background: rgba(15, 23, 42, 0.56);
}

.narrorift-mode input,
.narrorift-mode textarea,
.narrorift-mode select {
    border-color: #334155;
    color: #e5e7eb;
    background: #080c14;
}

.narrorift-mode .list-item p,
.narrorift-mode .prompt-block p {
    color: #cbd5e1;
}

.narrorift-mode .generated-panel-frame img {
    background: #080c14;
}

.narrorift-mode .secondary-action,
.narrorift-mode .icon-button {
    border-color: #334155;
    color: #e5e7eb;
    background: #111827;
}

.narrorift-mode .secondary-action:hover,
.narrorift-mode .icon-button:hover {
    border-color: #60a5fa;
    background: #172033;
}

.narrorift-mode .pill {
    color: #dbeafe;
    background: #1e293b;
}

.narrorift-mode .pill.success {
    color: #bbf7d0;
    background: rgba(34, 197, 94, 0.18);
}

.narrorift-mode .pill.warning {
    color: #fde68a;
    background: rgba(245, 158, 11, 0.18);
}

.narrorift-mode .pill.danger {
    color: #fecaca;
    background: rgba(248, 113, 113, 0.18);
}

.narrorift-mode .chapter-pill {
    border-color: #334155;
    color: #cbd5e1;
    background: #0f172a;
}

.narrorift-mode .chapter-pill.current {
    border-color: rgba(34, 197, 94, 0.4);
    color: #bbf7d0;
    background: rgba(34, 197, 94, 0.18);
}

.is-read-only input,
.is-read-only textarea,
.is-read-only select {
    opacity: 0.78;
}

.is-read-only .primary-action {
    opacity: 0.58;
}

/* Topbar Manga Creator CTA. The headline button — gradient-bordered pill
   with a sparkle icon and a slow shimmer sweep that draws the eye on first
   load. Once the user has clicked it, studio.js sets data-seen="1" which
   suppresses the shimmer (no nag after first use). */
.studio-topbar-cta {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
    padding: 8px 18px;
    min-height: 40px;
    border: 1.5px solid transparent;
    border-radius: 999px;
    color: #fff;
    font: inherit;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    background:
        linear-gradient(#13151c, #13151c) padding-box,
        linear-gradient(135deg, #ef4444 0%, #f59e0b 45%, #38bdf8 100%) border-box;
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.18);
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.studio-topbar-cta:hover {
    transform: translateY(-1px) scale(1.02);
    box-shadow: 0 10px 28px rgba(239, 68, 68, 0.32);
}

.studio-topbar-cta:active {
    transform: translateY(0) scale(0.99);
}

.studio-topbar-cta.active {
    background:
        linear-gradient(135deg, rgba(239, 68, 68, 0.32), rgba(245, 158, 11, 0.28), rgba(56, 189, 248, 0.30)) padding-box,
        linear-gradient(135deg, #ef4444, #f59e0b 45%, #38bdf8) border-box;
}

.studio-topbar-cta-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    color: #fde68a;
}

.studio-topbar-cta-icon svg {
    width: 20px;
    height: 20px;
}

.studio-topbar-cta-label {
    position: relative;
    z-index: 1;
    font-size: 0.94rem;
}

.studio-topbar-cta-shimmer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(120deg, transparent 30%, rgba(255, 255, 255, 0.35) 50%, transparent 70%);
    transform: translateX(-100%);
    animation: studio-cta-shimmer 3.4s ease-in-out infinite;
}

.studio-topbar-cta[data-seen="1"] .studio-topbar-cta-shimmer,
.studio-topbar-cta.active .studio-topbar-cta-shimmer {
    display: none;
}

@keyframes studio-cta-shimmer {
    0%   { transform: translateX(-100%); }
    55%  { transform: translateX(150%); }
    100% { transform: translateX(150%); }
}

.narrorift-mode .studio-topbar-cta {
    background:
        linear-gradient(#070a11, #070a11) padding-box,
        linear-gradient(135deg, #38bdf8 0%, #22c55e 50%, #ef4444 100%) border-box;
    box-shadow: 0 6px 20px rgba(56, 189, 248, 0.22);
}

.narrorift-mode .studio-topbar-cta:hover {
    box-shadow: 0 10px 28px rgba(56, 189, 248, 0.4);
}

.narrorift-mode .studio-topbar-cta-icon {
    color: #bae6fd;
}

/* Manga Creator workspace tabs (Panels / Pages / Chapters) */
.manga-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 18px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-strong);
    width: fit-content;
    max-width: 100%;
    overflow-x: auto;
}

.manga-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.manga-tab:hover {
    color: var(--ink);
    background: rgba(0, 0, 0, 0.04);
}

.manga-tab.active {
    color: var(--ink);
    background: var(--paper);
    border-color: var(--line);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset;
}

.manga-tab svg {
    width: 16px;
    height: 16px;
}

.manga-tab-pill {
    margin-left: 4px;
    padding: 2px 7px;
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.18);
    color: var(--amber);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.narrorift-mode .manga-tabs {
    background: rgba(15, 23, 42, 0.7);
}

.narrorift-mode .manga-tab.active {
    background: #0f172a;
    border-color: #334155;
    color: #f8fafc;
    box-shadow: none;
}

.manga-tab-panel {
    display: grid;
    gap: 24px;
}

.manga-coming-soon {
    display: grid;
    gap: 10px;
    place-content: center;
    text-align: center;
    padding: 56px 24px;
    border: 1px dashed var(--line);
    border-radius: 16px;
    background: var(--surface-strong);
    color: var(--muted);
}

.manga-coming-soon h3 {
    margin: 0;
    color: var(--ink);
}

.manga-coming-soon p {
    margin: 0 auto;
    max-width: 60ch;
    line-height: 1.6;
}

.manga-coming-soon svg {
    width: 32px;
    height: 32px;
    margin: 0 auto 4px;
    color: var(--accent);
}

/* Clean illustration toggle — emphasized so it reads as the recommended
   default. Sits between the format/finish/quality row and the tweak field. */
.clean-illustration-toggle {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px;
    align-items: start;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(34, 197, 94, 0.08);
    cursor: pointer;
}

.clean-illustration-toggle input {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    accent-color: var(--green);
    cursor: pointer;
}

.clean-illustration-copy {
    display: grid;
    gap: 3px;
}

.clean-illustration-copy strong {
    color: var(--ink);
    font-size: 0.95rem;
}

.clean-illustration-copy small {
    color: var(--muted);
    line-height: 1.5;
}

.narrorift-mode .clean-illustration-toggle {
    border-color: rgba(34, 197, 94, 0.35);
    background: rgba(34, 197, 94, 0.12);
}

.narrorift-mode .clean-illustration-copy strong {
    color: #f8fafc;
}

/* Panel Library — thumbnail grid of every generation, surfaced under the
   Panels tab. In Phase 2 the tiles become drag sources for the Page Editor. */
.panel-library {
    display: grid;
    gap: 16px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 253, 250, 0.95);
    box-shadow: var(--shadow);
}

.panel-library-heading {
    display: grid;
    gap: 12px;
}

.panel-library-heading-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.panel-library-heading h3 {
    margin: 0;
}

.panel-library-heading .muted-copy {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

.panel-library-count-badge {
    flex-shrink: 0;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.08);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.panel-library-toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.panel-library-search {
    flex: 1;
    min-width: 220px;
    position: relative;
    display: flex;
    align-items: center;
}

.panel-library-search-icon {
    position: absolute;
    left: 12px;
    pointer-events: none;
    color: var(--muted);
    font-size: 0.9rem;
}

.panel-library-search input {
    width: 100%;
    padding: 9px 12px 9px 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font-size: 0.88rem;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.panel-library-search input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(210, 59, 69, 0.15);
}

.panel-library-filters {
    display: inline-flex;
    gap: 4px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
}

.panel-library-filter {
    padding: 6px 14px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.panel-library-filter:hover {
    color: var(--ink);
}

.panel-library-filter.active {
    background: var(--ink);
    color: var(--paper);
}

.panel-library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
}

.panel-library-empty {
    grid-column: 1 / -1;
    display: grid;
    gap: 6px;
    justify-items: center;
    padding: 44px 24px;
    text-align: center;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.02);
}

.panel-library-empty h4 {
    margin: 0;
    color: var(--ink);
    font-size: 1rem;
}

.panel-library-empty p {
    margin: 0;
    max-width: 360px;
    font-size: 0.85rem;
    line-height: 1.5;
}

.panel-library-empty-icon {
    font-size: 2rem;
    line-height: 1;
    margin-bottom: 4px;
    opacity: 0.7;
}

.panel-library-tile {
    display: grid;
    grid-template-rows: auto 1fr;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-strong);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
    cursor: grab;
}

.panel-library-tile:active {
    cursor: grabbing;
}

.panel-library-tile:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.14);
    border-color: rgba(15, 23, 42, 0.25);
}

.panel-library-thumb {
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: #0c0c10;
    cursor: zoom-in;
}

.panel-library-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.4s ease;
}

.panel-library-tile:hover .panel-library-thumb img {
    transform: scale(1.04);
}

.panel-library-thumb-missing {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.8rem;
    background: linear-gradient(135deg, #1f2937, #0f172a);
}

.panel-library-thumb .panel-library-flag {
    position: absolute;
    top: 8px;
    left: 8px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    backdrop-filter: blur(4px);
}

.panel-library-thumb .panel-library-flag.clean {
    background: rgba(34, 197, 94, 0.85);
    color: #052e16;
}

.panel-library-thumb .panel-library-flag.bubbles {
    background: rgba(96, 165, 250, 0.85);
    color: #0c1e3a;
}

.panel-library-hover {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 12px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
    opacity: 0;
    transition: opacity 0.18s ease;
    pointer-events: none;
}

.panel-library-tile:hover .panel-library-hover {
    opacity: 1;
}

.panel-library-hover-action {
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

.panel-library-meta {
    display: grid;
    gap: 8px;
    padding: 12px 14px 14px;
}

.panel-library-meta h4 {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.35;
    color: var(--ink);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.panel-library-meta .meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.panel-library-actions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.panel-library-actions .library-action-btn {
    flex: 0 0 auto;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--paper);
    color: var(--ink);
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
}

.panel-library-actions .library-action-btn.primary {
    flex: 1;
    min-width: 0;
    padding: 0 10px;
    font-size: 0.76rem;
    background: var(--ink);
    color: var(--paper);
    border-color: var(--ink);
}

.panel-library-actions .library-action-btn.primary:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.panel-library-actions .library-action-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.panel-library-actions .library-action-btn.danger:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: rgba(185, 28, 28, 0.08);
}

.narrorift-mode .panel-library {
    border-color: var(--line);
    background: rgba(17, 21, 31, 0.94);
}

.narrorift-mode .panel-library-count-badge {
    background: rgba(148, 163, 184, 0.18);
    color: #cbd5f5;
}

.narrorift-mode .panel-library-tile {
    background: rgba(15, 23, 42, 0.7);
    border-color: #1f2937;
}

.narrorift-mode .panel-library-tile:hover {
    border-color: rgba(148, 163, 184, 0.45);
    box-shadow: 0 18px 36px rgba(0, 0, 0, 0.55);
}

.narrorift-mode .panel-library-empty {
    background: rgba(148, 163, 184, 0.04);
    border-color: rgba(148, 163, 184, 0.25);
}

.narrorift-mode .panel-library-search input {
    background: #0b1220;
    border-color: #334155;
    color: #e5e7eb;
}

.narrorift-mode .panel-library-filters {
    background: #0b1220;
    border-color: #334155;
}

.narrorift-mode .panel-library-filter.active {
    background: var(--accent);
    color: #0b1220;
}

.narrorift-mode .panel-library-actions .library-action-btn {
    background: #0b1220;
    color: #e5e7eb;
    border-color: #334155;
}

.narrorift-mode .panel-library-actions .library-action-btn.primary {
    background: var(--accent);
    color: #0b1220;
    border-color: var(--accent);
}

.narrorift-mode .panel-library-actions .library-action-btn.primary:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #0b1220;
}

/* Lightbox modal — full-screen overlay shown on tile click. */
.panel-library-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: rgba(8, 11, 18, 0.86);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.18s ease;
}

.panel-library-lightbox.is-open {
    opacity: 1;
}

.panel-library-lightbox-close {
    position: absolute;
    top: 18px;
    right: 18px;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(15, 23, 42, 0.6);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
}

.panel-library-lightbox-close:hover {
    background: rgba(15, 23, 42, 0.9);
    border-color: rgba(255, 255, 255, 0.4);
}

.panel-library-lightbox-close [data-lucide] {
    width: 18px;
    height: 18px;
}

.panel-library-lightbox-dialog {
    width: min(1100px, 100%);
    max-height: calc(100vh - 64px);
    overflow: hidden;
    border-radius: 16px;
    background: var(--surface-strong);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
    transform: translateY(8px) scale(0.98);
    transition: transform 0.18s ease;
}

.panel-library-lightbox.is-open .panel-library-lightbox-dialog {
    transform: translateY(0) scale(1);
}

.panel-library-lightbox-body {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr);
    max-height: calc(100vh - 64px);
}

.panel-library-lightbox-image {
    background: #050810;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-height: 320px;
}

.panel-library-lightbox-image img {
    max-width: 100%;
    max-height: calc(100vh - 64px);
    object-fit: contain;
    display: block;
}

.panel-library-lightbox-side {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 24px;
    overflow-y: auto;
}

.panel-library-lightbox-side header h3 {
    margin: 4px 0 0;
    font-size: 1.15rem;
    line-height: 1.3;
}

.panel-library-lightbox-side .eyebrow {
    margin: 0;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.panel-library-lightbox-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.panel-library-lightbox-prompt summary {
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--muted);
    padding: 6px 0;
}

.panel-library-lightbox-prompt[open] summary {
    color: var(--ink);
}

.panel-library-lightbox-prompt pre {
    margin: 4px 0 0;
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.06);
    border-radius: 8px;
    font-size: 0.78rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
}

.panel-library-lightbox-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: auto;
}

.panel-library-lightbox-actions .primary-action,
.panel-library-lightbox-actions .secondary-action,
.panel-library-lightbox-actions .ghost-action {
    flex: 1;
    min-width: 120px;
}

body.panel-library-lightbox-open {
    overflow: hidden;
}

.narrorift-mode .panel-library-lightbox-dialog {
    background: #11151f;
}

.narrorift-mode .panel-library-lightbox-prompt pre {
    background: rgba(148, 163, 184, 0.08);
    color: #cbd5f5;
}

@media (max-width: 780px) {
    .panel-library-lightbox-body {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(220px, 50vh) auto;
        overflow-y: auto;
    }
    .panel-library-lightbox-image img {
        max-height: 50vh;
    }
}

.manga-creator-layout {
    display: grid;
    grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

.manga-creator-controls {
    position: sticky;
    top: 24px;
    display: grid;
    gap: 14px;
}

.manga-creator-preview {
    display: grid;
    gap: 14px;
}

.manga-preview-panel {
    margin-top: 0;
    min-height: 320px;
}

.manga-preview-empty {
    display: grid;
    gap: 8px;
    place-content: center;
    min-height: 280px;
    padding: 28px;
    text-align: center;
    color: var(--muted);
}

.manga-preview-empty h3 {
    margin: 0;
}

.manga-preview-empty p {
    margin: 0;
    max-width: 38ch;
    line-height: 1.55;
}

.manga-scene-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-strong);
    color: var(--ink);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: default;
    width: fit-content;
}

.manga-scene-chip[data-state="empty"] {
    color: var(--muted);
}

.manga-scene-chip[data-state="locked"] {
    border-color: rgba(34, 197, 94, 0.45);
    background: rgba(34, 197, 94, 0.12);
    color: var(--green);
}

.manga-scene-chip .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.7;
}

.manga-tweak-field {
    display: grid;
    gap: 6px;
}

.manga-tweak-field small {
    color: var(--muted);
    font-weight: 400;
}

.manga-tweak-field textarea {
    width: 100%;
    resize: vertical;
}

.manga-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.manga-technical-details {
    margin-top: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 14px;
    background: var(--surface-strong);
}

.manga-technical-details summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--muted);
}

.manga-technical-details[open] summary {
    margin-bottom: 8px;
    color: var(--ink);
}

.manga-technical-details p {
    margin: 0;
    white-space: pre-wrap;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.55;
}

.narrorift-mode .manga-scene-chip {
    border-color: #334155;
    background: rgba(15, 23, 42, 0.6);
    color: #cbd5e1;
}

.narrorift-mode .manga-scene-chip[data-state="locked"] {
    border-color: rgba(34, 197, 94, 0.5);
    background: rgba(34, 197, 94, 0.18);
    color: #bbf7d0;
}

.narrorift-mode .manga-technical-details {
    border-color: #334155;
    background: rgba(15, 23, 42, 0.55);
}

/* Narrorift-first workflow shell */
.studio-view {
    grid-template-rows: 72px 1fr;
    background: var(--paper);
}

.studio-topbar {
    min-height: 72px;
    padding: 0 clamp(16px, 3vw, 32px);
    background: #101827;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.studio-context {
    min-width: 0;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.studio-context-main {
    min-width: 0;
    max-width: min(44vw, 620px);
    display: grid;
    gap: 2px;
    color: #f8fafc;
}

.studio-context-main strong,
.studio-context-main small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.studio-context-main small {
    color: #cbd5e1;
    font-size: 0.78rem;
}

.workflow-status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    border-radius: 999px;
    color: #dbeafe;
    background: rgba(96, 165, 250, 0.16);
    padding: 0 10px;
    font-size: 0.76rem;
    font-weight: 820;
    white-space: nowrap;
}

.workflow-status-pill[data-state="ready"],
.workflow-status-pill[data-state="complete"] {
    color: #bbf7d0;
    background: rgba(34, 197, 94, 0.18);
}

.workflow-status-pill[data-state="progress"] {
    color: #fde68a;
    background: rgba(245, 158, 11, 0.18);
}

.studio-layout {
    grid-template-columns: 236px minmax(0, 1fr);
}

.studio-sidebar {
    top: 72px;
    height: calc(100vh - 72px);
    padding: 18px 12px;
    border-right: 1px solid var(--line);
    background: #ffffff;
}

.nav-item {
    min-height: 46px;
    color: #334155;
    border-radius: 8px;
    font-weight: 780;
}

.nav-item:hover,
.nav-item.active {
    border-color: #cbd5e1;
    color: #0f172a;
    background: #eef4ff;
}

.nav-item.active {
    box-shadow: inset 3px 0 0 var(--blue);
}

.studio-main {
    padding: 28px clamp(18px, 3vw, 36px) 56px;
}

.studio-status {
    margin-bottom: 18px;
}

.studio-status h2 {
    font-size: clamp(1.55rem, 2.4vw, 2.05rem);
}

.tool-panel,
.result-panel,
.panel-library {
    border-color: var(--line);
    background: var(--surface);
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
}

.chapter-home-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
    gap: 18px;
    align-items: start;
    margin-bottom: 18px;
}

.project-workspace-grid {
    margin-top: 18px;
}

.chapter-brief,
.chapter-metrics {
    min-height: 100%;
}

.context-chip-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.context-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 30px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: #334155;
    background: #f8fafc;
    padding: 0 11px;
    font-size: 0.78rem;
    font-weight: 720;
}

.context-chip strong {
    color: #0f172a;
}

.readiness-list {
    display: grid;
    gap: 8px;
}

.readiness-item {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    padding: 12px;
    color: var(--ink);
    text-align: left;
}

.readiness-item:hover {
    border-color: #bfdbfe;
    background: #f8fbff;
}

.readiness-item.done {
    border-color: rgba(34, 197, 94, 0.28);
    background: #f0fdf4;
}

.readiness-check {
    display: inline-grid;
    place-items: center;
    min-width: 42px;
    min-height: 26px;
    border-radius: 999px;
    color: #1d4ed8;
    background: #dbeafe;
    font-size: 0.72rem;
    font-weight: 880;
}

.readiness-item.done .readiness-check {
    color: #047857;
    background: #d1fae5;
}

.readiness-item strong,
.readiness-item small {
    display: block;
}

.readiness-item small {
    margin-top: 3px;
    color: var(--muted);
    line-height: 1.35;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.metric-card {
    min-height: 82px;
    display: grid;
    place-content: center;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
    text-align: center;
}

.metric-card strong {
    color: #0f172a;
    font-size: 1.55rem;
}

.metric-card span {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 760;
}

.workflow-jump-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.workflow-section-intro {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.workflow-section-intro h3 {
    margin: 0;
    font-size: 1.25rem;
}

.workflow-section-intro-actions {
    display: inline-flex;
    gap: 8px;
    flex-wrap: wrap;
}

.bible-tabs {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #eef2f7;
}

.bible-tab {
    min-height: 34px;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--muted);
    background: transparent;
    padding: 0 12px;
    font-weight: 780;
}

.bible-tab.active {
    border-color: var(--line);
    color: var(--ink);
    background: #ffffff;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
}

.bible-tab-panel {
    display: grid;
    gap: 16px;
}

.manga-creator-layout {
    grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
    gap: 18px;
}

.manga-creator-controls {
    top: 92px;
}

.manga-preview-panel {
    min-height: 360px;
}

.panel-library {
    margin-top: 18px;
}

.topbar-actions .user-email {
    max-width: 180px;
}

body.narrorift-mode {
    color-scheme: dark;
    --paper: #080a0f;
    --surface: #10151d;
    --surface-strong: #151b25;
    --ink: #eef3f8;
    --muted: #94a3b8;
    --line: #293244;
    --charcoal: #070a10;
    --charcoal-2: #0c1119;
    --accent: #f05260;
    --accent-dark: #dc3545;
    --blue: #57b6ff;
    --green: #38d996;
    --amber: #f7b955;
    --danger: #fb7185;
    --shadow: 0 18px 42px rgba(0, 0, 0, 0.36);
    background:
        linear-gradient(180deg, #080a0f 0%, #0b0f16 44%, #080a0f 100%);
}

.narrorift-mode .studio-topbar {
    border-bottom-color: #1d2634;
    background: #070a10;
}

.narrorift-mode .studio-sidebar {
    border-right-color: #1d2634;
    background: #0c1119;
}

.narrorift-mode .nav-item {
    color: #cbd5e1;
}

.narrorift-mode .nav-item:hover,
.narrorift-mode .nav-item.active {
    border-color: #34445c;
    color: #f8fafc;
    background: #182131;
}

.narrorift-mode .tool-panel,
.narrorift-mode .result-panel,
.narrorift-mode .list-item,
.narrorift-mode .draft-card,
.narrorift-mode .panel-library {
    border-color: var(--line);
    background: rgba(16, 21, 29, 0.96);
    box-shadow: var(--shadow);
}

.narrorift-mode input,
.narrorift-mode textarea,
.narrorift-mode select {
    border-color: #334155;
    color: var(--ink);
    background: #0b1018;
}

.narrorift-mode input::placeholder,
.narrorift-mode textarea::placeholder {
    color: #64748b;
}

.narrorift-mode .secondary-action,
.narrorift-mode .icon-button {
    border-color: #334155;
    color: var(--ink);
    background: #151b25;
}

.narrorift-mode .secondary-action:hover,
.narrorift-mode .icon-button:hover {
    border-color: #57b6ff;
    background: #1b2432;
}

.narrorift-mode .primary-action {
    border-color: var(--accent-dark);
    color: #ffffff;
    background: var(--accent);
}

.narrorift-mode .primary-action:hover {
    background: var(--accent-dark);
}

.narrorift-mode .empty-state {
    border-color: #334155;
    color: var(--muted);
    background: rgba(11, 16, 24, 0.82);
}

.narrorift-mode .list-item p,
.narrorift-mode .draft-card p,
.narrorift-mode .prompt-block p,
.narrorift-mode .panel-library-meta h4,
.narrorift-mode .clean-illustration-copy strong {
    color: var(--ink);
}

.narrorift-mode label,
.narrorift-mode .form-section p,
.narrorift-mode .panel-library-heading .muted-copy,
.narrorift-mode .manga-preview-empty,
.narrorift-mode .clean-illustration-copy small,
.narrorift-mode .manga-tweak-field small,
.narrorift-mode .manga-technical-details p,
.narrorift-mode .detail-list dt {
    color: var(--muted);
}

.narrorift-mode .form-section h4,
.narrorift-mode .detail-list dd,
.narrorift-mode .draft-card h4,
.narrorift-mode .tool-panel h3,
.narrorift-mode .result-panel h3,
.narrorift-mode .workflow-section-intro h3,
.narrorift-mode .manga-preview-empty h3 {
    color: var(--ink);
}

.narrorift-mode .pill {
    color: #dbeafe;
    background: #1d2736;
}

.narrorift-mode .pill.success {
    color: #b7f7d8;
    background: rgba(56, 217, 150, 0.16);
}

.narrorift-mode .pill.warning {
    color: #ffe3a3;
    background: rgba(247, 185, 85, 0.16);
}

.narrorift-mode .pill.danger {
    color: #fecdd3;
    background: rgba(251, 113, 133, 0.16);
}

.narrorift-mode .manga-scene-chip,
.narrorift-mode .manga-technical-details,
.narrorift-mode .clean-illustration-toggle {
    border-color: var(--line);
    background: #151b25;
    color: var(--ink);
}

.narrorift-mode .manga-scene-chip[data-state="locked"] {
    border-color: rgba(56, 217, 150, 0.38);
    background: rgba(56, 217, 150, 0.12);
    color: #b7f7d8;
}

.narrorift-mode .studio-context-main strong,
.narrorift-mode .studio-context-main small,
.narrorift-mode .brand,
.narrorift-mode .user-email {
    color: #f8fafc;
}

.narrorift-mode .brand small,
.narrorift-mode .studio-context-main small {
    color: #aeb9c8;
}

.narrorift-mode .mode-badge {
    border-color: #334155;
    color: #dbeafe;
    background: #111827;
}

.narrorift-mode .return-link {
    border-color: rgba(56, 217, 150, 0.42);
    color: #b7f7d8;
    background: rgba(56, 217, 150, 0.1);
}

.narrorift-mode .workflow-status-pill {
    color: #bae6fd;
    background: rgba(87, 182, 255, 0.16);
}

.narrorift-mode .workflow-status-pill[data-state="ready"],
.narrorift-mode .workflow-status-pill[data-state="complete"] {
    color: #b7f7d8;
    background: rgba(56, 217, 150, 0.16);
}

.narrorift-mode .workflow-status-pill[data-state="progress"] {
    color: #ffe3a3;
    background: rgba(247, 185, 85, 0.16);
}

.narrorift-mode .context-chip {
    border-color: #2b3546;
    color: #cbd5e1;
    background: #151b25;
}

.narrorift-mode .context-chip strong {
    color: #f8fafc;
}

.narrorift-mode .readiness-item {
    border-color: #293244;
    color: var(--ink);
    background: #111721;
}

.narrorift-mode .readiness-item:hover {
    border-color: #3d5877;
    background: #162033;
}

.narrorift-mode .readiness-item.done {
    border-color: rgba(56, 217, 150, 0.28);
    background: rgba(56, 217, 150, 0.08);
}

.narrorift-mode .readiness-check {
    color: #bae6fd;
    background: rgba(87, 182, 255, 0.18);
}

.narrorift-mode .readiness-item.done .readiness-check {
    color: #b7f7d8;
    background: rgba(56, 217, 150, 0.18);
}

.narrorift-mode .metric-card {
    border-color: #293244;
    background: #111721;
}

.narrorift-mode .metric-card strong {
    color: #f8fafc;
}

.narrorift-mode .bible-tabs {
    border-color: #293244;
    background: #0c1119;
}

.narrorift-mode .bible-tab {
    color: #94a3b8;
}

.narrorift-mode .bible-tab.active {
    border-color: #334155;
    color: #f8fafc;
    background: #1b2432;
    box-shadow: none;
}

.narrorift-mode .panel-library-tile,
.narrorift-mode .panel-library-actions a,
.narrorift-mode .panel-library-actions button,
.narrorift-mode .manga-technical-details {
    border-color: #293244;
    background: #111721;
    color: var(--ink);
}

.narrorift-mode .panel-library-actions a:hover,
.narrorift-mode .panel-library-actions button:hover {
    border-color: var(--blue);
    color: #bae6fd;
}

.narrorift-mode .generated-panel-frame img {
    border-color: #293244;
    background: #0b1018;
}

.narrorift-mode .project-select-field {
    display: none;
}

[hidden] {
    display: none !important;
}

@media (max-width: 920px) {
    .manga-creator-layout {
        grid-template-columns: 1fr;
    }

    .manga-creator-controls {
        position: static;
    }
}

@media (max-width: 920px) {
    .auth-view,
    .studio-layout,
    .workspace-grid {
        grid-template-columns: 1fr;
    }

    .auth-view {
        align-items: start;
    }

    .studio-view {
        grid-template-rows: auto 1fr;
    }

    .studio-topbar {
        min-height: 68px;
    }

    .studio-sidebar {
        position: static;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        height: auto;
        border-right: 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    }

    .nav-item {
        justify-content: center;
        padding: 0 8px;
    }

    .nav-item span:last-child {
        display: none;
    }

    .studio-status {
        display: block;
    }

    .studio-status .form-message {
        text-align: left;
    }
}

@media (max-width: 640px) {
    .auth-view {
        padding: 32px 16px;
    }

    .auth-copy h1 {
        font-size: 2.55rem;
    }

    .form-grid,
    .cast-detail-grid,
    .panel-generator-options,
    .trait-grid,
    .studio-sidebar {
        grid-template-columns: 1fr;
    }

    .form-grid .span-2,
    .cast-detail-grid .span-2 {
        grid-column: auto;
    }

    .studio-sidebar {
        grid-auto-flow: column;
        grid-auto-columns: 56px;
        overflow-x: auto;
    }

    .topbar-actions {
        flex: 1;
        justify-content: flex-end;
    }

    .mode-badge,
    .return-link {
        max-width: 134px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .user-email {
        display: none;
    }

    .studio-topbar-cta {
        padding: 8px 12px;
    }

    .studio-topbar-cta-label {
        display: none;
    }
}

@media (max-width: 920px) {
    .studio-topbar {
        min-height: auto;
        flex-wrap: wrap;
        align-items: flex-start;
        padding: 12px 16px;
    }

    .studio-context {
        order: 3;
        flex-basis: 100%;
        justify-content: flex-start;
    }

    .studio-context-main {
        max-width: none;
    }

    .studio-sidebar {
        grid-template-columns: repeat(6, minmax(116px, 1fr));
        overflow-x: auto;
        gap: 8px;
        padding: 10px;
    }

    .nav-item {
        justify-content: flex-start;
        margin-bottom: 0;
    }

    .nav-item span:last-child {
        display: inline;
    }

    .chapter-home-grid {
        grid-template-columns: 1fr;
    }

    .metric-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .workflow-section-intro {
        align-items: flex-start;
    }
}

@media (max-width: 640px) {
    .studio-context {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 8px;
    }

    .studio-context .mode-badge {
        grid-column: 1 / -1;
        width: fit-content;
        max-width: none;
    }

    .workflow-status-pill {
        justify-self: end;
    }

    .studio-sidebar {
        grid-template-columns: none;
        grid-auto-flow: column;
        grid-auto-columns: 132px;
    }

    .nav-item span:last-child {
        display: inline;
    }

    .workflow-section-intro {
        display: grid;
    }

    .bible-tabs {
        width: 100%;
    }

    .bible-tab {
        flex: 1;
    }

    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .readiness-item {
        grid-template-columns: 1fr;
    }
}

/* =====================================================================
   Story Bible v2 — two-pane layout, slide-over forge, tier colors,
   avatars, accordions, search/filter rails, completeness pips.
   ===================================================================== */

/* Tier pill — used everywhere a character tier is shown. */
.tier-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 24px;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 0 10px;
    font-size: 0.75rem;
    font-weight: 760;
    letter-spacing: 0.01em;
    text-transform: capitalize;
}

.tier-pill::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.7;
}

.tier-pill[data-tier="main"] {
    color: var(--tier-main-fg);
    background: var(--tier-main-bg);
    border-color: var(--tier-main-ring);
}
.tier-pill[data-tier="secondary"] {
    color: var(--tier-secondary-fg);
    background: var(--tier-secondary-bg);
    border-color: var(--tier-secondary-ring);
}
.tier-pill[data-tier="recurring_minor"] {
    color: var(--tier-recurring_minor-fg);
    background: var(--tier-recurring_minor-bg);
    border-color: var(--tier-recurring_minor-ring);
}
.tier-pill[data-tier="one_scene_extra"] {
    color: var(--tier-one_scene_extra-fg);
    background: var(--tier-one_scene_extra-bg);
    border-color: var(--tier-one_scene_extra-ring);
}
.tier-pill[data-tier="crowd_type"] {
    color: var(--tier-crowd_type-fg);
    background: var(--tier-crowd_type-bg);
    border-color: var(--tier-crowd_type-ring);
}

/* Bible status banner — sits next to the section title and mirrors the
   "x/5 ready" pill at the top of the studio. Click a chip to jump tabs. */
.bible-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.bible-summary-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--ink);
    padding: 4px 12px;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: border-color 0.12s ease, background 0.12s ease;
}

.bible-summary-chip:hover {
    border-color: var(--accent);
}

.bible-summary-chip[data-state="empty"] {
    color: var(--muted);
}

.bible-summary-chip[data-state="ready"] {
    color: var(--green);
    border-color: rgba(4, 120, 87, 0.4);
    background: rgba(209, 250, 229, 0.55);
}

.bible-summary-chip-count {
    min-width: 18px;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.08);
    text-align: center;
    font-size: 0.7rem;
}

.bible-summary-chip[data-state="ready"] .bible-summary-chip-count {
    background: rgba(16, 185, 129, 0.18);
}

/* Tabs above the panels, full-width, with counters. */
.bible-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    margin-bottom: 16px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.04);
}

.bible-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 1;
    min-height: 38px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    padding: 0 14px;
    font-weight: 780;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.bible-tab:hover {
    color: var(--ink);
    background: rgba(15, 23, 42, 0.04);
}

.bible-tab.active {
    border-color: var(--line);
    color: var(--ink);
    background: var(--surface);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
}

.bible-tab-count {
    min-width: 22px;
    padding: 2px 7px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.08);
    color: inherit;
    font-size: 0.72rem;
    font-weight: 760;
    line-height: 1;
}

.bible-tab.active .bible-tab-count {
    background: rgba(190, 18, 60, 0.12);
    color: var(--accent);
}

/* Two-pane shell: rail on left, editor on right. */
.bible-shell {
    display: grid;
    grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.bible-rail {
    position: sticky;
    top: 96px;
    display: grid;
    gap: 14px;
    max-height: calc(100vh - 130px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 14px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.bible-rail-toolbar {
    display: grid;
    gap: 10px;
}

.bible-rail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.bible-rail-actions .primary-action,
.bible-rail-actions .secondary-action {
    flex: 1;
    min-height: 36px;
    padding: 0 12px;
    font-size: 0.85rem;
}

.bible-search {
    display: block;
    margin: 0;
}

.bible-search input[type="search"] {
    width: 100%;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--paper);
    color: var(--ink);
    padding: 0 12px;
    font-size: 0.86rem;
}

.bible-search input[type="search"]:focus {
    outline: 2px solid rgba(190, 18, 60, 0.25);
    border-color: var(--accent);
}

.bible-rail-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.bible-filter-chip {
    min-height: 26px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    padding: 0 10px;
    font-size: 0.74rem;
    font-weight: 700;
    cursor: pointer;
    transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.bible-filter-chip:hover {
    color: var(--ink);
    border-color: rgba(15, 23, 42, 0.25);
}

.bible-filter-chip.active {
    color: var(--accent);
    background: rgba(190, 18, 60, 0.08);
    border-color: var(--accent);
}

.bible-rail-list {
    display: grid;
    gap: 6px;
    overflow-y: auto;
    margin: 0 -6px;
    padding: 4px 6px;
}

.bible-rail-list::-webkit-scrollbar {
    width: 8px;
}

.bible-rail-item {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    padding: 8px 10px;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
}

.bible-rail-item:hover {
    background: rgba(15, 23, 42, 0.04);
    border-color: var(--line);
}

.bible-rail-item.selected {
    background: rgba(190, 18, 60, 0.06);
    border-color: var(--accent);
}

.bible-rail-item-body {
    min-width: 0;
}

.bible-rail-item-name {
    margin: 0;
    color: var(--ink);
    font-size: 0.92rem;
    font-weight: 770;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bible-rail-item-meta {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 0.72rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bible-rail-item-aside {
    display: grid;
    justify-items: end;
    gap: 4px;
}

.bible-completeness {
    display: inline-block;
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.1);
    overflow: hidden;
}

.bible-completeness-fill {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--amber), var(--green));
    border-radius: inherit;
    transition: width 0.18s ease;
}

.bible-rail-empty {
    padding: 18px 12px;
    text-align: center;
    color: var(--muted);
    font-size: 0.84rem;
    border: 1px dashed var(--line);
    border-radius: 8px;
}

/* Avatar / swatch / icon chips inside rail items and editor headers. */
.character-avatar,
.org-swatch,
.scene-icon,
.canon-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--tier-secondary-bg);
    color: var(--tier-secondary-fg);
    font-size: 0.86rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    border: 1px solid var(--tier-secondary-ring);
    flex-shrink: 0;
}

.character-avatar[data-tier="main"] {
    background: var(--tier-main-bg);
    color: var(--tier-main-fg);
    border-color: var(--tier-main-ring);
}
.character-avatar[data-tier="secondary"] {
    background: var(--tier-secondary-bg);
    color: var(--tier-secondary-fg);
    border-color: var(--tier-secondary-ring);
}
.character-avatar[data-tier="recurring_minor"] {
    background: var(--tier-recurring_minor-bg);
    color: var(--tier-recurring_minor-fg);
    border-color: var(--tier-recurring_minor-ring);
}
.character-avatar[data-tier="one_scene_extra"] {
    background: var(--tier-one_scene_extra-bg);
    color: var(--tier-one_scene_extra-fg);
    border-color: var(--tier-one_scene_extra-ring);
}
.character-avatar[data-tier="crowd_type"] {
    background: var(--tier-crowd_type-bg);
    color: var(--tier-crowd_type-fg);
    border-color: var(--tier-crowd_type-ring);
}

.org-swatch {
    background: #f3f4f6;
    color: #1f2937;
    border-color: #cbd5e1;
}

.scene-icon,
.canon-icon {
    background: rgba(15, 23, 42, 0.06);
    color: var(--ink);
    border-color: var(--line);
    font-size: 1rem;
}

/* Editor pane. */
.bible-editor {
    display: grid;
    gap: 16px;
    min-width: 0;
}

.bible-editor-empty {
    display: grid;
    place-items: center;
    text-align: center;
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 56px 28px;
    color: var(--muted);
}

.bible-editor-empty-icon {
    font-size: 2.4rem;
    margin-bottom: 10px;
    opacity: 0.85;
}

.bible-editor-empty h4 {
    margin: 0 0 6px;
    color: var(--ink);
    font-size: 1.05rem;
}

.bible-editor-empty p {
    margin: 0;
    max-width: 380px;
    line-height: 1.55;
}

.bible-editor-form {
    display: grid;
    gap: 16px;
}

.bible-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 4px;
}

.bible-editor-header-main {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.bible-editor-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.bible-editor-header .eyebrow {
    margin: 0;
    font-size: 0.7rem;
}

.bible-editor-actions {
    display: flex;
    gap: 6px;
}

.ghost-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    padding: 0 12px;
    font-weight: 700;
    font-size: 0.84rem;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.ghost-action:hover {
    color: var(--ink);
    background: rgba(15, 23, 42, 0.05);
    border-color: var(--line);
}

.bible-forge-close-btn {
    font-size: 1.3rem;
    line-height: 1;
    min-width: 32px;
    padding: 0;
}

/* Accordions. Use native <details> for accessibility — chevron rotated
   via CSS so closed cards don't take up extra vertical space. */
.bible-accordion {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
}

.bible-accordion + .bible-accordion {
    margin-top: 0;
}

.bible-accordion > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    cursor: pointer;
    user-select: none;
    list-style: none;
    color: var(--ink);
    font-weight: 780;
}

.bible-accordion > summary::-webkit-details-marker {
    display: none;
}

.bible-accordion > summary::after {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
    margin-left: 8px;
}

.bible-accordion[open] > summary::after {
    transform: rotate(45deg);
}

.bible-accordion > summary:hover {
    background: rgba(15, 23, 42, 0.03);
}

.bible-accordion-title {
    font-size: 0.95rem;
}

.bible-accordion-meta {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    margin-left: auto;
    margin-right: 8px;
}

.bible-accordion-body {
    display: grid;
    gap: 14px;
    padding: 4px 14px 16px;
    border-top: 1px solid var(--line);
}

.bible-editor-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 8px;
}

/* Slide-over forge drawer. */
.bible-forge-drawer {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    justify-content: flex-end;
    pointer-events: none;
}

.bible-forge-drawer.is-open {
    pointer-events: auto;
}

.bible-forge-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.42);
    opacity: 0;
    transition: opacity 0.18s ease;
    cursor: pointer;
}

.bible-forge-drawer.is-open .bible-forge-backdrop {
    opacity: 1;
}

.bible-forge-panel {
    position: relative;
    width: min(520px, 96vw);
    max-width: 100%;
    height: 100%;
    background: var(--surface);
    box-shadow: -22px 0 50px rgba(15, 23, 42, 0.22);
    transform: translateX(110%);
    transition: transform 0.22s ease;
    display: flex;
    flex-direction: column;
}

.bible-forge-drawer.is-open .bible-forge-panel {
    transform: translateX(0);
}

.bible-forge-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
}

.bible-forge-header h3 {
    margin: 0;
    font-size: 1.05rem;
}

.bible-forge-header .eyebrow {
    margin: 0 0 2px;
}

.bible-forge-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: grid;
    gap: 14px;
}

.bible-forge-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.bible-forge-more {
    margin-left: auto;
    display: flex;
    gap: 4px;
}

.bible-forge-hint {
    margin: 0;
    color: var(--muted);
    font-size: 0.84rem;
    line-height: 1.5;
}

.bible-forge-hint strong {
    color: var(--ink);
}

/* Polished draft cards inside the forge drawer. */
.bible-forge-body .draft-card-grid {
    grid-template-columns: 1fr;
    margin-top: 4px;
}

.bible-forge-body .draft-card {
    background: var(--paper);
    border-color: var(--line);
}

.draft-card-identity {
    display: flex;
    align-items: center;
    gap: 12px;
}

.draft-card-identity h4 {
    margin: 0 0 4px;
}

/* Drafts list in the Cast rail. Visually distinct from saved characters —
   dashed border, "DRAFT" badge, smaller actions. Lives purely client-side;
   the AI never sees these. */
.bible-rail-drafts-section {
    display: grid;
    gap: 8px;
    padding-top: 10px;
    margin-top: 4px;
    border-top: 1px dashed var(--line);
}

.bible-rail-drafts-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.bible-rail-drafts-count {
    min-width: 22px;
    padding: 1px 8px;
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.18);
    color: var(--amber);
    font-size: 0.72rem;
    text-align: center;
    text-transform: none;
    letter-spacing: 0;
}

.bible-rail-drafts-hint {
    margin: 0;
    color: var(--muted);
    font-size: 0.72rem;
    line-height: 1.4;
}

.bible-rail-drafts-list {
    display: grid;
    gap: 8px;
    max-height: 360px;
    overflow-y: auto;
    margin: 0 -6px;
    padding: 4px 6px;
}

.bible-rail-draft {
    display: grid;
    gap: 8px;
    border: 1px dashed var(--amber);
    border-radius: 8px;
    background: rgba(245, 158, 11, 0.05);
    padding: 10px 12px;
}

.bible-rail-draft-header {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
}

.bible-rail-draft-body {
    min-width: 0;
}

.bible-rail-draft-name {
    margin: 0;
    color: var(--ink);
    font-size: 0.92rem;
    font-weight: 770;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bible-rail-draft-meta {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 0.72rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bible-rail-draft-badge {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 7px;
    border-radius: 999px;
    background: var(--amber);
    color: #ffffff;
    font-size: 0.66rem;
    font-weight: 820;
    letter-spacing: 0.06em;
}

.bible-rail-draft-summary {
    margin: 0;
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.bible-rail-draft-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.bible-rail-draft-actions button {
    flex: 1;
    min-height: 30px;
    padding: 0 10px;
    font-size: 0.78rem;
}

.narrorift-mode .bible-rail-draft {
    background: rgba(247, 185, 85, 0.06);
    border-color: rgba(247, 185, 85, 0.55);
}

.narrorift-mode .bible-rail-drafts-count {
    background: rgba(247, 185, 85, 0.2);
    color: var(--amber);
}

/* Archive UI — both the editor header button and the rail's archived
   section. Soft delete: visually muted, never red/destructive. */
.ghost-action.danger-action {
    color: var(--danger);
}

.ghost-action.danger-action:hover {
    background: rgba(185, 28, 28, 0.08);
    border-color: rgba(185, 28, 28, 0.3);
    color: var(--danger);
}

.bible-editor-archived-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid rgba(185, 28, 28, 0.3);
    background: rgba(185, 28, 28, 0.06);
    color: var(--ink);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.86rem;
    line-height: 1.5;
}

.bible-editor-archived-banner-text {
    flex: 1;
    min-width: 0;
}

#character-delete-btn {
    flex-shrink: 0;
    white-space: nowrap;
}

.narrorift-mode .bible-editor-archived-banner {
    background: rgba(251, 113, 133, 0.08);
    border-color: rgba(251, 113, 133, 0.35);
}

.bible-rail-archived-section {
    padding-top: 10px;
    margin-top: 4px;
    border-top: 1px solid var(--line);
}

.bible-rail-archived-section > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    list-style: none;
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 4px 0;
}

.bible-rail-archived-section > summary::-webkit-details-marker {
    display: none;
}

.bible-rail-archived-section > summary::after {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
    margin-left: auto;
}

.bible-rail-archived-section[open] > summary::after {
    transform: rotate(45deg);
}

.bible-rail-archived-label {
    flex: 1;
}

.bible-rail-archived-count {
    min-width: 22px;
    padding: 1px 8px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.08);
    color: var(--muted);
    font-size: 0.72rem;
    text-align: center;
    text-transform: none;
    letter-spacing: 0;
}

.bible-rail-archived-hint {
    margin: 4px 0 8px;
    color: var(--muted);
    font-size: 0.72rem;
    line-height: 1.4;
}

.bible-rail-archived-list {
    display: grid;
    gap: 6px;
    max-height: 320px;
    overflow-y: auto;
    margin: 0 -6px;
    padding: 4px 6px;
}

/* Archived rail items reuse the .bible-rail-item base styles but get a
   muted treatment so they read as "off-canon" at a glance. */
.bible-rail-item.archived {
    opacity: 0.62;
}

.bible-rail-item.archived .character-avatar {
    filter: grayscale(0.6);
}

.bible-rail-item.archived .bible-rail-item-name {
    text-decoration: line-through;
    text-decoration-color: rgba(100, 116, 139, 0.6);
}

/* Row wrapper around an archived rail item: lets the inline delete button
   sit as a sibling (not nested inside the select <button>, which would be
   invalid HTML). The trash icon is hidden by default and slides in on row
   hover so the rail stays calm at rest. */
.bible-rail-item-row {
    position: relative;
    display: block;
}

.bible-rail-item-row.archived .bible-rail-item {
    width: 100%;
    padding-right: 38px;
}

.bible-rail-item-delete {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s ease, color 0.12s ease,
        background 0.12s ease, border-color 0.12s ease;
}

.bible-rail-item-row:hover .bible-rail-item-delete,
.bible-rail-item-delete:focus-visible {
    opacity: 1;
}

.bible-rail-item-delete:hover {
    color: var(--danger);
    background: rgba(185, 28, 28, 0.1);
    border-color: rgba(185, 28, 28, 0.35);
}

.bible-rail-item-delete [data-lucide] {
    width: 16px;
    height: 16px;
}

.narrorift-mode .bible-rail-item-delete:hover {
    color: var(--danger);
    background: rgba(248, 113, 113, 0.12);
    border-color: rgba(248, 113, 113, 0.4);
}

.narrorift-mode .bible-rail-archived-count {
    background: rgba(148, 163, 184, 0.18);
}

/* Genre tags rendered inside the chapter context chip strip. */
.genre-tag-chip {
    display: inline-flex;
    align-items: center;
    height: 20px;
    margin-left: 6px;
    padding: 0 8px;
    border-radius: 999px;
    background: rgba(190, 18, 60, 0.1);
    color: var(--accent);
    font-size: 0.72rem;
    font-weight: 720;
    text-transform: capitalize;
}

.narrorift-mode .genre-tag-chip {
    background: rgba(240, 82, 96, 0.16);
    color: var(--accent);
}

/* When the slide-over is open, lock body scroll so the page underneath
   doesn't scroll. */
body.bible-forge-open {
    overflow: hidden;
}

/* Responsive: collapse the two-pane layout to a single column with the
   rail on top below ~960px. */
@media (max-width: 960px) {
    .bible-shell {
        grid-template-columns: minmax(0, 1fr);
    }

    .bible-rail {
        position: static;
        max-height: none;
    }

    .bible-rail-list {
        max-height: 320px;
    }
}

@media (max-width: 640px) {
    .bible-tab-label {
        font-size: 0.82rem;
    }

    .bible-rail-filters {
        gap: 3px;
    }

    .bible-filter-chip {
        padding: 0 8px;
        font-size: 0.7rem;
    }

    .bible-forge-panel {
        width: 100%;
    }
}

/* Dark-mode (narrorift) variants. */
.narrorift-mode {
    --tier-main-bg: rgba(244, 63, 94, 0.14);
    --tier-main-fg: #fda4af;
    --tier-main-ring: #fb7185;
    --tier-secondary-bg: rgba(59, 130, 246, 0.16);
    --tier-secondary-fg: #93c5fd;
    --tier-secondary-ring: #60a5fa;
    --tier-recurring_minor-bg: rgba(139, 92, 246, 0.16);
    --tier-recurring_minor-fg: #c4b5fd;
    --tier-recurring_minor-ring: #a78bfa;
    --tier-one_scene_extra-bg: rgba(245, 158, 11, 0.16);
    --tier-one_scene_extra-fg: #fcd34d;
    --tier-one_scene_extra-ring: #f59e0b;
    --tier-crowd_type-bg: rgba(100, 116, 139, 0.2);
    --tier-crowd_type-fg: #cbd5e1;
    --tier-crowd_type-ring: #94a3b8;
}

.narrorift-mode .bible-tabs {
    background: rgba(148, 163, 184, 0.08);
    border-color: var(--line);
}

.narrorift-mode .bible-tab.active {
    background: var(--surface-strong);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.36);
}

.narrorift-mode .bible-tab-count {
    background: rgba(148, 163, 184, 0.18);
}

.narrorift-mode .bible-tab.active .bible-tab-count {
    background: rgba(240, 82, 96, 0.22);
    color: var(--accent);
}

.narrorift-mode .bible-rail,
.narrorift-mode .bible-editor-empty,
.narrorift-mode .bible-accordion,
.narrorift-mode .bible-forge-panel {
    background: var(--surface);
    border-color: var(--line);
}

.narrorift-mode .bible-rail-item:hover {
    background: rgba(148, 163, 184, 0.08);
}

.narrorift-mode .bible-rail-item.selected {
    background: rgba(240, 82, 96, 0.1);
    border-color: var(--accent);
}

.narrorift-mode .bible-summary-chip {
    background: var(--surface-strong);
    border-color: var(--line);
    color: var(--ink);
}

.narrorift-mode .bible-summary-chip[data-state="empty"] {
    color: var(--muted);
}

.narrorift-mode .bible-summary-chip[data-state="ready"] {
    background: rgba(56, 217, 150, 0.12);
    border-color: rgba(56, 217, 150, 0.4);
    color: var(--green);
}

.narrorift-mode .bible-filter-chip {
    background: var(--surface);
    border-color: var(--line);
    color: var(--muted);
}

.narrorift-mode .bible-filter-chip.active {
    background: rgba(240, 82, 96, 0.14);
    border-color: var(--accent);
    color: var(--accent);
}

.narrorift-mode .bible-completeness {
    background: rgba(148, 163, 184, 0.2);
}

.narrorift-mode .ghost-action:hover {
    background: rgba(148, 163, 184, 0.1);
    border-color: var(--line);
}

.narrorift-mode .bible-accordion > summary::after {
    border-color: var(--muted);
}

.narrorift-mode .bible-forge-backdrop {
    background: rgba(0, 0, 0, 0.6);
}

/* =====================================================================
   Studio loading screen. Full-screen branded interstitial that covers
   the studio shell while reloadEverything() is in flight. Hidden by
   default; revealed on auth-success, dismissed once the workspace data
   has landed. Manga-themed: pulsing 2D mark, floating panel frames,
   shimmering progress bar, rotating status steps.
   ===================================================================== */
.studio-loading-screen {
    position: fixed;
    inset: 0;
    z-index: 9200;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 30%, rgba(240, 82, 96, 0.18), transparent 55%),
        radial-gradient(circle at 78% 70%, rgba(56, 189, 248, 0.14), transparent 55%),
        linear-gradient(180deg, #060810 0%, #0b0f17 55%, #060810 100%);
    color: #eef2f7;
    overflow: hidden;
    transition: opacity 0.32s ease;
}

.studio-loading-screen.is-dismissing {
    opacity: 0;
    pointer-events: none;
}

/* Subtle dotted grid behind everything — same vibe as narrorift-mode body. */
.studio-loading-grid {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(90deg, rgba(148, 163, 184, 0.06) 1px, transparent 1px),
        linear-gradient(180deg, rgba(148, 163, 184, 0.06) 1px, transparent 1px);
    background-size: 38px 38px;
    mask-image: radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 80%);
    -webkit-mask-image: radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 80%);
}

/* Floating manga panel outlines. Four of them drift slowly so the bg
   feels alive without being noisy. Border-only so they read as empty
   panels waiting to be drawn. */
.studio-loading-frames {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.studio-loading-frame {
    position: absolute;
    border: 2px solid rgba(148, 163, 184, 0.18);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.015);
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.4);
    animation: studioFrameDrift 9s ease-in-out infinite;
}

.studio-loading-frame--1 {
    top: 12%;
    left: 9%;
    width: 220px;
    height: 140px;
    transform: rotate(-7deg);
    animation-delay: 0s;
}

.studio-loading-frame--2 {
    top: 14%;
    right: 11%;
    width: 180px;
    height: 240px;
    transform: rotate(5deg);
    animation-delay: 1.4s;
    border-color: rgba(240, 82, 96, 0.28);
}

.studio-loading-frame--3 {
    bottom: 14%;
    left: 14%;
    width: 260px;
    height: 180px;
    transform: rotate(4deg);
    animation-delay: 2.6s;
    border-color: rgba(56, 189, 248, 0.22);
}

.studio-loading-frame--4 {
    bottom: 10%;
    right: 8%;
    width: 200px;
    height: 130px;
    transform: rotate(-5deg);
    animation-delay: 3.8s;
}

@keyframes studioFrameDrift {
    0%, 100% { transform: translateY(0) rotate(var(--rot, -7deg)); opacity: 0.7; }
    50%      { transform: translateY(-12px) rotate(var(--rot, -7deg)); opacity: 1; }
}

/* Center card — where the user actually looks. */
.studio-loading-card {
    position: relative;
    display: grid;
    justify-items: center;
    gap: 14px;
    max-width: 460px;
    padding: 36px 32px 32px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 16px;
    background: rgba(11, 15, 23, 0.78);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
    text-align: center;
}

.studio-loading-card .eyebrow {
    margin: 0;
    color: #38bdf8;
    font-size: 0.74rem;
    letter-spacing: 0.18em;
}

.studio-loading-card h2 {
    margin: 0;
    font-size: 1.32rem;
    color: #f8fafc;
}

/* Pulsing brand mark — same "2D" as the topbar, scaled up. Two animated
   rings give it a "tuning in" feel. */
.studio-loading-mark {
    position: relative;
    display: grid;
    place-items: center;
    width: 88px;
    height: 88px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--accent) 0%, #b82734 100%);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.12),
        0 14px 38px rgba(240, 82, 96, 0.4);
    margin-bottom: 4px;
}

.studio-loading-mark-text {
    position: relative;
    z-index: 2;
    color: #fff;
    font-weight: 900;
    font-size: 1.6rem;
    letter-spacing: 0.02em;
}

.studio-loading-mark-ring {
    position: absolute;
    inset: -8px;
    border: 2px solid rgba(240, 82, 96, 0.55);
    border-radius: 22px;
    animation: studioMarkPulse 1.8s ease-in-out infinite;
}

.studio-loading-mark-ring--alt {
    inset: -18px;
    border-color: rgba(56, 189, 248, 0.32);
    border-radius: 28px;
    animation-delay: 0.6s;
}

@keyframes studioMarkPulse {
    0%   { transform: scale(0.92); opacity: 0.85; }
    70%  { transform: scale(1.08); opacity: 0; }
    100% { transform: scale(0.92); opacity: 0; }
}

/* Indeterminate shimmer bar — keeps the "we're doing something" tempo. */
.studio-loading-shimmer {
    position: relative;
    width: 100%;
    max-width: 280px;
    height: 4px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.18);
    overflow: hidden;
    margin: 4px 0 2px;
}

.studio-loading-shimmer span {
    position: absolute;
    inset-block: 0;
    width: 38%;
    border-radius: inherit;
    background: linear-gradient(90deg, transparent, var(--accent) 50%, transparent);
    animation: studioShimmer 1.4s ease-in-out infinite;
}

@keyframes studioShimmer {
    0%   { left: -40%; }
    100% { left: 100%; }
}

.studio-loading-status {
    margin: 0;
    color: #94a3b8;
    font-size: 0.88rem;
    min-height: 1.3em;
    transition: opacity 0.22s ease;
}

.studio-loading-status.is-changing {
    opacity: 0;
}

/* Step checklist — checks off as we progress through the auth/load flow. */
.studio-loading-steps {
    list-style: none;
    padding: 14px 18px 4px;
    margin: 8px 0 0;
    display: grid;
    gap: 6px;
    width: 100%;
    border-top: 1px solid rgba(148, 163, 184, 0.14);
    text-align: left;
}

.studio-loading-steps li {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #6b7280;
    font-size: 0.82rem;
    transition: color 0.18s ease;
}

.studio-loading-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 1.5px solid rgba(148, 163, 184, 0.35);
    background: transparent;
    flex-shrink: 0;
    transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.studio-loading-steps li.is-active {
    color: #f8fafc;
}

.studio-loading-steps li.is-active .studio-loading-dot {
    border-color: var(--accent);
    background: var(--accent);
    box-shadow: 0 0 0 4px rgba(240, 82, 96, 0.18);
    animation: studioStepActivePulse 1.1s ease-in-out infinite;
}

.studio-loading-steps li.is-done {
    color: #cbd5e1;
}

.studio-loading-steps li.is-done .studio-loading-dot {
    border-color: var(--green, #22c55e);
    background: var(--green, #22c55e);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
}

@keyframes studioStepActivePulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(240, 82, 96, 0.18); }
    50%      { box-shadow: 0 0 0 8px rgba(240, 82, 96, 0.08); }
}

@media (max-width: 540px) {
    .studio-loading-card {
        padding: 28px 22px 24px;
    }

    .studio-loading-frame--1,
    .studio-loading-frame--2,
    .studio-loading-frame--3,
    .studio-loading-frame--4 {
        display: none;
    }
}

/* Reduced-motion users get the layout without the drift / shimmer loops. */
@media (prefers-reduced-motion: reduce) {
    .studio-loading-frame,
    .studio-loading-mark-ring,
    .studio-loading-shimmer span,
    .studio-loading-steps li.is-active .studio-loading-dot {
        animation: none !important;
    }
}

/* =====================================================================
   Session-expired overlay. Fires when the Narrorift launch session's
   editExpiresAt has lapsed — proactively (timer/focus) or reactively
   (backend returned a launch-expired / story-locked error).
   ===================================================================== */
.session-expired-overlay {
    position: fixed;
    inset: 0;
    z-index: 9500;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 20%, rgba(210, 59, 69, 0.18), transparent 55%),
        radial-gradient(circle at 80% 80%, rgba(56, 189, 248, 0.14), transparent 55%),
        rgba(8, 12, 20, 0.78);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    animation: sessionExpiredFade 280ms ease;
}

@keyframes sessionExpiredFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Card uses a layered glow + an outer gradient border. The pseudo-element
   provides the animated border; the actual card surface sits on top. */
.session-expired-card {
    position: relative;
    width: min(520px, 100%);
    border-radius: 18px;
    background: var(--surface);
    color: var(--ink);
    padding: 40px 36px 28px;
    text-align: center;
    box-shadow:
        0 32px 80px rgba(0, 0, 0, 0.5),
        0 0 0 1px var(--line);
    animation: sessionExpiredPop 360ms cubic-bezier(0.16, 0.84, 0.44, 1);
    transition: transform 0.22s ease, box-shadow 0.22s ease;
    overflow: hidden;
}

.session-expired-card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(135deg, rgba(210, 59, 69, 0.55), rgba(56, 189, 248, 0.2) 50%, rgba(210, 59, 69, 0.0));
    -webkit-mask:
        linear-gradient(#000 0 0) content-box,
        linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    pointer-events: none;
    opacity: 0.85;
}

.session-expired-card::after {
    content: "";
    position: absolute;
    top: -1px;
    left: 24px;
    right: 24px;
    height: 3px;
    border-radius: 0 0 6px 6px;
    background: linear-gradient(90deg, transparent, var(--accent) 30%, var(--accent) 70%, transparent);
    opacity: 0.85;
}

.session-expired-card:hover {
    transform: translateY(-3px);
    box-shadow:
        0 38px 90px rgba(0, 0, 0, 0.55),
        0 0 0 1px var(--line);
}

@keyframes sessionExpiredPop {
    0%   { transform: translateY(18px) scale(0.96); opacity: 0; }
    60%  { opacity: 1; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* Soft radial wash that lives behind the icon and bleeds into the card —
   visible but subtle, gives the card depth without a hard vignette. */
.session-expired-glow {
    position: absolute;
    top: -80px;
    left: 50%;
    transform: translateX(-50%);
    width: 360px;
    height: 360px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(210, 59, 69, 0.28), transparent 65%);
    pointer-events: none;
}

/* Icon block: a glyph (the &#9201; clock) framed by two pulsing rings.
   The rings stagger via .delay so the eye always sees motion without the
   element feeling busy. */
.session-expired-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 84px;
    height: 84px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: linear-gradient(140deg, rgba(210, 59, 69, 0.18), rgba(210, 59, 69, 0.04));
    border: 1px solid rgba(210, 59, 69, 0.32);
    color: var(--accent);
}

.session-expired-icon-glyph {
    position: relative;
    z-index: 2;
    font-size: 2.4rem;
    line-height: 1;
    filter: drop-shadow(0 4px 10px rgba(210, 59, 69, 0.35));
}

.session-expired-icon-ring {
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    border: 1px solid rgba(210, 59, 69, 0.5);
    opacity: 0;
    animation: sessionExpiredRing 2.4s ease-out infinite;
}

.session-expired-icon-ring.delay {
    animation-delay: 1.2s;
}

@keyframes sessionExpiredRing {
    0%   { transform: scale(0.85); opacity: 0; }
    20%  { opacity: 0.55; }
    100% { transform: scale(1.55); opacity: 0; }
}

.session-expired-card .eyebrow {
    position: relative;
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 0.74rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-weight: 800;
}

.session-expired-card h2 {
    position: relative;
    margin: 0 0 14px;
    font-size: 1.55rem;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

.session-expired-message {
    position: relative;
    max-width: 420px;
    margin: 0 auto 24px;
    color: var(--muted);
    line-height: 1.65;
    font-size: 0.95rem;
}

.session-expired-message strong {
    color: var(--ink);
    font-weight: 700;
}

.session-expired-actions {
    position: relative;
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

/* The "Return to Narrorift" CTA. Inline-flex with an arrow that slides
   forward on hover — small motion, big "go" signal. */
.session-expired-cta {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 46px;
    padding: 0 22px;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    border-radius: 999px;
    box-shadow: 0 14px 32px rgba(210, 59, 69, 0.35);
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.session-expired-cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 18px 40px rgba(210, 59, 69, 0.45);
}

.session-expired-cta:active {
    transform: translateY(0);
}

.session-expired-cta-arrow {
    display: inline-block;
    transition: transform 0.22s ease;
}

.session-expired-cta:hover .session-expired-cta-arrow {
    transform: translateX(4px);
}

.session-expired-foot {
    position: relative;
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

/* Pulsing green dot — a tiny "you're still connected, just unlock the
   session" signal sitting in front of the tip line. */
.session-expired-foot-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45);
    animation: sessionExpiredDotPulse 1.8s ease-out infinite;
}

@keyframes sessionExpiredDotPulse {
    0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
    70%  { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

body.session-expired-locked {
    overflow: hidden;
}

.narrorift-mode .session-expired-overlay {
    background:
        radial-gradient(circle at 20% 20%, rgba(210, 59, 69, 0.22), transparent 55%),
        radial-gradient(circle at 80% 80%, rgba(56, 189, 248, 0.18), transparent 55%),
        rgba(0, 0, 0, 0.82);
}

.narrorift-mode .session-expired-card {
    background: linear-gradient(180deg, rgba(21, 27, 39, 0.96), rgba(13, 17, 26, 0.96));
    box-shadow:
        0 32px 80px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(148, 163, 184, 0.18);
}

.narrorift-mode .session-expired-card:hover {
    box-shadow:
        0 38px 90px rgba(0, 0, 0, 0.7),
        0 0 0 1px rgba(148, 163, 184, 0.28);
}

/* === Custom dialog system =============================================
   2DGuild-branded replacement for the browser-native confirm/alert
   prompts. A single root element (#tg-dialog-root) is mounted lazily by
   assets/js/dialog.js and its inner markup is rebuilt per call. The
   styling is theme-aware via CSS custom properties, so narrorift-mode
   (dark) and the standalone light theme both look correct without any
   theme-specific overrides for the dialog itself. */
.tg-dialog-root {
    position: fixed;
    inset: 0;
    z-index: 1400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.16s ease;
}

.tg-dialog-root.is-open {
    opacity: 1;
    pointer-events: auto;
}

.tg-dialog-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 11, 18, 0.62);
    backdrop-filter: blur(3px);
}

.tg-dialog {
    position: relative;
    width: min(460px, 100%);
    max-height: calc(100vh - 48px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface-strong);
    color: var(--ink);
    box-shadow: 0 28px 72px rgba(0, 0, 0, 0.35);
    transform: translateY(10px) scale(0.97);
    opacity: 0;
    transition: transform 0.18s ease, opacity 0.18s ease;
}

.tg-dialog-root.is-open .tg-dialog {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* Top accent bar — a coloured strip whose hue communicates intent at a
   glance. Primary (brand red) for routine confirms, red for destructive
   actions, slate for neutral notices. */
.tg-dialog::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--accent);
}

.tg-dialog.is-danger::before {
    background: linear-gradient(90deg, var(--danger), #f97316);
}

.tg-dialog.is-neutral::before {
    background: linear-gradient(90deg, #64748b, #94a3b8);
}

.tg-dialog-header {
    padding: 20px 24px 6px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.tg-dialog-header h3 {
    margin: 0;
    font-size: 1.05rem;
    line-height: 1.35;
    font-weight: 800;
    letter-spacing: 0.01em;
    color: var(--ink);
}

.tg-dialog-body {
    padding: 4px 24px 8px;
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.55;
    overflow-y: auto;
}

.tg-dialog-body strong,
.tg-dialog-body b {
    color: var(--ink);
    font-weight: 700;
}

.tg-dialog-body em,
.tg-dialog-body i {
    color: var(--ink);
    font-style: italic;
}

.tg-dialog-footer {
    padding: 16px 24px 20px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    border-top: 1px solid transparent;
}

.tg-dialog-btn {
    min-width: 96px;
    padding: 9px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 0.86rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease,
        color 0.12s ease, box-shadow 0.12s ease;
}

.tg-dialog-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.28);
}

.tg-dialog-btn-secondary {
    background: transparent;
    color: var(--ink);
}

.tg-dialog-btn-secondary:hover {
    background: rgba(15, 23, 42, 0.06);
    border-color: rgba(15, 23, 42, 0.18);
}

.tg-dialog-btn-primary {
    background: var(--ink);
    color: var(--paper);
    border-color: var(--ink);
}

.tg-dialog-btn-primary:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

.tg-dialog-btn-danger {
    background: var(--danger);
    color: #ffffff;
    border-color: var(--danger);
}

.tg-dialog-btn-danger:hover {
    background: #991b1b;
    border-color: #991b1b;
}

body.tg-dialog-open {
    overflow: hidden;
}

/* Dark-theme touch-ups. The base rules already pull from CSS variables
   that flip with `body.narrorift-mode`, so we only override what reads
   differently against a dark backdrop. */
.narrorift-mode .tg-dialog {
    background: #11151f;
    border-color: rgba(148, 163, 184, 0.22);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

.narrorift-mode .tg-dialog-btn-secondary:hover {
    background: rgba(148, 163, 184, 0.12);
    border-color: rgba(148, 163, 184, 0.35);
}

.narrorift-mode .tg-dialog-btn-primary {
    background: var(--accent);
    color: #0b1220;
    border-color: var(--accent);
}

.narrorift-mode .tg-dialog-btn-primary:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #0b1220;
}

.narrorift-mode .tg-dialog-btn-danger {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #fff;
}

.narrorift-mode .tg-dialog-btn-danger:hover {
    background: #7f1d1d;
    border-color: #7f1d1d;
}

@media (max-width: 480px) {
    .tg-dialog-footer {
        flex-direction: column-reverse;
    }
    .tg-dialog-btn {
        width: 100%;
    }
}
