/* character-player.css — layout and styles for the Character Player.
   Loaded after character-studio.css; inherits its CSS variables and .btn classes. */

/* ── App shell ───────────────────────────────────────────────── */

#player-app
{
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────── */

#app-header
{
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 10px;
    gap: 6px;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

#application-name,
#app-version
{
    font-family: var(--font-serif);
    font-size: 17px;
    font-style: italic;
    color: var(--accent);
    letter-spacing: 0.02em;
    white-space: nowrap;
    flex-shrink: 0;
}

#app-version { text-decoration: underline; transition: color 0.15s; flex: 1}
#app-version:hover { color: var(--text-bright); }

.char-name
{
    color: var(--text-dim);
    font-size: 13px;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.header-spacer { flex: 1; }

.icon-btn
{
    padding: 5px 8px;
    font-size: 14px;
    line-height: 1;
    min-width: 32px;
}

/* ── Header overflow menu (phone-width screens only) ─────────── */

#btn-overflow { display: none; }

#overflow-menu
{
    position: absolute;
    top: 100%;
    right: 8px;
    margin-top: 4px;
    min-width: 180px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.45);
    flex-direction: column;
    padding: 4px;
    z-index: 50;
}

.overflow-item
{
    display: block;
    padding: 9px 12px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
    background: none;
    border: none;
    border-radius: calc(var(--radius) - 2px);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.overflow-item:hover
{
    background: var(--surface2);
    color: var(--text-bright);
}

/* ── Character update banner ─────────────────────────────────── */

#char-update-banner
{
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text);
}

#char-update-text        { flex: 1; min-width: 0; }
#char-update-banner .banner-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Chat history ────────────────────────────────────────────── */

#chat-history
{
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

#chat-history::-webkit-scrollbar              { width: 4px; }
#chat-history::-webkit-scrollbar-thumb        { background: var(--border); border-radius: 2px; }
#chat-history:hover::-webkit-scrollbar        { width: 8px; }
#chat-history:hover::-webkit-scrollbar-thumb  { background: var(--text-dim); border-radius: 4px; }

/* ── Message bubbles ─────────────────────────────────────────── */

.message
{
    display: flex;
    flex-direction: column;
    max-width: 82%;
}

.message.user-message
{
    align-self: flex-end;
    align-items: flex-end;
}

.message.assistant-message
{
    align-self: flex-start;
    align-items: flex-start;
}

.message-bubble
{
    padding: 10px 14px;
    border-radius: 14px;
    font-family: var(--chat-font);
    font-size: var(--chat-size);
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.user-message .message-bubble
{
    background: var(--user-bubble);
    border: 1px solid var(--border);
    border-bottom-right-radius: 4px;
    color: var(--text);
}

.assistant-message .message-bubble
{
    background: var(--ai-bubble);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    color: var(--text-bright);
}

/* Model reasoning (reasoning_content) for a response.
   Rendered as a collapsed <details> above the response bubble. */
.agent-thinking
{
    font-size: 0.82em;
    font-style: italic;
    color: var(--text-dim);
    border-left: 2px solid var(--accent-dim);
    padding: 2px 10px;
    margin-bottom: 6px;
}

.agent-thinking-toggle
{
    cursor: pointer;
    list-style: none;       /* hide default triangle in Firefox */
    user-select: none;
    color: var(--text-dim);
    padding: 2px 0;
}
.agent-thinking-toggle::-webkit-details-marker { display: none; }  /* hide in Chrome/Safari */

.agent-thinking-toggle::after          { content: " >"; }
.agent-thinking[open] .agent-thinking-toggle::after { content: " v"; }

.agent-thinking-text
{
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    color: var(--text-dim);
}

/* Agent activity — tool calls the model made during a response.
   Rendered as a collapsed <details> above the response bubble. */
.agent-activity
{
    font-size: 0.82em;
    color: var(--text-dim);
    border-left: 2px solid var(--border);
    padding: 2px 10px;
    margin-bottom: 6px;
}

.agent-activity-toggle
{
    cursor: pointer;
    list-style: none;
    user-select: none;
    color: var(--text-dim);
    padding: 2px 0;
}
.agent-activity-toggle::-webkit-details-marker { display: none; }

.agent-activity-toggle::after          { content: " >"; }
.agent-activity[open] .agent-activity-toggle::after { content: " v"; }

.agent-activity-call
{
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    word-break: break-word;
}

.agent-activity-name
{
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 0.95em;
    color: var(--text-dim);
    white-space: pre-wrap;
}

.agent-activity-result
{
    margin-top: 2px;
    padding-left: 10px;
    white-space: pre-wrap;
}

/* Streaming cursor pulse on the active assistant bubble */
.assistant-message.streaming .message-bubble::after
{
    content: '▌';
    display: inline-block;
    color: var(--accent);
    animation: blink-cursor 0.9s step-end infinite;
    margin-left: 2px;
}

@keyframes blink-cursor
{
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

/* Markdown resets inside bubbles */
/* white-space: normal undoes pre-wrap for block-level markdown elements so
   HTML whitespace between tags doesn't render as visible blank lines. */
.message-bubble p,
.message-bubble ul,
.message-bubble ol,
.message-bubble li,
.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble blockquote { white-space: normal; }

.message-bubble p       { margin: 0 0 0.5em; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul,
.message-bubble ol      { margin: 0.4em 0 0.4em 1.4em; }
.message-bubble li      { margin: 0.2em 0; }
.message-bubble h1,
.message-bubble h2,
.message-bubble h3      { font-size: 1em; font-weight: bold; margin: 0.5em 0 0.25em; }
.message-bubble code    { font-family: var(--font-mono); font-size: 0.9em; background: rgba(255,255,255,0.07); padding: 1px 4px; border-radius: 3px; }
.message-bubble pre     { background: rgba(0,0,0,0.35); border-radius: var(--radius); padding: 10px 12px; margin: 0.5em 0; overflow-x: auto; }
.message-bubble pre code { background: none; padding: 0; }
.message-bubble blockquote { border-left: 3px solid var(--border); padding-left: 10px; color: var(--text-dim); margin: 0.5em 0; }

/* ── Status bar ──────────────────────────────────────────────── */

#status-bar
{
    height: 22px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    flex-shrink: 0;
}

#status-text
{
    font-size: 11px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#status-text.error { color: #c06060; }
#status-text.info  { color: var(--accent); }

/* ── Input area ──────────────────────────────────────────────── */

#chat-input-area
{
    position: relative;       /* anchor for #commands-dropdown */
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 8px 10px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* ── Input button group ──────────────────────────────────────── */

.input-btn-group
{
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* ── Command palette dropdown ────────────────────────────────── */

#commands-dropdown
{
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    max-height: 40vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    z-index: 200;
    box-shadow: 0 -6px 24px rgba(0,0,0,0.4);
}

.cmd-group-header
{
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 8px 12px 4px;
    border-top: 1px solid var(--border);
}
.cmd-group-header:first-child { border-top: none; }

.cmd-item
{
    padding: 7px 12px;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid var(--border);
}
.cmd-item:last-child    { border-bottom: none; }
.cmd-item:hover         { background: var(--surface2); }

.cmd-syntax
{
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--accent);
}

.cmd-desc
{
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
    white-space: normal;
}

/* ── Input Corrector diff ────────────────────────────────────── */

.corrector-diff
{
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

/* .diff-del / .diff-ins live in character-studio.css (shared) */

/* ── Settings divider ────────────────────────────────────────── */

.setting-divider
{
    border: none;
    border-top: 1px solid var(--border);
    margin: 4px 0;
}

/* ── Collapsible settings sections ──────────────────────────── */

details.settings-section
{
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

summary.settings-section-title
{
    cursor: pointer;
    padding: 9px 14px;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-bright);
    background: var(--surface2);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
}

summary.settings-section-title::-webkit-details-marker { display: none; }

summary.settings-section-title::after
{
    content: "\25B8";
    color: var(--text-dim);
    font-size: 10px;
    margin-left: auto;
    flex-shrink: 0;
    transition: transform 0.15s;
}

details.settings-section[open] > summary::after { transform: rotate(90deg); }

.settings-section-body
{
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ── Key capture row ─────────────────────────────────────────── */

.key-capture-row
{
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 5px;
}

.mod-label
{
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-dim);
    cursor: pointer;
    user-select: none;
}

.btn.key-capturing
{
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent);
    animation: key-capture-pulse 0.8s ease-in-out infinite;
}

@keyframes key-capture-pulse
{
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.55; }
}

/* ── "desktop" hint tag in section headers ───────────────────── */

.desktop-only-hint
{
    font-size: 9px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-dim);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 5px;
    font-weight: normal;
}

/* ── Markdown spacing modes ──────────────────────────────────── */

#chat-history[data-markdown-style="tight"]    .message-bubble p,
#chat-history[data-markdown-style="tight"]    .message-bubble ul,
#chat-history[data-markdown-style="tight"]    .message-bubble ol,
#chat-history[data-markdown-style="tight"]    .message-bubble li { margin-bottom: 0.15em; }

#chat-history[data-markdown-style="spacious"] .message-bubble p,
#chat-history[data-markdown-style="spacious"] .message-bubble ul,
#chat-history[data-markdown-style="spacious"] .message-bubble ol,
#chat-history[data-markdown-style="spacious"] .message-bubble li { margin-bottom: 1em; }

/* ── PTT button recording state ─────────────────────────────── */

#btn-ptt.recording
{
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
    animation: ptt-pulse 1s ease-in-out infinite;
}

@keyframes ptt-pulse
{
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.55; }
}

#chat-input
{
    flex: 1;
    field-sizing: content;
    min-height: 38px;
    max-height: 25dvh;
    resize: none;
    overflow-y: auto;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--chat-font);
    font-size: var(--chat-size);
    padding: 9px 12px;
    line-height: 1.45;
    outline: none;
    transition: border-color 0.15s;
}

#chat-input:focus { border-color: var(--accent-dim); }
#chat-input:disabled { opacity: 0.4; }

/* ── Dialogs ─────────────────────────────────────────────────── */

dialog
{
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-right: none;
    border-radius: 0 0 0 calc(var(--radius) + 2px);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 13px;
    padding: 0;
    position: fixed;
    top: var(--header-h);
    right: 0;
    left: auto;
    margin: 0;
    width: min(480px, 94vw);
    max-height: calc(100dvh - var(--header-h));
    flex-direction: column;
    box-shadow: -8px 8px 32px rgba(0,0,0,0.55);
    overflow: hidden;
}

dialog::backdrop
{
    background: rgba(0,0,0,0.55);
}

#dlg-settings { max-height: min(75dvh, calc(100dvh - var(--header-h))); }
#dlg-story    { width: min(700px, 96vw); max-height: min(88dvh, calc(100dvh - var(--header-h))); }

/* ── Story Converter ─────────────────────────────────────────── */

.story-params
{
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.story-num    { width: 65px; }
.story-select { width: 130px; }

.story-options
{
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.story-check
{
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}

.story-check input[type="checkbox"] { accent-color: var(--accent); width: 13px; height: 13px; }

.story-status
{
    font-size: 11px;
    color: var(--text-dim);
    min-height: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.story-output
{
    width: 100%;
    min-height: 220px;
    max-height: 40vh;
    resize: vertical;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.7;
    padding: 10px 12px;
    outline: none;
    overflow-y: auto;
    white-space: pre-wrap;
    box-sizing: border-box;
}

dialog[open]
{
    display: flex;
}

.dlg-header
{
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
    flex-shrink: 0;
}

.dlg-title
{
    flex: 1;
    font-size: 14px;
    color: var(--text-bright);
    font-family: var(--font-serif);
    font-style: italic;
}

.dlg-close
{
    padding: 3px 8px;
    font-size: 12px;
}

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

.dlg-body::-webkit-scrollbar              { width: 4px; }
.dlg-body::-webkit-scrollbar-thumb        { background: var(--border); border-radius: 2px; }

.dlg-footer
{
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

/* ── Tab bar (inside load-character dialog) ──────────────────── */

.tab-bar
{
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}

.tab-btn
{
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 6px 14px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-dim);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    margin-bottom: -1px;
}

.tab-btn:hover           { color: var(--text); }
.tab-btn.active          { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel               { display: none; flex-direction: column; gap: 10px; padding-top: 8px; }
.tab-panel.active        { display: flex; }

/* ── Form inputs ─────────────────────────────────────────────── */

.text-input
{
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 12.5px;
    padding: 7px 10px;
    outline: none;
    width: 100%;
    transition: border-color 0.15s;
}

.text-input:focus { border-color: var(--accent-dim); }

input[type="file"]
{
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-dim);
}

.setting-row
{
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.setting-row label
{
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.setting-row.row-inline
{
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.setting-row.row-inline label { text-transform: none; font-size: 13px; color: var(--text); letter-spacing: 0; }

.setting-hint
{
    font-size: 11px;
    color: var(--text-dim);
    font-style: italic;
}

.hint
{
    font-size: 12px;
    color: var(--text-dim);
}

/* ── Library home screen ─────────────────────────────────────── */

#library-home
{
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.library-home-header
{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}

.library-home-title
{
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 17px;
    color: var(--accent);
}

.library-home-empty
{
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex: 1;
    color: var(--text-dim);
    font-size: 13px;
    text-align: center;
}

/* ── Character library cards ─────────────────────────────────── */

.library-grid
{
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr));
    gap: 10px;
    margin: 0;
    padding: 0;
}

.char-card
{
    display: flex;
    gap: 12px;
    min-height: 110px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface2);
    overflow: hidden;
    transition: border-color 0.15s;
}

.char-card:hover            { border-color: var(--accent-dim); }
.char-card.active-char      { border-color: var(--accent); }

.char-card-portrait
{
    width: 90px;
    min-width: 90px;
    align-self: stretch;
    overflow: hidden;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: var(--accent);
    font-family: var(--font-serif);
    font-style: italic;
}

.char-card-portrait img
{
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top;
    display: block;
}

.char-card-portrait-placeholder
{
    background: var(--surface);
}

.char-card-info
{
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 10px 10px 10px 0;
}

.char-card-name
{
    font-size: 14px;
    font-family: var(--font-serif);
    font-style: italic;
    color: var(--accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.char-card-desc
{
    font-size: 11.5px;
    color: var(--text-dim);
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex: 1;
}

.char-card-footer
{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-top: auto;
}

.char-card-footer .btn
{
    flex-shrink: 0;
}

.char-card-date
{
    font-size: 10px;
    color: var(--text-dim);
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Conversation list (reuse item-row for conversations) ─────── */

.item-list
{
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    padding: 0;
}

.item-row
{
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface2);
    transition: border-color 0.12s;
}

.item-row:hover { border-color: var(--accent-dim); }

.item-row-info
{
    flex: 1;
    min-width: 0;
}

.item-row-name
{
    font-size: 13px;
    color: var(--text-bright);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-row-date
{
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}

.item-row-actions
{
    display: flex;
    gap: 5px;
    flex-shrink: 0;
}

.item-row.active-conv .item-row-name { color: var(--accent); }

.empty-hint
{
    font-size: 12px;
    color: var(--text-dim);
    text-align: center;
    padding: 24px 0;
}

/* ── Message action buttons ─────────────────────────────────── */

.message-actions
{
    display: none;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 4px;
    /* Pin the row to the top of the chat viewport while the top of its message
       is scrolled off-screen; otherwise it sits at the top of the block.
       (Matches Studio's sticky message header.) */
    position: sticky;
    top: -16px;              /* counteract #chat-history's 16px top padding */
    z-index: 10;
    background: var(--bg);   /* solid so bubble text scrolling behind is hidden */
    padding: 3px 0;
}

.message:hover .message-actions { display: flex; }

.user-message .message-actions  { justify-content: flex-end; }

.msg-action-btn
{
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 2px 7px;
    cursor: pointer;
    transition: color 0.12s, border-color 0.12s;
    line-height: 1.6;
}

.msg-action-btn:hover { color: var(--text-bright); border-color: var(--accent-dim); }

/* ── Inline message editor ───────────────────────────────────── */

.edit-textarea
{
    width: 100%;
    min-height: 80px;
    background: var(--surface2);
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--chat-font);
    font-size: var(--chat-size);
    padding: 9px 12px;
    resize: vertical;
    outline: none;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
    box-sizing: border-box;
}

/* Mirrors .message-bubble so entering edit mode barely moves the text.
   Width/height are set inline from the measured bubble; these rules match
   the bubble's typography and colors. */
.edit-textarea.bubble-mirror
{
    min-height: 0;
    min-width: min(420px, 100%);
    max-width: 100%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: var(--chat-size);
    line-height: 1.55;
    resize: none;          /* auto-grows on input instead */
    overflow-y: auto;
}

.user-message .edit-textarea.bubble-mirror
{
    background: var(--user-bubble);
    border-bottom-right-radius: 4px;
}

.assistant-message .edit-textarea.bubble-mirror
{
    background: var(--ai-bubble);
    color: var(--text-bright);
    border-bottom-left-radius: 4px;
}

.edit-controls
{
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    margin-top: 5px;
}

/* Expand the message row to full width while an inline editor is open */
.message:has(.edit-textarea)
{
    max-width: 100%;
    align-self: stretch;
}

/* ── Intro message ───────────────────────────────────────────── */

.intro-message .message-bubble
{
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-dim);
    font-style: italic;
}

/* ── Mobile ──────────────────────────────────────────────────── */

@media (max-width: 480px)
{
    .char-name          { font-size: 15px; }
    #chat-history       { padding: 10px 8px; }
    .message-actions    { top: -10px; }   /* match the reduced chat padding */
    .message            { max-width: 94%; }
    .message-bubble     { padding: 8px 11px; font-size: 14px; }
    .edit-textarea.bubble-mirror { padding: 8px 11px; font-size: 14px; }
    #chat-input         { font-size: 15px; }
    #btn-conversations  { display: none; }
    .overflow-collapse  { display: none; }
    #btn-overflow       { display: inline-block; }
    dialog              { top: var(--header-h); bottom: auto; left: 0; right: 0; width: 100vw; max-height: calc(90dvh - var(--header-h)); border: 1px solid var(--border); border-top: none; border-radius: 0 0 calc(var(--radius) + 4px) calc(var(--radius) + 4px); box-shadow: 0 8px 32px rgba(0,0,0,0.55); }
}

/* ── Light mode ──────────────────────────────────────────────── */

@media (prefers-color-scheme: light)
{
    :root:not([data-theme="dark"])
    {
        --bg:          #f5f3ef;
        --surface:     #ede9e2;
        --surface2:    #e2ddd5;
        --border:      #c8c3ba;
        --accent:      #8a6820;
        --accent-dim:  #c4a060;
        --text:        #2a2520;
        --text-dim:    #7a7268;
        --text-bright: #16120c;
        --user-bubble: #d8e4f0;
        --ai-bubble:   #e8e4dc;
        --danger:      #c04040;
        --success:     #2d6b3a;
    }
}

:root[data-theme="light"]
{
    --bg:          #f5f3ef;
    --surface:     #ede9e2;
    --surface2:    #e2ddd5;
    --border:      #c8c3ba;
    --accent:      #8a6820;
    --accent-dim:  #c4a060;
    --text:        #2a2520;
    --text-dim:    #7a7268;
    --text-bright: #16120c;
    --user-bubble: #d8e4f0;
    --ai-bubble:   #e8e4dc;
    --danger:      #c04040;
    --success:     #2d6b3a;
}

:root[data-theme="dark"]
{
    /* Explicit dark — same as :root defaults above; keeps the toggle honest */
    --bg:          #0e0f11;
    --surface:     #16181c;
    --surface2:    #1e2026;
    --border:      #2a2d35;
    --accent:      #c8a96e;
    --accent-dim:  #7a6440;
    --text:        #d4cfc8;
    --text-dim:    #6b6760;
    --text-bright: #f0ebe3;
    --user-bubble: #1a2235;
    --ai-bubble:   #1a1f18;
    --danger:      #8b3a3a;
    --success:     #3a6b4a;
}

/* ── Greeting chooser button ─────────────────────────────────── */
/* The Player's input area is a flex ROW; wrapping lets the chooser row
   claim a full-width line of its own above the textarea. */
#chat-input-area      { flex-wrap: wrap; }
#greeting-chooser-row { flex-basis: 100%; }
