/* Reflections: stylesheet
 *
 * A self-contained design system, written for this app rather than inherited
 * from a framework. Bootstrap's stylesheet is no longer loaded at all: the
 * handful of its classes the markup uses (btn, form-control, progress and
 * visually-hidden) are implemented here, so the interface speaks one visual
 * language instead of a framework's defaults with patches on top.
 *
 * Contents:
 *   1. Design tokens, light then dark
 *   2. Reset and typography
 *   3. Layout shell: header, navigation, menus
 *   4. Controls: buttons, forms, progress, messages
 *   5. The writing view: model tabs, sections, starters, editor, sidebar
 *   6. The library and the reading view
 *   7. Empty states and dialogs
 *   8. Small screens
 *   9. Print, which is a first-class view rather than a stripped screen
 *
 * Bootstrap Icons is still loaded, purely for glyphs; it carries no layout.
 */

/* ============================================================ 1. Tokens === */

:root {
    /* Surfaces: warm paper rather than the usual cold grey */
    --paper: #faf9f7;
    --surface: #ffffff;
    --surface-sunken: #f2f0ec;
    --surface-hover: #f7f5f1;
    --header-bg: rgba(250, 249, 247, .85);

    /* Ink, named by role so contrast can be reasoned about */
    --ink: #15171c;
    --ink-secondary: #4c525c;
    --ink-muted: #5f6772;
    --line: #e6e2da;
    --line-strong: #d0cabe;

    /* One accent, used sparingly */
    --accent: #4b3ae0;
    --accent-strong: #3b2cc4;
    --accent-tint: #eeebff;
    --accent-contrast: #ffffff;
    --accent-ring: rgba(75, 58, 224, .22);

    /* Status colours, all readable as text on --paper */
    --success: #17734a;
    --danger: #b23a2e;
    --danger-contrast: #ffffff;
    --warning: #7d5200;

    /* Shape and depth */
    --radius-sm: .15rem;
    --radius: .125rem;
    --radius-lg: .275rem;
    --radius-xl: .2rem;
    --shadow-overlay: 0 12px 32px -12px rgba(18, 20, 28, .28), 0 2px 6px rgba(18, 20, 28, .06);
    --shadow-raised: 0 1px 2px rgba(18, 20, 28, .06);
    --shadow-primary: 0 1px 2px rgba(28, 20, 90, .22);

    --font-sans: system-ui, -apple-system, 'Segoe UI Variable Text', 'Segoe UI', Roboto,
        'Helvetica Neue', Arial, sans-serif;
    --font-serif: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Times New Roman', serif;

    --app-width: 74rem;
    --header-height: 3.5rem;
}

html.dark-theme {
    --paper: #0f1115;
    --surface: #171a20;
    --surface-sunken: #1e222a;
    --surface-hover: #222732;
    --header-bg: rgba(15, 17, 21, .82);

    --ink: #eceff4;
    --ink-secondary: #aeb6c2;
    --ink-muted: #99a2b0;
    --line: #262b34;
    --line-strong: #3f4653;

    --accent: #a79bff;
    --accent-strong: #c3baff;
    --accent-tint: #221f3d;
    --accent-contrast: #14122b;
    --accent-ring: rgba(167, 155, 255, .28);

    --success: #5fce9b;
    --danger: #ff9c90;
    --danger-contrast: #2a0d09;
    --warning: #e4c169;

    --shadow-overlay: 0 16px 40px -16px rgba(0, 0, 0, .7), 0 2px 8px rgba(0, 0, 0, .4);
    --shadow-raised: none;
    --shadow-primary: none;
}

/* ================================================= 2. Reset and typography = */

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.6;
    color: var(--ink);
    background: var(--paper);
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
    margin: 0 0 .5em;
    line-height: 1.22;
    font-weight: 600;
    letter-spacing: -.015em;
}

p {
    margin: 0 0 1em;
}

a {
    color: var(--accent);
    text-decoration-color: var(--line-strong);
    text-underline-offset: 2px;
}

a:hover {
    color: var(--accent-strong);
    text-decoration-color: currentColor;
}

strong {
    font-weight: 650;
}

hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 1rem 0;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 100;
    padding: .6rem 1rem;
    border: 1px solid var(--accent);
    border-radius: 0 0 var(--radius) 0;
    background: var(--surface);
    color: var(--ink);
    font-size: .875rem;
}

.skip-link:focus {
    left: 0;
}

::selection {
    background: var(--accent-tint);
    color: var(--ink);
}

/* ==================================================== 3. Layout and shell = */

.app-main {
    max-width: var(--app-width);
    margin: 0 auto;
    padding: 1.75rem 1.25rem 6rem;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--header-bg);
    backdrop-filter: saturate(150%) blur(12px);
    -webkit-backdrop-filter: saturate(150%) blur(12px);
    border-bottom: 1px solid var(--line);
}

.app-navbar__inner {
    max-width: var(--app-width);
    margin: 0 auto;
    padding: 0 1.25rem;
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    color: var(--ink);
    font-size: .9375rem;
    font-weight: 600;
    letter-spacing: -.01em;
    text-decoration: none;
    white-space: nowrap;
}

/* The mark: a small gradient square, so the header has an identity of its own */
.app-brand::before {
    content: '';
    width: 1.6rem;
    height: 1.6rem;
    border-radius: var(--radius-sm);
    background: linear-gradient(145deg, var(--accent), var(--accent-strong));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .28);
}

.app-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.app-nav__link {
    position: relative;
    display: inline-block;
    padding: .35rem 0;
    color: var(--ink-secondary);
    font-size: .875rem;
    text-decoration: none;
}

.app-nav__link::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -.15rem;
    height: 2px;
    border-radius: 2px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform .18s ease;
}

.app-nav__link:hover {
    color: var(--ink);
}

.app-nav__link:hover::after,
.app-nav__link.is-active::after {
    transform: scaleX(1);
}

.app-nav__link.is-active {
    color: var(--ink);
    font-weight: 600;
}

.app-navbar__actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .5rem;
}

/* The library link and the desktop New reflection button give way to the
 * floating action button on small screens. */
@media (max-width: 991.98px) {
    .app-nav {
        display: none;
    }

    /* Data and Print keep their icons and drop their labels */
    .menu__label {
        display: none;
    }
}

@media (min-width: 992px) {
    #createBtn.fab {
        display: none !important;
    }
}

/* ========================================================== 4. Controls = */

/* Buttons: one shape, three weights, no gradients */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    height: 2.25rem;
    padding: 0 .9rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink);
    font-family: inherit;
    font-size: .84375rem;
    font-weight: 550;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.btn i {
    font-size: .95em;
}

.btn-sm {
    height: 1.9rem;
    padding: 0 .65rem;
    border-radius: var(--radius-sm);
    font-size: .78125rem;
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-contrast);
    box-shadow: var(--shadow-primary);
}

.btn-primary:hover {
    background: var(--accent-strong);
    color: var(--accent-contrast);
}

.btn-outline-secondary {
    border-color: var(--line-strong);
    background: var(--surface);
    color: var(--ink-secondary);
}

.btn-outline-secondary:hover {
    border-color: var(--line-strong);
    background: var(--surface-hover);
    color: var(--ink);
}

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

.btn-danger:hover {
    filter: brightness(1.06);
    color: var(--danger-contrast);
}

.btn:disabled,
.btn[disabled] {
    opacity: .55;
    cursor: not-allowed;
}

/* Forms */
.form-control,
.form-select {
    width: 100%;
    height: 2.4rem;
    padding: 0 .75rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: .875rem;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.form-control::placeholder {
    color: var(--ink-muted);
}

.form-control:focus,
.form-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.form-control-lg {
    height: 3rem;
    padding: 0 1rem;
    border-radius: var(--radius-lg);
    font-size: 1.0625rem;
    font-weight: 550;
    letter-spacing: -.01em;
}

.form-select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 2.1rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4.5 6 8.5l4-4' fill='none' stroke='%235f6772' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .7rem center;
    cursor: pointer;
}

html.dark-theme .form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4.5 6 8.5l4-4' fill='none' stroke='%2399a2b0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* Progress */
.progress {
    height: .4rem;
    border-radius: 999px;
    background: var(--surface-sunken);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    border-radius: 999px;
    background: var(--accent);
    transition: width .3s ease;
}

/* Menus */
.menu {
    position: relative;
}

