/* Marginalia: a keeper's ledger. Green-grey ledger stock, faded blue rules,
   a red margin line, blue-black iron-gall ink. Choices and deductions are
   marked the way they would be on paper: circled in blue pencil, struck
   through in graphite, sealed in wax when they rest on a source.
   No inline styles anywhere (strict CSP). */

@font-face { font-family: 'Fell'; src: url('../fonts/fell-roman.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Fell'; font-style: italic; src: url('../fonts/fell-italic.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Fell SC'; src: url('../fonts/fell-sc.woff2') format('woff2'); font-display: swap; }

:root {
  --paper: #e2e6d5;
  --paper-2: #d6dbc6;
  --paper-3: #c8ceb6;
  --ink: #1d2230;
  --ink-2: #5a5445;
  --rule: #9fb6c7;
  --margin: #b14d42;
  --pencil: #2f55a4;
  --graphite: #5d5e63;
  --seal: #8f2b25;
  --flame: #c98a2b;
  --drift: #5a4d9a;
  --shadow: rgba(29, 34, 48, .2);
  --line: 32px;
  --gutter: 16px;
  --margin-col: 76px;
  --head-h: 76px;
  --nav-h: 62px;
  color-scheme: light dark;
}
/* By lamplight: the same ledger, read at night. */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #20231c;
    --paper-2: #2a2e25;
    --paper-3: #363b2f;
    --ink: #e9e0c9;
    --ink-2: #a89e86;
    --rule: #3a5061;
    --margin: #c3655b;
    --pencil: #95b3ee;
    --graphite: #a5a59c;
    --seal: #d65b50;
    --flame: #e8b04a;
    --drift: #b4a6ea;
    --shadow: rgba(0, 0, 0, .45);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font: 18px/1.5 'Fell', Georgia, 'Times New Roman', serif;
  font-kerning: normal;
  -webkit-tap-highlight-color: transparent;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--pencil); outline-offset: 2px; border-radius: 2px; }
h1, h2, h3 { font-weight: 400; margin: 0; }
p { margin: 0 0 .75em; }
.ic { width: 24px; height: 24px; flex: none; }
.sc { font-family: 'Fell SC', 'Fell', Georgia, serif; letter-spacing: .02em; }
.quiet { color: var(--ink-2); }
.hidden { display: none !important; }

/* ---------- shell ---------- */

#app { min-height: 100dvh; }
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.head {
  position: sticky; top: 0; z-index: 20;
  background: var(--paper);
  padding: calc(env(safe-area-inset-top) + 8px) var(--gutter) 6px;
  border-bottom: 1px solid var(--rule);
}
.head-row { display: flex; align-items: center; gap: 12px; min-height: 30px; }
.head-week { font-family: 'Fell SC', 'Fell', serif; font-size: 19px; }
/* Fell's old-style 1 reads as a roman I; Palatino's lining figures do not. */
.num { font-family: 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif; font-variant-numeric: lining-nums; font-size: .9em; }
.head-week small { font-family: 'Fell', serif; font-style: italic; font-size: 15px; color: var(--ink-2); margin-left: 4px; }
.head-moon { display: flex; align-items: center; gap: 6px; font-style: italic; font-size: 16px; color: var(--ink-2); }
.head-moon .ic { width: 18px; height: 18px; color: var(--ink); }
.candles { margin-left: auto; display: flex; gap: 3px; color: var(--ink); }
.candles .cd { width: 11px; height: 20px; }
.candles .flame { fill: var(--flame); }
.candles .out { color: var(--ink-2); }
.gauges { display: flex; gap: 16px; align-items: center; font-size: 14px; color: var(--ink-2); }
.sanity { display: flex; align-items: center; gap: 8px; }
.sanity-bar { width: 70px; height: 3px; background: var(--paper-3); position: relative; }
.sanity-fill { position: absolute; inset: 0 auto 0 0; background: var(--ink); }
.sanity.t-margins .sanity-fill { background: var(--pencil); }
.sanity.t-drift .sanity-fill { background: var(--margin); }
.sanity.t-visions .sanity-fill { background: var(--seal); }
.sanity.t-drift, .sanity.t-visions { color: var(--margin); }
.mind { font-style: italic; color: var(--margin); margin: -8px 0 6px; }
.conj { margin-left: auto; font-style: italic; }
.conj.near { color: var(--margin); }

.layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr); }
.view { width: 100%; max-width: 680px; margin: 0 auto; padding: 18px var(--gutter) calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px); }
.side { display: none; }

.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: flex; justify-content: space-around;
  background: var(--paper-2);
  border-top: 1px solid var(--rule);
  padding: 4px 4px calc(env(safe-area-inset-bottom) + 4px);
}
.tab {
  flex: 1; max-width: 120px; min-height: 52px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: none; border: 0; color: var(--ink-2); font-size: 14px;
}
.tab .ic { width: 23px; height: 23px; }
.tab.is-on { color: var(--ink); }
.tab.is-on span { text-decoration: underline; text-decoration-color: var(--margin); text-underline-offset: 3px; }
.tab .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--margin); position: absolute; margin: -18px 0 0 22px; }
.tab { position: relative; }

/* Wide screens: the notebook stays open beside whatever you are reading. */
@media (min-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr) minmax(420px, 520px); }
  .side { display: block; border-left: 1px solid var(--rule); height: calc(100dvh - var(--head-h)); position: sticky; top: var(--head-h); overflow-y: auto; }
  .side .view { padding-bottom: 32px; }
  .tab[data-tab="notebook"] { display: none; }
  .tabs { right: auto; width: calc(100% - min(520px, max(420px, 100% - 680px))); }
}

/* ---------- type within views ---------- */

