/* TalkScrolls reading view and home page. Soft dark by default; warm paper when the reader picks light. */

:root
{
    --bg: #131211;
    --surface: #1c1a18;
    --paper: #25221f;
    --ink: #e7e2d9;
    --muted: #aaa397;
    --faint: #756f65;
    --rule: #302d29;
    --thread: #e06a5f;
    --highlight: #4a3f1c;
    --highlight-note: #5c4c1d;
    --shadow: rgba(0, 0, 0, 0.5);
    --reader-size: 19px;
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color-scheme: dark;
}

:root[data-theme="light"]
{
    --bg: #f5f2ec;
    --surface: #fffdf9;
    --paper: #ece6db;
    --ink: #1e1c19;
    --muted: #625c53;
    --faint: #8f887d;
    --rule: #dcd5c9;
    --thread: #9e2f28;
    --highlight: #f2e1a8;
    --highlight-note: #ecd38a;
    --shadow: rgba(30, 28, 25, 0.16);
    color-scheme: light;
}

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

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

body
{
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--serif);
    font-size: 17px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a
{
    color: inherit;
}

button
{
    font: inherit;
    color: inherit;
}

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

[hidden]
{
    display: none !important;
}

/* Top bar */

.progress
{
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 4;
    height: 2px;
}

.progress span
{
    display: block;
    width: 0;
    height: 100%;
    background: var(--thread);
}

.bar
{
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--rule);
    font-family: var(--sans);
    font-size: 14px;
}

.home
{
    font-family: var(--serif);
    font-size: 18px;
    font-weight: 600;
    text-decoration: none;
    letter-spacing: 0.01em;
}

.tools
{
    display: flex;
    gap: 6px;
}

.tools button
{
    min-width: 38px;
    min-height: 36px;
    padding: 0 10px;
    border: 1px solid var(--rule);
    border-radius: 18px;
    background: var(--surface);
    cursor: pointer;
}

.tools button:hover
{
    border-color: var(--faint);
}

.tools .count
{
    display: inline-block;
    min-width: 1.4em;
    color: var(--thread);
    font-weight: 600;
}

.preview-banner
{
    padding: 8px 16px;
    background: var(--paper);
    color: var(--muted);
    font-family: var(--sans);
    font-size: 13px;
    text-align: center;
}

/* Story */

.reader
{
    max-width: 38em;
    margin: 0 auto;
    padding: 56px 20px 96px;
    font-size: var(--reader-size);
}

.story-head
{
    margin-bottom: 2.6em;
    text-align: center;
}

.story-head h1
{
    margin: 0;
    font-size: 2.1em;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: 0.005em;
}

.story-subtitle
{
    margin: 0.6em 0 0;
    color: var(--muted);
    font-style: italic;
    font-size: 1.05em;
}

.story-meta
{
    margin: 1.2em 0 0;
    color: var(--faint);
    font-family: var(--sans);
    font-size: 13px;
}

.story
{
    line-height: 1.7;
    hyphens: auto;
    -webkit-hyphens: auto;
    overflow-wrap: break-word;
}

.story p
{
    margin: 0;
    text-indent: 1.5em;
}

.story p.first
{
    text-indent: 0;
}

.story h2
{
    margin: 2.4em 0 1em;
    font-size: 1.3em;
    font-weight: 600;
    text-align: center;
    line-height: 1.3;
}

.story h2:first-child
{
    margin-top: 0;
}

.story h3
{
    margin: 2em 0 0.8em;
    font-size: 1.05em;
    font-weight: 600;
    font-style: italic;
    text-align: center;
}

.story .scene-break
{
    width: 3em;
    margin: 1.8em auto;
    border: 0;
    border-top: 1px solid var(--faint);
}

.story-end
{
    margin: 2.5em 0 0;
    color: var(--faint);
    text-align: center;
    font-size: 1.3em;
}

.story ::selection
{
    background: color-mix(in srgb, var(--thread) 28%, transparent);
}

mark.hl
{
    background: var(--highlight);
    color: inherit;
    border-radius: 2px;
    cursor: pointer;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
}

mark.hl.has-note
{
    background: var(--highlight-note);
    border-bottom: 2px solid var(--thread);
}

mark.hl.flash
{
    animation: flash 1.2s ease-out;
}

@keyframes flash
{
    from
    {
        box-shadow: 0 0 0 4px color-mix(in srgb, var(--thread) 45%, transparent);
    }
    to
    {
        box-shadow: 0 0 0 4px transparent;
    }
}

/* Selection toolbar */

.select-tools
{
    position: absolute;
    z-index: 5;
    display: flex;
    gap: 2px;
    padding: 4px;
    border-radius: 22px;
    background: var(--ink);
    box-shadow: 0 6px 20px var(--shadow);
    font-family: var(--sans);
    font-size: 14px;
}

