/* Thousand Year Old Vampire — Companion Notebook
   The organising idea is the palimpsest: a page written, scraped, and written
   again, where the earlier text stays faintly visible under the new. */

@import url('../fonts/fonts.css');

:root {
  --vellum:      #E8E0CE;
  --vellum-deep: #DDD2BA;
  --iron-fresh:  #23252B;
  --iron-aged:   #6B5334;
  --verdigris:   #3F6B62;
  --rubric:      #8C3A2B;

  --page: var(--vellum);
  --card: var(--vellum-deep);
  --ink: var(--iron-fresh);
  --aged: var(--iron-aged);
  --accent: var(--verdigris);
  --danger: var(--rubric);
  --rule: color-mix(in srgb, var(--iron-fresh) 18%, transparent);
  --rule-strong: color-mix(in srgb, var(--iron-fresh) 32%, transparent);
  --shadow: 0 1px 0 color-mix(in srgb, var(--iron-fresh) 10%, transparent);

  --display: 'Fraunces', Georgia, serif;
  --body: 'Spectral', Georgia, serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;

  --measure: 40rem;
  --tap: 44px;
  --pad: 1rem;
  color-scheme: light;
}

/* The night theme inverts to a deep ink ground; the aged/fresh relationship
   has to survive the inversion, so aged becomes a warmer, dimmer vellum
   rather than a darker brown. Both pairs clear 4.5:1. */
[data-theme='night'] {
  --page: #171922;
  --card: #1E212C;
  --ink: #E4DCC8;
  --aged: #A08A63;
  --accent: #7FB3A6;
  --danger: #D08475;
  --rule: color-mix(in srgb, #E4DCC8 16%, transparent);
  --rule-strong: color-mix(in srgb, #E4DCC8 30%, transparent);
  --shadow: none;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  [data-theme='system'] {
    --page: #171922; --card: #1E212C; --ink: #E4DCC8; --aged: #A08A63;
    --accent: #7FB3A6; --danger: #D08475;
    --rule: color-mix(in srgb, #E4DCC8 16%, transparent);
    --rule-strong: color-mix(in srgb, #E4DCC8 30%, transparent);
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
  overflow-wrap: break-word;
}

h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.15; margin: 0 0 .4em; }
h1 { font-size: 1.9rem; font-variation-settings: 'opsz' 96, 'WONK' 1, 'SOFT' 20; letter-spacing: -.01em; }
h2 { font-size: 1.35rem; font-variation-settings: 'opsz' 40, 'WONK' 1; }
h3 { font-size: 1.05rem; font-variation-settings: 'opsz' 20, 'WONK' 1; }

/* Utility type: anything the *game* tracks. Never what the player writes. */
.u, .promptref, .count, .badge, .stamp, .log-line, kbd {
  font-family: var(--mono);
  font-size: .74rem;
  letter-spacing: .04em;
  text-transform: none;
}

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

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; padding: 0; color: inherit; }

.btn {
  min-height: var(--tap); padding: .4rem .9rem;
  border: 1px solid var(--rule-strong); border-radius: 3px;
  background: var(--card); color: var(--ink);
  font-family: var(--mono); font-size: .78rem; letter-spacing: .04em;
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--page); }
.btn-primary:hover:not(:disabled) { color: var(--page); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--rubric) 45%, transparent); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: var(--page); border-color: var(--danger); }
.btn-quiet { border-color: transparent; background: none; min-height: 2rem; padding: .2rem .5rem; }
.btn-quiet:hover { border-color: var(--rule); }
.btn-sm { min-height: 2rem; padding: .15rem .5rem; font-size: .7rem; }

input[type=text], input[type=number], textarea, select {
  width: 100%; background: transparent; color: var(--ink);
  border: none; border-bottom: 1px solid var(--rule-strong);
  padding: .45rem .1rem; font-family: var(--body); min-height: var(--tap);
}
input:focus, textarea:focus { outline: none; border-bottom-color: var(--accent); }
textarea { resize: vertical; line-height: 1.65; }
label.field { display: block; margin: .8rem 0; }
label.field > span { display: block; font-family: var(--mono); font-size: .72rem;
  letter-spacing: .05em; color: var(--aged); margin-bottom: .1rem; }