.menu__list {
    position: absolute;
    right: 0;
    top: calc(100% + .5rem);
    z-index: 40;
    min-width: 20rem;
    padding: .4rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-overlay);
}

.menu__item {
    display: flex;
    gap: .65rem;
    width: 100%;
    padding: .55rem .6rem;
    border: 0;
    border-radius: var(--radius);
    background: none;
    color: var(--ink);
    font-family: inherit;
    font-size: .875rem;
    text-align: left;
    cursor: pointer;
    transition: background-color .12s ease;
}

.menu__item i {
    color: var(--accent);
    font-size: 1.05rem;
    line-height: 1.35;
}

.menu__item span {
    display: flex;
    flex-direction: column;
    gap: .1rem;
}

.menu__item small {
    color: var(--ink-muted);
    font-size: .75rem;
    line-height: 1.35;
}

.menu__item:hover,
.menu__item:focus-visible {
    background: var(--surface-hover);
}

.menu__item--danger i,
.menu__item--danger span {
    color: var(--danger);
}

.menu__divider {
    margin: .35rem .2rem;
    border: 0;
    border-top: 1px solid var(--line);
}

.menu__note {
    padding: .35rem .6rem .55rem;
    color: var(--ink-muted);
    font-size: .78125rem;
}

.menu__note p {
    margin: 0 0 .5rem;
}

/* Save indicator */
.save-status {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    min-height: 1.5rem;
    color: var(--ink-muted);
    font-size: .78125rem;
    white-space: nowrap;
}

.save-status.is-saving {
    color: var(--accent);
}

.save-status.is-saved {
    color: var(--success);
}

.save-status.is-error {
    color: var(--danger);
    font-weight: 600;
}

.save-status .pulse {
    width: .5rem;
    height: .5rem;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 1s infinite ease-in-out;
}

@keyframes pulse {
    0%, 100% { opacity: .3; }
    50% { opacity: 1; }
}

/* Floating action button, small screens only */
.fab {
    position: fixed;
    right: 1.1rem;
    bottom: 1.1rem;
    z-index: 25;
    width: 3.25rem;
    height: 3.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-contrast);
    font-size: 1.35rem;
    box-shadow: 0 8px 24px -8px rgba(28, 20, 90, .5);
}

.fab:hover {
    background: var(--accent-strong);
}

/* Messages */
.app-toast-root {
    position: fixed;
    left: 50%;
    bottom: 1.25rem;
    transform: translateX(-50%);
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    pointer-events: none;
}

.app-toast {
    max-width: min(32rem, calc(100vw - 2rem));
    padding: .6rem 1.1rem;
    border-radius: 999px;
    background: var(--ink);
    color: var(--paper);
    font-size: .84375rem;
    box-shadow: var(--shadow-overlay);
    pointer-events: none;
}

.app-toast--action {
    display: inline-flex;
    align-items: center;
    gap: .6rem;
    padding: .5rem .6rem .5rem 1.1rem;
    border-radius: var(--radius-lg);
    pointer-events: auto;
}

.app-toast--error {
    background: var(--danger);
    color: var(--danger-contrast);
}

html.dark-theme .app-toast {
    border: 1px solid var(--line);
    background: var(--surface-sunken);
    color: var(--ink);
}

html.dark-theme .app-toast--error {
    border-color: transparent;
    background: var(--danger);
    color: var(--danger-contrast);
}

.storage-warning {
    margin: 0;
    padding: .7rem 1.25rem;
    background: var(--danger);
    color: var(--danger-contrast);
    font-size: .875rem;
    text-align: center;
}

.notice {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1.5rem;
    padding: .9rem 1.1rem;
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: .875rem;
}

.notice__text {
    flex: 1 1 20rem;
    margin: 0;
}

/* Badges */
.model-badge {
    display: inline-block;
    padding: .1rem .5rem;
    border-radius: 999px;
    background: var(--accent-tint);
    color: var(--accent);
    font-size: .6875rem;
    font-weight: 650;
    letter-spacing: .02em;
}

.badge-soft {
    display: inline-block;
    padding: .1rem .5rem;
    border-radius: 999px;
    background: var(--surface-sunken);
    color: var(--ink-muted);
    font-size: .6875rem;
    font-weight: 550;
}

