/*
 * Plainchant stylesheet. Desktop-first: two panes side by side; the mobile block near the end swaps to
 * one pane below 1024px (mirrored by MOBILE_QUERY and FIT_QUERY in src/app/layout.js; keep them in sync).
 */
:root {
    /* Open Source Theme Variables - Easy to adapt */
    --bg-void: #0f1115;
    --text-void: #a1a1aa;
    --text-void-muted: #64748b;
    --bg-paper: #ffffff;
    --text-ink: #000000;
    --border-void: #1e293b;
    --border-paper: #e5e7eb;
    --btn-bg: #1e293b;
    --btn-text: #e2e8f0;
    --btn-hover: #334155;
    --btn-success: #15803d;

    --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
    --font-screenplay: 'Courier Prime', Courier, monospace;
}

* {
    box-sizing: border-box;
}

/* Layout is desktop-first: two panes side by side. The "mobile" block near the end of this stylesheet
   swaps to one pane at a time below 1024px. Its media query is mirrored in MOBILE_QUERY in the script;
   keep both in sync. */
body {
    margin: 0;
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: row;
    background-color: var(--bg-void);
    font-family: var(--font-ui);
    color: var(--text-void);
    overflow: hidden;
}

/* Touch devices and narrow windows: size the app to the visual viewport so an on-screen keyboard never
   covers the text. --app-height / --app-top come from window.visualViewport (fitToViewport); without them
   this falls back to the dynamic viewport height. Mirrored by FIT_QUERY in the script. */
@media (pointer: coarse), (max-width: 1023px) {
    body {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: var(--app-height, 100dvh);
        transform: translateY(var(--app-top, 0px));
    }
}

/* Fingers need bigger targets than a mouse pointer, in every layout */
@media (pointer: coarse) {
    .btn { min-height: 44px; }
    textarea { font-size: 16px; } /* 16px+ stops iOS Safari zooming the page when the field is focused */
}

/* --- THE VOID (Input) --- */
/* min-width: 0 lets a pane shrink below its content's minimum. Without it the two panes could not fit in
   anything under ~1110px and the preview was clipped off the right edge of the screen. */
.pane-void {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-void);
    background-color: var(--bg-void);
}

.header {
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-void);
}

.header h1, .header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.025em;
}

