Something went wrong. Try again.
A free, open-source, self-hosted place to write a novel.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366<script lang="ts"> import { SvelteSet } from 'svelte/reactivity'; import { enhance, type SubmitFunction } from '$app/forms'; import { resolve } from '$app/paths'; import { retainForm } from '#lib/retain-form.ts'; import { clearToLeave } from '#lib/leave-guard.ts'; import { countWords } from '#lib/words.ts'; import NoteEditor from '#lib/components/NoteEditor.svelte'; import Swatch from '#lib/components/Swatch.svelte'; import type { SceneNoteLink } from '#lib/server/links.ts'; import type { NoteCard, NoteImage } from '#lib/server/notes.ts'; import type { NoteType } from '#lib/server/note-types.ts';
/** * Story notes beside the draft. The list is the spine and the open note shares * its column, so planning never pushes the prose off the screen. * * Notes group by type rather than folder, because "who is this person" is a * type, not a place. * * Delete is a soft delete, so Recovery trash brings the note back. */ let { projectId, notes, types, selectedId, noteScenes, preserveOriginals = true, onset, onscene, onclose }: { projectId: string; notes: NoteCard[]; types: NoteType[]; selectedId: string | null; /** Every scene-to-note link in the project; the panel reads it in reverse. */ noteScenes: SceneNoteLink[]; preserveOriginals?: boolean; onset: (id: string | null) => void; onscene: (sceneId: string) => void; /** Set where the panel covers the prose, so the writer needs a way back. */ onclose?: () => void; } = $props();
let creating = $state(false); let newTitle = $state(''); let newType = $state(''); let createdNoteId = $state('');
/* Per-note controls. They reset when the panel opens another note. */ let renaming = $state(false); let draftTitle = $state(''); let confirmingDelete = $state(false); let noteError = $state<string | null>(null); const collapsedGroups = new SvelteSet<string>(); const createForm = retainForm({ message: (message) => (noteError = message), saved: (result) => { if (result.type === 'success' && typeof result.data?.id === 'string') createdNoteId = result.data.id; }, accepted: () => { creating = false; newTitle = ''; createdNoteId = ''; } });
type NoteRequestState = { pending: boolean; error: string | null };
let noteImages = $state<Record<string, NoteImage | null>>({}); let keepOriginal = $state(true); let imageDragging = $state(false); let imageRequests = $state<Record<string, NoteRequestState>>({}); const uploadingImage = $derived(selectedId ? imageRequests[selectedId]?.pending === true : false); const imageError = $derived(selectedId ? imageRequests[selectedId]?.error : null); let templateRequests = $state<Record<string, NoteRequestState>>({}); const applyingTemplate = $derived( selectedId ? templateRequests[selectedId]?.pending === true : false ); const templateError = $derived(selectedId ? templateRequests[selectedId]?.error : null); let selectionGeneration = 0; let imageSelection: string | null | undefined; $effect(() => { if (imageSelection === selectedId) return; imageSelection = selectedId; selectionGeneration += 1; replacing = false; confirmingRemove = false; keepOriginal = true; imageDragging = false; }); let replacing = $state(false); let confirmingRemove = $state(false);
let imageFileInput: HTMLInputElement | undefined = $state(); let replaceFileInput: HTMLInputElement | undefined = $state();
/* * Bumped when a template fills the open note. The editor is keyed on it as well * as the note id, because the editor mounted on the empty body and must rebuild * around the template's words. */ let editorEpoch = $state(0); let noteEditor: ReturnType<typeof NoteEditor> | undefined = $state();
const selected = $derived(notes.find((note) => note.id === selectedId) ?? null);
const currentImage = $derived.by(() => { if (!selected) return null; if (Object.hasOwn(noteImages, selected.id)) { return noteImages[selected.id]; } return selected.image; });
const selectedType = $derived( selected ? (types.find((type) => type.id === selected.typeId) ?? null) : null );
const scenesForNote = $derived( selected ? noteScenes.filter((link) => link.noteId === selected.id) : [] );
/** * A note with no type, or one whose type row has gone, still needs a group. * Without it the note sits in the data and never renders, so it cannot be * renamed, reclassified, or deleted. */ const grouped = $derived.by(() => { const known = new Set(types.map((type) => type.id)); const groups = types .map((type) => ({ type, items: notes.filter((note) => note.typeId === type.id) })) .filter((group) => group.items.length > 0); const unfiled = notes.filter((note) => note.typeId === null || !known.has(note.typeId));
if (unfiled.length > 0) { groups.push({ type: { id: 'unfiled', name: 'Unfiled', pluralName: 'Unfiled', accent: 'blue-screen', revision: 0, hasTemplate: false }, items: unfiled }); }
return groups; });
/* * The newest words this panel saved for each note, by id. Page data is read * once at load: without this, a note reopened after an edit mounts on its old * revision and its first save conflicts with the earlier one. */ let latest = $state.raw<Record<string, { body: unknown; text: string; revision: number }>>({});
const fresh = $derived.by(() => { const mine = selected ? latest[selected.id] : undefined;
return selected && mine && mine.revision > selected.revision ? mine : null; });
const noteIsEmpty = $derived( selected ? (fresh?.text ?? selected.bodyText).trim().length === 0 : false );
/** * The workspace does not render form failures, and a silently ignored rename * reads as a broken button, so each note action reports its own refusal. */ const afterAction = (onSuccess?: () => void): SubmitFunction => () => async ({ result, update }) => { if (result.type === 'failure') { const message = (result.data as { message?: string } | undefined)?.message; noteError = message ?? 'That did not work.'; } else { noteError = null; onSuccess?.(); }
await update(); };
/** A select applies at once, so a change submits the form. */ function applyType(event: Event & { currentTarget: HTMLSelectElement }) { event.currentTarget.form?.requestSubmit(); }
/** * The server only applies a template to an empty note. The panel offers the * button on the same condition, so it never promises something the save * refuses. * * The target note id is captured on submit so a delayed response updates only * that note's cache and remounts only if that same note's editor is still * mounted, clean, and empty. */ const applyTemplate: SubmitFunction = ({ formData, cancel }) => { const id = String(formData.get('id') ?? '') || selectedId; if (!id || templateRequests[id]?.pending) { cancel(); return; }
templateRequests[id] = { pending: true, error: null };
return async ({ result, update }) => { try { if (result.type === 'failure') { const message = (result.data as { message?: string } | undefined)?.message; templateRequests[id] = { pending: false, error: message ?? 'The template was not applied.' }; await update({ reset: false }); return; }
if (result.type === 'error') { templateRequests[id] = { pending: false, error: 'The template was not applied.' }; return; }
templateRequests[id] = { pending: false, error: null };
if (result.type === 'success') { const applied = result.data as { body?: unknown; bodyText?: string; revision?: number } | undefined;
if (applied?.body !== undefined) { const nextRevision = applied.revision ?? 0; const cached = latest[id]; if (!cached || nextRevision > cached.revision) { latest = { ...latest, [id]: { body: applied.body, text: applied.bodyText ?? '', revision: nextRevision } }; }
if (selectedId === id && noteEditor?.canReplaceWithTemplate(id)) { editorEpoch += 1; } } }
await update({ reset: false }); } finally { if (templateRequests[id]?.pending) { templateRequests[id] = { pending: false, error: templateRequests[id]?.error ?? null }; } } }; };
function startRename() { if (!selected) return;
// A half-confirmed delete has no business sitting under a rename form. confirmingDelete = false; draftTitle = selected.title; renaming = true; }
function openNote(id: string | null) { creating = false; createdNoteId = ''; renaming = false; confirmingDelete = false; replacing = false; confirmingRemove = false; keepOriginal = true; noteError = null; onset(id); }
/** Back to the list removes the note editor, so its unconfirmed words are settled first. */ async function leaveNote() { if (await clearToLeave('note:')) openNote(null); }
async function handleImageFile(file: File) { if (!selected || uploadingImage) return; const id = selected.id; const generation = selectionGeneration; imageRequests[id] = { pending: true, error: null };
const form = new FormData(); form.set('file', file); if (preserveOriginals && keepOriginal) { form.set('preserveOriginal', 'on'); }
try { const res = await fetch(`/api/notes/${id}/image`, { method: 'POST', body: form }); const body = await res.json(); if (!res.ok) { imageRequests[id].error = body.message ?? 'The image was not uploaded.'; return; } noteImages[id] = { noteId: id, imageId: body.image.imageId, mime: body.image.mime, bytes: body.image.bytes, width: body.image.width, height: body.image.height, alt: body.image.alt ?? '', originalName: body.image.originalName ?? '', createdAt: new Date() }; if (selectedId === id && generation === selectionGeneration) replacing = false; } catch { imageRequests[id].error = 'The image was not uploaded.'; } finally { imageRequests[id].pending = false; } }
async function executeRemoveImage() { if (!selected || uploadingImage) return; const id = selected.id; const generation = selectionGeneration; imageRequests[id] = { pending: true, error: null }; try { const res = await fetch(`/api/notes/${id}/image`, { method: 'DELETE' }); if (res.ok) { noteImages[id] = null; if (selectedId === id && generation === selectionGeneration) { confirmingRemove = false; replacing = false; } } else { const body = await res.json(); imageRequests[id].error = body.message ?? 'The image was not removed.'; } } catch { imageRequests[id].error = 'The image was not removed.'; } finally { imageRequests[id].pending = false; } }</script>
<aside class="notes-panel" class:selected aria-label="Story notes"> {#if selected} <div class="note-head"> <div class="note-actions"> <button class="btn btn-sm btn-ghost" type="button" onclick={leaveNote}>← All</button> {#if !renaming} <button class="btn btn-sm btn-ghost" type="button" onclick={startRename}>Rename</button> {/if} <!-- eslint-disable svelte/no-navigation-without-resolve --> <a class="btn btn-sm btn-ghost" href={`${resolve('/p/[id]/recovery', { id: projectId })}?tab=history&kind=note&item=${selected.id}`} >Note versions</a > <!-- eslint-enable svelte/no-navigation-without-resolve --> </div>
<div class="note-image-head"> {#if currentImage} {#if currentImage.imageId === null} <div class="image-missing"> <p>This note names an image the instance does not have.</p> </div> {:else} {@const isPreserved = currentImage.bytes > 0}
{#if isPreserved} <a class="image-band" href={`${resolve('/api/projects/[id]/images/[image]', { id: projectId, image: currentImage.imageId })}?original=1`} target="_blank" rel="noopener noreferrer external" aria-label={`Open the image for ${selected.title} at full size`} > <img src={resolve('/api/projects/[id]/images/[image]', { id: projectId, image: currentImage.imageId })} alt={currentImage.alt} width={currentImage.width || undefined} height={currentImage.height || undefined} decoding="async" loading="lazy" class="image-media" /> </a> {:else} <div class="image-band"> <img src={resolve('/api/projects/[id]/images/[image]', { id: projectId, image: currentImage.imageId })} alt={currentImage.alt} width={currentImage.width || undefined} height={currentImage.height || undefined} decoding="async" loading="lazy" class="image-media" /> </div> {/if}
{#if currentImage.mime === 'image/gif'} <p class="image-hint"> An animated GIF flattens to its first frame in the display copy. The original keeps every frame. </p> {/if}
<form class="image-alt-form" method="POST" action="?/noteImageAlt" use:enhance={afterAction()} > <input type="hidden" name="id" value={selected.id} /> <label class="field-label" for="note-image-alt">Description</label> <input id="note-image-alt" class="field" type="text" name="alt" value={currentImage.alt} placeholder="Describe this image for screen readers" onchange={(e) => { if (currentImage) { noteImages[selected.id] = { ...currentImage, alt: e.currentTarget.value }; } e.currentTarget.form?.requestSubmit(); }} /> </form>
{#if replacing} <div class="image-prompt-box"> <p class="image-prompt-notice"> Replace this image? The previous image is not kept in history. </p> <input bind:this={replaceFileInput} tabindex="-1" class="sr-only" type="file" accept="image/png,image/jpeg,image/webp,image/avif,image/gif" onchange={(e) => { const file = e.currentTarget.files?.[0]; if (file) handleImageFile(file); e.currentTarget.value = ''; }} /> <div class="image-prompt-actions"> <button class="btn btn-sm" type="button" disabled={uploadingImage} onclick={() => replaceFileInput?.click()} > Choose replacement image </button> <button class="btn btn-sm btn-ghost" type="button" onclick={() => (replacing = false)} > Keep current </button> </div> </div> {:else if confirmingRemove} <div class="image-prompt-box"> <p class="image-prompt-notice"> Remove this image? The previous image is not kept in history. </p> <div class="image-prompt-actions"> <button class="btn btn-sm btn-danger" type="button" disabled={uploadingImage} onclick={executeRemoveImage} > Remove </button> <button class="btn btn-sm btn-ghost" type="button" onclick={() => (confirmingRemove = false)} > Keep </button> </div> </div> {:else} <div class="image-actions"> <button class="btn btn-sm btn-ghost" type="button" onclick={() => { confirmingRemove = false; replacing = true; }} > Replace </button> <button class="btn btn-sm btn-ghost" type="button" onclick={() => { replacing = false; confirmingRemove = true; }} > Remove </button> </div> {/if} {/if} {:else} <div class="image-drop-area"> <!-- svelte-ignore a11y_no_static_element_interactions --> <div class="drop image-drop-well" class:dragging={imageDragging} ondragover={(e) => { e.preventDefault(); imageDragging = true; }} ondragleave={() => (imageDragging = false)} ondrop={(e) => { e.preventDefault(); imageDragging = false; const file = e.dataTransfer?.files?.[0]; if (file) handleImageFile(file); }} > <input bind:this={imageFileInput} tabindex="-1" class="sr-only" type="file" accept="image/png,image/jpeg,image/webp,image/avif,image/gif" onchange={(e) => { const file = e.currentTarget.files?.[0]; if (file) handleImageFile(file); e.currentTarget.value = ''; }} /> {#if uploadingImage} <p class="drop-words">Preparing image…</p> {:else} <p class="drop-words">Drop an image here, or</p> <button class="btn btn-sm btn-ghost" type="button" onclick={() => imageFileInput?.click()} > Choose an image </button> {/if} </div>
{#if preserveOriginals} <label class="toggle-row image-preserve-toggle" for="preserve-original-{selected.id}"> <input class="check" id="preserve-original-{selected.id}" type="checkbox" bind:checked={keepOriginal} /> <span> <span class="toggle-title">Keep the full-size original</span> <span class="toggle-hint"> The file exactly as it arrived. A 6 MB photo is about 400 KB once prepared. </span> </span> </label> {/if} </div> {/if}
{#if imageError} <p class="note-error" role="alert">{imageError}</p> {/if} </div>
{#if renaming} <form class="rename" method="POST" action="?/noteRename" use:enhance={afterAction(() => (renaming = false))} > <input type="hidden" name="id" value={selected.id} /> <input class="field" name="title" type="text" bind:value={draftTitle} aria-label="Note title" required /> <div class="rename-acts"> <button class="btn btn-sm" type="submit">Save name</button> <button class="btn btn-sm btn-ghost" type="button" onclick={() => (renaming = false)}> Cancel </button> </div> </form> {:else} <div class="note-title"> <h2>{selected.title}</h2>
<!-- A type is one selection, so it applies as soon as it is picked. Keeping the form keeps the post and its guard the one path reclassification takes. --> <form class="type-pick" method="POST" action="?/noteType" use:enhance={afterAction()}> <input type="hidden" name="id" value={selected.id} /> <label class="type-label" for="note-type">Type</label> <Swatch accent={selected.accent} size={8} /> <select id="note-type" class="field type-select" name="typeId" value={selected.typeId ?? ''} onchange={applyType} > {#each types as type (type.id)} <option value={type.id}>{type.name}</option> {/each} <option value="">Unfiled</option> </select> </form> </div> {/if}
{#if !renaming && selectedType?.hasTemplate && noteIsEmpty} <div class="template-offer"> <p>{selectedType.name} starts from a template.</p> <form method="POST" action="?/applyTemplate" use:enhance={applyTemplate}> <input type="hidden" name="id" value={selected.id} /> <button class="btn btn-sm" type="submit" disabled={applyingTemplate} >Use template</button > </form> </div> {/if}
{#if templateError} <p class="note-error" role="alert">{templateError}</p> {/if}
{#if noteError} <p class="note-error" role="alert">{noteError}</p> {/if}
{#if !renaming} <div class="note-danger"> {#if confirmingDelete} <p class="danger-question">Delete “{selected.title}”? Recovery can restore it.</p> <form class="danger-acts" method="POST" action="?/noteRemove" use:enhance={afterAction(() => { confirmingDelete = false; openNote(null); })} > <input type="hidden" name="id" value={selected.id} /> <button class="btn btn-sm btn-danger" type="submit">Delete</button> <button class="btn btn-sm btn-ghost" type="button" onclick={() => (confirmingDelete = false)}>Keep</button > </form> {:else} <button class="btn btn-sm btn-ghost" type="button" onclick={() => (confirmingDelete = true)}>Delete note</button > {/if} </div> {/if} </div>
<div class="note-editor"> {#key `${selected.id}:${editorEpoch}`} <NoteEditor bind:this={noteEditor} noteId={selected.id} title={selected.title} initialBody={fresh ? fresh.body : selected.body} initialWords={countWords(fresh ? fresh.text : selected.bodyText)} initialRevision={fresh ? fresh.revision : selected.revision} onsaved={(saved) => { latest = { ...latest, [saved.id]: { body: saved.body, text: saved.text, revision: saved.revision } }; if (saved.text.trim().length > 0 && templateRequests[saved.id]?.error) { templateRequests[saved.id] = { ...templateRequests[saved.id], error: null }; } }} /> {/key} </div>
<!-- The reverse of the scene inspector's list. It sits below the words, so a note in a dozen scenes does not push its body off the screen. --> <section class="note-scenes" aria-labelledby="note-scenes-title"> <h3 class="group-head" id="note-scenes-title"> In scenes <span class="tnum group-count">{scenesForNote.length}</span> </h3> {#if scenesForNote.length === 0} <p class="scenes-empty">Not linked to a scene yet. Link it from the scene inspector.</p> {:else} <ul class="scene-list"> {#each scenesForNote as link (link.sceneId)} <li> <button class="scene-open" type="button" onclick={() => onscene(link.sceneId)}> {link.sceneTitle} <span class="scene-chapter">{link.chapterTitle} · {link.status}</span> </button> </li> {/each} </ul> {/if} </section> {:else} <div class="list-head"> <h2 class="label">Story notes</h2> <div class="list-acts"> {#if !creating} <a class="btn btn-sm btn-ghost" href={resolve('/p/[id]/types', { id: projectId })} aria-label="Manage note types">Types</a > <button class="btn btn-sm btn-ghost" type="button" onclick={() => { newType ||= types[0]?.id ?? ''; creating = true; }} > Add </button> {/if} {#if onclose} <button type="button" class="close tap-area" onclick={onclose} aria-label="Close story notes" > × </button> {/if} </div> </div>
{#if noteError} <p class="note-error" role="alert">{noteError}</p> {/if} {#if creating} <form class="new" method="POST" action={createdNoteId ? '?/noteDraft' : '?/note'} use:enhance={createForm} > <input type="hidden" name="id" value={createdNoteId} /> <input class="field" name="title" type="text" bind:value={newTitle} placeholder="Maren Hale" aria-label="Note title" required /> <select class="field" name="typeId" bind:value={newType} aria-label="Note type"> {#each types as type (type.id)} <option value={type.id}>{type.name}</option> {/each} </select> <div class="new-acts"> <button class="btn btn-sm" type="submit" >{createdNoteId ? 'Save note' : 'Add note'}</button > <button class="btn btn-sm btn-ghost" type="button" onclick={() => { creating = false; createdNoteId = ''; }} > Cancel </button> </div> </form> {/if}
<div class="list"> {#if notes.length === 0} <p class="empty"> No notes yet. Characters, places, and objects you want beside the draft go here. </p> {:else} {#each grouped as group (group.type.id)} {@const collapsed = collapsedGroups.has(group.type.id)} <section class="group"> <h3 class="group-head"> <button class="group-toggle" type="button" aria-expanded={!collapsed} onclick={() => { if (collapsedGroups.has(group.type.id)) collapsedGroups.delete(group.type.id); else collapsedGroups.add(group.type.id); }} > <Swatch accent={group.type.accent} size={8} /> <span>{group.type.pluralName}</span> <span class="tnum group-count">{group.items.length}</span> </button> </h3> {#if !collapsed} {#each group.items as note (note.id)} <button class="note-item" type="button" onclick={() => openNote(note.id)}> <span class="note-name">{note.title}</span> {#if note.summary} <span class="note-summary">{note.summary}</span> {/if} </button> {/each} {/if} </section> {/each} {/if} </div> {/if}</aside>
<style> /* The name `panel` belongs to the card in components.css, which would draw a rounded box with four walls. A board needs one wall, on its inner edge. */ .notes-panel { display: flex; flex-direction: column; min-height: 0; height: 100%; background: var(--dr-surface-secondary); border-left: 2px solid var(--dr-border-color-container); }
.notes-panel.selected { overflow-y: auto; overscroll-behavior-y: contain; }
.note-editor { display: flex; flex-direction: column; flex: 1 0 16rem; min-height: 16rem; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: var(--dr-space-sm); padding: var(--dr-space-md) var(--dr-space-md) 0.75rem; border-bottom: 1px solid var(--dr-border-color-container); flex: none; }
.list-head h2 { margin: 0; color: var(--dr-heading); }
.list-acts { display: flex; align-items: center; gap: var(--dr-space-sm); }
/* * The panel covers the draft on a phone, so its way back rides in the head at * both widths, beside the keys the head already carries. */ .close { border: 1px solid transparent; border-radius: var(--dr-radius-sm); background: transparent; color: var(--dr-text-secondary); font-size: var(--dr-text-lg); line-height: 1; cursor: pointer; padding: 0 0.25rem; }
.close:hover { background: var(--dr-surface-highlight); color: var(--dr-text-primary); }
.close:focus-visible { outline: var(--dr-focus-ring); outline-offset: 1px; }
/* * The offer sits under the title, before the words, because it is about the * note as a whole and not about anything inside the body. */ .template-offer { display: flex; align-items: center; justify-content: space-between; gap: var(--dr-space-sm); margin: 0 var(--dr-space-md) var(--dr-space-sm); padding: var(--dr-space-sm) var(--dr-space-md); border: 1px solid var(--dr-border-color-container); background: var(--dr-surface-elevated); }
.template-offer p { margin: 0; color: var(--dr-text-muted); }
.new { display: flex; flex-direction: column; gap: var(--dr-space-sm); padding: var(--dr-space-md); border-bottom: 1px solid var(--dr-border-color-container); }
.new-acts { display: flex; gap: var(--dr-space-sm); }
.list { overflow-y: auto; padding-bottom: var(--dr-space-lg); min-height: 0; }
.group { padding-top: var(--dr-space-sm); }
.group-head { display: flex; align-items: center; gap: 0.4375rem; margin: 0; padding: var(--dr-space-sm) var(--dr-space-md) 0.375rem; font-family: var(--dr-font-heading); font-weight: 600; font-size: var(--fw-text-2xs); letter-spacing: 0.12em; text-transform: uppercase; color: var(--dr-heading-sub); }
.group-head:has(.group-toggle) { display: block; padding: 0; }
.group-toggle { display: flex; align-items: center; gap: 0.4375rem; width: 100%; padding: var(--dr-space-sm) var(--dr-space-md) 0.375rem; border: 0; background: transparent; font: inherit; letter-spacing: inherit; text-transform: inherit; color: inherit; text-align: left; cursor: pointer; }
.group-toggle:hover { color: var(--dr-text-primary); }
.group-toggle:focus-visible { outline: var(--dr-focus-ring); outline-offset: -2px; }
.group-count { margin-left: auto; color: var(--dr-text-muted); }
.note-item { display: flex; flex-direction: column; gap: 0.1875rem; width: 100%; padding: 0.5rem var(--dr-space-md); border: 0; background: transparent; text-align: left; cursor: pointer; color: var(--dr-text-secondary); transition: background-color var(--dr-transition-fast); }
.note-item:hover { background: var(--dr-surface-highlight); color: var(--dr-text-primary); }
.note-name { font-size: var(--dr-text-sm); }
/* Two lines, then an ellipsis: enough to recognise the note, and short enough that the list stays scannable. */ .note-summary { font-size: var(--dr-text-xs); line-height: 1.4; color: var(--dr-text-muted); display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty { margin: 0; padding: var(--dr-space-lg) var(--dr-space-md); font-size: var(--dr-text-sm); line-height: 1.5; color: var(--dr-text-muted); }
.note-head { display: flex; flex-direction: column; gap: var(--dr-space-sm); padding: var(--dr-space-md); border-bottom: 1px solid var(--dr-border-color-container); flex: none; }
.note-actions { display: flex; flex-wrap: wrap; gap: var(--dr-space-sm); align-items: center; }
.note-title h2 { margin: 0.125rem 0 0; font-family: var(--dr-font-body); font-weight: 500; font-size: var(--dr-text-lg); color: var(--dr-text-primary); overflow-wrap: anywhere; }
/* The type switch is a control, not a label, so it wears the field border and keeps the swatch beside it as the mark the list groups by. */ .type-pick { display: flex; align-items: center; flex-wrap: wrap; gap: 0.375rem; margin-top: var(--dr-space-sm); }
.type-label { font-family: var(--dr-font-heading); font-size: var(--fw-text-2xs); letter-spacing: 0.12em; text-transform: uppercase; color: var(--dr-heading-sub); }
.type-select { /* A field is a full-width well. This one is a single word in a row. */ width: auto; max-width: 12rem; padding: 0.2rem 0.4rem; font-size: var(--dr-text-xs); }
.rename { display: flex; flex-direction: column; align-items: flex-start; gap: var(--dr-space-sm); }
.rename .field { width: 100%; }
.rename-acts, .danger-acts { display: flex; flex-wrap: wrap; gap: var(--dr-space-sm); }
.note-error { margin: 0; font-size: var(--dr-text-xs); line-height: 1.4; color: var(--dr-danger-text, var(--dr-text-primary)); }
/* * Deleting a note sits at the bottom of its own header, quiet until it is asked * for. The warm accent is rationed to unsaved words, the one primary action and * the current place. This is a ghost button that only turns into a danger button * after the writer confirms. */ .note-danger { display: flex; flex-direction: column; align-items: flex-start; gap: var(--dr-space-sm); padding-top: var(--dr-space-xs); border-top: 1px solid var(--dr-border-color-container); }
.danger-question { margin: 0; font-size: var(--dr-text-xs); line-height: 1.4; color: var(--dr-text-secondary); }
/* * The reverse list. It is capped and scrolls, because a character in thirty * scenes must not take the note's own words off the screen. */ .note-scenes { display: flex; flex-direction: column; gap: 0.25rem; flex: none; max-height: 11rem; overflow-y: auto; padding: var(--dr-space-sm) var(--dr-space-md) var(--dr-space-md); border-top: 1px solid var(--dr-border-color-container); background: var(--dr-surface-secondary); }
.scenes-empty { margin: 0; font-size: var(--dr-text-xs); line-height: 1.4; color: var(--dr-text-muted); }
.scene-list { display: flex; flex-direction: column; gap: 1px; margin: 0; padding: 0; list-style: none; }
.scene-open { display: flex; flex-direction: column; align-items: flex-start; gap: 0.0625rem; width: 100%; padding: 0.25rem 0; border: 0; background: transparent; text-align: left; font-size: var(--dr-text-sm); color: var(--dr-text-primary); cursor: pointer; }
.scene-open:hover { color: var(--dr-accent-hover); }
.scene-open:focus-visible { outline: var(--dr-focus-ring); outline-offset: 2px; }
.scene-chapter { font-family: var(--dr-font-heading); font-size: var(--fw-text-2xs); letter-spacing: 0.1em; text-transform: uppercase; color: var(--dr-text-muted); }
@media (pointer: coarse) { .scene-open { min-height: 44px; justify-content: center; } }
.notes-panel :global(.ProseMirror) { padding: var(--dr-space-md); font-size: var(--dr-text-sm); }
.note-image-head { margin-bottom: var(--dr-space-md); }
.image-band { display: block; width: 100%; aspect-ratio: 3 / 2; border: 1px solid var(--dr-border-color-container); border-radius: var(--dr-radius); box-shadow: var(--dr-shadow-inner-lowlight); overflow: hidden; background: var(--dr-surface-base); margin-bottom: var(--dr-space-sm); text-decoration: none; }
.image-media { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-missing { padding: var(--dr-space-sm) var(--dr-space-md); border: 2px solid var(--dr-border-color-container); border-radius: 4px; background: var(--dr-surface-base); color: var(--dr-text-muted); font-size: var(--dr-text-sm); margin-bottom: var(--dr-space-sm); }
.image-missing p { margin: 0; }
.image-hint { margin: 0 0 var(--dr-space-xs); font-size: var(--dr-text-xs); color: var(--dr-text-muted); }
.image-alt-form { margin-bottom: var(--dr-space-sm); }
.image-actions { display: flex; gap: var(--dr-space-sm); margin-bottom: var(--dr-space-sm); }
.image-prompt-box { padding: var(--dr-space-sm) var(--dr-space-md); border: 1px solid var(--dr-border-color-container); border-radius: var(--dr-radius); background: var(--dr-surface-base); margin-bottom: var(--dr-space-sm); }
.image-prompt-notice { margin: 0 0 var(--dr-space-xs); font-size: var(--dr-text-xs); color: var(--dr-text-muted); }
.image-prompt-actions { display: flex; flex-wrap: wrap; gap: var(--dr-space-sm); }
.image-drop-area { margin-bottom: var(--dr-space-sm); }
.image-drop-well { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--dr-space-sm); min-height: 4.5rem; padding: var(--dr-space-sm) var(--dr-space-md); border: 2px dashed var(--dr-border-color); border-radius: var(--dr-radius); background: var(--dr-surface-base); box-shadow: var(--dr-shadow-inner-lowlight); transition: border-color var(--dr-transition-fast), background-color var(--dr-transition-fast); }
.image-drop-well.dragging { border-color: var(--dr-border-color-warm); background: var(--dr-surface-highlight); }
.image-preserve-toggle { display: flex; gap: 0.625rem; align-items: flex-start; margin-top: var(--dr-space-xs); font-size: var(--dr-text-sm); }</style>