*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:         #060b14;
    --panel:      #0a1220;
    --panel2:     #0f1a2e;
    --border:     #1e3a5f;
    --accent:     #7eb8e8;
    --gold:       #dda878;
    --cream:      #faf4ec;
    --text:       #dce8f5;
    --muted:      #6a88a8;
    --danger:     #d48a8a;
    --player-bg:  #0e1f35;
    --player-bdr: #2a5080;
}

html { height: 100%; max-width: 100vw; overflow-x: hidden; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Nunito', sans-serif;
    font-weight: 400;
    display: grid;
    grid-template-columns: 300px 1fr;
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
        "banner  banner"
        "header  header"
        "sidebar main";
    height: 100vh;
    overflow: hidden;
    max-width: 100vw;
}

/* ── Story summary warning banner ── */
.story-warn-banner {
    background: rgba(180, 140, 30, 0.18);
    border-bottom: 1px solid rgba(200, 160, 40, 0.4);
    padding: 0.5rem 1.2rem;
    display: none;
    align-items: center;
    gap: 0.8rem;
    font-size: 0.82rem;
    color: var(--gold);
    flex-wrap: wrap;
}
.story-warn-banner.show { display: flex; }
.story-warn-banner button {
    background: rgba(200,160,40,0.2);
    border: 1px solid rgba(200,160,40,0.4);
    border-radius: 6px;
    color: var(--gold);
    padding: 0.2rem 0.7rem;
    font-size: 0.8rem;
    cursor: pointer;
}
.story-warn-banner button:hover { background: rgba(200,160,40,0.35); }

/* ── Offline banner ── */
.offline-banner {
    grid-area: banner;
    background: rgba(180, 60, 60, 0.18);
    border-bottom: 1px solid #a04040;
    padding: 0.6rem 2rem;
    display: none;
    align-items: center;
    gap: 1rem;
    font-size: 0.82rem;
    color: #f0a0a0;
}
.offline-banner.show { display: flex; }
.offline-banner code {
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    padding: 0.15em 0.5em;
    font-size: 0.9em;
    color: #ffc8c8;
}

/* ── Header ── */
header {
    grid-area: header;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(to right, var(--panel), #0a1428, var(--panel));
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

header .brand-banner {
    height: 68px;
    width: 360px;
    object-fit: cover;
    object-position: center;
    display: block;
}

header .tagline {
    flex: 1;
    font-size: 0.7rem;
    color: var(--muted);
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.server-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--muted);
    flex-shrink: 0;
    cursor: default;
}
.server-dot.ok  { background: #7ec88a; box-shadow: 0 0 5px #7ec88a88; }
.server-dot.err { background: var(--danger); }

.settings-corner {
    position: fixed;
    top: 0.6rem;
    right: 0.9rem;
    z-index: 300;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.settings-gear-btn {
    width: 34px; height: 34px;
    background: rgba(6,11,20,0.75);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--muted);
    font-size: 1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: color 0.15s, border-color 0.15s;
    backdrop-filter: blur(6px);
}
.settings-gear-btn:hover { color: var(--accent); border-color: var(--accent); }
.settings-menu {
    display: none;
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0;
    background: var(--panel2);
    border: 1px solid var(--border);
    border-radius: 7px;
    overflow: hidden;
    min-width: 160px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.settings-menu.open { display: block; }
.settings-menu button {
    display: block; width: 100%;
    background: none; border: none;
    color: var(--text);
    padding: 0.65rem 1rem;
    text-align: left; cursor: pointer;
    font-family: 'Nunito', sans-serif;
    font-size: 0.8rem; letter-spacing: 0.07em;
    transition: background 0.12s, color 0.12s;
}
.settings-menu button:hover { background: var(--panel); color: var(--accent); }

/* ── Sidebar ── */
.sidebar {
    grid-area: sidebar;
    border-right: 1px solid var(--border);
    background: var(--panel);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Token counter */
.token-panel {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, #060e1c, #0a1428);
}

.token-label {
    font-size: 0.62rem;
    letter-spacing: 0.2em;
    color: var(--muted);
    text-transform: uppercase;
    margin-bottom: 0.6rem;
}

.token-main {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}

.token-count {
    font-family: 'Cormorant Garamond', serif;
    font-size: 2.2rem;
    font-weight: 300;
    color: var(--gold);
    line-height: 1;
    text-shadow: 0 0 18px rgba(221,168,120,0.4);
    transition: all 0.3s;
}
.token-count.bump { animation: countBump 0.4s ease; }

@keyframes countBump {
    0%  { transform: scale(1); }
    40% { transform: scale(1.22); color: #f8c898; }
    100%{ transform: scale(1); }
}

.token-unit {
    font-size: 0.78rem;
    color: var(--muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.token-total {
    font-size: 0.7rem;
    color: var(--muted);
    letter-spacing: 0.08em;
}
.token-total span { color: var(--text); }

/* Tasks */
.tasks-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
}
.tasks-wrap::-webkit-scrollbar { width: 3px; }
.tasks-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.section-label {
    font-size: 0.62rem;
    letter-spacing: 0.2em;
    color: var(--muted);
    text-transform: uppercase;
    margin-bottom: 0.65rem;
}
.task-count-badge {
    margin-left: 0.45rem;
    font-size: 0.6rem;
    letter-spacing: 0.05em;
    opacity: 0.45;
    font-weight: 400;
    text-transform: none;
}

@keyframes sparkle-fly {
    0%   { transform: translate(-50%,-50%) translate(0,0) scale(1); opacity: 1; }
    100% { transform: translate(-50%,-50%) translate(var(--sx),var(--sy)) scale(0); opacity: 0; }
}
.sparkle-p {
    position: fixed; pointer-events: none; z-index: 9999;
    font-size: 0.85rem; color: var(--gold);
    animation: sparkle-fly 0.75s ease-out forwards;
    will-change: transform, opacity;
}

.task-list { list-style: none; display: flex; flex-direction: column; gap: 0.3rem; }

.task-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.45rem 0.5rem;
    border-radius: 5px;
    border: 1px solid transparent;
    transition: border-color 0.15s, background 0.15s;
}
.task-item:hover { background: rgba(255,255,255,0.04); border-color: var(--border); }
.task-item.done  { opacity: 0.42; }

.task-check {
    width: 16px; height: 16px;
    border: 1px solid var(--border);
    border-radius: 3px;
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.18s;
}
.task-item:not(.done) .task-check:hover { border-color: var(--gold); background: rgba(221,168,120,0.14); }
.task-item.done .task-check { background: var(--gold); border-color: var(--gold); }
.task-check::after {
    content: ''; display: none;
    width: 4px; height: 7px;
    border-right: 1.5px solid var(--bg);
    border-bottom: 1.5px solid var(--bg);
    transform: rotate(45deg) translate(-1px, -1px);
}
.task-item.done .task-check::after { display: block; }

.task-icon {
    font-size: 1rem;
    flex-shrink: 0;
    margin-top: 0px;
    width: 1.4rem;
    text-align: center;
    line-height: 1.3;
}

.task-text {
    flex: 1;
    font-size: 0.88rem;
    margin-left: 0.35rem;
    line-height: 1.45;
    color: var(--text);
    min-width: 0;
}
.task-item.done .task-text { text-decoration: line-through; color: var(--muted); }

.task-del, .task-edit {
    opacity: 0;
    background: none; border: none;
    cursor: pointer;
    font-size: 0.72rem;
    padding: 1px 4px;
    border-radius: 3px;
    flex-shrink: 0;
    margin-top: 1px;
    transition: opacity 0.15s;
}
.task-del  { color: var(--danger); }
.task-edit { color: var(--muted); }
.task-item:hover .task-del  { opacity: 0.6; }
.task-item:hover .task-edit { opacity: 0.5; }
.task-del:hover  { opacity: 1 !important; }
.task-edit:hover { opacity: 1 !important; color: var(--accent); }
.task-del.armed  { opacity: 1 !important; color: var(--gold); font-size: 0.7rem; letter-spacing: 0.04em; }
.task-check.armed { outline: 2px solid var(--gold); border-radius: 4px; opacity: 1 !important; }
.task-item.done .task-edit { display: none; }

/* ── Frog Pond ── */
.frog-pond-header {
    background: linear-gradient(90deg, rgba(100,180,80,0.1), transparent);
    border-bottom-color: rgba(100,200,80,0.25) !important;
    margin-top: 0 !important;
}
.frog-pond-header .section-header-label { color: #8ecb6a; letter-spacing: 0.06em; }
.frog-pond-divider {
    list-style: none;
    border-top: 1px dashed rgba(100,200,80,0.2);
    margin: 0.4rem 0 0.55rem;
    padding: 0;
    height: 0;
}

/* ── Daily Manifest ── */
.manifest-header {
    background: linear-gradient(90deg, rgba(230,180,60,0.12), transparent);
    border-bottom-color: rgba(230,190,80,0.3) !important;
    margin-top: 0 !important;
}
.manifest-header .section-header-label { color: var(--danger); letter-spacing: 0.06em; }
.manifest-divider {
    list-style: none;
    border-top: 1px dashed rgba(230,190,80,0.25);
    margin: 0.4rem 0 0.55rem;
    padding: 0;
    height: 0;
}

/* ── Section headers in task list ── */
.task-item.section-header-item {
    padding: 0.55rem 0.3rem 0.2rem;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: transparent !important;
    margin-top: 0.55rem;
    align-items: center;
}
.task-item.section-header-item:first-child { margin-top: 0; }
.section-header-label {
    flex: 1; min-width: 0;
    font-size: 0.62rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
    font-family: 'Nunito', sans-serif;
    font-weight: 600;
    cursor: text;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.section-header-input {
    flex: 1; min-width: 0;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--accent);
    border-radius: 0;
    padding: 0 0.15rem;
    color: var(--accent);
    font-size: 0.62rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-family: 'Nunito', sans-serif;
    font-weight: 600;
    outline: none;
}
.section-task-count {
    font-size: 0.6rem;
    color: var(--muted);
    letter-spacing: 0.04em;
    flex-shrink: 0;
    margin-left: 0.25rem;
    opacity: 0.7;
}
.section-toggle-btn {
    background: none; border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0.4rem 0.6rem;
    flex-shrink: 0;
    line-height: 1;
    opacity: 0.45;
    transition: opacity 0.15s, color 0.15s;
}
.task-item.section-header-item:hover .section-toggle-btn { opacity: 0.8; }
.section-toggle-btn:hover { opacity: 1 !important; color: var(--accent); }
.task-item.section-header-item.active {
    box-shadow: inset 2px 0 0 var(--accent);
    border-bottom-color: var(--accent);
    background: rgba(126, 184, 232, 0.05) !important;
}
.task-item.section-header-item.active .section-header-label { color: var(--cream); }

/* ── Daily task visual indicator ── */
.task-daily-pip {
    font-size: 0.92rem;
    color: var(--accent);
    opacity: 0.55;
    flex-shrink: 0;
    line-height: 1;
    pointer-events: none;
}
.task-item.daily .task-edit  { color: var(--accent); opacity: 0.45; }
.task-item.daily:hover .task-edit { opacity: 1 !important; }

.task-item.frog .task-text {
    color: #a8f0a8;
    background: linear-gradient(180deg, #a8f0a8, #e8f4ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.task-frog-pip { font-size: 0.82rem; opacity: 0.75; flex-shrink: 0; line-height: 1; pointer-events: none; }
.task-menu-item.frog-on { color: #6dbb6d; }

.task-item.manifest .task-text { color: var(--text); }
.task-manifest-pip { font-size: 0.82rem; opacity: 0.75; flex-shrink: 0; line-height: 1; pointer-events: none; }
.task-menu-item.manifest-on { color: var(--gold); }

/* ── Task options floating menu ── */
#taskMenu {
    position: fixed;
    background: var(--panel2);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.45);
    z-index: 2000;
    min-width: 138px;
    overflow: hidden;
    display: none;
}
#taskMenu.show { display: block; }
.task-menu-item {
    padding: 0.42rem 0.9rem;
    font-size: 0.78rem;
    cursor: pointer;
    color: var(--text);
    display: flex; align-items: center; gap: 0.5rem;
    white-space: nowrap;
    transition: background 0.12s, color 0.12s;
    font-family: 'Nunito', sans-serif;
}
.task-menu-item:hover { background: rgba(255,255,255,0.06); color: var(--accent); }
.task-menu-item.daily-on { color: var(--accent); }

/* ── Completed sub-section ── */
.completed-section-header {
    margin-top: 0.7rem;
    cursor: default;
}
.completed-section-header .section-header-label {
    color: var(--muted);
    cursor: default;
    letter-spacing: 0.14em;
}
.add-section-row {
    padding: 0.3rem 1.25rem 0.6rem;
    border-top: none;
}
.add-section-btn {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    padding: 0;
    font-family: 'Nunito', sans-serif;
    transition: color 0.15s;
}
.add-section-btn:hover { color: var(--accent); }

.task-edit-input {
    flex: 1; min-width: 0;
    background: var(--panel2);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 0.05rem 0.4rem;
    color: var(--cream);
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    line-height: 1.45;
}

.add-task {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
}
.add-task input {
    flex: 1;
    background: var(--panel2);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 0.5rem 0.7rem;
    color: var(--cream);
    font-family: 'Nunito', sans-serif;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.18s;
}
.add-task input:focus { border-color: var(--accent); }
.add-task input::placeholder { color: var(--muted); }
.add-task button {
    background: var(--panel2);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--accent);
    cursor: pointer;
    padding: 0.5rem 0.8rem;
    font-size: 1.15rem;
    line-height: 1;
    transition: all 0.18s;
    min-width: 36px;
}
.add-task button:hover:not(:disabled) { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.add-task button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Story area ── */
.story-area {
    grid-area: main;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.story-feed {
    flex: 1;
    overflow-y: auto;
    padding: 1.75rem 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
}
.story-feed::-webkit-scrollbar { width: 3px; }
.story-feed::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.story-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--muted);
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 1.1rem;
    text-align: center;
    pointer-events: none;
}
.story-empty .ornament { font-size: 1.4rem; opacity: 0.3; letter-spacing: 0.4em; }

.post-player {
    align-self: flex-end;
    max-width: 60%;
    background: var(--player-bg);
    border: 1px solid var(--player-bdr);
    border-radius: 10px 10px 2px 10px;
    padding: 0.9rem 1.1rem;
    animation: fadeUp 0.35s ease;
    position: relative;
}
.post-player .who {
    font-size: 0.6rem;
    letter-spacing: 0.2em;
    color: var(--accent);
    text-transform: uppercase;
    margin-bottom: 0.4rem;
    opacity: 0.8;
}
.post-player .body { font-size: 0.92rem; line-height: 1.6; color: var(--cream); white-space: pre-wrap; }

.post-story {
    align-self: stretch;
    border-left: 2px solid var(--gold);
    padding-left: 1.5rem;
    position: relative;
    animation: fadeUp 0.5s ease;
}
.post-story::before {
    content: '✦';
    position: absolute;
    left: -0.52rem; top: 0.15rem;
    font-size: 0.55rem;
    color: var(--gold);
    background: var(--bg);
    padding: 0 2px;
}
.post-story .body {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.1rem;
    line-height: 1.85;
    color: var(--cream);
    font-weight: 300;
    white-space: pre-wrap;
}
.post-story .body em { font-style: italic; color: #c8dfff; }

.post-loading {
    align-self: stretch;
    border-left: 2px solid var(--border);
    padding-left: 1.5rem;
    color: var(--muted);
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 1.05rem;
}

.dot-anim::after { content: ''; animation: dots 1.4s infinite; }

.post-regen-btn {
    display: none; margin-top: 0.6rem;
    background: none; border: 1px solid var(--border); border-radius: 5px;
    color: var(--muted); cursor: pointer; padding: 0.3rem 0.7rem;
    font-family: 'Cormorant Garamond', serif; font-size: 0.78rem;
    letter-spacing: 0.06em; transition: all 0.15s;
}
.post-regen-btn:hover { border-color: var(--gold); color: var(--gold); }

.post-edit-prompt-btn {
    display: none;
    position: absolute; bottom: 6px; right: 8px;
    background: none; border: none;
    color: var(--muted); cursor: pointer;
    font-size: 0.75rem; padding: 2px 4px;
    opacity: 0; transition: opacity 0.15s, color 0.15s;
    line-height: 1;
}
.post-player:hover .post-edit-prompt-btn { opacity: 0.5; }
.post-edit-prompt-btn:hover { opacity: 1 !important; color: var(--accent); }

.post-edit-ta {
    width: 100%; background: var(--panel2); border: 1px solid var(--accent);
    border-radius: 5px; color: var(--cream); font-size: 0.92rem; line-height: 1.6;
    padding: 0.5rem 0.6rem; font-family: inherit; resize: vertical;
    min-height: 120px; outline: none; margin-top: 0.3rem;
}
.post-edit-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.4rem; align-items: center; }
.post-edit-warning { font-size: 0.72rem; color: var(--danger); font-style: italic; width: 100%; margin-bottom: 0.1rem; }
.post-edit-save   { background: var(--accent); border: none; border-radius: 5px; color: #000;
    cursor: pointer; padding: 0.3rem 0.8rem; font-size: 0.78rem; font-family: inherit; }
.post-edit-cancel { background: none; border: 1px solid var(--border); border-radius: 5px;
    color: var(--muted); cursor: pointer; padding: 0.3rem 0.8rem; font-size: 0.78rem; font-family: inherit; }

/* ── Task drag handle ── */
.task-drag-handle {
    cursor: grab; color: var(--muted); font-size: 0.75rem;
    padding: 1px 3px; flex-shrink: 0; opacity: 0; transition: opacity 0.15s;
    user-select: none; margin-top: 2px;
}
.task-item:hover .task-drag-handle { opacity: 0.4; }
.task-item.dragging { opacity: 0.4; }
@keyframes dots {
    0%  { content: ''; }  25% { content: '.'; }
    50% { content: '..'; } 75% { content: '...'; } 100% { content: ''; }
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Post input ── */
.post-input-area {
    padding: 1rem 2.5rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--panel);
}
.post-hint {
    font-size: 0.68rem;
    letter-spacing: 0.13em;
    color: var(--muted);
    text-transform: uppercase;
    margin-bottom: 0.6rem;
}
.slot-badge { transition: color 0.3s; }
.post-row { display: flex; gap: 0.75rem; align-items: flex-end; }

#postTextarea {
    flex: 1;
    background: var(--panel2);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 0.75rem 0.9rem;
    color: var(--cream);
    font-family: 'Nunito', sans-serif;
    font-size: 0.9rem;
    outline: none;
    resize: vertical;
    height: 130px;
    max-height: 480px;
    overflow-y: auto;
    transition: border-color 0.18s;
    line-height: 1.55;
}
#postTextarea:focus { border-color: var(--accent); }
#postTextarea::placeholder { color: var(--muted); font-style: italic; }
#postTextarea:disabled { opacity: 0.35; cursor: not-allowed; }

#postBtn {
    background: linear-gradient(135deg, #0a1e3a, #0d2a50);
    border: 1px solid #2a5a8a;
    border-radius: 7px;
    color: var(--cream);
    cursor: pointer;
    padding: 0 1.1rem;
    height: 72px;
    font-family: 'Cormorant Garamond', serif;
    font-size: 1rem;
    letter-spacing: 0.08em;
    transition: all 0.2s;
    white-space: nowrap;
    min-width: 88px;
}
#postBtn:hover:not(:disabled) {
    background: linear-gradient(135deg, #0d2a52, #104070);
    box-shadow: 0 0 14px rgba(100,170,230,0.3);
}
#postBtn:disabled { opacity: 0.28; cursor: not-allowed; background: var(--panel2); border-color: var(--border); }

/* ── Modal shell ── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.75);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }

.modal {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: min(92vw, 900px);
    height: 84vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(0,0,0,0.8);
    animation: fadeUp 0.22s ease;
}

/* Full-page variant — used by the story editor */
.modal-loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(6, 11, 20, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 50;
}
.modal-loading-spinner {
    width: 42px; height: 42px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: modal-spin 0.8s linear infinite;
}
@keyframes modal-spin { to { transform: rotate(360deg); } }
.modal-loading-text {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.05rem;
    color: var(--cream);
    letter-spacing: 0.04em;
}
.modal-loading-bar-track {
    width: 220px;
    height: 6px;
    background: var(--panel2);
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.modal-loading-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--gold));
    transition: width 0.25s linear;
}
.modal-loading-pct {
    font-size: 0.78rem;
    color: var(--muted);
    letter-spacing: 0.04em;
}

.modal-fullpage {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    border-radius: 0;
    border: none;
}

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
}
.modal-header h2 {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.15rem; font-weight: 300;
    letter-spacing: 0.2em; color: var(--accent);
}
.modal-close {
    background: none; border: none;
    color: var(--muted); cursor: pointer;
    font-size: 0.9rem; padding: 4px 8px; border-radius: 4px;
    transition: color 0.15s;
}
.modal-close:hover { color: var(--cream); }

.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    flex-shrink: 0;
    overflow-x: auto;
}
.modal-tabs::-webkit-scrollbar { display: none; }

.modal-tab {
    background: none; border: none;
    border-bottom: 2px solid transparent;
    color: var(--muted); cursor: pointer;
    padding: 0.6rem 1rem;
    font-family: 'Nunito', sans-serif;
    font-size: 0.73rem; letter-spacing: 0.12em; text-transform: uppercase;
    transition: all 0.15s; margin-bottom: -1px; white-space: nowrap;
}
.modal-tab:hover { color: var(--text); }
.modal-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.modal-body {
    flex: 1; overflow: hidden;
    display: flex; flex-direction: column;
}

.modal-footer {
    padding: 0.85rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0; gap: 1rem;
}
.modal-footer-note { font-size: 0.7rem; color: var(--muted); }
.modal-footer-btns { display: flex; gap: 0.6rem; }

.btn-secondary {
    background: none; border: 1px solid var(--border); border-radius: 6px;
    color: var(--muted); cursor: pointer;
    padding: 0.45rem 0.9rem;
    font-family: 'Nunito', sans-serif; font-size: 0.8rem;
    transition: all 0.15s;
}
.btn-secondary:hover { border-color: var(--text); color: var(--text); }

.btn-primary {
    background: linear-gradient(135deg, #0a1e3a, #0d2a50);
    border: 1px solid #2a5a8a; border-radius: 6px;
    color: var(--cream); cursor: pointer;
    padding: 0.45rem 1.1rem;
    font-family: 'Cormorant Garamond', serif;
    font-size: 0.95rem; letter-spacing: 0.08em;
    transition: all 0.18s;
}
.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #0d2a52, #104070);
    box-shadow: 0 0 12px rgba(100,170,230,0.25);
}
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Doc section ── */
.doc-section {
    flex: 1; overflow: hidden;
    padding: 1.1rem 1.5rem 1rem;
    display: flex; flex-direction: column; gap: 0.55rem;
}
.doc-hint { font-size: 0.7rem; color: var(--muted); letter-spacing: 0.06em; flex-shrink: 0; }
.doc-hint em { color: var(--accent); font-style: normal; }

.doc-textarea {
    flex: 1; width: 100%;
    background: var(--panel2);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 1rem 1.1rem;
    color: var(--cream);
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.84rem; line-height: 1.65;
    resize: none; outline: none;
    transition: border-color 0.18s; overflow-y: auto;
}
.doc-textarea:focus { border-color: var(--accent); }
.doc-textarea::-webkit-scrollbar { width: 3px; }
.doc-textarea::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Characters section ── */
.chars-section { flex: 1; overflow: hidden; display: flex; }

.chars-sidebar {
    width: 195px; flex-shrink: 0;
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; overflow: hidden;
}

.chars-list {
    flex: 1; overflow-y: auto;
    padding: 0.6rem 0.5rem;
    display: flex; flex-direction: column; gap: 0.2rem;
}
.chars-list::-webkit-scrollbar { width: 3px; }
.chars-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.char-item {
    display: flex; align-items: center; gap: 0.4rem;
    padding: 0.45rem 0.6rem;
    border-radius: 5px; cursor: pointer;
    font-size: 0.85rem; color: var(--text);
    border: 1px solid transparent; transition: all 0.15s; min-width: 0;
}
.char-item:hover { background: rgba(255,255,255,0.04); border-color: var(--border); }
.char-item.active { background: rgba(100,170,230,0.12); border-color: #2a5080; color: var(--accent); }
.char-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.char-item-del {
    opacity: 0; background: none; border: none;
    color: var(--danger); cursor: pointer;
    font-size: 0.65rem; padding: 1px 3px; border-radius: 3px; flex-shrink: 0;
    transition: opacity 0.15s;
}
.char-item:hover .char-item-del { opacity: 0.55; }
.char-item-del:hover { opacity: 1 !important; }

.chars-add-btn {
    margin: 0.5rem;
    background: none; border: 1px dashed var(--border); border-radius: 5px;
    color: var(--muted); cursor: pointer;
    padding: 0.45rem; font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase;
    transition: all 0.15s; flex-shrink: 0;
}
.chars-add-btn:hover { border-color: var(--accent); color: var(--accent); }

.chars-editor {
    flex: 1; overflow: hidden;
    display: flex; flex-direction: column; padding: 1rem 1.25rem; gap: 0.6rem;
}
.chars-empty-state {
    flex: 1; display: flex; align-items: center; justify-content: center;
    color: var(--muted);
    font-family: 'Cormorant Garamond', serif; font-style: italic; font-size: 1rem; text-align: center;
}
.char-name-row {
    display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0;
}
.story-time-row {
    display: flex; gap: 1rem; flex-shrink: 0; margin-bottom: 0.4rem;
}
.story-time-field {
    display: flex; align-items: center; gap: 0.5rem; flex: 1;
}
.story-time-field .char-name-input { max-width: 140px; flex: 0 0 auto; }
.char-name-label {
    font-size: 0.62rem; letter-spacing: 0.15em; text-transform: uppercase;
    color: var(--muted); white-space: nowrap; flex-shrink: 0;
}
.char-name-input {
    flex: 1;
    background: var(--panel2); border: 1px solid var(--border); border-radius: 5px;
    padding: 0.5rem 0.75rem; color: var(--cream);
    font-family: 'Nunito', sans-serif; font-size: 0.9rem; outline: none;
    transition: border-color 0.18s;
}
.char-name-input:focus { border-color: var(--accent); }
.char-name-input::placeholder { color: var(--muted); font-style: italic; }
.char-birth-date-input { color-scheme: dark; }

/* ── Protagonist section ── */
.protagonist-section {
    flex: 1; overflow: hidden;
    display: flex; gap: 1.25rem;
    padding: 1.1rem 1.5rem 1rem;
}

.portrait-panel {
    width: 170px; flex-shrink: 0;
    display: flex; flex-direction: column; gap: 0.6rem;
}

.portrait-frame {
    width: 100%; aspect-ratio: 2 / 3;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--panel2);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 0.5rem;
    overflow: hidden; position: relative;
}

.portrait-frame img {
    position: absolute; inset: 0;
    width: 100%; height: 100%; object-fit: cover; border-radius: 7px; display: block;
}

.portrait-placeholder {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 0.4rem;
    color: var(--muted); text-align: center; padding: 0.5rem;
}
.portrait-placeholder .p-ornament { font-size: 1.1rem; opacity: 0.3; }
.portrait-placeholder .p-label    { font-size: 0.68rem; letter-spacing: 0.1em; font-style: italic; }


.portrait-upload-btn {
    background: var(--panel2); border: 1px solid var(--border); border-radius: 6px;
    color: var(--muted); cursor: pointer; padding: 0.45rem 0.6rem;
    font-family: 'Cormorant Garamond', serif; font-size: 0.82rem;
    letter-spacing: 0.04em; transition: all 0.18s; white-space: nowrap;
}
.portrait-upload-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ── Character portrait in editor ── */
.char-portrait-row { display: flex; gap: 0.75rem; align-items: flex-start; }
.char-portrait-frame {
    width: 100px; flex-shrink: 0; aspect-ratio: 2/3;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--panel2); display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    overflow: hidden; position: relative;
}
.char-portrait-frame img {
    position: absolute; inset: 0;
    width: 100%; height: 100%; object-fit: cover; border-radius: 7px; display: block;
}
.char-portrait-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.45rem; }
.char-portrait-url-row { display: flex; gap: 0.35rem; margin-top: 0.2rem; }
.char-portrait-url-input { flex: 1; background: var(--input-bg, #0d1b2a); border: 1px solid var(--border); border-radius: 5px; color: var(--text); font-size: 0.75rem; padding: 0.35rem 0.5rem; font-family: 'Nunito', sans-serif; min-width: 0; }
.char-portrait-url-input::placeholder { color: var(--muted); }
.char-portrait-url-row .portrait-upload-btn { font-size: 0.78rem; padding: 0.35rem 0.5rem; white-space: nowrap; }
.char-portrait-age-input {
    width: 58px; flex-shrink: 0;
    background: var(--input-bg, #0d1b2a); border: 1px solid var(--border); border-radius: 5px;
    color: var(--text); font-size: 0.75rem; padding: 0.35rem 0.5rem;
    font-family: 'Nunito', sans-serif;
}
.char-portrait-age-input::placeholder { color: var(--muted); }
.char-portrait-age-hint {
    font-size: 0.68rem; color: var(--muted); font-style: italic;
    margin-top: 0.3rem; line-height: 1.35;
}
.char-portrait-age-list {
    display: flex; flex-wrap: wrap; gap: 0.35rem;
    margin-top: 0.4rem; max-height: 110px; overflow-y: auto;
}
.char-age-row {
    display: flex; align-items: center; gap: 0.4rem;
    background: var(--panel2); border: 1px solid var(--border); border-radius: 6px;
    padding: 0.2rem 0.4rem; cursor: pointer; transition: border-color 0.18s;
}
.char-age-row:hover  { border-color: var(--gold); }
.char-age-row.active { border-color: var(--accent); }
.char-age-row-thumb {
    width: 24px; height: 32px; object-fit: cover; border-radius: 4px; flex-shrink: 0;
    background: var(--panel);
}
.char-age-row-label { font-family: 'Nunito', sans-serif; font-size: 0.72rem; color: var(--text); white-space: nowrap; }
.char-age-row-del {
    background: none; border: none; color: var(--muted); cursor: pointer;
    font-size: 0.78rem; padding: 0 0.15rem; line-height: 1;
}
.char-age-row-del:hover { color: #e05c6e; }

/* ── Story backup ── */
.backup-btn-row { display: flex; gap: 0.6rem; flex-wrap: wrap; }

/* ── Scene header (bg image + portraits, above posts) ── */
.scene-header {
    position: relative;
    height: 23vh;
    flex-shrink: 0;
    overflow: hidden;
}
.scene-regen-btn {
    position: absolute; top: 8px; right: 8px; z-index: 5;
    background: rgba(0,0,0,0.52); border: 1px solid rgba(255,255,255,0.12);
    border-radius: 5px; color: var(--muted); cursor: pointer;
    font-size: 0.7rem; padding: 0.28rem 0.6rem;
    font-family: 'Cormorant Garamond', serif; letter-spacing: 0.07em;
    transition: all 0.15s; opacity: 0;
}
.scene-header:hover .scene-regen-btn { opacity: 1; }
.scene-regen-btn:hover  { background: rgba(0,0,0,0.75); border-color: var(--gold); color: var(--gold); }
.scene-regen-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.scene-bg-full {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover; pointer-events: none;
    transition: opacity 1.2s ease;
}
/* Overlay: subtle dark tint top, blends to exact --bg colour at bottom */
.scene-bg-overlay {
    position: absolute; inset: 0;
    background: linear-gradient(to bottom,
        rgba(6,11,20,0.30) 0%,
        rgba(6,11,20,0.18) 35%,
        rgba(6,11,20,0.62) 68%,
        rgba(6,11,20,0.92) 88%,
        #060b14             100%);
    pointer-events: none;
}
/* Portraits sit at the bottom of the header, inside the blend */
.scene-portraits-inner {
    position: absolute; bottom: 0; left: 0; right: 0;
    display: flex; justify-content: space-between; align-items: flex-end;
    padding: 0 14px; pointer-events: none;
}
.scene-portrait-wrap    { position: relative; }
.scene-protagonist-slot { pointer-events: all; }
.scene-char-slots       { display: flex; gap: 8px; align-items: flex-end; pointer-events: all; }
.scene-protagonist-slot .scene-portrait-thumb { height: 19vh; width: calc(19vh * 2 / 3); }
.scene-char-slots .scene-portrait-thumb       { height: 15vh; width: calc(15vh * 2 / 3); }

.scene-portrait-thumb {
    border-radius: 6px 6px 0 0; border: 1px solid var(--gold); border-bottom: none;
    object-fit: cover; display: block;
    box-shadow: 0 0 22px rgba(0,0,0,0.8), inset 0 -40px 40px rgba(0,0,0,0.35);
}
.scene-portrait-label {
    position: absolute; bottom: 0; left: -4px; right: -4px;
    font-size: 0.62rem; letter-spacing: 0.07em; text-align: center;
    background: rgba(0,0,0,0.78); color: var(--gold);
    padding: 4px 5px; border-radius: 0 0 5px 5px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-family: 'Cormorant Garamond', serif; font-style: italic;
    opacity: 0; transform: translateY(4px);
    transition: opacity 0.18s, transform 0.18s; pointer-events: none;
}
.scene-portrait-wrap:hover .scene-portrait-label { opacity: 1; transform: translateY(0); }

.protagonist-bio {
    flex: 1; display: flex; flex-direction: column; gap: 0.55rem; overflow: hidden; min-width: 0;
}

/* ── Images section ── */
.images-section {
    flex: 1;
    padding: 1.75rem 2rem;
    display: flex; flex-direction: column; gap: 0.6rem; max-width: 540px;
    overflow-y: auto;
}
.style-presets {
    display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.4rem 0 0.2rem;
}
.style-preset-btn {
    padding: 0.38rem 0.9rem;
    border-radius: 8px;
    border: 1px solid rgba(200,160,40,0.25);
    background: rgba(255,255,255,0.04);
    color: var(--text-muted);
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.style-preset-btn:hover { background: rgba(200,160,40,0.1); color: var(--text); }
.style-preset-btn.active {
    background: rgba(200,160,40,0.18);
    border-color: var(--gold);
    color: var(--gold);
}
.style-extra-textarea {
    width: 100%;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: var(--text);
    padding: 0.6rem 0.8rem;
    font-size: 0.85rem;
    font-family: inherit;
    resize: vertical;
    box-sizing: border-box;
    margin-top: 0.3rem;
}
.style-extra-textarea:focus { outline: none; border-color: rgba(200,160,40,0.4); }

/* ── API Key section ── */
.apikey-section {
    flex: 1;
    padding: 1.75rem 2rem;
    display: flex; flex-direction: column; gap: 1.25rem; max-width: 540px;
    overflow-y: auto;
}
.apikey-heading {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.05rem; font-weight: 300; color: var(--cream); letter-spacing: 0.05em;
}
.apikey-info { font-size: 0.83rem; color: var(--muted); line-height: 1.65; }
.apikey-info code {
    background: var(--panel2); border: 1px solid var(--border); border-radius: 3px;
    padding: 0.1em 0.4em; font-size: 0.88em; color: var(--cream);
}
.apikey-field { display: flex; gap: 0.5rem; }
.apikey-input {
    flex: 1;
    background: var(--panel2); border: 1px solid var(--border); border-radius: 6px;
    padding: 0.6rem 0.85rem; color: var(--cream);
    font-family: 'Courier New', Courier, monospace; font-size: 0.88rem; outline: none;
    transition: border-color 0.18s; letter-spacing: 0.04em;
}
.apikey-input:focus { border-color: var(--accent); }
.apikey-input::placeholder { color: var(--muted); font-family: 'Nunito', sans-serif; letter-spacing: normal; }
.apikey-input.masked { -webkit-text-security: disc; letter-spacing: 0.1em; }
.apikey-toggle {
    background: var(--panel2); border: 1px solid var(--border); border-radius: 6px;
    color: var(--muted); cursor: pointer; padding: 0.6rem 0.75rem; font-size: 0.75rem;
    transition: all 0.15s; flex-shrink: 0;
}
.apikey-toggle:hover { border-color: var(--accent); color: var(--accent); }
.apikey-save-btn {
    align-self: flex-start;
    background: linear-gradient(135deg, #0a1e3a, #0d2a50);
    border: 1px solid #2a5a8a; border-radius: 6px; color: var(--cream);
    cursor: pointer; padding: 0.5rem 1.25rem;
    font-family: 'Cormorant Garamond', serif; font-size: 0.95rem; letter-spacing: 0.08em;
    transition: all 0.18s;
}
.apikey-save-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #0d2a52, #104070);
    box-shadow: 0 0 12px rgba(100,170,230,0.25);
}
.apikey-save-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.apikey-divider { border: none; border-top: 1px solid var(--border); margin: 0.25rem 0; }
.general-list {
    display: flex; flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(255,255,255,0.02);
    overflow: hidden;
}
.general-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1.1rem;
    border-bottom: 1px solid var(--border);
}
.general-row:last-child { border-bottom: none; }
.general-row-text { display: flex; flex-direction: column; gap: 0.2rem; }
.general-row-label {
    font-family: 'Cormorant Garamond', serif; font-size: 1rem; color: var(--cream); letter-spacing: 0.03em;
}
.general-row-sub { font-size: 0.75rem; color: var(--muted); line-height: 1.4; }
.general-row-btn {
    background: var(--panel2); border: 1px solid var(--border); border-radius: 6px;
    color: var(--text); cursor: pointer; padding: 0.45rem 1rem;
    font-family: 'Nunito', sans-serif; font-size: 0.8rem;
    transition: all 0.15s; flex-shrink: 0;
}
.general-row-btn:hover { border-color: var(--accent); color: var(--accent); }
.apikey-status {
    font-size: 0.78rem; padding: 0.5rem 0.75rem; border-radius: 5px; display: none;
}
.apikey-status.ok  { display: block; background: rgba(126,200,138,0.12); border: 1px solid #7ec88a55; color: #7ec88a; }
.apikey-status.err { display: block; background: rgba(212,138,138,0.12); border: 1px solid #d48a8a55; color: var(--danger); }

/* ── Toast ── */
.toast {
    position: fixed; bottom: 1.75rem; right: 1.75rem;
    background: var(--panel2); border: 1px solid var(--accent); border-radius: 7px;
    padding: 0.65rem 1rem; color: var(--cream); font-size: 0.85rem;
    z-index: 9999; animation: fadeUp 0.3s ease; max-width: 290px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.6);
}
.toast.err { border-color: var(--danger); color: var(--danger); }

/* ── Auth overlay ── */
.auth-overlay {
    position: fixed; inset: 0;
    background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    z-index: 10000;
    transition: opacity 0.3s;
}
.auth-overlay.hidden { opacity: 0; pointer-events: none; }
.auth-box {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.5rem 2rem;
    width: 340px;
    display: flex; flex-direction: column; gap: 1rem;
}
.auth-box h2 {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.6rem; font-weight: 300;
    color: var(--accent); letter-spacing: 0.2em;
    text-align: center; margin-bottom: 0.25rem;
}
.auth-box .auth-sub {
    font-size: 0.72rem; color: var(--muted);
    text-align: center; letter-spacing: 0.1em;
}
.auth-input {
    background: var(--panel2); border: 1px solid var(--border);
    border-radius: 6px; padding: 0.6rem 0.8rem;
    color: var(--cream); font-family: 'Nunito', sans-serif;
    font-size: 0.88rem; outline: none; width: 100%;
    transition: border-color 0.18s;
}
.auth-input:focus { border-color: var(--accent); }
.auth-btn {
    background: linear-gradient(135deg, #0a1e3a, #0d2a50);
    border: 1px solid #2a5a8a; border-radius: 6px;
    color: var(--accent); font-family: 'Nunito', sans-serif;
    font-size: 0.88rem; padding: 0.65rem; cursor: pointer;
    transition: all 0.18s; width: 100%;
}
.auth-btn:hover { background: linear-gradient(135deg, #0d2a50, #104070); }
.auth-btn.google {
    background: var(--panel2); border-color: var(--border);
    color: var(--text); display: flex; align-items: center;
    justify-content: center; gap: 0.5rem;
}
.auth-divider {
    display: flex; align-items: center; gap: 0.75rem;
    font-size: 0.68rem; color: var(--muted);
}
.auth-divider::before, .auth-divider::after {
    content: ''; flex: 1; height: 1px; background: var(--border);
}
.auth-toggle {
    font-size: 0.75rem; color: var(--muted);
    text-align: center; cursor: pointer;
}
.auth-toggle span { color: var(--accent); text-decoration: underline; }
.auth-error {
    font-size: 0.75rem; color: var(--danger);
    text-align: center; min-height: 1rem;
}

/* ── Onboarding modal ── */
.onboarding-box { width: 420px; }
.onboarding-reason-row {
    display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center;
}
.onboarding-reason-btn {
    padding: 0.38rem 0.9rem;
    border-radius: 8px;
    border: 1px solid rgba(200,160,40,0.25);
    background: rgba(255,255,255,0.04);
    color: var(--text-muted);
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.onboarding-reason-btn:hover { background: rgba(200,160,40,0.1); color: var(--text); }
.onboarding-reason-btn.active {
    background: rgba(200,160,40,0.18);
    border-color: var(--gold);
    color: var(--gold);
}
.onboarding-choice-row {
    display: flex; gap: 0.6rem;
}
.onboarding-choice-row .auth-btn { width: auto; flex: 1; }

/* ── RTL / Hebrew layout ── */
body.rtl { direction: rtl; }
body.rtl .sidebar {
    border-right: none;
    border-left: 1px solid var(--border);
}
body.rtl .task-text          { margin-left: 0; margin-right: 0.35rem; }
body.rtl .task-count-badge   { margin-left: 0; margin-right: 0.45rem; }
body.rtl .section-task-count { margin-left: 0; margin-right: 0.25rem; }
body.rtl .task-item.section-header-item.active {
    box-shadow: inset -2px 0 0 var(--accent);
}
body.rtl .post-story {
    border-left: none;
    border-right: 2px solid var(--gold);
    padding-left: 0;
    padding-right: 1.5rem;
}
body.rtl .post-story::before { left: auto; right: -0.52rem; }
body.rtl .post-loading {
    border-left: none;
    border-right: 2px solid var(--border);
    padding-left: 0;
    padding-right: 1.5rem;
}
body.rtl .toast { right: auto; left: 1.75rem; }
body.rtl .settings-corner { right: auto; left: 0.9rem; }
body.rtl .settings-menu   { right: auto; left: 0; }

/* ── Mobile nav bar (hidden on desktop) ── */
.mobile-nav { display: none; }
.post-expand-tab { display: none !important; }

@media (max-width: 768px) {
    body {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        grid-template-areas:
            "banner"
            "content"
            "mobile-nav";
        height: 100dvh;
    }

    .sidebar    { grid-area: content; border-right: none; border-bottom: 1px solid var(--border); }
    .story-area { grid-area: content; }

    /* Default: show story */
    body:not(.mobile-tasks) .sidebar { display: none; }
    body.mobile-tasks .story-area    { display: none; }

    header { display: none; }

    .post-row { flex-direction: column; gap: 0.5rem; }
    #postBtn  { width: 100%; height: 44px; }
    #postTextarea { width: 100%; height: 100px; max-height: 320px; overflow-y: auto; resize: vertical; }
    .post-input-area { display: none; }
    .post-input-area.visible { display: block; }
    .post-hint { display: none; }
    .post-expand-tab {
        position: sticky; bottom: 0; left: 0; right: 0; z-index: 10;
        width: 100%; padding: 0.4rem 1rem;
        background: var(--panel); border-top: 1px solid var(--border);
        text-align: center; cursor: pointer;
        color: var(--muted); font-size: 0.72rem; letter-spacing: 0.1em;
        text-transform: uppercase;
        display: block !important;
    }
    .post-expand-tab.hidden { display: none !important; }

    .story-feed      { padding: 1rem; }
    .post-input-area { padding: 0.75rem 1rem; }
    .scene-header    { height: 18vh; }

    .post-story, .post-player {
        font-size: 1rem;
        padding-left: 1rem;
    }

    /* Config modal */
    .modal-overlay { align-items: flex-end; }
    .modal {
        width: 100vw;
        max-width: 100vw;
        height: calc(100dvh - 56px);
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        overflow-x: hidden;
    }
    .modal-header   { padding: 0.75rem 1rem; }
    .modal-footer   { padding: 0.65rem 1rem; flex-wrap: wrap; }
    .modal-footer-note { display: none; }
    .modal-footer-btns { margin-left: auto; }
    .doc-section    { padding: 0.75rem 1rem; }
    .modal-tab      { padding: 0.5rem 0.65rem; font-size: 0.65rem; }

    /* Characters / World / Backstory inner layout */
    .chars-section  { flex-direction: column; }
    .chars-sidebar  { width: 100%; border-right: none; border-bottom: 1px solid var(--border); max-height: 120px; overflow-y: auto; }

    .mobile-nav {
        grid-area: mobile-nav;
        display: flex;
        border-top: 1px solid var(--border);
        background: var(--panel);
        flex-shrink: 0;
    }

    .mobile-tab-btn {
        flex: 1;
        background: none;
        border: none;
        color: var(--muted);
        cursor: pointer;
        padding: 0.65rem 0.5rem 0.5rem;
        font-family: 'Nunito', sans-serif;
        font-size: 0.65rem;
        letter-spacing: 0.12em;
        text-transform: uppercase;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.2rem;
        transition: color 0.15s;
    }
    .mobile-tab-btn.active { color: var(--accent); }
    .mobile-tab-btn .tab-icon { font-size: 1.05rem; line-height: 1; }
}