.header h1 { color: #f8fafc; }

.header p {
    margin: 0.25rem 0 0 0;
    font-size: 0.75rem;
    color: var(--text-void-muted);
}

/* In a narrow split (1024-1279px, panes under 640px) the tagline is squeezed to three lines beside the buttons */
@media (max-width: 1279px) {
    .pane-void .header p { display: none; }
}

.btn {
    padding: 0.5rem 1rem;
    background-color: var(--btn-bg);
    color: var(--btn-text);
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    font-family: inherit;
}

.btn:hover { background-color: var(--btn-hover); }
.btn.success { background-color: var(--btn-success); color: white; }

textarea {
    flex: 1;
    width: 100%;
    padding: 1.5rem;
    background: transparent;
    border: none;
    resize: none;
    outline: none;
    color: var(--text-void);
    font-family: monospace;
    font-size: 0.875rem;
    line-height: 1.6;
}

/* --- ELEMENT BAR: shows what the current line is, and changes it --- */
.element-bar {
    display: flex;
    flex-shrink: 0;
    gap: 0.25rem;
    padding: 0.375rem 0.75rem;
    overflow-x: auto;
    border-top: 1px solid var(--border-void);
    background-color: var(--bg-void);
}
.el-btn,
.suggest-chip {
    flex: 0 0 auto;
    padding: 0.35rem 0.7rem;
    border: 1px solid transparent;
    border-radius: 0.375rem;
    background: transparent;
    color: var(--text-void-muted);
    font: 500 0.75rem var(--font-ui);
    cursor: pointer;
    touch-action: manipulation; /* no double-tap zoom on a fast second tap */
}
.el-btn:hover,
.suggest-chip:hover { color: var(--btn-text); }
.el-btn[aria-pressed="true"] { background-color: var(--btn-bg); border-color: var(--border-void); color: #f8fafc; }
.el-btn .short { display: none; }
/* Autocomplete: suggestions replace the element buttons while a name is being typed (P2-04). Chips are built like the
   buttons, so the bar keeps its height. The first is the one Tab takes, so it looks selected. */
.suggestions { display: flex; flex: 1 1 auto; gap: 0.25rem; min-width: 0; }
.suggestions[hidden] { display: none; }
.element-bar.suggesting .el-btn { display: none; }
.suggest-chip { min-width: 0; max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-chip:first-child { background-color: var(--btn-bg); border-color: var(--border-void); color: #f8fafc; }
/* A keyboard user is told which key takes it; a touch screen has no such key */
@media (hover: hover) and (pointer: fine) {
    .suggest-chip:first-child::after { content: "Tab"; margin-left: 0.6em; padding: 0 0.35em; border: 1px solid var(--border-void); border-radius: 0.25rem; font-size: 0.85em; opacity: 0.7; }
}
/* "?" at the end of the bar: help on the elements. Phones have no room; they use Help in the menu. */
.el-help {
    flex: 0 0 auto;
    align-self: center;
    width: 1.9rem;
    height: 1.9rem;
    margin-left: auto;
    border: 1px solid var(--border-void);
    border-radius: 50%;
    background: transparent;
    color: var(--text-void-muted);
    font: 600 0.8rem var(--font-ui);
    cursor: pointer;
}
.el-help:hover { color: var(--btn-text); }
@media (pointer: coarse) { .el-help { width: 44px; height: 44px; } }
@media (max-width: 480px) { .el-help { display: none; } }
@media (pointer: coarse) {
    .el-btn, .suggest-chip { min-height: 44px; font-size: 0.85rem; padding: 0 0.9rem; }
}
/* Phones: shorter names, sharing the row equally, so all six fit without scrolling sideways */
@media (max-width: 480px) {
    .element-bar { padding-inline: 0.5rem; gap: 0.125rem; }
    .el-btn { flex: 1 1 auto; padding-inline: 0.3rem; text-align: center; }
    .suggest-chip { flex: 1 1 0; padding-inline: 0.3rem; text-align: center; }
    .el-btn .long { display: none; }
    .el-btn .short { display: inline; }
}

/* --- THE CANVAS (Output) --- */
.pane-canvas {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-paper);
    position: relative;
}

.pane-canvas .header {
    background-color: white;
    border-bottom: 1px solid var(--border-paper);
    z-index: 20;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.pane-canvas .header h2 { color: var(--text-ink); }

.font-badge {
    font-family: monospace;
    font-size: 0.75rem;
    background: #f3f4f6;
    color: #6b7280;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    border: 1px solid #e5e7eb;
}

/* The scroll area is also a size container: the @container rules below re-proportion the screenplay by the
   width of *this column*, not by the device, so phones, portrait tablets and a narrow split all work. */
#render-target {
    flex: 1;
    overflow-y: auto;
    padding: 3rem clamp(1rem, 2.5vw, 4rem);
    color: var(--text-ink);
    background-color: var(--bg-paper);
    container: sheet / inline-size;
}

/* Screenplay Formatting (CSS Implementation of Fountain Rules).
   Indents are variables so a narrow column can re-proportion them (see @container below). */
.screenplay-font {
    --ind-char: 22ch;
    --ind-paren: 16ch;
    --w-paren: 15ch;
    --ind-dialogue: 10ch;
    --w-dialogue: 35ch;
    --ind-transition: 40ch;
    --transition-align: left;

    font-family: var(--font-screenplay);
    font-size: 12pt; /* Standard 12pt Courier */
    line-height: 1.1;
    /* A fixed column: as wide as the pane allows up to 6 inches (60ch at 10-pitch), centred as a page.
       The explicit width keeps it from shrinking to fit its contents. */
    width: 100%;
    max-width: 60ch;
    margin: 0 auto;
    text-align: left; /* Enforce rigid left alignment */
}

/* Spacing comes from margins only: the parser emits no spacer elements. */
.script-scene-heading { text-transform: uppercase; font-weight: 700; margin: 1.5rem 0 1rem; }
.script-scene-num { float: right; font-weight: 400; color: #6b7280; }
.script-action { margin: 0 0 1rem; width: 100%; white-space: pre-wrap; }

.script-dialogue-block { margin: 0 0 1rem; }
.script-character { text-transform: uppercase; margin-left: var(--ind-char); }
.script-parenthetical { margin-left: var(--ind-paren); max-width: var(--w-paren); }
.script-dialogue { margin-left: var(--ind-dialogue); max-width: var(--w-dialogue); }

/* Dual dialogue: two blocks side by side, indents scaled down to fit half width */
.script-dual {
    --ind-char: 8ch; --ind-paren: 4ch; --w-paren: none; --ind-dialogue: 0; --w-dialogue: none;
    display: flex; gap: 2ch; margin-bottom: 1rem;
}
.script-dual .script-dialogue-block { flex: 1; min-width: 0; margin: 0; }

/* The nowrap ensures CUT TO: does not collapse under responsive pressure (mobile lets it wrap) */
.script-transition {
    text-transform: uppercase;
    margin: 0 0 1rem var(--ind-transition);
    text-align: var(--transition-align);
    white-space: nowrap;
}
/* A true page is 60ch of text (6 inches at 10-pitch). When the column is narrower than that, re-proportion the
   indents as percentages of the column instead of fixed character counts: nothing overflows, nothing forces
   the pane wider, and transitions wrap. 36rem is 60ch at 12pt Courier. Below ~26rem (phones) the type also
   steps down so a line still holds a useful number of characters. */
@container sheet (max-width: 36rem) {
    .screenplay-font {
        --ind-char: 30%;
        --ind-paren: 20%;
        --w-paren: 60%;
        --ind-dialogue: 8%;
        --w-dialogue: 84%;
        --ind-transition: 0;
        --transition-align: right;
    }
    .script-transition { white-space: normal; }
    /* Two half-width columns would be unreadably narrow: stack dual dialogue instead */
    .script-dual {
        flex-direction: column;
        gap: 1rem;
        --ind-char: 30%; --ind-paren: 20%; --w-paren: 60%; --ind-dialogue: 8%; --w-dialogue: 84%;
    }
}
@container sheet (max-width: 26rem) {
    .screenplay-font { font-size: 14px; line-height: 1.25; }
}

.script-centered { text-align: center; margin: 0 0 1rem; }
.script-lyrics { font-style: italic; margin: 0 0 1rem; }
.script-page-break { border: 0; border-top: 1px dashed #cbd5e1; margin: 1.5rem 0; }
.script-note {
    font-family: var(--font-ui); font-size: 0.75em; background: #fef9c3; color: #713f12;
    padding: 0 0.3em; border-radius: 0.2rem;
}

/* Outline aids: visible while writing, not part of the screenplay itself */
.script-section {
    font-family: var(--font-ui); font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.08em; color: #94a3b8; border-bottom: 1px solid var(--border-paper);
    margin: 1.5rem 0 0.75rem; padding-bottom: 0.25rem;
}
.script-synopsis { font-family: var(--font-ui); font-size: 0.75rem; font-style: italic; color: #6b7280; margin: 0 0 1rem; }

.script-title-page { text-align: center; padding: 4rem 0 3rem; margin-bottom: 2rem; border-bottom: 1px dashed #cbd5e1; }
.script-title-page .tp-title { text-transform: uppercase; font-weight: 700; margin-bottom: 2rem; }
.script-title-page .tp-author { margin-bottom: 2rem; }
.script-title-page .tp-meta { margin-top: 1rem; font-size: 10pt; }

/* Custom Scrollbars */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #27272a; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3f3f46; }
.pane-canvas ::-webkit-scrollbar-thumb { background: #cbd5e1; }
.pane-canvas ::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* --- MODALS & UI --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 17, 21, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 50;
}
.modal-overlay.active { display: flex; }
.modal-content {
    background: var(--bg-void);
    border: 1px solid var(--border-void);
    border-radius: 0.5rem;
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    max-height: 85dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}
.modal-content.wide { max-width: 46rem; }
.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-void);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h2 { margin: 0; font-size: 1rem; color: #f8fafc; }
.modal-close { min-width: 36px; min-height: 36px; border-radius: 0.375rem; background: transparent; color: var(--text-void-muted); border: none; cursor: pointer; font-size: 1.25rem; }
.modal-close:hover { color: #f8fafc; }
.modal-body {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-void);
}
.btn.primary { background-color: #e2e8f0; color: #0f1115; font-weight: 600; }
.btn.primary:hover { background-color: #ffffff; }
.btn.ghost { background: transparent; color: var(--text-void-muted); }
.btn.ghost:hover { color: var(--btn-text); }
.script-item:focus-visible { outline: 2px solid #94a3b8; outline-offset: -2px; }

/* Help window */
/* Topics wrap onto a second row on a phone, rather than scrolling sideways and hiding some of them */
.help-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    flex-shrink: 0;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-void);
}
.chip {
    flex: 0 0 auto;
    padding: 0.4rem 0.8rem;
    border: 1px solid transparent;
    border-radius: 0.375rem;
    background: transparent;
    color: var(--text-void-muted);
    font: 500 0.8125rem var(--font-ui);
    cursor: pointer;
}
.chip:hover { color: var(--btn-text); }
.chip[aria-pressed="true"] { background-color: var(--btn-bg); border-color: var(--border-void); color: #f8fafc; }
.help-section h3, .tour-step h3 { margin: 1.25rem 0 0.5rem; font-size: 0.95rem; color: #f8fafc; }
.help-section h3:first-child { margin-top: 0; }
.help-section p, .help-section li, .tour-step p, .tour-step li {
    margin: 0 0 0.6rem;
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--text-void);
}
.help-section ul, .tour-step ul { margin: 0 0 0.6rem; padding-left: 1.2rem; }
.help-section a { color: #cbd5e1; }
kbd {
    padding: 0.05rem 0.4rem;
    border: 1px solid #334155;
    border-bottom-width: 2px;
    border-radius: 0.25rem;
    background: #161a21;
    color: #e2e8f0;
    font: 0.8em ui-monospace, Consolas, monospace;
    white-space: nowrap;
}
.callout {
    margin: 0.75rem 0;
    padding: 0.6rem 0.8rem;
    border-left: 3px solid #475569;
    border-radius: 0 0.375rem 0.375rem 0;
    background: #12151b;
}
.callout p { margin: 0; }
.help-table { width: 100%; border-collapse: collapse; }
.help-table th {
    padding: 0.4rem 0.6rem;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-void-muted);
}
.help-table td { padding: 0.6rem; vertical-align: top; border-top: 1px solid var(--border-void); font-size: 0.8125rem; line-height: 1.5; }
.help-table td:first-child { width: 22%; color: #f8fafc; font-weight: 600; }
.help-table code, .sample {
    display: block;
    padding: 0.5rem 0.65rem;
    border-radius: 0.375rem;
    background: #0b0d11;
    color: #cbd5e1;
    font: 0.8125rem/1.5 ui-monospace, Consolas, monospace;
    white-space: pre-wrap;
    overflow-x: auto;
}
code.inline, .help-table code.inline {
    display: inline;
    padding: 0.05rem 0.35rem;
    border-radius: 0.25rem;
    background: #0b0d11;
    color: #cbd5e1;
    font: 0.85em ui-monospace, Consolas, monospace;
    white-space: normal;
}
.help-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }

/* Welcome tour */
.tour-step[hidden], .help-section[hidden] { display: none; }
.tour-step h3 { margin-top: 0.25rem; font-size: 1.2rem; }
.tour-dots { display: flex; gap: 0.4rem; }
.tour-dots span { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: #334155; }
.tour-dots span[aria-current="step"] { background: #e2e8f0; }
.sample-io { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin: 0.75rem 0; }
.sample-io h4 { margin: 0 0 0.3rem; font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-void-muted); }
.sample-io .sample { margin: 0; min-height: 11rem; }
.sample-sheet { container: sheet / inline-size; min-height: 11rem; padding: 0.75rem; border-radius: 0.375rem; background: #fff; color: #000; overflow: hidden; }
.sample-sheet .screenplay-font { font-size: 10px; line-height: 1.25; }
.hint-touch { display: none; }
/* Device-specific wording: touch devices see the touch hint, everything else sees the keyboard one */
@media (pointer: coarse) {
    .hint-touch { display: revert; }
    .hint-keys { display: none; }
}
@media (max-width: 560px) {
    .sample-io { grid-template-columns: 1fr; }
    .sample-io .sample, .sample-sheet { min-height: 0; }
    .help-table thead { display: none; }
    .help-table tr { display: block; padding: 0.5rem 0; border-top: 1px solid var(--border-void); }
    .help-table td { display: block; width: auto !important; padding: 0.15rem 0.2rem; border: 0; }
}
/* --- Library --- */
.library-tools { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border-void); }
.library-search {
    flex: 1 1 12rem;
    min-width: 0;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-void);
    border-radius: 0.375rem;
    background: #0b0d11;
    color: var(--btn-text);
    font: 0.875rem var(--font-ui);
}
.library-search:focus-visible { outline: 2px solid #94a3b8; outline-offset: 1px; }
.library-views { display: flex; gap: 0.25rem; }
.script-item { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border-void); }
.script-item:last-child { border-bottom: none; }
.script-open {
    display: block;
    width: 100%;
    padding: 0.25rem 0.5rem;
    margin: 0 -0.5rem;
    box-sizing: content-box;
    border: 0;
    border-radius: 0.375rem;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.script-open:hover { background: var(--border-void); }
.script-open:focus-visible, .mini:focus-visible { outline: 2px solid #94a3b8; outline-offset: 1px; }
.script-title { font-weight: 600; color: #f8fafc; margin-bottom: 0.15rem; overflow-wrap: anywhere; }
.script-preview { font-size: 0.75rem; color: var(--text-void-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.script-meta { margin-top: 0.15rem; font-size: 0.7rem; color: #64748b; }
.script-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.5rem; }
.mini {
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--border-void);
    border-radius: 0.375rem;
    background: transparent;
    color: var(--text-void-muted);
    font: 500 0.75rem var(--font-ui);
    cursor: pointer;
}
.mini:hover { color: var(--btn-text); background: var(--btn-bg); }
.mini.danger:hover { color: #fecaca; border-color: #7f1d1d; background: #2a1215; }
.mini.armed { color: #fff; border-color: #b91c1c; background: #b91c1c; }
@media (pointer: coarse) { .mini { min-height: 44px; padding-inline: 0.9rem; font-size: 0.85rem; } }
.rename-form { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.rename-form input {
    flex: 1 1 10rem;
    min-width: 0;
    padding: 0.45rem 0.65rem;
    border: 1px solid #475569;
    border-radius: 0.375rem;
    background: #0b0d11;
    color: #f8fafc;
    font: 0.9375rem var(--font-ui);
}
.rename-form input:focus-visible { outline: 2px solid #94a3b8; outline-offset: 1px; }
.rename-form input[aria-invalid="true"] { border-color: #b91c1c; }
.library-note { margin: 0; padding: 0.75rem 1rem; font-size: 0.8125rem; line-height: 1.5; color: var(--text-void-muted); }
.library-note .mini { margin-left: 0.5rem; }
.library-toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--border-void);
    background: #161a21;
    font-size: 0.8125rem;
    color: var(--btn-text);
}
.library-toast span { flex: 1; overflow-wrap: anywhere; }
#library-status:empty { display: none; }
.button-group { display: flex; gap: 0.5rem; }
/* Help is "?" wherever the actions sit in a row, and the word "Help" in the phone drop-down menu */
.button-group .txt-long { display: none; }
.button-group .help-btn { padding-inline: 0.75rem; }
@media (max-width: 699px) {
    .button-group .txt-long { display: inline; }
    .button-group .txt-short { display: none; }
}

/* --- MOBILE BAR (shown below 1024px; see the mobile block below) --- */
.mobile-bar { display: none; }

/* --- ONE PANE AT A TIME, switched from the top bar (P2-05, D-009) ---
   Below 1024px two panes are too cramped to be useful (each would get under 512px), so phones AND portrait
   tablets show one pane with a Write | Preview switch. Landscape tablets (1024px+) keep the split.
   Landscape phones count too: a keyboard leaves them too little height for two panes.
   Mirrored by MOBILE_QUERY in the script. The screenplay's own responsiveness is not here: it follows the
   width of the preview column via @container above. */
@media (max-width: 1023px), (pointer: coarse) and (max-height: 500px) {
    body {
        --bar-h: 52px;
        flex-direction: column;
        padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    }
    body.kb-open { padding-bottom: 0; }

    .mobile-bar {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        flex: 0 0 var(--bar-h);
        height: var(--bar-h);
        padding: 0 0.75rem;
        border-bottom: 1px solid var(--border-void);
        background-color: var(--bg-void);
    }
    .seg {
        flex: 1;
        display: flex;
        gap: 3px;
        padding: 3px;
        background-color: var(--btn-bg);
        border-radius: 0.5rem;
    }
    .seg button {
        flex: 1;
        min-height: 40px;
        border: none;
        border-radius: 0.375rem;
        background: transparent;
        color: var(--text-void-muted);
        font: 600 0.9rem var(--font-ui);
        cursor: pointer;
    }
    .seg button[aria-pressed="true"] { background-color: var(--btn-hover); color: #f8fafc; }
    .menu-btn { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; }

    /* Only the selected pane is shown, and it fills whatever height the viewport has left */
    .pane-void, .pane-canvas { flex: 1; height: auto; min-height: 0; border: 0; }
    .pane-canvas { display: none; }
    body[data-view="preview"] .pane-canvas { display: flex; }
    /* While previewing, the Void's box goes away but its menu (a fixed-position child) must stay reachable */
    body[data-view="preview"] .pane-void { display: contents; }
    body[data-view="preview"] .pane-void textarea,
    body[data-view="preview"] .element-bar { display: none; }

    .pane-canvas > .header { display: none; }

    /* The Void's header disappears; its action buttons become a drop-down menu under the top bar */
    .pane-void > .header { display: contents; }
    .pane-void > .header > div:first-child { display: none; }
    .pane-void > .header .button-group {
        display: none;
        position: fixed;
        z-index: 40;
        top: calc(var(--bar-h) + env(safe-area-inset-top));
        right: calc(0.75rem + env(safe-area-inset-right));
        flex-direction: column;
        min-width: 11rem;
        padding: 0.25rem;
        background-color: var(--bg-void);
        border: 1px solid var(--border-void);
        border-radius: 0.5rem;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    }
    body.menu-open .pane-void > .header .button-group { display: flex; }
    .button-group .btn { min-height: 44px; text-align: left; }

    textarea { padding: 1rem; font-size: 16px; }

    #render-target { padding: 1rem; overscroll-behavior: contain; }

    .modal-close { min-width: 44px; min-height: 44px; }
}

/* --- TABLET TIER of the one-pane layout (700px and up) ---
   There is room for the actions in the bar itself, so no menu. The editor's text keeps a readable line
   length instead of stretching across the screen, and the preview is a full-size page. */
@media (min-width: 700px) and (max-width: 1023px), (min-width: 700px) and (pointer: coarse) and (max-height: 500px) {
    .menu-btn { display: none; }
    .seg { flex: 0 1 16rem; }
    .mobile-bar { padding: 0 1rem; }
    .pane-void > .header .button-group {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
        top: env(safe-area-inset-top);
        right: calc(1rem + env(safe-area-inset-right));
        height: var(--bar-h);
        min-width: 0;
        padding: 0;
        background: none;
        border: 0;
        box-shadow: none;
    }
    .button-group .btn { min-height: 40px; padding: 0 0.75rem; text-align: center; }

    /* Full-width box (the whole screen stays tappable) with the text held to ~44rem in the middle */
    textarea { padding-inline: max(1.5rem, calc((100vw - 44rem) / 2)); padding-block: 1.5rem; }
    #render-target { padding: 2rem; }
}

/* --- Import: the drop target while a file is dragged over the page, and the message afterwards --- */
.drop-hint {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 17, 21, 0.85);
    border: 3px dashed #94a3b8;
    color: #f8fafc;
    font: 600 1.25rem var(--font-ui);
    pointer-events: none;
}
.drop-hint[hidden] { display: none; }
.notice {
    position: fixed;
    left: 50%;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 60;
    width: max-content;
    max-width: calc(100vw - 2rem);
    padding: 0.6rem 1rem;
    border: 1px solid var(--border-void);
    border-radius: 0.5rem;
    background: #161a21;
    color: var(--btn-text);
    font: 0.875rem/1.5 var(--font-ui);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
    overflow-wrap: anywhere;
}
.notice.error { border-color: #b91c1c; }
.notice:empty { display: none; }