/* ===================================================== 5. Writing view = */

.page__head--editor {
    align-items: flex-start;
}

.page__head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.25rem;
    margin-bottom: 1.75rem;
}
.page__head>div {
    flex: 1;
}

.page__title {
    margin: 0 0 .3rem;
    font-size: 1.75rem;
    letter-spacing: -.02em;
}

.page__subtitle {
    margin: 0;
    color: var(--ink-muted);
    font-size: .90625rem;
}

.editor__title-field {
    flex: 1 1 26rem;
}

.editor__hint {
    margin: .5rem 0 0;
    color: var(--ink-muted);
    font-size: .8125rem;
}

.editor__head-actions {
    display: flex;
    gap: .5rem;
}

/* Model chooser: a segmented control, not a dropdown and not a row of pills */
.model-picker {
    min-width: 0;
    margin: 0 0 1.5rem;
    padding: 0;
    border: 0;
}

.model-picker__legend {
    margin-bottom: .6rem;
    padding: 0;
    color: var(--ink-muted);
    font-size: .6875rem;
    font-weight: 650;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.model-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
    padding: .3rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface-sunken);
}

.model-tab {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .5rem .8rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink-secondary);
    font-family: inherit;
    font-size: .84375rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease, box-shadow .15s ease;
}

.model-tab:hover {
    background: var(--surface);
    color: var(--ink);
}

.model-tab[aria-selected="true"] {
    border-color: var(--line);
    background: var(--surface);
    box-shadow: var(--shadow-raised);
    color: var(--ink);
    font-weight: 650;
}

.model-tab__dot {
    width: .4rem;
    height: .4rem;
    border-radius: 50%;
    background: var(--line-strong);
}

.model-tab__dot.is-started {
    background: var(--accent);
}

.model-picker__note {
    max-width: 80ch;
    margin: .7rem 0 0;
    color: var(--ink-muted);
    font-size: .8125rem;
}

.editor__layout {
    display: grid;
    gap: 1.5rem;
}

/* Grid children default to a minimum width of their content, which lets long
 * words in the editor push the whole layout sideways. */
.editor__sections {
    min-width: 0;
}

@media (min-width: 1200px) {
    .editor__layout {
        grid-template-columns: minmax(0, 1fr) 20rem;
        align-items: start;
    }

    .editor__sidebar {
        position: sticky;
        top: calc(var(--header-height) + 1.25rem);
    }
}

/* Sections read as sheets of paper, with an accent spine once written in */
.section {
    margin-bottom: 1.25rem;
    padding: 1.15rem 1.35rem 1.3rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    background: var(--surface);
    transition: border-color .15s ease;
}

.section.is-started {
    border-left: 3px solid var(--accent);
}

.section__header {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    margin-bottom: .4rem;
}

.section__number {
    color: var(--ink-muted);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.section__title {
    margin: 0;
    font-size: 1.0625rem;
}

.section__progress {
    margin-left: auto;
    color: var(--ink-muted);
    font-size: .75rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.section__prompt {
    margin: 0 0 .85rem;
    color: var(--ink-secondary);
    font-size: .90625rem;
}

.section__help {
    margin-bottom: .85rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-sunken);
}

.section__help > summary {
    display: flex;
    align-items: center;
    gap: .45rem;
    padding: .55rem .8rem;
    color: var(--ink-secondary);
    font-size: .8125rem;
    font-weight: 550;
    cursor: pointer;
    list-style: none;
}

.section__help > summary::-webkit-details-marker {
    display: none;
}

.section__help > summary::before {
    content: '';
    width: .45rem;
    height: .45rem;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg);
    transition: transform .18s ease;
}

.section__help[open] > summary::before {
    transform: rotate(45deg);
}

.section__help > summary:hover {
    color: var(--ink);
}

.section__help-body {
    padding: 0 .85rem .85rem;
    color: var(--ink-secondary);
    font-size: .84375rem;
}

.section__help-body p {
    margin: 0 0 .7rem;
}

.section__help-body strong {
    display: block;
    margin-bottom: .25rem;
    color: var(--ink);
    font-size: .75rem;
    font-weight: 650;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.section__help-example {
    padding: .7rem .85rem;
    border-left: 2px solid var(--accent);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--surface);
    color: var(--ink);
    font-size: .84375rem;
}