.select-tools button
{
    min-height: 36px;
    padding: 0 14px;
    border: 0;
    border-radius: 18px;
    background: transparent;
    color: var(--bg);
    cursor: pointer;
}

.select-tools button:hover
{
    background: color-mix(in srgb, var(--bg) 16%, transparent);
}

/* Note card */

.note-card
{
    position: fixed;
    left: 50%;
    bottom: 16px;
    z-index: 6;
    width: min(520px, calc(100% - 32px));
    transform: translateX(-50%);
    padding: 16px;
    border: 1px solid var(--rule);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 12px 40px var(--shadow);
    font-family: var(--sans);
    font-size: 15px;
}

.note-card blockquote
{
    max-height: 7.5em;
    overflow: auto;
    margin: 0 0 12px;
    padding-left: 12px;
    border-left: 3px solid var(--thread);
    color: var(--muted);
    font-family: var(--serif);
    font-style: italic;
}

.note-card textarea
{
    display: block;
    width: 100%;
    min-height: 96px;
    padding: 10px 12px;
    border: 1px solid var(--rule);
    border-radius: 8px;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.5 var(--serif);
    resize: vertical;
}

.note-actions
{
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 12px;
}

.note-actions div
{
    display: flex;
    gap: 8px;
}

.note-actions button
{
    min-height: 38px;
    padding: 0 16px;
    border: 1px solid var(--rule);
    border-radius: 19px;
    background: var(--surface);
    cursor: pointer;
}

.note-actions .primary
{
    border-color: var(--ink);
    background: var(--ink);
    color: var(--bg);
}

.note-actions .danger
{
    color: var(--thread);
}

/* Notes drawer */

.drawer
{
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 6;
    display: flex;
    flex-direction: column;
    width: min(400px, 100%);
    border-left: 1px solid var(--rule);
    background: var(--surface);
    box-shadow: -12px 0 40px var(--shadow);
    font-family: var(--sans);
    font-size: 15px;
}

.drawer-head
{
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--rule);
}

.drawer-head h2
{
    margin: 0;
    font-family: var(--serif);
    font-size: 19px;
    font-weight: 600;
}

.drawer-head button
{
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 19px;
    background: transparent;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.drawer-hint
{
    margin: 0;
    padding: 12px 16px;
    color: var(--faint);
    font-size: 13px;
}

.drawer-list
{
    flex: 1;
    overflow: auto;
    margin: 0;
    padding: 0 16px 24px;
    list-style: none;
}

.drawer-list li
{
    padding: 12px 0;
    border-top: 1px solid var(--rule);
}

.drawer-list button
{
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.drawer-list .quote
{
    display: block;
    font-family: var(--serif);
    font-style: italic;
    color: var(--muted);
}

.drawer-list .note
{
    display: block;
    margin-top: 6px;
    white-space: pre-wrap;
}

.drawer-list .lost
{
    display: block;
    margin-top: 6px;
    color: var(--thread);
    font-size: 13px;
}

.drawer-list .empty
{
    color: var(--faint);
}

/* Home page */

.home-page
{
    max-width: 40em;
    margin: 0 auto;
    padding: 72px 20px 96px;
}

.site-head
{
    margin-bottom: 48px;
    text-align: center;
}

.site-head h1
{
    margin: 0;
    font-size: clamp(38px, 9vw, 56px);
    font-weight: 600;
    line-height: 1.05;
    letter-spacing: 0.01em;
}

.site-tagline
{
    margin: 12px 0 0;
    color: var(--muted);
    font-style: italic;
    font-size: 19px;
}

.site-byline
{
    margin: 6px 0 0;
    color: var(--faint);
    font-family: var(--sans);
    font-size: 14px;
}

.story-list
{
    margin: 0;
    padding: 0;
    list-style: none;
}

.story-list li
{
    border-top: 1px solid var(--rule);
}

.story-list li:last-child
{
    border-bottom: 1px solid var(--rule);
}

.story-list a
{
    display: block;
    padding: 24px 4px;
    text-decoration: none;
}

.story-list a:hover h2
{
    color: var(--thread);
}

.story-list h2
{
    margin: 0;
    font-size: 25px;
    font-weight: 600;
    line-height: 1.2;
}

.entry-subtitle
{
    margin: 6px 0 0;
    color: var(--muted);
    font-style: italic;
}

.entry-meta
{
    margin: 8px 0 0;
    color: var(--faint);
    font-family: var(--sans);
    font-size: 13px;
}

.story-list .empty
{
    padding: 24px 4px;
    color: var(--faint);
    text-align: center;
}

@media (max-width: 640px)
{
    .reader
    {
        padding: 36px 18px 80px;
    }

    .tools button
    {
        min-width: 36px;
        padding: 0 8px;
    }
}

@media (prefers-reduced-motion: reduce)
{
    mark.hl.flash
    {
        animation: none;
    }
}