.view-title { font-size: 26px; line-height: 1.2; margin: 4px 0 4px; }
.view-sub { color: var(--ink-2); font-style: italic; font-size: 16px; margin-bottom: 18px; }
.section { margin: 26px 0 0; }
.section-title { font-family: 'Fell SC', 'Fell', serif; font-size: 17px; color: var(--ink-2); margin-bottom: 8px; border-bottom: 1px solid var(--rule); padding-bottom: 2px; }
.empty { color: var(--ink-2); font-style: italic; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 8px 18px;
  background: transparent; color: var(--ink);
  border: 1px solid var(--ink); border-radius: 3px;
  font-size: 17px; line-height: 1.2; text-align: center;
}
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-wide { width: 100%; }
.btn-quiet { border-color: transparent; text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 4px; padding-left: 4px; padding-right: 4px; }
.btn:disabled { opacity: .4; cursor: default; }
.btn small { font-style: italic; font-size: 15px; opacity: .85; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.btn-row .btn { flex: 1 1 140px; }
.link { background: none; border: 0; padding: 0; color: var(--pencil); text-decoration: underline; text-underline-offset: 3px; font-size: inherit; }

/* ---------- the word: notebook cells and rite choices ---------- */

.w {
  position: relative; display: inline-flex; align-items: center;
  height: var(--line); padding: 0 8px; margin: 0 1px;
  background: none; border: 0; color: var(--ink);
  font-size: 17px; line-height: 1; white-space: nowrap;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.w-text { position: relative; z-index: 1; }
.w .mk { position: absolute; pointer-events: none; overflow: visible; }
.w .mk-circle { inset: 2px -1px 1px -1px; width: calc(100% + 2px); height: calc(100% - 3px); color: var(--pencil); }
.w .mk-strike { left: 3px; right: 3px; top: 0; width: calc(100% - 6px); height: 100%; color: var(--graphite); }
.w.is-struck .w-text { color: var(--ink-2); }
.w.is-implied .w-text { opacity: .42; }
.w.is-implied .mk-strike { opacity: .38; }
.w.is-query::after { content: '?'; position: absolute; top: -3px; right: -2px; font-size: 15px; font-style: italic; color: var(--pencil); }
.w .seal { position: absolute; top: 3px; left: -1px; width: 9px; height: 9px; color: var(--seal); }
.w:disabled { opacity: .35; cursor: default; }
/* A mark the madness moved: the same pencil, a slightly different hand. */
.w.is-drifted .mk-circle { color: var(--drift); }
.w.is-drifted .w-text { color: var(--drift); }
.w.is-lamplit { background: color-mix(in srgb, var(--seal) 12%, transparent); outline: 1px dashed var(--seal); outline-offset: -2px; border-radius: 3px; }
@media (hover: hover) { .w:not(:disabled):hover .w-text { text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 4px; } }

/* ---------- notebook ---------- */

.pages { display: flex; gap: 2px; margin: 0 0 10px; border-bottom: 1px solid var(--rule); }
.page-tab {
  background: none; border: 0; padding: 6px 14px 4px; min-height: 40px;
  font-family: 'Fell SC', 'Fell', serif; font-size: 17px; color: var(--ink-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.page-tab.is-on { color: var(--ink); border-bottom-color: var(--margin); }

.ledger {
  position: relative;
  background: repeating-linear-gradient(to bottom, transparent 0 calc(var(--line) - 1px), var(--rule) calc(var(--line) - 1px) var(--line));
  padding-left: var(--margin-col);
  margin: 0 calc(-1 * var(--gutter));
  padding-right: var(--gutter);
}
.ledger::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: calc(var(--margin-col) - 10px); width: 4px;
  border-left: 1px solid var(--margin); border-right: 1px solid var(--margin); opacity: .65;
}
.nb-row { position: relative; min-height: var(--line); }
.nb-label {
  position: absolute; left: calc(-1 * var(--margin-col) + var(--gutter)); width: calc(var(--margin-col) - var(--gutter) - 14px);
  top: 0; height: var(--line); display: flex; align-items: center;
  font-size: 13px; line-height: 1.05; color: var(--ink-2); font-style: italic;
}
.nb-words { display: flex; flex-wrap: wrap; align-items: center; margin-left: -6px; }
.nb-gap { height: var(--line); }
.nb-hour { display: flex; align-items: center; height: var(--line); }
.nb-hour .moon { width: 15px; height: 15px; margin: 0 6px 0 2px; color: var(--ink-2); }
.nb-hour .phase { width: 92px; font-size: 15px; color: var(--ink-2); font-style: italic; }
.nb-class { font-size: 12px; color: var(--ink-2); font-style: italic; padding: 0 2px 0 8px; height: var(--line); display: inline-flex; align-items: center; }
.nb-title {
  width: 100%; height: var(--line); border: 0; background: transparent; padding: 0 2px;
  font-size: 20px; font-style: italic; color: var(--ink);
}
.nb-title::placeholder, .nb-note::placeholder { color: var(--ink-2); opacity: .7; }
.nb-note {
  width: 100%; min-height: calc(var(--line) * 4); border: 0; resize: vertical;
  background: transparent; padding: 6px 2px 0; line-height: var(--line); font-size: 17px; color: var(--ink);
}
.nb-help { font-size: 14px; color: var(--ink-2); font-style: italic; margin: 10px 0 0; }

.trust { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 2px 12px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.trust-title { font-style: italic; }
.trust-meta { font-size: 14px; color: var(--ink-2); width: 100%; }

/* ---------- desk ---------- */

.post { display: grid; gap: 14px; }
.letter { background: var(--paper-2); padding: 14px 16px; border-left: 2px solid var(--rule); }
.letter p:last-child { margin-bottom: 0; }
.letter.portent { border-left-color: var(--margin); font-style: italic; font-size: 19px; }
.letter.answer { font-style: italic; }
.letter.event { border-left-color: var(--ink); }
/* A note in another hand: no paper of its own, slightly askew, in pencil. */
.letter.margin { background: none; border-left: 1px dashed var(--drift); color: var(--drift); font-style: italic; transform: rotate(-.6deg); }
.pin-row { display: flex; gap: 8px; justify-content: flex-end; }
.clip-head { font-family: 'Fell SC', 'Fell', serif; font-size: 15px; color: var(--ink-2); display: block; margin-bottom: 4px; }
.calendar { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; margin-top: 4px; }
.cal-day { position: relative; display: flex; flex-direction: column; align-items: center; padding: 6px 0 4px; font-size: 13px; color: var(--ink-2); }
.cal-day .ic { width: 20px; height: 20px; color: var(--ink); }
.cal-day.is-now { color: var(--ink); }
.cal-day.is-now .mk { position: absolute; inset: -2px 2px; width: calc(100% - 4px); height: calc(100% + 4px); color: var(--pencil); pointer-events: none; }
.cal-day.is-after { opacity: .35; }
.cal-day.is-conj::after { content: ''; position: absolute; right: 0; top: 4px; bottom: 4px; border-right: 2px solid var(--margin); }

/* ---------- shelf and reader ---------- */

.books { list-style: none; margin: 0; padding: 0; }
.book { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--rule); padding: 12px 0; }
.book-title { font-style: italic; font-size: 18px; line-height: 1.3; }
.book-meta { grid-column: 1; font-size: 14px; color: var(--ink-2); }
.book-cost { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-size: 14px; color: var(--ink-2); text-align: right; }
.book.is-read .book-cost { color: var(--pencil); font-style: italic; }

.reader { max-width: 36em; margin: 0 auto; }
.reader-title { font-size: 26px; line-height: 1.2; font-style: italic; }
.reader-by { color: var(--ink-2); margin: 4px 0 20px; }
.reader p { line-height: 1.62; }
.reader .heading { font-family: 'Fell SC', 'Fell', serif; font-size: 18px; display: block; margin-top: 6px; }
.claim {
  cursor: pointer; border-radius: 2px; text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--pencil) 45%, transparent);
  text-decoration-thickness: 1.5px; text-underline-offset: 4px;
}
.claim.is-pinned { text-decoration-color: var(--pencil); }
.claim .seal { display: inline-block; width: 9px; height: 9px; color: var(--seal); vertical-align: super; margin-left: 2px; }
.reader-hint { font-size: 14px; color: var(--ink-2); font-style: italic; border-top: 1px solid var(--rule); padding-top: 10px; margin-top: 20px; }

/* ---------- rite ---------- */

.pick { margin-top: 14px; }
.pick-label { font-size: 14px; color: var(--ink-2); font-style: italic; }
.pick .nb-words { margin-left: -8px; }
.pick-sub { font-size: 12px; color: var(--ink-2); font-style: italic; margin-left: 3px; }
.mode { display: flex; gap: 6px; margin: 6px 0 0 -8px; }
.mode .w { font-size: 19px; }

.result { border-left: 2px solid var(--margin); padding: 2px 0 2px 14px; margin: 18px 0 0; scroll-margin-top: calc(var(--head-h) + 16px); }
.result p { margin-bottom: .55em; }
.result .ink { animation: ink .7s ease-out both; }
@keyframes ink { from { opacity: 0; filter: blur(1.5px); } to { opacity: 1; filter: none; } }
@media (prefers-reduced-motion: reduce) { .result .ink { animation: none; } .sheet { transition: none !important; } }
.obs { list-style: none; padding: 0; margin: 10px 0 0; }
.obs li { display: flex; align-items: flex-start; gap: 8px; padding: 6px 0; border-top: 1px dotted var(--rule); font-size: 16px; }
.obs-text { flex: 1; }
.pin { min-width: 40px; min-height: 36px; padding: 2px 8px; background: none; border: 1px solid var(--rule); border-radius: 3px; font-family: 'Fell SC', 'Fell', serif; font-size: 15px; color: var(--pencil); }
.pin.is-done { border-color: var(--pencil); }
.obs-head { font-size: 14px; color: var(--ink-2); font-style: italic; margin-top: 12px; }
.market-head { font-size: 17px; font-style: italic; margin: 16px 0 4px; }
.lot { padding: 6px 0 10px; border-bottom: 1px dotted var(--rule); }
.lot p { margin-bottom: 6px; }
.lot .nb-words { margin-left: -8px; }

/* ---------- journal ---------- */

.week-head { font-family: 'Fell SC', 'Fell', serif; font-size: 17px; color: var(--ink-2); border-bottom: 1px solid var(--rule); margin: 24px 0 8px; }
.entry { margin: 0 0 12px; }
.entry.small { font-size: 15px; color: var(--ink-2); font-style: italic; }

/* ---------- sheets ---------- */

.scrim { position: fixed; inset: 0; background: var(--shadow); z-index: 40; opacity: 0; transition: opacity .2s; }
.scrim.is-open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--paper); border-top: 1px solid var(--rule);
  box-shadow: 0 -10px 34px var(--shadow);
  padding: 14px var(--gutter) calc(env(safe-area-inset-bottom) + 20px);
  transform: translateY(102%); transition: transform .22s ease-out;
}
.sheet.is-open { transform: none; }
.sheet-full { top: 0; max-height: none; border-top: 0; padding-top: calc(env(safe-area-inset-top) + 10px); }
.sheet-inner { max-width: 640px; margin: 0 auto; }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.sheet-head h2 { flex: 1; font-size: 22px; line-height: 1.25; padding-top: 6px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; background: none; border: 0; color: var(--ink); flex: none; margin: -4px -8px 0 0; }
.sheet .quote { font-style: italic; border-left: 2px solid var(--rule); padding-left: 12px; margin: 4px 0 14px; }
.marks-preview { list-style: none; padding: 0; margin: 0 0 14px; font-size: 16px; color: var(--ink-2); }
@media (min-width: 700px) {
  .sheet:not(.sheet-full) { left: 50%; right: auto; width: 640px; margin-left: -320px; bottom: 24px; border: 1px solid var(--rule); max-height: 80dvh; }
}