.section__help-list {
    margin: 0 0 .7rem 1.1rem;
    padding: 0;
}

.section__help-list li {
    margin-bottom: .3rem;
}

/* Writing starters */
.section__tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem;
    margin-bottom: .7rem;
}

.section__tools-label {
    margin-right: .1rem;
    color: var(--ink-muted);
    font-size: .6875rem;
    font-weight: 650;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.app-chip {
    height: 1.9rem;
    padding: 0 .7rem;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-secondary);
    font-family: inherit;
    font-size: .78125rem;
    cursor: pointer;
    transition: background-color .14s ease, border-color .14s ease, color .14s ease;
}

.app-chip:hover {
    border-style: solid;
    border-color: var(--accent);
    background: var(--accent-tint);
    color: var(--accent);
}

.app-chip--sample {
    border-style: solid;
}

.section__counts {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    margin: .6rem 0 0;
    color: var(--ink-muted);
    font-size: .75rem;
    font-variant-numeric: tabular-nums;
}

.section__counts .is-short {
    color: var(--warning);
}

.section__counts .is-good {
    color: var(--success);
}

/* Quill, restyled from its snow theme to match everything else */
.quill-editor {
    background: var(--surface);
}

.ql-toolbar.ql-snow {
    padding: .35rem .4rem;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--surface-sunken);
}

.ql-toolbar.ql-snow .ql-formats {
    margin-right: .5rem;
}

.ql-snow.ql-toolbar button {
    width: 1.7rem;
    height: 1.7rem;
    padding: .25rem;
    border-radius: var(--radius-sm);
}

.ql-snow.ql-toolbar button:hover,
.ql-snow.ql-toolbar button:focus {
    background: var(--surface-hover);
}

.ql-snow.ql-toolbar button.ql-active {
    background: var(--accent-tint);
}

.ql-container.ql-snow {
    border: 1px solid var(--line);
    border-radius: 0 0 var(--radius) var(--radius);
    background: var(--surface);
    font-family: var(--font-serif);
    font-size: 1.0625rem;
    line-height: 1.65;
}

.section:focus-within .ql-container.ql-snow {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.section:focus-within .ql-toolbar.ql-snow {
    border-color: var(--accent);
}

.ql-editor {
    min-height: 11rem;
    padding: 1rem 1.1rem;
    color: var(--ink);
}

.ql-editor.ql-blank::before {
    color: var(--ink-muted);
    font-style: normal;
    opacity: 1;
}

.ql-snow .ql-stroke {
    stroke: var(--ink-secondary);
}

.ql-snow .ql-fill,
.ql-snow .ql-stroke.ql-fill {
    fill: var(--ink-secondary);
}

.ql-snow .ql-picker {
    color: var(--ink-secondary);
    font-size: .8125rem;
}

.ql-snow .ql-picker-options {
    padding: .3rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-overlay);
}

.ql-snow .ql-tooltip {
    padding: .4rem .6rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-overlay);
}

.ql-snow .ql-tooltip input[type=text] {
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
}

.ql-snow.ql-toolbar button:hover .ql-stroke,
.ql-snow.ql-toolbar button.ql-active .ql-stroke {
    stroke: var(--accent);
}

.ql-snow.ql-toolbar button:hover .ql-fill,
.ql-snow.ql-toolbar button.ql-active .ql-fill {
    fill: var(--accent);
}

.ql-snow .ql-editor blockquote {
    margin: 0 0 1rem;
    padding-left: .9rem;
    border-left: 2px solid var(--line-strong);
    color: var(--ink-secondary);
}

.ql-snow .ql-editor h3,
.ql-snow .ql-editor h4 {
    margin-top: 1rem;
}

/* Sidebar */
.editor__sidebar {
    display: flex;
    flex-direction: column;
    gap: .85rem;
}

.sidebar-card {
    padding: 1rem 1.1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    font-size: .84375rem;
}