/* ---------------------------------------------------------- the signature */
/* Struck items stay in place, in aged ink, with a hairline rule at 60% and a
   very slight downward drift. Nothing else is as expressive as this. */

.aged, del.aged {
  color: var(--aged);
  /* A real hairline strikethrough at 60%, which follows wrapped lines the way
     a drawn rule cannot, and prints as a genuine strikethrough. */
  text-decoration: line-through;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, currentColor 60%, transparent);
  text-underline-offset: 0;
  transform: translateY(.5px);
  display: inline;
}
del { text-decoration: none; }
.aged-fade { transition: color 400ms ease; }
@media (prefers-reduced-motion: reduce) { .aged-fade { transition: none; } }

/* A mention of something lost ages automatically. */
.ref { color: var(--accent); text-decoration: none; border-bottom: 1px dotted currentColor; }
.ref.gone { color: var(--aged); border-bottom-style: solid; opacity: .95; }
.ref.dangling { color: var(--aged); border-bottom: none; }

/* ---------------------------------------------------------- layout */

#app { min-height: 100vh; display: flex; flex-direction: column; }
.wrap { width: 100%; max-width: var(--measure); margin: 0 auto; padding: 0 var(--pad); }
.wrap-wide { max-width: 68rem; }

header.top {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--page) 94%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--rule);
}
.top-row { display: flex; align-items: center; gap: .5rem; padding: .4rem 0; min-height: 3rem; }
.top-name { font-family: var(--display); font-size: 1rem; font-variation-settings: 'opsz' 20,'WONK' 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.top-actions { display: flex; gap: .15rem; align-items: center; }
.savedot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--rule-strong); flex: none; }
.savedot.dirty { background: var(--accent); }

nav.views { display: flex; gap: .1rem; overflow-x: auto; border-bottom: 1px solid var(--rule);
  scrollbar-width: none; }
nav.views::-webkit-scrollbar { display: none; }
nav.views a {
  font-family: var(--mono); font-size: .72rem; letter-spacing: .06em; text-transform: uppercase;
  padding: .55rem .6rem; color: var(--aged); text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent; min-height: 2.4rem; display: flex; align-items: center;
}
nav.views a[aria-current='page'] { color: var(--ink); border-bottom-color: var(--accent); }

main { flex: 1; padding: 1rem 0 6rem; }

.sheet-cols { display: grid; gap: 1.5rem; }
@media (min-width: 62rem) {
  .wrap.sheet { max-width: 68rem; }
  .sheet-cols { grid-template-columns: 1.35fr 1fr; align-items: start; }
}

