:root {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  --manuscript-font: Baskerville, "Iowan Old Style", "Palatino Linotype", serif;
  color: #e6e2dc;
  background: #161719;
  --muted: #9c9b98;
  --border: #ffffff12;
  --accent: #dfa1bd;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100dvh; background-position: center; background-size: cover; background-attachment: fixed; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; border: 1px solid var(--border); border-radius: 7px; background: #ffffff08; color: inherit; padding: .6rem .85rem; }
button:hover { background: #ffffff12; }
button:disabled { opacity: .5; cursor: wait; }
input, select { width: 100%; border: 1px solid var(--border); background: #ffffff05; color: inherit; padding: .8rem; border-radius: 7px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
input::placeholder, textarea::placeholder { color: #777875; }
.muted { color: var(--muted); font-size: .85rem; }
.brand { font-family: Georgia, serif; font-size: 2.6rem; letter-spacing: -.16rem; -webkit-user-select: none; user-select: none; }
.brand span { color: var(--accent); }
.login-screen { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; background: #161719d9; }
.login-card { position: relative; width: min(100%, 27rem); display: grid; grid-template-rows: 5rem 2.4rem 3.25rem; justify-items: center; gap: 1.75rem; }
.login-brand { font-family: Georgia, serif; font-size: 4rem; line-height: 1; font-weight: 400; letter-spacing: -.18rem; margin: 0; align-self: center; }
.password-fields { width: min(100%, 24.77rem); height: 2.4rem; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: 2.4rem; gap: clamp(.28rem, 1.6vw, .6rem); }
.password-fields input { min-width: 0; height: 2.4rem; padding: 0; border-radius: .52rem; text-align: center; font-size: 1.08rem; caret-color: transparent; transition: color .15s ease; }
.password-fields input:focus, .password-fields.is-pending input { outline: none; border-color: var(--accent); background: color-mix(in srgb, var(--accent) 4%, transparent); }
.password-fields:not(.is-pending) input:focus { animation: password-focus-pulse 1.5s ease-in-out -.375s infinite; }
@keyframes password-focus-pulse {
  0%, 100% { background-color: color-mix(in srgb, var(--accent) 4%, transparent); }
  50% { background-color: color-mix(in srgb, var(--accent) 10%, transparent); }
}
.password-fields.is-pending input { opacity: 1; -webkit-text-fill-color: currentColor; }
.password-fields input.is-masked { font-family: ui-monospace, monospace; }
.password-fields input.is-fading { color: transparent; }
.password-fields[aria-invalid="true"] input { border-color: #ce918980; }
.login-key { display: grid; place-items: center; width: 3.25rem; height: 3.25rem; border-radius: 50%; padding: 0; color: var(--accent); }
.login-key svg { width: 1.5rem; height: 1.5rem; }
.login-key:disabled { cursor: wait; }
.login-card[aria-busy="true"] .login-key { opacity: 1; }
#login-error { position: absolute; top: 100%; left: 0; width: 100%; margin: 1.25rem 0 0; color: #e6a49c; text-align: center; font-size: .8rem; line-height: 1.5; }
.workspace { height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; background: #161719eb; }
.workspace-header { position: relative; z-index: 3; display: flex; align-items: center; flex-wrap: wrap; gap: .65rem 1rem; padding: .85rem clamp(1.2rem, 4vw, 3rem); background: transparent; }
.workspace-header .brand { flex: none; font-size: 2rem; line-height: 1; }
.manuscript-control { position: relative; flex: 0 1 auto; max-width: 28rem; min-width: 0; }
.manuscript-trigger, #manuscript-name { min-height: 1.9rem; padding: .3rem .55rem; text-align: left; font-size: .82rem; background: transparent; border: 1px solid transparent; border-radius: 4px; }
.manuscript-trigger { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.manuscript-trigger.is-empty { border-style: dashed; border-color: #ffffff30; color: var(--muted); }
.manuscript-trigger:hover { background: #ffffff05; }
#manuscript-picker { width: clamp(10rem, 25vw, 18rem); max-width: 100%; }
#manuscript-name { border-color: var(--border); }
.manuscript-options { position: absolute; top: calc(100% + .5rem); left: 0; width: max(100%, 14rem); max-width: calc(100vw - 6rem); padding: .5rem; border: 1px solid var(--border); border-radius: 5px; background: #1b1c1f; box-shadow: 0 1rem 3rem #0005; z-index: 2; }
#manuscript-list { display: flex; flex-direction: column; max-height: 45dvh; overflow-y: auto; }
.manuscript-option { border: 0; background: none; text-align: left; font-size: .9rem; overflow-wrap: anywhere; }
.manuscript-option.active { color: var(--accent); }
.manuscript-error { margin: .5rem; color: #e6a49c; font-size: .8rem; line-height: 1.5; overflow-wrap: anywhere; }
.manuscript-options > button { width: 100%; margin-top: .4rem; padding: .65rem .85rem; text-align: left; border-top: 1px solid var(--border); border-radius: 0; }
.overview-toggle { flex: none; margin-left: auto; padding: .5rem; background: none; border: 0; color: var(--muted); }
.icon { display: block; width: 1.15rem; height: 1.15rem; fill: currentColor; }
.sidebar { position: fixed; inset: 0 auto 0 0; margin: 0; padding: 0; width: min(22rem, 100vw); height: 100dvh; max-width: 100vw; max-height: 100dvh; border: 0; border-right: 1px solid var(--border); background: #191a1d; color: inherit; }
.sidebar::backdrop { background: #0007; }
.overview-content { display: flex; flex-direction: column; gap: 1.5rem; min-height: 100%; padding: 1.5rem; }
.sidebar header { display: flex; align-items: center; justify-content: space-between; }
.sidebar header h2 { margin: 0; font-size: 1rem; font-weight: 500; }
.sidebar input { font-size: .85rem; }
.chapters-heading { display: flex; align-items: center; justify-content: space-between; }
.chapters-heading h2 { text-transform: uppercase; letter-spacing: .15em; font-size: .7rem; color: var(--muted); }
.chapters-heading button { font-size: 1.2rem; padding: .15rem .55rem; }
#chapter-list { display: flex; flex-direction: column; gap: .4rem; flex: 1; }
.chapter { text-align: left; border-color: transparent; overflow-wrap: anywhere; }
.chapter.active { background: color-mix(in srgb, var(--accent) 7%, transparent); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 14%, transparent); }
.chapter small { display: block; margin-top: .4rem; color: var(--muted); font-size: .75rem; font-weight: 400; }
.sidebar footer { display: flex; flex-direction: column; align-items: flex-start; gap: .6rem; border-top: 1px solid var(--border); padding-top: 1.2rem; }
.quiet { color: var(--muted); background: none; border: none; padding: .3rem 0; font-size: .8rem; }
.writing-area { position: relative; width: 100%; min-width: 0; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 1rem clamp(.5rem, 3vw, 3rem); }
.editor-controls { display: flex; align-items: center; gap: .35rem; flex: 1 1 auto; flex-wrap: wrap; min-width: 0; }
.editor-controls button, .editor-controls select { width: auto; font-size: .78rem; padding: .4rem .6rem; min-height: 2rem; }
.editor-controls button[aria-pressed="true"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, transparent); }
.toolbar-spacer { flex: 1; }
.editor-controls select { background: #202124; }
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .35rem 1rem; color: var(--muted); font-size: .75rem; }
.writing-area > .notice { max-width: 900px; margin-inline: auto; }
.editor { margin: 1.5rem auto 0; }
#chapter-content { width: 100%; min-height: 60dvh; font-family: var(--manuscript-font); }
#chapter-content > div { margin-inline: auto; }
/* Override the library's inline white page background. */
#chapter-content canvas[data-index] { background-color: transparent !important; box-shadow: none; border-radius: .75rem; outline: 1px solid #ffffff26; outline-offset: -1px; -webkit-backdrop-filter: blur(0px); backdrop-filter: blur(0px); transition: backdrop-filter .4s ease, -webkit-backdrop-filter .4s ease; }
#chapter-content.is-pointer-active canvas[data-index] { -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.pagination-measurement { position: fixed; left: -20000px; top: 0; width: 1000px; height: 1px; overflow: hidden; contain: strict; visibility: hidden; pointer-events: none; }
.settings-dialog { width: min(36rem, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); padding: 1.5rem; border: 1px solid var(--border); border-radius: .7rem; background: #1b1c1f; color: inherit; }
.settings-dialog::backdrop { background: #0009; }
.settings-dialog header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.settings-dialog h2 { margin: 0; font-size: 1.15rem; font-weight: 500; overflow-wrap: anywhere; }
.settings-dialog form > label { display: block; margin: 1rem 0 .5rem; }
.settings-dialog fieldset { margin: 1.25rem 0; border: 1px solid var(--border); border-radius: .4rem; padding: .8rem; }
.settings-dialog legend, .settings-grid label { font-size: .8rem; color: var(--muted); }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.settings-grid input { margin-top: .4rem; padding: .5rem; }
.settings-error { color: #e6a49c; font-size: .85rem; line-height: 1.5; }
.dictionary-form { display: flex; gap: .5rem; margin: 1rem 0; }
.dictionary-form input { min-width: 0; }
.dictionary-list { display: flex; flex-direction: column; gap: .4rem; max-height: 45dvh; overflow: auto; margin: 1rem 0; }
.dictionary-entry { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .5rem; overflow-wrap: anywhere; }
.spelling-dialog { width: min(24rem, calc(100vw - 2rem)); }
.writing-finding + .writing-finding { border-top: 1px solid var(--border); padding-top: 1rem; }
.writing-finding h3 { margin: .25rem 0; font-size: .95rem; font-weight: 500; }
.writing-finding p { font-size: .85rem; line-height: 1.6; overflow-wrap: anywhere; }
.writing-excerpt { white-space: pre-wrap; color: var(--muted); }
.danger { color: #ce9189; }
.notice { border: 1px solid #ce91894d; background: #362422; padding: 1rem; margin-top: 1rem; font-size: .9rem; line-height: 1.5; }
.notice button { margin: .5rem; }
.empty-state { margin: 15vh auto; text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
@media (prefers-reduced-motion: reduce) {
  .password-fields input { transition: none; animation: none !important; }
  #chapter-content canvas[data-index] { transition: none; }
}
@media (max-width: 1200px) {
  .workspace-header .editor-controls { order: 1; flex-basis: 100%; }
  .workspace-header .toolbar { margin-left: auto; }
}
@media (max-width: 700px) {
  .workspace-header { gap: .75rem; }
  .workspace-header .toolbar { order: 2; flex-basis: 100%; margin-left: 0; }
  .manuscript-control { flex: 1; }
  .overview-content { padding: 1.2rem; }
  .editor { margin-top: 2rem; }
}