.field { display: block; margin: 12px 0; }
.field select, .field input { display: block; width: 100%; min-height: 44px; margin-top: 4px; padding: 6px 10px; background: var(--paper-2); border: 1px solid var(--rule); border-radius: 3px; font-size: 17px; }
.field span { font-size: 14px; color: var(--ink-2); font-style: italic; }

.rules p { margin-bottom: .6em; }
.rules h3 { font-family: 'Fell SC', 'Fell', serif; font-size: 18px; margin: 16px 0 6px; color: var(--ink-2); }
.ledger-reveal { margin: 0; padding: 0; list-style: none; }
.ledger-reveal li { padding: 10px 0; border-bottom: 1px solid var(--rule); font-size: 16px; }
.ledger-reveal b { font-weight: 400; font-style: italic; font-size: 19px; }

/* ---------- start ---------- */

.start {
  min-height: 100dvh; display: flex; flex-direction: column; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 40px) var(--gutter) calc(env(safe-area-inset-bottom) + 40px) calc(var(--margin-col) + 4px);
  position: relative; max-width: 640px; margin: 0 auto;
}
.start::before { content: ''; position: absolute; top: 0; bottom: 0; left: calc(var(--margin-col) - 14px); width: 4px; border-left: 1px solid var(--margin); border-right: 1px solid var(--margin); opacity: .65; }
.wordmark { font-size: 60px; line-height: 1; letter-spacing: -.01em; }
.start-lede { font-size: 20px; line-height: 1.45; font-style: italic; color: var(--ink-2); margin: 18px 0 28px; max-width: 26em; }
.start .btn { margin-bottom: 10px; }
.circles { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 4px -8px; }
.circles .w { font-size: 19px; }
.circle-blurb { font-size: 16px; font-style: italic; color: var(--ink-2); min-height: 3em; margin-bottom: 14px; }
.start-foot { margin-top: 26px; font-size: 14px; color: var(--ink-2); }

