/* Sharpened p1: charcoal + one orange, cards not bubbles, drawers not clutter. */

:root {
    --bg-main: #171717;
    --bg-panel: #1F1F1F;
    --bg-raised: #232323;
    --bg-card: #2A2A2A;
    --bg-card-header: #1F1F1F;
    --border: #2E2E2E;
    --border-strong: #3A3A3A;

    --fg: #DCDCD2;
    --fg-dim: #999990;
    --fg-faint: #66665f;

    --accent: #FF8C42;
    --accent-hover: #FF9D5C;
    --accent-active: #E67A30;
    --accent-dim: #CC6F35;
    --accent-wash: rgba(255, 140, 66, 0.1);

    --danger: #FF5555;
    --warn: #FFBB33;
    --ok: #57B36A;

    --radius: 8px;
    --radius-sm: 5px;
    --portrait: 88px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
}

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

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    background: var(--bg-main);
    color: var(--fg);
}

img, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

/* ===== app frame ===== */

.app {
    display: flex;
    flex-direction: column;
    width: 100dvw;
    height: 100dvh;
}

.upper-row {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr auto 400px;
    transition: grid-template-columns 220ms ease;
}

.upper-row.collapsed { grid-template-columns: 1fr auto 0px; }

.left-col {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

.drawer-tabs {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 6px;
    gap: 6px;
    border-left: 1px solid var(--border);
}

.btn-drawer-tab {
    all: unset;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05em;
    border-radius: 7px;
    border: 1px solid transparent;
    cursor: pointer;
    color: var(--fg-dim);
    transition: background 130ms ease, border-color 130ms ease, color 130ms ease;
}

.btn-drawer-tab:hover {
    color: var(--fg);
    background: var(--accent-wash);
    border-color: var(--accent-dim);
}

.btn-drawer-tab.active {
    background: var(--accent-active);
    color: #1A1A1A;
    border-color: var(--accent);
}

.btn-menu { margin-bottom: 10px; color: var(--accent); }

.right-col {
    background: var(--bg-raised);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.upper-row.collapsed .right-col { border-left-color: transparent; }

.drawer-panel {
    display: none;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    flex-direction: column;
    gap: 18px;
    padding: 14px 12px 20px;
}

.drawer-panel.active { display: flex; }

.lower-row {
    background: var(--bg-raised);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

/* ===== thread ===== */

.message-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px clamp(12px, 4vw, 48px);
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    align-items: stretch;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.message--player { border-left: 2px solid var(--accent-dim); }

.message--system { opacity: 0.75; font-style: italic; }

.message--pending { border-style: dashed; }

.message-portrait {
    width: var(--portrait);
    height: var(--portrait);
    align-self: flex-start;
    flex-shrink: 0;
    object-fit: cover;
    object-position: top center;
    border-right: 1px solid var(--border-strong);
    border-bottom: 1px solid var(--border-strong);
    border-bottom-right-radius: var(--radius);
    background: var(--bg-panel);
}

.portrait-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.6em;
    color: var(--fg-faint);
    width: var(--portrait);
    height: var(--portrait);
    align-self: flex-start;
    flex-shrink: 0;
    border-right: 1px solid var(--border-strong);
    border-bottom: 1px solid var(--border-strong);
    border-bottom-right-radius: var(--radius);
    background: var(--bg-panel);
}

.message-main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 3px 10px;
    background: var(--bg-card-header);
    border-bottom: 1px solid var(--border-strong);
    min-height: 30px;
}

.message-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.message-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.message-character-name {
    font-weight: 600;
    font-size: 0.82em;
    color: var(--accent);
    white-space: nowrap;
}

/* Which model generated this turn. A glyph per family, full model name
   on hover; dim by default so a thread of forty turns doesn't read as
   forty badges. */
.message-model-badge {
    font-size: 0.85em;
    line-height: 1;
    color: var(--fg-faint);
    cursor: help;
    user-select: none;
    transition: color 130ms ease;
}

.message-model-badge:hover { color: var(--fg-dim); }

.config-section-header .message-model-badge { margin-left: 6px; }

.message-render-badge {
    font-size: 0.68em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim, #888);
    border: 1px solid var(--border, #444);
    border-radius: 3px;
    padding: 0 5px;
    margin-left: 6px;
    opacity: 0.7;
}

.message-player-badge {
    font-size: 0.68em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #1A1A1A;
    background: var(--accent-dim);
    border-radius: 3px;
    padding: 0 5px;
    margin-left: 6px;
}

.message-meta {
    font-size: 0.72em;
    color: var(--fg-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* verbs fade in on hover; takes always visible */
.message-icons {
    display: flex;
    align-items: center;
    gap: 2px;
    opacity: 0;
    transition: opacity 130ms ease;
}

.message:hover .message-icons,
.message:focus-within .message-icons,
.message-icons.action-menu-host--open { opacity: 1; }

.message-take-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 0.78rem;
    color: var(--fg-dim);
}

.message-take-info {
    user-select: none;
    min-width: 30px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.message-icon-btn {
    all: unset;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    color: var(--fg-dim);
    font-size: 0.85em;
    transition: color 130ms ease, background 130ms ease;
}

.message-icon-btn:hover { color: var(--accent); background: var(--accent-wash); }
.message-icon-btn.active { color: var(--accent); background: var(--accent-wash); }
.message-icon-btn--danger:hover { color: var(--danger); background: rgba(255, 85, 85, 0.12); }

.message-index {
    font-size: 0.72em;
    color: var(--fg-faint);
    user-select: none;
    font-variant-numeric: tabular-nums;
}

.message-delete-confirm {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: 6px;
}

.message-delete-confirm-text {
    font-size: 0.75em;
    color: var(--danger);
}

.message-body {
    padding: 10px 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 1rem;
}

.message-body--editing { padding: 8px; }

.message-body-bold { font-weight: 700; color: var(--fg); }
.message-body-italic { font-style: italic; color: color-mix(in srgb, var(--fg), #000 32%); }
/* Spoken text takes the speaker's colour when they have one: the card
   sets --quote-color, and this is the system accent when nobody did. */
.message-body-quote { color: var(--quote-color, var(--accent-active)); }
/* A wiki quote marker that resolved to nothing: shown as written. */
.message-body-broken-quote {
    color: var(--danger);
    text-decoration: underline wavy;
    text-underline-offset: 3px;
    cursor: help;
}

.message-body-code {
    font-family: var(--mono);
    font-size: 0.88em;
    background: #1A1A1A;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 1px 5px;
}

.message-body-code-block {
    font-family: var(--mono);
    font-size: 0.85em;
    background: #1A1A1A;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 10px 12px;
    margin: 6px 0;
    white-space: pre-wrap;
    overflow-x: auto;
}

/* turn spans: prose segments + folded tool traffic */

.message-segment { position: relative; }

.message-segment + .message-segment,
.turn-tools + .message-segment,
.message-segment + .turn-tools,
.turn-thinking + .message-segment,
.turn-thinking + .turn-tools,
.turn-tools + .turn-thinking,
.message-segment + .turn-thinking { margin-top: 8px; }

/* reasoning traces: collapsed, quieter than tool traffic */
.turn-thinking {
    border: 1px dashed var(--border-strong);
    border-radius: 6px;
    font-size: 0.85em;
    overflow: hidden;
}

.turn-thinking-summary {
    cursor: pointer;
    user-select: none;
    padding: 4px 10px;
    color: var(--fg-faint);
    font-style: italic;
    list-style-position: inside;
}

.turn-thinking-summary:hover { color: var(--fg-dim); background: var(--accent-wash); }

.turn-thinking-text {
    padding: 8px 10px;
    border-top: 1px dashed var(--border-strong);
    color: var(--fg-dim);
    white-space: pre-wrap;
    max-height: 320px;
    overflow-y: auto;
}

.turn-thinking-text--redacted { font-style: italic; opacity: 0.7; }

/* back-to-back text blocks of one message: a rule, not just a gap */
.message-segment--cont {
    border-top: 1px dashed var(--border-strong);
    padding-top: 8px;
}
.message-body--editing .message-segment--cont { border-top: none; padding-top: 0; }

.turn-tools {
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    background: color-mix(in srgb, var(--bg-panel), #000 12%);
    font-size: 0.85em;
    overflow: hidden;
}

.turn-tools-summary {
    cursor: pointer;
    user-select: none;
    padding: 4px 10px;
    color: var(--fg-faint);
    list-style-position: inside;
}

.turn-tools-summary:hover { color: var(--fg-dim); background: var(--accent-wash); }

.turn-tools-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 10px;
    border-top: 1px dashed var(--border-strong);
}

.turn-tool-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.turn-tool-call {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.turn-tool-name {
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
}

.turn-tool-audience {
    font-size: 0.8em;
    color: var(--fg-dim);
    white-space: nowrap;
}

.turn-tool-args {
    font-family: var(--mono);
    font-size: 0.9em;
    color: var(--fg-dim);
    word-break: break-all;
}

.turn-tool-result {
    font-family: var(--mono);
    font-size: 0.9em;
    color: var(--fg-dim);
    background: #1A1A1A;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 4px 8px;
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
}

.turn-tool-result--pending { opacity: 0.55; font-style: italic; }

/* interim chip in the streaming bubble between tool rounds */
.turn-tools-chip {
    font-size: 0.78em;
    color: var(--fg-faint);
    font-style: italic;
    margin: 6px 0;
}

/* typing dots */
.message-typing { display: inline-flex; gap: 4px; padding: 4px 0; }

.message-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--fg-faint);
    animation: typing-bounce 1.2s infinite ease-in-out;
}

.message-typing span:nth-child(2) { animation-delay: 0.15s; }
.message-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* edit-in-place */
.message-edit {
    width: 100%;
    min-height: 80px;
    padding: 10px 12px;
    font-family: inherit;
    line-height: 1.5;
    background: var(--bg-panel);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    resize: vertical;
    color: var(--fg);
}

.message-edit:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-wash);
}

.message-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    padding-top: 6px;
}

/* ===== scene dividers ===== */

.scene-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 4px 4px;
    flex-shrink: 0;
    user-select: none;
}

.scene-divider-line {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-strong));
}