section.card {
  background: var(--card); border: 1px solid var(--rule);
  border-radius: 4px; padding: .8rem .9rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.sec-head { display: flex; align-items: baseline; gap: .5rem; margin-bottom: .4rem; }
.sec-head h2 { margin: 0; flex: 1; }
.sec-head .count { color: var(--aged); }

ul.rows { list-style: none; margin: 0; padding: 0; }
li.row { display: flex; gap: .5rem; align-items: flex-start; padding: .35rem 0;
  border-bottom: 1px solid var(--rule); }
li.row:last-child { border-bottom: none; }
.row-text { flex: 1; min-width: 0; }
.row-text[contenteditable] { outline: none; }
.row-actions { display: flex; gap: .1rem; flex: none; align-items: center; }
.row-note { display: block; color: var(--aged); font-size: .85rem; font-style: italic; }
.badge { color: var(--aged); border: 1px solid var(--rule-strong); border-radius: 2px;
  padding: 0 .3rem; flex: 0 1 auto; align-self: center; min-width: 0; }
.badge.warn { color: var(--danger); border-color: color-mix(in srgb, var(--rubric) 40%, transparent); }

.addline { display: flex; gap: .4rem; align-items: center; padding-top: .3rem; }
.addline input { border-bottom-style: dashed; }
.empty { color: var(--aged); font-style: italic; padding: .4rem 0; }

/* memories */
.mem { border: 1px solid var(--rule); border-radius: 3px; padding: .55rem .7rem; margin-bottom: .6rem;
  background: color-mix(in srgb, var(--page) 45%, var(--card)); }
.mem.gone { border-style: dashed; }
.mem-head { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.mem-title { flex: 1 1 auto; min-width: 10rem; font-family: var(--display); font-size: 1rem;
  font-variation-settings:'opsz' 14,'WONK' 1; }
/* A memory's state badge can be long ("in A vellum book…, lost"), so give it
   its own line rather than letting it crush the title. */
.mem-head .badge { order: 9; flex: 0 1 auto; align-self: flex-start; margin-top: .15rem; }
.mem-head::after { content: ''; order: 8; flex-basis: 100%; height: 0; }
.mem-title:empty::before { content: 'Untitled'; color: var(--aged); font-style: italic; }
ol.exps { margin: .3rem 0 .2rem; padding-left: 1.2rem; }
ol.exps li { padding: .1rem 0; }
ol.exps li::marker { font-family: var(--mono); font-size: .7rem; color: var(--aged); }
.exp-meta { color: var(--aged); margin-left: .35rem; }

.chip { font-family: var(--mono); font-size: .7rem; padding: .15rem .4rem; border: 1px solid var(--rule-strong);
  border-radius: 999px; color: var(--aged); background: none; }
.chip[aria-pressed='true'], .chip.on { color: var(--page); background: var(--accent); border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }

/* dialogs */
dialog {
  border: 1px solid var(--rule-strong); border-radius: 5px; background: var(--page); color: var(--ink);
  padding: 0; max-width: min(38rem, 94vw); width: 100%; box-shadow: 0 8px 40px rgba(0,0,0,.28);
}
dialog::backdrop { background: color-mix(in srgb, var(--iron-fresh) 55%, transparent); }
.dlg-body { padding: 1rem 1.1rem; max-height: 70vh; overflow: auto; }
.dlg-foot { display: flex; gap: .5rem; justify-content: flex-end; padding: .7rem 1.1rem;
  border-top: 1px solid var(--rule); flex-wrap: wrap; }
.dlg-foot .spacer { flex: 1; }
.opt { display: block; width: 100%; text-align: left; border: 1px solid var(--rule-strong);
  border-radius: 3px; padding: .6rem .7rem; margin-bottom: .5rem; background: var(--card); }
.opt:hover { border-color: var(--accent); }
.opt[disabled] { opacity: .6; }
.opt .opt-title { font-family: var(--mono); font-size: .76rem; letter-spacing: .04em; display: block; }
.opt .opt-why { color: var(--aged); font-size: .87rem; font-style: italic; }

/* toast */
#toasts { position: fixed; left: 0; right: 0; bottom: 4.2rem; z-index: 60; display: flex;
  flex-direction: column; align-items: center; gap: .4rem; pointer-events: none; padding: 0 var(--pad); }
.toast { pointer-events: auto; background: var(--card); border: 1px solid var(--rule-strong);
  border-radius: 4px; padding: .5rem .7rem; display: flex; gap: .7rem; align-items: center;
  box-shadow: 0 4px 18px rgba(0,0,0,.18); max-width: var(--measure); width: 100%; }
.toast .t-msg { flex: 1; font-size: .9rem; }

/* banners */
.banner { border: 1px solid var(--rule-strong); border-left: 3px solid var(--accent);
  background: var(--card); padding: .55rem .75rem; margin: .6rem 0; display: flex; gap: .6rem;
  align-items: center; flex-wrap: wrap; font-size: .9rem; }
.banner.warn { border-left-color: var(--danger); }
.banner .b-msg { flex: 1; min-width: 12rem; }

/* quick add */
.quickadd { position: fixed; right: 1rem; bottom: 1rem; z-index: 50;
  width: 3.4rem; height: 3.4rem; border-radius: 50%; background: var(--accent); color: var(--page);
  font-size: 1.5rem; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.28); border: none; }

/* shelf */
.shelf-item { display: block; width: 100%; text-align: left; border: 1px solid var(--rule);
  background: var(--card); border-radius: 4px; padding: .8rem .9rem; margin-bottom: .7rem; }
.shelf-item:hover { border-color: var(--accent); }
.shelf-name { font-family: var(--display); font-size: 1.2rem; font-variation-settings:'opsz'40,'WONK'1; }
.shelf-meta { color: var(--aged); display: flex; gap: .8rem; flex-wrap: wrap; margin-top: .2rem; }