/* M4: today's pantheon, the Codex, the house. */
.daily { border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 12px 0 6px; margin: 6px 0 18px; }
.daily-head { font-family: 'Fell SC', 'Fell', serif; font-size: 18px; color: var(--ink-2); margin: 0 0 4px; }
.start-links { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 18px; font-size: 16px; }
.start-links .link { color: var(--pencil); }
.sigil { display: block; width: 100%; height: 100%; }
.sigil .sg-fill { fill: currentColor; stroke: none; }
.sigil .sg-faint { stroke-opacity: .35; }
.sigil-big { width: 132px; height: 132px; margin: 6px auto 4px; color: var(--seal); }
.codex { list-style: none; margin: 10px 0 0; padding: 0; }
.codex-entry { display: grid; grid-template-columns: 72px 1fr; gap: 14px; align-items: start; padding: 14px 0; border-bottom: 1px solid var(--rule); }
.codex-entry h3 { font-size: 21px; font-style: italic; margin: 0 0 2px; }
.codex-entry h3 small { font-style: normal; font-size: 15px; color: var(--ink-2); }
.codex-entry p { font-size: 16px; margin: 0 0 4px; }
.codex-sigil { width: 72px; height: 72px; color: var(--seal); }
.calendar.is-long { grid-template-columns: repeat(12, 1fr); }
.btn-stack { flex-direction: column; gap: 0; }
.reader > .btn-row:has(+ .section-title) { margin-bottom: 22px; }
.inherit { margin: 8px 0 18px; }
.seed-row { display: flex; gap: 8px; margin-top: 8px; }
.seed-row input { flex: 1; min-width: 0; min-height: 44px; padding: 6px 10px; background: transparent; border: 0; border-bottom: 1px solid var(--rule); font-size: 17px; }

/* ---------- toasts ---------- */

#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); z-index: 60; display: grid; justify-items: center; gap: 6px; pointer-events: none; }
.toast { background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: 3px; font-size: 16px; max-width: calc(100% - 32px); box-shadow: 0 4px 16px var(--shadow); animation: toast 2.6s ease both; }
@keyframes toast { 0% { opacity: 0; transform: translateY(6px); } 10%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }
