/* Writing screen for the author. One question at a time beside the photo. Paper and pen ink:
   the author compares the text with photos of white pages, so the light theme is the default
   and the one accent is the blue of a pen. Words to check are amber. The dark theme follows
   the system setting. UI type is Source Sans 3; the page text is Source Serif 4, like a book. */
:root {
    --paper: #f3f3f0;
    --surface: #ffffff;
    --text: #1c1c1a;
    --muted: #55554f;
    --rule: #dadad4;
    --control: #8a8a83;      /* control borders: 3:1 or more against white */
    --ink: #1e4fd8;          /* the one accent */
    --ink-dark: #163ca6;
    --ink-soft: #eef3ff;
    --on-ink: #ffffff;
    --check-bg: #ffe29a;     /* words that need a check */
    --check-text: #3d2a00;
    --check-line: #a35300;   /* 5.5:1 on white, also used for text */
    --ok: #2f5a1f;
    --error: #b3261e;
    --del-bg: #fbe0dd;
    --ins-bg: #dcefe2;
    --box: rgba(255, 196, 61, 0.22);
    --radius: 10px;
    --sans: "Source Sans 3", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    --serif: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --paper: #16171a;
        --surface: #1e1f23;
        --text: #ececee;
        --muted: #b0b0b8;
        --rule: #34353b;
        --control: #8d8e96;
        --ink: #9db2ff;
        --ink-dark: #c3d0ff;
        --ink-soft: #262c42;
        --on-ink: #16171a;
        --check-bg: #5a4210;
        --check-text: #ffe9bd;
        --check-line: #ffb454;
        --ok: #8fd6a5;
        --error: #ff8f87;
        --del-bg: #4a2522;
        --ins-bg: #1f3b2a;
        --box: rgba(255, 180, 84, 0.2);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
    margin: 0;
    background: var(--paper);
    color: var(--text);
    font: 18px/1.5 var(--sans);
}
h1, h2, h3 { line-height: 1.25; margin: 0; text-wrap: balance; }
h2 { font-size: 1.15rem; }
p { text-wrap: pretty; }
a { color: var(--ink); }
a:hover { color: var(--ink-dark); }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* Controls */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 48px; padding: 0 18px;
    font: inherit; font-size: 1rem; color: var(--text);
    background: var(--surface); border: 1px solid var(--control); border-radius: 8px;
    cursor: pointer;
}
.btn:hover { border-color: var(--ink); }
.btn:disabled { cursor: not-allowed; color: var(--muted); border-style: dashed; }
.btn-primary { background: var(--ink); color: var(--on-ink); border-color: var(--ink); font-weight: 600; }
.btn-primary:hover { background: var(--ink-dark); border-color: var(--ink-dark); }
.btn-primary:disabled { background: var(--surface); color: var(--muted); border-color: var(--control); }
.btn-large { min-height: 56px; font-size: 1.1rem; padding: 0 26px; border-radius: var(--radius); }
.btn-small { min-height: 44px; padding: 0 14px; font-size: 0.95rem; }
.link-btn {
    display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px;
    font: inherit; font-size: 1rem; color: var(--ink); background: none; border: 0; border-radius: 8px;
    cursor: pointer; text-decoration: none;
}
.link-btn:hover { color: var(--ink-dark); text-decoration: underline; }
.link-btn:disabled { color: var(--muted); cursor: default; text-decoration: none; }
.input { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--control); border-radius: 8px; min-height: 48px; padding: 8px 12px; }

.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px 20px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px 12px; flex-wrap: wrap; }

/* Top bar: book, pages, save state */
.bar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px;
    padding: 10px 24px; border-bottom: 1px solid var(--rule); background: var(--surface);
}
.book-title {
    font-family: var(--serif); font-size: 1.3rem; font-weight: 600; color: var(--text); text-decoration: none;
    flex: 1 1 160px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.book-title:hover { color: var(--ink); }
.pager { display: flex; gap: 8px; align-items: center; flex: 0 1 auto; }
.pager .btn { padding: 0 14px; }
.pager .arrow { font-size: 1.4rem; line-height: 1; }
.page-select { font-weight: 600; max-width: 300px; }
.bar-end { display: flex; gap: 4px 8px; align-items: center; justify-content: flex-end; flex: 1 1 160px; flex-wrap: wrap; }
.save-state { color: var(--ok); font-size: 0.95rem; padding-right: 6px; }
.save-state.error { color: var(--error); font-weight: 600; }

.progress-strip {
    display: flex; align-items: center; gap: 12px; padding: 4px 24px 12px;
    background: var(--surface); border-bottom: 1px solid var(--rule); color: var(--muted); font-size: 0.9rem;
}
.progress-strip progress { width: min(320px, 40vw); height: 6px; appearance: none; border: 0; border-radius: 3px; background: var(--rule); overflow: hidden; }
.progress-strip progress::-webkit-progress-bar { background: var(--rule); }
.progress-strip progress::-webkit-progress-value { background: var(--ink); }
.progress-strip progress::-moz-progress-bar { background: var(--ink); }

.banner { padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--rule); }

main { padding: 24px; max-width: 1480px; margin: 0 auto; }
.state { color: var(--muted); }
.state-panel { max-width: 680px; margin: 24px auto; padding: 24px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }

/* The desk: photo on the left, the question and the page on the right */
.desk { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 24px; align-items: start; }
.photo-side { position: sticky; top: 12px; padding: 14px; }
.small-heading { font-size: 0.95rem; color: var(--muted); font-weight: 600; }
.narrow-only { display: none; }
.photo-scroll { max-height: calc(100dvh - 150px); overflow: auto; margin-top: 10px; border-radius: 8px; background: var(--paper); }
.frame { position: relative; width: 100%; }
.frame.zoomed { width: 200%; }
.frame img { display: block; width: 100%; height: auto; }
.box { position: absolute; border: 3px solid var(--check-line); background: var(--box); border-radius: 6px; pointer-events: none; }
.box.estimate { border-style: dashed; }

.write-side { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* The question: one place to check, with the photo of that place */
.check { border: 2px solid var(--ink); display: flex; flex-direction: column; gap: 12px; }
.check h2 { font-size: 1.25rem; }
.snippet-figure { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.snippet-figure figcaption { font-size: 0.9rem; color: var(--muted); }
.snippet { position: relative; overflow: hidden; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); height: 96px; }
.snippet img { position: absolute; left: 0; width: 100%; height: auto; display: block; }
.snippet-mark { position: absolute; border: 3px solid var(--check-line); border-radius: 6px; pointer-events: none; }
.context { font-family: var(--serif); font-size: 1.1rem; line-height: 1.7; margin: 0; }
.context mark { background: var(--check-bg); color: var(--check-text); padding: 1px 3px; border-radius: 3px; }
.check-question { margin: 0; font-size: 1.1rem; }
.choices { display: grid; gap: 10px; }
.choice {
    display: flex; align-items: center; justify-content: space-between; gap: 4px 12px; flex-wrap: wrap; text-align: left;
    min-height: 56px; padding: 10px 16px; font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--control); border-radius: var(--radius); cursor: pointer;
}
.choice:hover { border-color: var(--ink); }
.choice:disabled { cursor: wait; opacity: 0.6; }
.choice.suggested { border: 2px solid var(--ink); background: var(--ink-soft); }
.choice .words { font-family: var(--serif); font-size: 1.3rem; overflow-wrap: anywhere; }
.choice .who { color: var(--muted); font-size: 0.9rem; }
.choice.suggested .who { color: var(--ink); font-weight: 600; }
.choice.other { border-style: dashed; min-height: 48px; font-size: 1rem; }
.look { color: var(--muted); margin: 0; font-size: 0.95rem; }
.error-text { color: var(--error); margin: 8px 0 0; }
.error-text:empty { display: none; }

/* The page being written */
.sheet h2 { font-size: 1.25rem; }
.summary-line { color: var(--muted); margin: 4px 0 12px; }

/* The editor is a textarea over a copy of the same text that paints the check marks.
   Both must have exactly the same box, font and wrapping. */
.editor { position: relative; }
.editor textarea, .backdrop {
    display: block; width: 100%; margin: 0;
    padding: 14px 18px; border: 1px solid transparent; border-radius: 8px;
    font-family: var(--serif); font-size: 1.2rem; line-height: 1.75; letter-spacing: normal;
    white-space: pre-wrap; overflow-wrap: break-word; word-break: normal; tab-size: 4;
}
.backdrop { position: absolute; inset: 0; color: transparent; pointer-events: none; overflow: hidden; }
.backdrop mark { color: transparent; background: var(--check-bg); border-radius: 3px; }
.backdrop mark.current { box-shadow: inset 0 -3px 0 var(--check-line); }
.backdrop mark.grammar { background: none; text-decoration: underline wavy var(--ink); text-decoration-thickness: 2px; text-underline-offset: 5px; }
.editor textarea {
    position: relative; resize: none; overflow: hidden; min-height: 40dvh;
    background: transparent; color: var(--text); border-color: var(--rule); caret-color: var(--ink);
}
.editor textarea:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.editor textarea[readonly] { color: var(--muted); }
.preview { font-family: var(--serif); font-size: 1.2rem; line-height: 1.75; padding: 14px 18px; border: 1px solid var(--rule); border-radius: 8px; min-height: 40dvh; }
.preview h3, .preview h4 { font-family: var(--serif); margin: 0.6em 0 0.3em; }
.preview p { margin: 0 0 0.9em; }
.help { color: var(--muted); font-size: 0.95rem; margin: 10px 0 0; }
.source { margin: 10px 0 0; padding: 10px 12px; background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; }
.source:empty { display: none; }

.finish { display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap; }
.finish .muted { margin: 0; }

/* History: a panel on the right, one entry per step, newest first */
.history {
    margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; width: min(560px, 100vw); padding: 0;
    border: 0; border-left: 1px solid var(--rule); border-radius: 0; background: var(--surface); color: var(--text);
}
.history::backdrop { background: rgba(0, 0, 0, 0.35); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 20px 24px 14px; border-bottom: 1px solid var(--rule); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dialog-head h2 { font-size: 1.35rem; }
.dialog-intro { margin: 6px 0 0; color: var(--muted); font-size: 0.95rem; }
.history .state { margin: 14px 24px; }
.timeline { list-style: none; margin: 0; padding: 8px 24px 24px; display: flex; flex-direction: column; }
.phase { display: grid; grid-template-columns: 20px 1fr; column-gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--rule); }
.phase:last-child { border-bottom: 0; }
.phase .dot::before { content: ""; display: block; margin-top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--control); }
.phase.author .dot::before { background: var(--ink); }
.phase .body { min-width: 0; }
.phase h3 { font-size: 1.05rem; }
.phase .meta { color: var(--muted); font-size: 0.9rem; margin: 2px 0 6px; }
.phase ul { margin: 6px 0; padding-left: 20px; }
.phase li { margin: 3px 0; }
.phase summary { cursor: pointer; color: var(--ink); min-height: 44px; display: flex; align-items: center; }
.diff { font-family: var(--serif); white-space: pre-wrap; overflow-wrap: anywhere; background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; padding: 12px 14px; margin: 8px 0; max-height: 360px; overflow: auto; }
.diff del { background: var(--del-bg); color: var(--text); text-decoration: line-through; }
.diff ins { background: var(--ins-bg); color: var(--text); text-decoration: none; }

/* Tablet and narrow laptop: the photo goes above and can be folded away; the snippet
   in the question still shows the place on the photo. */
@media (max-width: 960px) {
    .desk { grid-template-columns: 1fr; gap: 16px; }
    .photo-side { position: static; order: 2; }
    .photo-scroll { max-height: 50dvh; }
    .narrow-only { display: inline-flex; }
    .bar { padding: 10px 16px; }
    .progress-strip { padding: 4px 16px 10px; }
    main { padding: 16px 16px 40px; }
}
/* Phone: page arrows around the page menu, and "done" stays at the bottom of the screen. */
@media (max-width: 600px) {
    .book-title { display: none; }
    .pager { width: 100%; order: 1; }
    .page-select { flex: 1 1 auto; max-width: none; min-width: 0; }
    .wide-only { display: none; }
    .bar-end { order: 2; width: 100%; justify-content: space-between; flex-basis: 100%; }
    .card { padding: 14px; }
    .editor textarea, .backdrop, .preview { font-size: 1.1rem; padding: 12px; }
    .choice .words { font-size: 1.2rem; }
    .finish {
        position: sticky; bottom: 0; z-index: 2; margin: 0 -16px -40px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
        background: var(--surface); border-top: 1px solid var(--rule);
    }
    .finish .btn-large { flex: 1 1 auto; }
    .finish .muted { flex-basis: 100%; font-size: 0.9rem; }
}
/* A short screen (a phone turned sideways): the bar would cover too much, so it scrolls with the page. */
@media (max-width: 600px) and (max-height: 560px) {
    .finish { position: static; margin: 0; padding: 0; border-top: 0; background: none; }
}

/* Overview of all pages */
.overview { max-width: 1160px; padding: 32px 24px 48px; }
.overview-stack { display: flex; flex-direction: column; gap: 24px; }
.hero { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 20px 24px; padding: 24px; }
.hero-text { display: flex; flex-direction: column; gap: 10px; flex: 1 1 360px; }
.hero h1 { font-size: 1.75rem; }
.hero p { margin: 0; }
.hero progress { width: min(480px, 100%); height: 10px; appearance: none; border: 0; border-radius: 5px; background: var(--rule); overflow: hidden; }
.hero progress::-webkit-progress-bar { background: var(--rule); }
.hero progress::-webkit-progress-value { background: var(--ink); }
.hero progress::-moz-progress-bar { background: var(--ink); }
.hero .btn-large { text-decoration: none; }
.pages { display: flex; flex-direction: column; gap: 14px; }
.pages h2 { font-size: 1.35rem; }
.pill {
    min-height: 44px; padding: 0 16px; border-radius: 22px; font: inherit; font-size: 0.95rem; cursor: pointer;
    border: 1px solid var(--control); background: var(--surface); color: var(--text);
}
.pill[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.tiles { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile {
    display: flex; flex-direction: column; gap: 4px; min-height: 72px; padding: 12px 14px; text-decoration: none;
    background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); color: var(--text);
}
.tile:hover { border-color: var(--ink); color: var(--text); }
.tile-name { font-weight: 700; font-size: 1.1rem; }
.tile-status { font-size: 0.95rem; font-weight: 600; color: var(--muted); }
.tile.open { border: 2px solid var(--check-line); }
.tile.open .tile-status { color: var(--check-line); }
.tile.done .tile-status { color: var(--ok); }
.plain-list { margin: 8px 0 0; padding-left: 20px; }
.plain-list li { margin: 6px 0; }
.number-fix { margin-top: 6px; }
.ok-text { color: var(--ok); }
.more summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; }
.more-row { margin-top: 14px; }
.more-row .btn { text-decoration: none; }
.more h3 { font-size: 1rem; margin-top: 16px; }
.signed-in { font-size: 0.9rem; padding-right: 4px; }
.status-line { margin: 10px 0 0; }
.status-line:empty { display: none; }
@media (max-width: 600px) {
    .overview { padding: 16px 16px 40px; }
    .hero { padding: 18px; }
    .hero .btn-large { width: 100%; }
    .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Sign-in page */
.login { display: grid; place-items: start center; min-height: 100dvh; padding: 12vh 16px 48px; }
.login-card {
    display: grid; gap: 8px; width: 100%; max-width: 400px; padding: 28px 24px;
    background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
}
.login-card h1 { font-family: var(--serif); font-size: 1.6rem; }
.login-card p { margin: 0 0 8px; }
.login-card label { font-weight: 600; margin-top: 8px; }
.login-card .btn { margin-top: 16px; }
.login-card .small { font-size: 0.95rem; margin-top: 8px; }
.sign-out { margin: 0; }
.quiet-btn { font: inherit; font-size: 1rem; color: var(--ink); background: none; border: 0; padding: 12px 4px; cursor: pointer; text-decoration: underline; min-height: 44px; }