.scene-divider-line:last-child {
    background: linear-gradient(90deg, var(--border-strong), transparent);
}

.scene-divider-name {
    font-size: 0.78em;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--fg-dim);
    white-space: nowrap;
}

/* click-to-rename labels (util.js renameable): scene names */
.renameable { cursor: text; border-radius: var(--radius-sm); }
.renameable:hover, .renameable:focus-visible { color: var(--accent); outline: none; }
.renameable-input {
    font: inherit;
    min-width: 8em;
    padding: 1px 6px;
    background: var(--bg-panel);
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius-sm);
    color: var(--fg);
    outline: none;
    user-select: text;
}
.scene-row-name.renameable-input { flex: 1; min-width: 0; }

.scene-divider-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0.45;
    transition: opacity 130ms ease;
}

.scene-divider:hover .scene-divider-controls { opacity: 1; }

.scene-divider-mode {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--fg-dim);
    font-size: 0.72em;
    padding: 1px 4px;
    cursor: pointer;
}

.scene-divider-mode:focus { outline: none; border-color: var(--accent); color: var(--fg); }

.scene-divider-btn {
    all: unset;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    cursor: pointer;
    color: var(--fg-dim);
    font-size: 0.8em;
}

.scene-divider-btn:hover { color: var(--accent); background: var(--accent-wash); }

