/* Shared by the public site and the dashboard: colors, type, buttons, forms, covers. */
:root {
  --paper: #ece7d8;
  --paper-2: #e3dcc7;
  --ink: #1e2927;
  --ink-soft: #505b57;
  --rule: #bdb59b;
  --field: #f5f1e5;
  --accent: #2c4a3a;
  --accent-hover: #203a2d;
  --on-accent: #f3efe2;
  --brass: #8f6f2c;
  --danger: #8c2f2b;
  --grain: .5;
  --shadow: 0 1px 0 rgba(0,0,0,.06), 0 14px 26px -14px rgba(30,41,39,.45);
  --display: 'IM Fell English', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --text: 'Newsreader', 'Iowan Old Style', 'Palatino Linotype', Georgia, 'Times New Roman', serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #161a18; --paper-2: #1e2421; --ink: #e7e1cf; --ink-soft: #a9b0a6;
    --rule: #3b443f; --field: #1b201e; --accent: #9cc3a8; --accent-hover: #b4d4bd;
    --on-accent: #10201a; --brass: #c9a75a; --danger: #e59089; --grain: .18;
    --shadow: 0 1px 0 rgba(0,0,0,.4), 0 14px 26px -14px rgba(0,0,0,.8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #161a18; --paper-2: #1e2421; --ink: #e7e1cf; --ink-soft: #a9b0a6;
  --rule: #3b443f; --field: #1b201e; --accent: #9cc3a8; --accent-hover: #b4d4bd;
  --on-accent: #10201a; --brass: #c9a75a; --danger: #e59089; --grain: .18;
  --shadow: 0 1px 0 rgba(0,0,0,.4), 0 14px 26px -14px rgba(0,0,0,.8);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 5rem; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--text);
  font-size: 1.125rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
/* Paper grain sits behind everything */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  opacity: var(--grain); mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .3 0 0 0 0 .2 0 0 0 .16 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
/* Content sits above the grain. (Not applied to <dialog>, which needs its own top-layer positioning.) */
main, footer, #app { position: relative; z-index: 1; }
a { color: var(--accent); text-underline-offset: .18em; }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 3px; border-radius: 2px; }
h1, h2, h3 { font-family: var(--display); font-weight: 400; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--on-accent); padding: .6rem 1rem; z-index: 200; }
.skip:focus { left: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-size: 1rem; line-height: 1.2; padding: .65rem 1.15rem;
  border: 1px solid var(--accent); border-radius: 3px;
  background: var(--accent); color: var(--on-accent);
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--paper-2); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--paper-2); }
.btn.small { padding: .38rem .75rem; font-size: .95rem; }
.textbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--ink-soft); cursor: pointer; text-decoration: underline; text-underline-offset: .18em; }
.textbtn:hover { color: var(--ink); }

/* ---------- Ornaments ---------- */
.orn { display: flex; align-items: center; gap: .8rem; color: var(--brass); }
.orn::before, .orn::after { content: ""; flex: 1; height: 1px; background: currentColor; opacity: .6; }
.orn i { width: 9px; height: 9px; border: 1px solid currentColor; transform: rotate(45deg); }
.leader { flex: 1; min-width: 1rem; border-bottom: 1px dotted var(--ink-soft); opacity: .65; transform: translateY(-.3em); }

/* ---------- Book covers ---------- */
.cover {
  position: relative; width: 100%; max-width: 230px; container-type: inline-size;
  border-radius: 2px 5px 5px 2px; overflow: hidden; box-shadow: var(--shadow);
}
.cover::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,.30) 0, rgba(255,255,255,.12) 3%, rgba(0,0,0,.14) 6%, transparent 13%);
}
.cover.has-img img { display: block; width: 100%; height: auto; }
.cover.plain { aspect-ratio: 2 / 3; background: linear-gradient(160deg, var(--c1), var(--c2)); color: #f2ead6; }
.cover .frame {
  position: absolute; inset: 6cqw 6cqw 6cqw 10cqw; border: 1px solid rgba(242,234,214,.55);
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 9cqw 4cqw; text-align: center;
}
.cover .ct { font-family: var(--display); font-size: 11.5cqw; line-height: 1.08; }
.cover .cg { font-style: italic; font-size: 6.2cqw; opacity: .85; min-height: 1em; }
.cover .ca { font-size: 6cqw; letter-spacing: .05em; opacity: .9; }
.c-forest   { --c1: #2f4d3a; --c2: #1a2d22; }
.c-oxblood  { --c1: #6d2724; --c2: #3d1412; }
.c-midnight { --c1: #25395c; --c2: #131f38; }
.c-ochre    { --c1: #b27e2c; --c2: #764c12; }
.c-plum     { --c1: #5b3656; --c2: #331f31; }
.c-slate    { --c1: #4b5762; --c2: #2a3239; }

/* ---------- Forms ---------- */
input, select, textarea {
  width: 100%; font: inherit; font-size: 1rem; padding: .55rem .7rem;
  border: 1px solid var(--rule); border-radius: 3px; background: var(--field); color: var(--ink);
}
input[type="file"] { padding: .4rem; }
input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--accent); flex: none; }
.check { display: flex; align-items: center; gap: .6rem; font-weight: 400; cursor: pointer; }
textarea { min-height: 7rem; resize: vertical; line-height: 1.55; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1.1rem; }
.field { display: grid; gap: .3rem; margin-bottom: 1.1rem; align-content: start; }
.field.wide { grid-column: 1 / -1; }
.field label { font-weight: 500; font-size: 1rem; }
.hint { margin: 0; color: var(--ink-soft); font-size: .92rem; line-height: 1.4; }
.form-error { margin: 0 0 1rem; padding: .6rem .8rem; border-left: 3px solid var(--danger); color: var(--danger); background: var(--paper-2); }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- Dialogs and toast ---------- */
dialog {
  border: 1px solid var(--ink-soft); background: var(--paper); color: var(--ink); padding: 0;
  width: min(720px, calc(100vw - 1.5rem)); max-height: calc(100dvh - 1.5rem); overflow: auto;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.55);
}
dialog::backdrop { background: rgba(16, 22, 19, .6); }
dialog[open] { animation: rise .18s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
#toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 20px); z-index: 100;
  background: var(--ink); color: var(--paper); padding: .65rem 1.1rem; border-radius: 3px;
  font-size: 1rem; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 2rem);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  dialog[open] { animation: none; }
  #toast { transition: none; }
}