/* chronicle */
.entry { margin-bottom: 2rem; }
.entry-body { max-width: 68ch; }
.entry-body p { margin: 0 0 .9em; }
.entry-body blockquote { border-left: 2px solid var(--rule-strong); margin: 0 0 .9em; padding-left: .9rem;
  color: var(--aged); font-style: italic; }
.entry-editor { width: 100%; border: none; border-bottom: none; min-height: 12rem; background: transparent;
  font-family: var(--body); font-size: 1.02rem; line-height: 1.7; padding: 0; }
.read-mode .entry { border-bottom: 1px solid var(--rule); padding-bottom: 1.5rem; }

/* archive */
.arch-row { display: flex; gap: .5rem; align-items: flex-start; padding: .5rem 0;
  border-bottom: 1px solid var(--rule); width: 100%; text-align: left; background: none; }
.arch-row:hover { background: color-mix(in srgb, var(--card) 60%, transparent); }
.arch-icon { font-family: var(--mono); font-size: .68rem; color: var(--aged); flex: none; width: 4.6rem;
  padding-top: .2rem; }
.arch-main { flex: 1; min-width: 0; }
.filter-rail { margin-bottom: 1rem; }
.filter-group { margin-bottom: .6rem; }
.filter-group > .u { color: var(--aged); display: block; margin-bottom: .25rem; }

/* history */
.log-group { margin-bottom: 1.2rem; }
.log-group h3 { color: var(--aged); font-family: var(--mono); font-size: .74rem; letter-spacing: .08em;
  border-bottom: 1px solid var(--rule); padding-bottom: .2rem; }
.log-line { display: flex; gap: .5rem; padding: .18rem 0; align-items: baseline; font-size: .8rem; }
.log-line .l-sum { flex: 1; font-family: var(--body); font-size: .95rem; letter-spacing: 0; }

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: .8rem; }
.stat { border: 1px solid var(--rule); border-radius: 3px; padding: .6rem .7rem; background: var(--card); }
.stat .n { font-family: var(--display); font-size: 1.7rem; display: block; line-height: 1.1; }
.stat .l { color: var(--aged); }
.bar { display: flex; height: .9rem; border-radius: 2px; overflow: hidden; border: 1px solid var(--rule-strong); }
.bar > span { display: block; }
.bar-key { display: flex; gap: .8rem; flex-wrap: wrap; margin-top: .3rem; color: var(--aged); }
.bar-key i { width: .7rem; height: .7rem; display: inline-block; border-radius: 1px; margin-right: .25rem; }
.keepsake { border: 1px solid var(--rule-strong); border-left: 3px solid var(--aged); padding: .7rem .9rem;
  background: var(--card); margin: .6rem 0; }

.hint { color: var(--aged); font-size: .87rem; font-style: italic; }
.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; }

/* print — a clean sheet and chronicle on paper; never the dark theme */
@media print {
  :root, [data-theme='night'], [data-theme='system'] {
    --page: #fff; --card: #fff; --ink: #000; --aged: #555; --accent: #000;
    --rule: #ccc; --rule-strong: #999; --shadow: none;
  }
  body { font-size: 11pt; background: #fff; color: #000; }
  header.top, nav.views, .quickadd, .addline, #toasts, .banner, .no-print,
  button, .chip, .row-actions, .menu-pop { display: none !important; }
  .wrap, .wrap.sheet, .wrap-wide { max-width: none; padding: 0; }
  /* One column on paper, whatever the screen was doing. */
  .sheet-cols { display: block; }
  section.card, .mem, .mem.gone, .keepsake, .stat { border: 0; padding: 0;
    margin: 0 0 .7rem; background: none; box-shadow: none; break-inside: avoid; }
  section.card { margin-bottom: 1.2rem; }
  h2 { border-bottom: 1px solid #000; padding-bottom: .1rem; margin-top: 1rem; }
  .badge { border: 0; padding: 0; color: #555; }
  .badge::before { content: '('; } .badge::after { content: ')'; }
  .aged, del.aged { text-decoration: line-through; text-decoration-color: currentColor; }
  .entry, .log-group, li.row { break-inside: avoid; }
  li.row { border-bottom: 1px solid #eee; }
  a { color: #000; text-decoration: none; }
  .ref { border-bottom: 0; }
  @page { margin: 18mm 16mm; }
}