.scene-divider-warn { color: var(--warn); font-size: 0.85em; cursor: help; }

/* ===== entry bar ===== */

.entry-row {
    display: flex;
    gap: 10px;
    padding: 14px 16px 8px;
    align-items: flex-end;
}

.txt-entry {
    flex: 1;
    field-sizing: content;
    max-height: 300px;
    min-height: 44px;
    padding: 10px 14px;
    background: var(--bg-panel);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    resize: none;
    line-height: 1.5;
    color: var(--fg);
    transition: border-color 150ms ease;
}

.txt-entry::placeholder { color: var(--fg-faint); }

.txt-entry:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-wash);
}

.entry-buttons { display: flex; align-items: center; gap: 8px; }

button {
    font-weight: 600;
    border-radius: 7px;
    cursor: pointer;
    transition: background 130ms ease, border-color 130ms ease, color 130ms ease;
}

.btn-send {
    background: var(--accent);
    border: 1px solid var(--accent);
    color: #1A1A1A;
    padding: 10px 22px;
}

.btn-send:hover { background: var(--accent-hover); }
.btn-send:active { background: var(--accent-active); }

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--fg-dim);
}

.btn-ghost:hover { color: var(--fg); border-color: var(--fg-dim); }

.btn-generate { padding: 10px 14px; font-weight: 500; }

.btn-cancel {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: 10px 16px;
}

.btn-cancel:hover { background: rgba(255, 85, 85, 0.12); }

.btn-small {
    font-size: 0.8em;
    padding: 5px 12px;
    background: var(--accent);
    border: 1px solid var(--accent);
    color: #1A1A1A;
}

.btn-small:hover { background: var(--accent-hover); }

.btn-small.btn-ghost {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--fg-dim);
}

.btn-small.btn-ghost:hover { color: var(--fg); border-color: var(--fg-dim); }

.btn-small.btn-danger { background: var(--danger); border-color: var(--danger); }

.btn-danger-ghost:hover { color: var(--danger) !important; border-color: var(--danger) !important; }

.queued-chip {
    display: none;
    font-size: 0.75em;
    color: var(--warn);
    border: 1px solid var(--warn);
    border-radius: 4px;
    padding: 2px 8px;
    white-space: nowrap;
}

.queued-chip.visible { display: inline-block; }

/* ===== status line ===== */

.status-line {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px 8px;
    font-size: 0.78em;
    color: var(--fg-dim);
    overflow: hidden;
}

.status-chip {
    padding: 2px 8px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 4px;
    white-space: nowrap;
}

.status-chip--ok { color: var(--ok); }
.status-chip--bad { color: var(--danger); }
.status-chip--time { font-variant-numeric: tabular-nums; }

.status-flash {
    margin-left: auto;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-flash--error { color: var(--danger); background: rgba(255, 85, 85, 0.1); }
.status-flash--warn { color: var(--warn); background: rgba(255, 187, 51, 0.1); }
.status-flash--info { color: var(--accent); background: var(--accent-wash); }

/* On mobile-ish viewports the status line moves into a drawer panel
   (see placeStatus in app.js); the tab exists only for that. */
@media (min-width: 769px) {
    .btn-drawer-tab[data-tab-id="status"] { display: none; }
}

/* In the drawer's narrow column, chips wrap instead of clipping. */
.status-panel .status-line {
    flex-wrap: wrap;
    padding: 0;
}

.status-panel .status-flash { margin-left: 0; }

/* A flash landed while the status drawer was closed on mobile. */
.btn-drawer-tab.attention { color: var(--warn); border-color: var(--warn); }

/* ===== panels: shared ===== */

.config-section { display: flex; flex-direction: column; }

.config-section-header {
    font-size: 0.72em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--fg-dim);
    padding: 0 2px 6px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.config-list { display: flex; flex-direction: column; gap: 8px; }

.config-empty {
    padding: 8px 4px;
    font-size: 0.85em;
    color: var(--fg-faint);
    font-style: italic;
}

/* ===== cast panel ===== */

.cast-card {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    overflow: hidden;
}

.cast-card--player { border-left: 2px solid var(--accent-dim); }

.cast-card-header {
    all: unset;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    cursor: pointer;
}

.cast-card-header:hover { background: var(--accent-wash); }

.cast-portrait {
    width: 40px;
    height: 40px;
    align-self: center;
    border-radius: 6px;
    object-fit: cover;
    object-position: top center;
    flex-shrink: 0;
    border: none;
}

.portrait-fallback.cast-portrait {
    display: flex;
    font-size: 1em;
    min-height: 40px;
    border: none;
    border-radius: 6px;
}

.cast-card-names {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.cast-card-name { font-size: 0.88em; font-weight: 600; }

.cast-card-subtitle {
    margin-left: 0.4em;
    font-weight: 400;
    color: var(--fg-faint);
}

.cast-card-tags {
    font-size: 0.72em;
    color: var(--fg-faint);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cast-card-muted { font-size: 0.8em; }

.cast-card-absent {
    font-size: 0.72em;
    color: var(--fg-faint);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 1px 7px;
    white-space: nowrap;
}

.chevron {
    color: var(--fg-faint);
    font-size: 0.75em;
    transition: transform 180ms ease;
}

.chevron.open { transform: rotate(180deg); }

.cast-card-detail {
    border-top: 1px solid var(--border-strong);
    background: var(--bg-panel);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cast-card-desc {
    font-size: 0.85em;
    line-height: 1.5;
    color: var(--fg);
    white-space: pre-wrap;
}

.cast-card-actions { display: flex; flex-wrap: wrap; gap: 6px; }
/* greyed but still hoverable: the tooltip says why */
.cast-card-actions button[disabled] { opacity: 0.35; cursor: not-allowed; }

/* action menu: the '⋯' dropdown (util.js actionMenu). Lives on <body>,
   fixed-positioned by JS; styled after the cast tag dropdown. */

.action-menu {
    position: fixed;
    z-index: 500;   /* over the thread, under modals (1000) */
    min-width: 150px;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    padding: 4px;
    display: flex;
    flex-direction: column;
}

.action-menu-item {
    all: unset;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85em;
    white-space: nowrap;
}

.action-menu-item:hover,
.action-menu-item:focus-visible { background: var(--accent-wash); }

.action-menu-glyph {
    width: 1.2em;
    text-align: center;
    color: var(--fg-dim);
}

.action-menu-item:hover .action-menu-glyph,
.action-menu-item:focus-visible .action-menu-glyph { color: var(--accent); }

.action-menu-item--danger:hover,
.action-menu-item--danger:focus-visible { color: var(--danger); background: rgba(255, 85, 85, 0.12); }
.action-menu-item--danger:hover .action-menu-glyph { color: var(--danger); }

/* search + tag filter bar */

.cast-filter { display: flex; flex-direction: column; gap: 6px; }

.cast-combo { position: relative; }

.cast-filter-row { display: flex; gap: 6px; align-items: stretch; }

.cast-search { flex: 1; min-width: 0; }

.cast-tags-btn { white-space: nowrap; flex-shrink: 0; }
.cast-tags-btn.active { color: var(--accent); border-color: var(--accent-dim); }

.cast-suggest {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 20;
    max-height: 260px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    padding: 4px;
}

.cast-suggest.open { display: block; }

.cast-suggest-empty {
    padding: 8px;
    font-size: 0.82em;
    color: var(--fg-faint);
    font-style: italic;
}

.cast-suggest-row {
    display: flex;
    align-items: stretch;
    gap: 4px;
    border-radius: var(--radius-sm);
}

.cast-suggest-row.active,
.cast-suggest-row:hover { background: var(--accent-wash); }

.cast-suggest-pick {
    all: unset;
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    cursor: pointer;
    font-size: 0.85em;
}

.cast-suggest-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cast-suggest-row--status .cast-suggest-label { font-style: italic; color: var(--fg-dim); }

.cast-suggest-count {
    font-size: 0.85em;
    color: var(--fg-faint);
    font-variant-numeric: tabular-nums;
}

.cast-suggest-not {
    all: unset;
    padding: 0 10px;
    font-size: 0.75em;
    font-weight: 600;
    color: var(--fg-faint);
    border-left: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
}

.cast-suggest-not:hover { color: var(--danger); }

.cast-pills { display: flex; flex-wrap: wrap; gap: 5px; }
.cast-pills:empty { display: none; }

.cast-pill {
    display: inline-flex;
    align-items: stretch;
    max-width: 100%;
    font-size: 0.78em;
    border: 1px solid var(--accent-dim);
    background: var(--accent-wash);
    border-radius: 999px;
    overflow: hidden;
}

.cast-pill--status .cast-pill-toggle { font-style: italic; }

.cast-pill--exclude {
    border-color: var(--danger);
    background: rgba(255, 85, 85, 0.08);
}

.cast-pill-toggle,
.cast-pill-remove {
    all: unset;
    cursor: pointer;
    padding: 3px 4px 3px 10px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cast-pill-not { font-weight: 700; color: var(--danger); }

.cast-pill-remove {
    padding: 3px 9px 3px 6px;
    color: var(--fg-dim);
}

.cast-pill-remove:hover { color: var(--fg); }

.cast-pills-clear {
    all: unset;
    cursor: pointer;
    font-size: 0.75em;
    color: var(--fg-faint);
    padding: 3px 6px;
}

.cast-pills-clear:hover { color: var(--fg); }

.config-empty .btn-small { margin-left: 6px; font-style: normal; }

/* ===== settings panel ===== */

.setting-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 2px;
}

.setting-row--inline {
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.setting-label {
    font-size: 0.8em;
    font-weight: 500;
    color: #BBB;
}

.setting-input {
    width: 100%;
    font-size: 0.88em;
    padding: 6px 9px;
    background: var(--bg-panel);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--fg);
    transition: border-color 130ms ease;
}

.setting-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-wash);
}

.setting-select {
    cursor: pointer;
    appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--accent) 50%),
        linear-gradient(135deg, var(--accent) 50%, transparent 50%);
    background-position: calc(100% - 14px) 55%, calc(100% - 9px) 55%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
    padding-right: 26px;
}

.setting-checkbox {
    width: 16px;
    height: 16px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--accent);
}

.setting-textarea { min-height: 72px; resize: vertical; }

.setting-slider-wrap { display: flex; align-items: center; gap: 10px; }

.setting-slider { flex: 1; padding: 0; cursor: pointer; accent-color: var(--accent); }

.setting-slider-display {
    min-width: 42px;
    text-align: right;
    font-size: 0.82em;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.setting-slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.68em;
    color: var(--fg-faint);
}

/* ===== scenes panel ===== */

.scene-row {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.scene-row--active { border-left: 2px solid var(--accent); }

.scene-row-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.scene-row-name {
    font-size: 0.86em;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* a select dressed as the old mode chip - the fader, reachable
   without scrolling to the divider */
.scene-row-mode {
    appearance: none;
    -webkit-appearance: none;
    background: var(--bg-panel);
    font-size: 0.7em;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 3px;
    border: 1px solid var(--border-strong);
    color: var(--fg-dim);
    white-space: nowrap;
    cursor: pointer;
}

.scene-row-mode:focus { outline: none; border-color: var(--accent); }

.scene-row-mode--visible, .scene-row-mode--present { color: var(--ok); border-color: var(--ok); }
.scene-row-mode--hidden, .scene-row-mode--omitted { color: var(--fg-faint); }
.scene-row-mode--summary, .scene-row-mode--pov,
.scene-row-mode--present_summary, .scene-row-mode--present_pov {
    color: var(--accent);
    border-color: var(--accent-dim);
}

.scene-row-cast {
    font-size: 0.75em;
    color: var(--fg-faint);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.scene-row-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.scene-row-bounce { font-size: 0.72em; color: var(--fg-faint); }
.scene-row-bounce.bounced { color: var(--ok); }

.scene-break-form { display: flex; flex-direction: column; gap: 8px; }

.scene-break-carry {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.85em;
    color: var(--fg-dim);
    cursor: pointer;
    user-select: none;
}

/* ===== models panel ===== */

.llm-row {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.llm-row-scope {
    font-size: 0.72em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent);
}

.llm-row-model {
    font-family: var(--mono);
    font-size: 0.8em;
    color: var(--fg);
    word-break: break-all;
}

.llm-row-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    padding-top: 3px;
}

.llm-form { display: flex; flex-direction: column; gap: 8px; }
.llm-form-actions { display: flex; justify-content: flex-end; gap: 6px; }

/* ===== modals ===== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--bg-main);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    width: min(640px, 92vw);
    max-height: 84vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-strong);
    background: var(--bg-card-header);
}

.modal-title { font-weight: 600; font-size: 0.95em; color: var(--accent); }

.modal-close {
    all: unset;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 5px;
    cursor: pointer;
    color: var(--fg-dim);
}

.modal-close:hover { color: var(--accent); background: var(--accent-wash); }

.modal-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* game menu */

.game-menu {
    display: grid;
    grid-template-columns: 5fr 6fr;
    gap: 22px;
    align-items: start;
}

.game-menu-col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

/* the game menu carries two columns; give it room */
.modal:has(.game-menu) { width: min(880px, 94vw); }

@media (max-width: 700px) {
    .game-menu { grid-template-columns: 1fr; }
}

.game-menu-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
}

.game-menu-info { flex: 1; min-width: 0; }

.game-menu-name { font-size: 0.9em; font-weight: 600; }

.game-menu-desc {
    font-size: 0.78em;
    color: var(--fg-dim);
    line-height: 1.4;
}

.game-menu-save { display: flex; gap: 8px; }
.game-menu-save .setting-input { flex: 1; }

/* save browser */

.save-browser { display: flex; flex-direction: column; gap: 8px; }

.save-browser-list {
    max-height: 56vh;
    overflow-y: auto;
}

.save-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    cursor: pointer;
    transition: border-color 130ms ease;
}

.save-row:hover, .save-row:focus-visible { border-color: var(--accent); outline: none; }

.save-row--broken { cursor: default; opacity: 0.55; }
.save-row--broken:hover { border-color: var(--border-strong); }

.save-row-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.save-row-name { font-weight: 600; font-size: 0.9em; }

.save-row-meta {
    font-size: 0.78em;
    color: var(--fg-dim);
    white-space: nowrap;
}

.save-row-snippet {
    font-size: 0.8em;
    color: var(--fg-dim);
    font-style: italic;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* summary modal */

.summary-view { display: flex; flex-direction: column; gap: 18px; }

.summary-text {
    font-size: 0.88em;
    line-height: 1.55;
    padding: 10px 12px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    white-space: pre-wrap;
    color: var(--fg);
}

.summary-actions { display: flex; justify-content: flex-end; gap: 6px; padding-top: 6px; }

/* hand-editor for a summary slot: same box as .summary-text, editable */
.summary-edit {
    width: 100%;
    box-sizing: border-box;
    min-height: 80px;
    resize: vertical;
    font: inherit;
    font-size: 0.88em;
    line-height: 1.55;
    padding: 10px 12px;
    background: var(--bg-panel);
    color: var(--fg);
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius-sm);
}
.summary-edit:focus { outline: none; border-color: var(--accent); }

.summary-pov .summary-actions { align-self: stretch; }

/* shadow inspector modal */

.shadow-view { display: flex; flex-direction: column; gap: 18px; }

.shadow-span {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.88em;
    line-height: 1.55;
    padding: 10px 12px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--fg);
}

.shadow-span .message-segment { white-space: pre-wrap; }

/* header row: type + badge left, edit/delete right. The buttons opt
   out of the section header's uppercase small-caps styling. */
.shadow-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.shadow-header-tools {
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: none;
    letter-spacing: normal;
    font-weight: 500;
    font-size: 1.25em;
}

.shadow-span--editing .message-edit { min-height: 60px; }

.shadow-hint {
    font-size: 0.8em;
    color: var(--fg-dim);
    line-height: 1.45;
}

.shadow-add { display: flex; flex-direction: column; gap: 8px; }
.shadow-add-note { font-size: 0.8em; color: var(--fg-dim); }
.shadow-add-note:empty { display: none; }

.summary-pov {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
}

.summary-pov-name { font-size: 0.82em; font-weight: 600; color: var(--accent); }

.summary-pov .btn-small { align-self: flex-end; }

.summary-working {
    align-self: flex-end;
    font-size: 0.82em;
    font-style: italic;
    color: var(--fg-dim);
    animation: summary-pulse 1.2s ease-in-out infinite;
}

@keyframes summary-pulse {
    0%, 100% { opacity: 0.45; }
    50% { opacity: 1; }
}

/* assemble (debug context) modal */

.modal:has(.assemble-view) { width: min(880px, 94vw); }

.assemble-view { display: flex; flex-direction: column; gap: 12px; }

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

.assemble-chip {
    font-size: 0.8em;
    padding: 3px 8px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--fg);
}

.assemble-chip-key { color: var(--fg-dim); }

.assemble-msg {
    border: 1px solid var(--border);
    border-left: 3px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-panel);
    overflow: hidden;
}

.assemble-msg--system { border-left-color: var(--accent-dim); }
.assemble-msg--assistant { border-left-color: var(--fg-faint); }

.assemble-msg-role {
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--fg-dim);
    padding: 6px 12px 0;
}

.assemble-msg-text {
    margin: 0;
    padding: 6px 12px 10px;
    font-size: 0.82em;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
    color: var(--fg);
}

/* tool GUI modal */

.tools-view { display: flex; flex-direction: column; gap: 14px; }

.tools-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tools-header .setting-select { flex: 1; min-width: 0; }

.tools-header-label {
    font-size: 0.8em;
    color: var(--fg-dim);
    flex-shrink: 0;
}

.tool-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.tool-card-header {
    all: unset;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    cursor: pointer;
    background: var(--bg-card-header);
}

.tool-card-header:hover { background: var(--bg-raised); }

.tool-card-name {
    flex: 1;
    font-size: 0.9em;
    font-weight: 600;
    color: var(--fg);
    font-family: var(--mono, monospace);
}

.tool-card-audience {
    font-size: 0.72em;
    padding: 2px 7px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    color: var(--fg-dim);
}

.tool-card-audience--all {
    color: var(--accent);
    border-color: var(--accent-dim);
    background: var(--accent-wash);
}

.tool-card-detail {
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-top: 1px solid var(--border);
}

.tool-card-desc {
    font-size: 0.82em;
    line-height: 1.5;
    color: var(--fg-dim);
    white-space: pre-wrap;
}

.tool-card-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tool-field { display: flex; flex-direction: column; gap: 3px; }

.tool-field-label {
    font-size: 0.78em;
    color: var(--fg-dim);
    font-family: var(--mono, monospace);
}

.tool-field-required { color: var(--accent); margin-left: 2px; }

.tool-card-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tool-card-result {
    flex: 1;
    min-width: 0;
    font-size: 0.8em;
    color: var(--fg-dim);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 8em;
    overflow-y: auto;
}

.tool-card-result--ok { color: var(--fg); }
.tool-card-result--error { color: var(--danger); }

/* command help modal */

.help-list { display: flex; flex-direction: column; gap: 10px; }

.help-note { font-size: 0.82em; color: var(--fg-dim); }

.help-row {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) 3fr;
    gap: 12px;
    align-items: baseline;
}

.help-usage { font-size: 0.82em; color: var(--accent); word-break: break-word; }

.help-desc { font-size: 0.85em; color: var(--fg); }

/* user prompt modal */

.prompt-modal { width: min(520px, 92vw); }

.prompt-text {
    font-size: 0.92em;
    line-height: 1.55;
    white-space: pre-wrap;
    padding: 10px 12px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--fg);
}

.prompt-input { resize: vertical; font-family: inherit; }

.prompt-actions { display: flex; justify-content: flex-end; gap: 8px; }

.prompt-countdown {
    font-size: 0.82em;
    font-variant-numeric: tabular-nums;
    color: var(--fg-dim);
}

.prompt-countdown--low { color: var(--warn); }

/* ===== responsive ===== */

@media (max-width: 768px) {
    .upper-row { grid-template-columns: 1fr auto 280px; }
    .upper-row.collapsed { grid-template-columns: 1fr auto 0px; }

    .message-list { padding: 10px; gap: 8px; }

    .message { flex-direction: column; position: relative; }

    .message-portrait,
    .portrait-fallback:not(.cast-portrait) {
        width: 32px;
        height: 32px;
        min-height: 32px;
        border-radius: 50%;
        border: none;
        position: absolute;
        top: 5px;
        left: 8px;
        z-index: 1;
    }

    .message-header { padding-left: 48px; min-height: 42px; }
    .message-main { width: 100%; }
    .message-body { padding: 8px 12px; }
    .message-icons { opacity: 1; }

    .entry-row { padding: 10px; flex-wrap: wrap; }
    .btn-generate { display: none; }
    /* Hidden only in the lower row - on mobile the line is rehomed
       into the status drawer panel, where it must stay visible. */
    .lower-row .status-line { display: none; }
}

/* ===== views (story / wiki fullscreen switch) ===== */

.view {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
}
.view.active { display: flex; }

/* ===== wiki view ===== */

.wiki-view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.wiki-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
}

.wiki-title { font-weight: 600; }
.wiki-nav { margin-left: auto; display: flex; gap: 4px; }
.wiki-nav button[disabled] { opacity: 0.35; pointer-events: none; }

.wiki-body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 300px 1fr;
}

.wiki-sidebar {
    min-height: 0;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    background: var(--bg-panel);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.wiki-main {
    min-height: 0;
    overflow-y: auto;
    padding: 20px 28px;
}

/* layers */

.wiki-layers { display: flex; flex-direction: column; gap: 2px; }

.wiki-layer-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--fg-dim);
    cursor: pointer;
    text-align: left;
}
.wiki-layer-row:hover { background: var(--bg-raised); color: var(--fg); }
.wiki-layer-row.active { background: var(--accent-wash); color: var(--fg); }

.wiki-layer-portrait {
    width: 24px;
    height: 24px;
    min-width: 24px;
    border-radius: 50%;
    object-fit: cover;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}
.wiki-layer-shared { color: var(--accent); }

.wiki-layer-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wiki-layer-badge {
    background: var(--accent-dim);
    color: var(--bg-main);
    font-size: 11px;
    font-weight: 700;
    border-radius: 9px;
    padding: 0 7px;
    line-height: 17px;
}

/* tree */

.wiki-tree { display: flex; flex-direction: column; gap: 1px; }

.wiki-tree-group {
    color: var(--fg-faint);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 8px 0 2px;
}

.wiki-tree-page {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--fg-dim);
    cursor: pointer;
    text-align: left;
    font-size: 14px;
}
.wiki-tree-page:hover { background: var(--bg-raised); color: var(--fg); }
.wiki-tree-page.active { background: var(--accent-wash); color: var(--fg); }
.wiki-tree-page--deleted .wiki-tree-title {
    text-decoration: line-through;
    color: var(--fg-faint);
}

.wiki-tree-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* provenance badges */

.wiki-badge {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-radius: 3px;
    padding: 1px 5px;
    border: none;
    line-height: 1.4;
}
.wiki-badge--overlay { background: rgba(87, 179, 106, 0.18); color: var(--ok); }
.wiki-badge--shadowed { background: var(--accent-wash); color: var(--accent); }
.wiki-badge--base { background: var(--bg-raised); color: var(--fg-faint); }
.wiki-badge--gated { background: none; padding: 0; }
/* unknown visibility mode: hidden from everyone, probably a typo */
.wiki-badge--broken { color: var(--warn, #e0a030); }
.wiki-badge--big { font-size: 11px; padding: 2px 8px; }
button.wiki-badge--shadowed { cursor: pointer; }
button.wiki-badge--shadowed:hover { background: rgba(255, 140, 66, 0.25); }

/* journal */

.wiki-journal { margin-top: auto; padding-top: 8px; border-top: 1px solid var(--border); }

.wiki-journal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: none;
    border: none;
    color: var(--fg-dim);
    cursor: pointer;
    padding: 4px 2px;
    font-size: 13px;
}
.wiki-journal-head:hover { color: var(--fg); }

.wiki-journal-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
    max-height: 240px;
    overflow-y: auto;
}

.wiki-journal-entry {
    background: var(--bg-raised);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    font-size: 13px;
    color: var(--fg-dim);
    white-space: pre-wrap;
}

/* page pane */

.wiki-page { max-width: 780px; }

.wiki-page-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 8px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.wiki-page-title { font-size: 26px; line-height: 1.2; }
.wiki-page-id { color: var(--fg-faint); font-family: var(--mono); font-size: 12px; }
.wiki-page-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.wiki-frontmatter { margin: 8px 0 14px; }
.wiki-frontmatter summary {
    cursor: pointer;
    color: var(--fg-faint);
    font-size: 12px;
    user-select: none;
}
.wiki-frontmatter-raw {
    margin-top: 6px;
    background: var(--bg-raised);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--fg-dim);
    white-space: pre-wrap;
}

/* rendered markdown */

.wiki-markdown { line-height: 1.65; }
.wiki-markdown h1, .wiki-markdown h2, .wiki-markdown h3 { margin: 18px 0 8px; line-height: 1.25; }
.wiki-markdown h1:first-child { display: none; }  /* the head already shows the title */
.wiki-markdown p, .wiki-markdown ul, .wiki-markdown ol, .wiki-markdown blockquote { margin: 0 0 12px; }
.wiki-markdown ul, .wiki-markdown ol { padding-left: 24px; }
.wiki-markdown blockquote {
    border-left: 3px solid var(--border-strong);
    padding-left: 12px;
    color: var(--fg-dim);
}
.wiki-markdown code {
    background: var(--bg-raised);
    border-radius: 3px;
    padding: 1px 5px;
    font-family: var(--mono);
    font-size: 0.9em;
}
.wiki-markdown pre {
    background: var(--bg-raised);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    overflow-x: auto;
    margin: 0 0 12px;
}
.wiki-markdown pre code { background: none; padding: 0; }
/* ```quotable blocks: the lines a turn can say verbatim */
.wiki-quotable {
    border-left: 3px solid var(--accent-dim);
    margin: 0 0 12px;
    padding: 6px 12px;
}
.wiki-quotable-head { color: var(--fg-dim); font-size: 0.8em; margin-bottom: 4px; }
.wiki-quotable-line { display: flex; gap: 10px; align-items: baseline; padding: 2px 0; }
.wiki-quotable-key { font-family: var(--mono); font-size: 0.85em; color: var(--accent); flex: none; }
.wiki-quotable-line--bad .wiki-quotable-key,
.wiki-quotable-line--bad .wiki-quotable-text { color: var(--warn); }
.wiki-markdown table { border-collapse: collapse; margin: 0 0 12px; }
.wiki-markdown th, .wiki-markdown td { border: 1px solid var(--border-strong); padding: 4px 10px; }
.wiki-markdown hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.wiki-markdown a { color: var(--accent); }
.wiki-markdown a.wiki-link { text-decoration: none; border-bottom: 1px dotted var(--accent-dim); }
.wiki-markdown a.wiki-link:hover { border-bottom-style: solid; }
.wiki-markdown a.wiki-link-dead {
    color: var(--danger);
    text-decoration: none;
    border-bottom: 1px dashed var(--danger);
    cursor: pointer;
}

/* diff */

.wiki-diff {
    font-family: var(--mono);
    font-size: 13px;
    background: var(--bg-raised);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    overflow-x: auto;
}
.wiki-diff-legend { display: flex; gap: 14px; margin-bottom: 8px; }
.wiki-diff-line { white-space: pre-wrap; }
.wiki-diff-line--add { color: var(--ok); background: rgba(87, 179, 106, 0.08); }
.wiki-diff-line--del { color: var(--danger); background: rgba(255, 85, 85, 0.08); }
.wiki-diff-line--same { color: var(--fg-dim); }

/* editor */

.wiki-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 100%;
    max-width: 900px;
}
.wiki-editor-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.wiki-editor-title { font-weight: 600; }
.wiki-editor-id { flex: 1; min-width: 200px; font-family: var(--mono); }
.wiki-editor-hint { color: var(--fg-faint); font-size: 12px; }
.wiki-editor-text {
    flex: 1;
    min-height: 320px;
    resize: none;
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.55;
    tab-size: 4;
}

.wiki-empty { margin-top: 40px; }
.wiki-new-page { align-self: stretch; }

@media (max-width: 768px) {
    .wiki-body { grid-template-columns: 240px 1fr; }
    .wiki-main { padding: 14px; }
}

/* ===== character factory (gamelib.charfactory) ===== */

.cast-factory-btn { width: 100%; margin: 8px 0 10px; text-align: left; }

.modal:has(.cf-view) { width: min(760px, 94vw); }

.cf-view { display: flex; flex-direction: column; gap: 14px; }

/* a disabled fieldset greys every control in the form at once while a call flies */
.cf-fieldset {
    border: 0;
    padding: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.cf-fieldset[disabled] { opacity: 0.55; }

.cf-busy {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius-sm);
    background: var(--accent-wash);
    font-size: 0.88em;
}
.cf-busy-text { flex: 1; }
.cf-busy-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent);
    animation: cf-pulse 1s ease-in-out infinite alternate;
}
@keyframes cf-pulse { from { opacity: 0.25; } to { opacity: 1; } }

.cf-hint { font-size: 0.8em; color: var(--fg-dim); }
.config-section > .cf-hint { margin: 2px 0 8px; }
.cf-view button[disabled] { opacity: 0.4; cursor: not-allowed; }

.cf-ask {
    font-size: 0.85em;
    color: var(--fg-dim);
    font-style: italic;
    border-left: 2px solid var(--border-strong);
    padding-left: 10px;
    white-space: pre-wrap;
}

.cf-textarea { resize: vertical; font-family: inherit; line-height: 1.45; }
.cf-mono, .cf-code { font-family: var(--mono); font-size: 0.8em; }

.cf-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.cf-actions--main { justify-content: flex-start; }
.cf-spacer { flex: 1; }
.cf-mode { width: auto; min-width: 0; }

.cf-stage-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cf-stage-header .btn-small { text-transform: none; letter-spacing: normal; font-weight: 500; }

.cf-card {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.cf-card--editing { gap: 10px; }
.cf-card-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.cf-card-name { font-weight: 600; font-size: 1.05em; }
.cf-card-id { font-size: 0.78em; color: var(--fg-faint); }
.cf-card-desc { font-size: 0.88em; line-height: 1.55; white-space: pre-wrap; }
.cf-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.cf-tag {
    font-size: 0.72em;
    padding: 1px 8px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    color: var(--fg-dim);
}

.cf-code {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 22em;
    overflow: auto;
}
.cf-source { white-space: pre; }
.cf-source-edit { min-height: 18em; white-space: pre; }

.cf-field { display: flex; flex-direction: column; gap: 4px; }
.cf-field-label { font-size: 0.75em; color: var(--fg-dim); }

.cf-check-row { display: flex; align-items: center; gap: 8px; font-size: 0.88em; margin-bottom: 10px; }

.cf-check { font-size: 0.85em; margin-bottom: 8px; }
.cf-check--ok { color: var(--ok); }
.cf-check--bad { color: var(--danger); display: flex; flex-direction: column; gap: 6px; }
.cf-check--bad .cf-code { color: var(--fg); }

.cf-details > summary { cursor: pointer; font-size: 0.85em; color: var(--fg-dim); margin-bottom: 8px; }
.cf-details[open] > summary { color: var(--fg); }

.cf-history { font-size: 0.82em; color: var(--fg-dim); margin-bottom: 8px; }
.cf-history-label { font-size: 0.9em; color: var(--fg-faint); }
.cf-history ul { margin: 2px 0 0; padding-left: 18px; }

.cf-confirm { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82em; color: var(--danger); }

@media (max-width: 768px) {
    .cf-actions { justify-content: stretch; }
    .cf-spacer { display: none; }
}