.sidebar-card__title {
    margin: 0 0 .7rem;
    color: var(--ink-muted);
    font-size: .6875rem;
    font-weight: 650;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.sidebar-card--details > summary {
    cursor: pointer;
    list-style: none;
}

.sidebar-card--details > summary::-webkit-details-marker {
    display: none;
}

.sidebar-card--details > summary::after {
    content: 'Show';
    float: right;
    color: var(--accent);
    font-size: .6875rem;
    letter-spacing: 0;
    text-transform: none;
}

.sidebar-card--details[open] > summary::after {
    content: 'Hide';
}

.sidebar-card__body {
    margin: 0 0 .6rem;
    color: var(--ink-secondary);
}

.sidebar-card__meta {
    margin: .45rem 0 0;
    color: var(--ink-muted);
    font-size: .78125rem;
    font-variant-numeric: tabular-nums;
}

.sidebar-card__list {
    margin: .3rem 0 .7rem 1.1rem;
    padding: 0;
    color: var(--ink-secondary);
}

.sidebar-card__list li {
    margin-bottom: .4rem;
}

.sidebar-card--note {
    background: var(--surface-sunken);
}

.sidebar-card--note .sidebar-card__body {
    margin-bottom: 0;
}

.outline {
    display: flex;
    flex-wrap: wrap;
    gap: .3rem;
    margin-top: .8rem;
}

.outline__button {
    padding: .25rem .6rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--ink-muted);
    font-family: inherit;
    font-size: .75rem;
    cursor: pointer;
    transition: border-color .14s ease, color .14s ease, background-color .14s ease;
}

.outline__button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.outline__button.is-done {
    border-color: var(--accent);
    background: var(--accent-tint);
    color: var(--accent);
}

/* A section carried over from an earlier model, shown read-only */
.section--carried {
    background: var(--surface-sunken);
}

.section--carried > summary {
    font-size: 1.0625rem;
    font-weight: 600;
    cursor: pointer;
}

/* ============================================ 6. Library and reading view = */

.library__toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
    margin-bottom: .9rem;
}

.library__field {
    flex: 1 1 16rem;
}

.library__field--select {
    flex: 0 1 13rem;
}

.library__count {
    margin: 0 0 .7rem;
    color: var(--ink-muted);
    font-size: .78125rem;
    font-variant-numeric: tabular-nums;
}

.library__list {
    display: flex;
    flex-direction: column;
    gap: .6rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.library-item {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: .95rem 1.15rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    transition: border-color .15s ease, background-color .15s ease;
}

.library-item:hover {
    border-color: var(--line-strong);
    background: var(--surface-hover);
}

.library-item__main {
    flex: 1 1 auto;
    min-width: 0;
}

.library-item__title {
    display: block;
    color: var(--ink);
    font-size: .96875rem;
    font-weight: 600;
    letter-spacing: -.01em;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.library-item__title:hover {
    color: var(--accent);
}

.library-item__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .45rem;
    margin: .3rem 0 0;
    color: var(--ink-muted);
    font-size: .75rem;
    font-variant-numeric: tabular-nums;
}

.library-item__snippet {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: .35rem 0 0;
    color: var(--ink-secondary);
    font-size: .8125rem;
    line-height: 1.5;
}

.library-item__actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: .35rem;
}

/* Reading: a measured column, set in a serif for the prose itself */
.view {
    max-width: 42rem;
    margin: 0 auto;
}

.view__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: 1.75rem;
}

.view__actions {
    display: flex;
    gap: .4rem;
}

.view__header {
    margin-bottom: 1.75rem;
    padding-bottom: 1.1rem;
    border-bottom: 1px solid var(--line);
}

.view__title {
    margin: 0 0 .5rem;
    font-size: 2rem;
    letter-spacing: -.025em;
    overflow-wrap: anywhere;
}

.view__model {
    margin: 0 0 .3rem;
    color: var(--ink-secondary);
    font-size: .875rem;
}

.view__model .model-badge {
    margin-right: .45rem;
}

.view__meta {
    margin: 0;
    color: var(--ink-muted);
    font-size: .78125rem;
    font-variant-numeric: tabular-nums;
}

.view__section {
    margin-bottom: 1.75rem;
}

.view__section-title {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    margin: 0 0 .6rem;
    color: var(--ink-muted);
    font-size: .6875rem;
    font-weight: 650;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.view__body {
    color: var(--ink);
    font-family: var(--font-serif);
    font-size: 1.0625rem;
    line-height: 1.7;
}

.view__body p {
    margin: 0 0 1rem;
}

.view__empty {
    margin: 0;
    color: var(--ink-muted);
    font-size: .875rem;
}

.view__carried {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--line);
}

.view__carried h3 {
    margin: .5rem 0 .35rem;
    font-size: .9375rem;
}

.view__example-note {
    margin-bottom: 1.5rem;
    padding: .8rem 1rem;
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink-secondary);
    font-size: .84375rem;
}

/* ============================== 7. Empty states and dialogs ================ */

.empty-state {
    max-width: 44rem;
    margin: 3rem auto;
    padding: 2.5rem 2rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    background: var(--surface);
    text-align: center;
}

.empty-state__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3.5rem;
    height: 3.5rem;
    margin-bottom: .5rem;
    border-radius: 50%;
    background: var(--accent-tint);
    color: var(--accent);
    font-size: 1.6rem;
}

.empty-state__title {
    margin: .5rem 0 .6rem;
    font-size: 1.5rem;
    letter-spacing: -.02em;
}

.empty-state p {
    color: var(--ink-secondary);
}

.empty-state__list {
    max-width: 34rem;
    margin: 1.25rem auto;
    padding: 0;
    color: var(--ink-secondary);
    font-size: .90625rem;
    list-style: none;
    text-align: left;
}

.empty-state__list li {
    position: relative;
    margin-bottom: .6rem;
    padding-left: 1.5rem;
}

.empty-state__list li::before {
    content: '';
    position: absolute;
    left: .25rem;
    top: .5em;
    width: .5rem;
    height: .5rem;
    border-radius: 50%;
    background: var(--accent-tint);
    box-shadow: inset 0 0 0 2px var(--accent);
}

.empty-state__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .6rem;
    margin-top: 1.5rem;
}

.dialog-root {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: rgba(14, 16, 22, .5);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.dialog-root.is-open {
    display: flex;
}

.dialog {
    width: min(35rem, 100%);
    max-height: min(85vh, 44rem);
    overflow: auto;
    padding: 1.5rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    background: var(--surface);
    box-shadow: var(--shadow-overlay);
}

.dialog__title {
    margin: 0 0 .65rem;
    font-size: 1.1875rem;
    letter-spacing: -.02em;
}

.dialog__body {
    color: var(--ink-secondary);
    font-size: .90625rem;
}

.dialog__body p {
    margin: 0 0 .8rem;
}

.dialog__body ul {
    margin: 0 0 .8rem 1.1rem;
    padding: 0;
}

.dialog__body li {
    margin-bottom: .35rem;
}

.dialog__body .dialog__warning {
    color: var(--danger);
    font-weight: 600;
}

.dialog__actions {
    display: flex;
    flex-wrap: wrap-reverse;
    justify-content: flex-end;
    gap: .5rem;
    margin-top: 1.5rem;
}

/* ==================================================== 8. Small screens ==== */

@media (max-width: 767.98px) {
    .app-main {
        padding: 1.25rem 1rem 5rem;
    }

    .library-item {
        flex-direction: column;
        align-items: stretch;
        gap: .75rem;
    }

    .library-item__actions {
        flex-wrap: wrap;
    }

    .library-item__actions .btn {
        min-height: 2.75rem;
        padding: .4rem .75rem;
    }

    .page__title {
        font-size: 1.5rem;
    }

    .view__title {
        font-size: 1.6rem;
    }
}

@media (max-width: 575.98px) {
    .menu__list {
        right: -.5rem;
        min-width: min(20rem, calc(100vw - 1.5rem));
    }

    .dialog__actions .btn {
        width: 100%;
    }

    .save-status {
        font-size: .75rem;
    }

    .empty-state {
        margin: 1.5rem auto;
        padding: 1.75rem 1.25rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ========================================================== 9. Print ======
   Printing is a first-class view, not the screen layout with parts hidden.
   app.js builds a semantic document into #printRoot whenever the practitioner
   prints (Ctrl+P, the Print buttons, or the browser's Print command), and this
   block is the only thing that decides how it looks.

   Two failure modes are designed out here:

   1. A dark page. If the operating system or browser is in dark mode the page
      canvas can be printed dark, which turned light text into a faint outline
      once the background was dropped. Colour scheme is therefore forced to
      light for print, with a white canvas and black text stated explicitly.

   2. Chrome printed by accident. The application shell, toolbar, buttons and
      dialogs are removed from the print output with display:none, so no
      off-screen or transparent trickery is needed.
   ========================================================================== */

/* Hidden on screen; the print rules below reveal it. */
.print-root {
    display: none;
}

@media print {

    @page {
        size: A4 portrait;
        margin: 16mm 14mm;
    }

    :root,
    html,
    body,
    html.dark-theme {
        color-scheme: light !important;
        background: #fff !important;
        color: #000 !important;
    }

    body {
        margin: 0;
        font-family: 'Times New Roman', Times, serif;
        font-size: 11pt;
        line-height: 1.45;
    }

    /* Everything interactive is removed rather than hidden off-canvas. */
    #app,
    #createBtn,
    #dialogRoot,
    #toastRoot,
    #storageWarning,
    .skip-link,
    .dialog-root,
    .app-toast-root,
    .fab,
    .menu__list {
        display: none !important;
    }

    .print-root {
        display: block !important;
    }

    /* No fills at all: borders and type do the work, so nothing depends on
       background printing being enabled. */
    .print-doc,
    .print-doc * {
        background: transparent !important;
        color: #000 !important;
        box-shadow: none !important;
        text-shadow: none !important;
        opacity: 1 !important;
        font-family: inherit !important;
    }

    .print-doc__title {
        margin: 0 0 4pt;
        font-size: 19pt;
        line-height: 1.2;
    }

    .print-doc__model {
        margin: 0 0 2pt;
        font-size: 11pt;
        font-weight: bold;
    }

    .print-doc__model-label {
        margin-right: 4pt;
        font-size: 8.5pt;
        font-weight: normal;
        letter-spacing: .06em;
        text-transform: uppercase;
    }

    .print-doc__meta,
    .print-doc__model-note,
    .print-doc__example-note,
    .print-index__meta {
        margin: 0 0 3pt;
        font-size: 9pt;
    }

    .print-doc__header {
        margin-bottom: 12pt;
        padding-bottom: 6pt;
        border-bottom: .75pt solid #000;
        break-after: avoid;
    }

    .print-doc__model-note {
        margin-top: 5pt;
        font-style: italic;
    }

    .print-doc__example-note {
        margin-bottom: 10pt;
        padding: 4pt 0;
        font-style: italic;
    }

    .print-doc__section {
        margin: 0 0 12pt;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .print-doc__section-title {
        margin: 0 0 4pt;
        font-size: 12.5pt;
        break-after: avoid;
        page-break-after: avoid;
    }

    .print-doc__number {
        font-weight: normal;
    }

    .print-doc__carried-title {
        margin: 8pt 0 3pt;
        font-size: 11pt;
        break-after: avoid;
    }

    .print-doc__body p,
    .print-doc__body li {
        margin: 0 0 6pt;
        orphans: 3;
        widows: 3;
    }

    .print-doc__body ul,
    .print-doc__body ol {
        margin: 0 0 6pt 16pt;
        padding: 0;
    }

    .print-doc__body blockquote {
        margin: 0 0 6pt;
        padding-left: 8pt;
        border-left: 1pt solid #000;
        font-style: italic;
    }

    .print-doc__body h1,
    .print-doc__body h2,
    .print-doc__body h3 {
        margin: 8pt 0 3pt;
        font-size: 11.5pt;
        break-after: avoid;
    }

    .print-doc__empty {
        font-style: italic;
    }

    .print-doc__section--carried {
        padding-top: 8pt;
        border-top: .5pt solid #000;
    }

    .print-doc__footer {
        margin-top: 14pt;
        padding-top: 6pt;
        border-top: .5pt solid #000;
        font-size: 8.5pt;
        break-inside: avoid;
    }

    .print-doc__footer p {
        margin: 0 0 3pt;
    }

    /* Library index, printed when Print is used on the list. */
    .print-index {
        margin: 0 0 0 16pt;
        padding: 0;
    }

    .print-index__item {
        margin-bottom: 7pt;
        break-inside: avoid;
    }

    .print-index__title {
        margin: 0;
        font-size: 11pt;
        font-weight: bold;
    }

    a[href]::after {
        content: '';
    }
}
