/* ReadYourStan Library: e-ink paper, black ink, fountain-pen blue. */
:root {
  --paper: #e8e8e3;
  --sheet: #f6f6f2;
  --ink: #000;
  --pencil: #5c5c57;
  --rule: #c8c8c0;
  --pen: #2b3fa8;
  --pen-soft: #dde1f3;
  --on-pen: #fff;
  --amber: #7a5600;
  --amber-soft: #f1e6c6;
  --red: #9e2a1f;
  --red-soft: #f5dcd8;

  --serif: 'Literata', 'Iowan Old Style', Georgia, serif;
  --hand: 'Homemade Apple', 'Segoe Script', cursive;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --r-small: 3px;
  --r-control: 6px;
  --r-panel: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1a1a19;
    --sheet: #242422;
    --ink: #f0f0ea;
    --pencil: #a6a69f;
    --rule: #3c3c39;
    --pen: #a3b2ff;
    --pen-soft: #262d52;
    --on-pen: #0d1233;
    --amber: #e3c06a;
    --amber-soft: #3a3019;
    --red: #ff8a7a;
    --red-soft: #3d1f1b;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.55 var(--serif);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3, p, ol, ul, dl, dd { margin: 0; }
b { font-weight: 600; }
button, input { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }

/* ---------- Wordmark: an autograph ---------- */
.wordmark {
  font: 400 24px/1.9 var(--hand);
  color: var(--pen);
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.wordmark--large {
  /* Measured ink of "ReadYourStan" in Homemade Apple, tilted -3deg: 7.5em wide, starting 0.1275em
     left of the box (the R's tail). Sizing to column/7.5 and nudging right by 0.1275em puts the
     ink edges exactly on the column edges, which the Sign in / Create account toggle fills. */
  font-size: 46px;
  font-size: calc(100cqi / 7.5);
  margin-left: 0.1275em;
  margin-bottom: 20px;
  line-height: 1.6;
  transform: rotate(-3deg);
  transform-origin: left center;
}

/* ---------- Controls ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 8px 18px;
  border: 1px solid var(--ink); border-radius: var(--r-control);
  background: transparent; color: var(--ink);
  font-weight: 500; font-size: 15px; text-decoration: none;
  cursor: pointer;
}
.button:not(.button--primary, .button--danger):hover { background: var(--sheet); }
.button--primary { background: var(--pen); border-color: var(--pen); color: var(--on-pen); }
.button--danger { background: var(--red); border-color: var(--red); color: var(--sheet); }
.button--primary:hover, .button--danger:hover { filter: brightness(1.12); }
.button:disabled { opacity: 0.55; cursor: progress; }
.button input[type=file] { position: absolute; }

.link {
  padding: 0; border: 0; background: none;
  color: var(--pen); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
  cursor: pointer;
}
.link--danger { color: var(--red); }

.field { display: grid; gap: 6px; font-size: 14px; color: var(--pencil); }
.field input {
  min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--rule); border-radius: var(--r-control);
  background: var(--sheet); color: var(--ink); font-size: 16px;
}
.field input:focus { border-color: var(--pen); outline: 1px solid var(--pen); outline-offset: 0; }

.form { display: grid; gap: 16px; }
.form__hint { font-size: 14px; color: var(--pencil); }
.form__error { color: var(--red); font-size: 15px; min-height: 0; }
.form__error:empty { display: none; }

/* ---------- Signed out ---------- */
.auth {
  width: min(100% - 32px, 380px);
  margin: clamp(40px, 12vh, 120px) auto 64px;
  container-type: inline-size;
}
.segmented {
  display: grid; grid-template-columns: 1fr 1fr;
  border: 1px solid var(--ink); border-radius: var(--r-control);
  overflow: hidden; margin-bottom: 24px;
}
.segmented button {
  min-height: 40px; border: 0; background: transparent; cursor: pointer; font-size: 15px;
}
.segmented button[aria-selected=true] { background: var(--ink); color: var(--paper); }

/* ---------- Signed in ---------- */
.app { width: min(100% - 32px, 1180px); margin: 0 auto; padding-bottom: 80px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 12px 0; margin-bottom: 24px;
  border-bottom: 1px solid var(--rule);
}
.topbar__account { display: flex; align-items: baseline; gap: 18px; font-size: 15px; flex-wrap: wrap; }
.topbar__user { color: var(--pencil); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-areas: "upload rail" "shelf rail";
  grid-template-rows: auto 1fr;
  gap: 40px 56px;
  align-items: start;
}
.upload { grid-area: upload; }
.rail { grid-area: rail; position: sticky; top: 24px; display: grid; gap: 32px; }
.shelf { grid-area: shelf; }

@media (max-width: 880px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "upload" "rail" "shelf"; grid-template-rows: auto; gap: 40px; }
  .rail { position: static; }
}

/* Drop zone */
.dropzone {
  display: grid; justify-items: start; gap: 10px;
  padding: 32px clamp(20px, 4vw, 40px);
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  position: relative;
}
.dropzone::after {
  content: ''; position: absolute; inset: 8px;
  border: 1px dashed var(--rule); border-radius: calc(var(--r-panel) - 5px);
  pointer-events: none;
}
.dropzone > * { position: relative; z-index: 1; }
.dropzone__title { font-size: clamp(24px, 3.4vw, 32px); font-weight: 500; line-height: 1.2; letter-spacing: -0.01em; }
.dropzone__sub { color: var(--pencil); max-width: 52ch; margin-bottom: 8px; }
.dropzone.is-over { border-color: var(--pen); background: var(--pen-soft); }
.dropzone.is-over::after { border-color: var(--pen); }

/* Upload queue */
.queue { list-style: none; padding: 0; display: grid; gap: 2px; margin-top: 12px; }
.queue li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; align-items: baseline;
  padding: 10px 2px; border-bottom: 1px solid var(--rule); font-size: 15px;
}
.queue__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue__status { color: var(--pencil); font-size: 14px; text-align: right; }
.queue__bar { grid-column: 1 / -1; height: 2px; background: var(--rule); overflow: hidden; }
.queue__bar span { display: block; height: 100%; width: 0; background: var(--pen); transition: width 0.2s linear; }
.queue li.is-done .queue__status { color: var(--ink); }
.queue li.is-done .queue__bar, .queue li.is-error .queue__bar, .queue li.is-skip .queue__bar { display: none; }
.queue li.is-error .queue__status { color: var(--red); text-align: left; grid-column: 1 / -1; }

/* Rail */
.rail__title { font-size: 19px; font-weight: 600; margin-bottom: 12px; }
.connect { padding: 24px; background: var(--sheet); border-radius: var(--r-panel); border: 1px solid var(--rule); }
.steps { padding-left: 20px; display: grid; gap: 14px; font-size: 15px; }
.steps li::marker { color: var(--pencil); font-variant-numeric: tabular-nums; }
.copysheet { display: grid; gap: 10px; margin-top: 12px; margin-left: -20px; }
.copysheet__row { display: grid; gap: 3px; }
.copysheet dt { font-size: 13px; color: var(--pencil); }
.copysheet dd {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--rule); border-radius: var(--r-control); background: var(--paper);
  padding: 4px 4px 4px 12px;
}
.copysheet code {
  flex: 1; min-width: 0; font: 14px/1.4 var(--mono); overflow-wrap: anywhere; color: var(--ink);
}
.copy {
  flex: none; min-height: 32px; min-width: 64px; padding: 2px 10px;
  border: 0; border-radius: var(--r-small); background: transparent; color: var(--pen);
  font-size: 14px; cursor: pointer;
}
.copy:hover { background: var(--pen-soft); }
.copy.is-copied { color: var(--ink); }
.note { font-size: 14px; color: var(--pencil); margin-top: 16px; }

.meter { height: 6px; border-radius: 3px; background: var(--rule); overflow: hidden; }
.meter__fill { height: 100%; width: 0; background: var(--ink); }
.meter.is-high .meter__fill { background: var(--red); }
.storage__text { font-size: 15px; color: var(--pencil); margin-top: 8px; font-variant-numeric: tabular-nums; }

/* Shelf */
.shelf__head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.shelf__title { font-size: 24px; font-weight: 500; }
.shelf__title small { font-size: 16px; color: var(--pencil); font-weight: 400; margin-left: 6px; }
.shelf__filter input {
  min-height: 38px; width: min(260px, 70vw); padding: 6px 12px;
  border: 1px solid var(--rule); border-radius: var(--r-control); background: var(--sheet); font-size: 15px;
}
.shelf__empty { color: var(--pencil); max-width: 48ch; }

.books {
  list-style: none; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 32px 22px;
}
.book {
  display: grid; gap: 4px; width: 100%; padding: 0; text-align: left;
  border: 0; background: none; cursor: pointer;
}
.book:hover .cover { transform: translateY(-3px); box-shadow: 0 6px 0 -2px var(--rule); }
.book__title {
  margin-top: 10px; font-size: 15px; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book__author { font-size: 14px; color: var(--pencil); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book__meta { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--pencil); flex-wrap: wrap; }
.tag { border: 1px solid currentColor; border-radius: var(--r-small); padding: 0 5px; font-size: 12px; line-height: 18px; }
.x4-note { font-size: 13px; color: var(--amber); }
.x4-note--no { color: var(--red); }

/* Covers, real or set in type */
.cover {
  aspect-ratio: 2 / 3; width: 100%;
  border-radius: var(--r-small);
  border: 1px solid var(--rule);
  overflow: hidden; background: var(--sheet);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover--set {
  display: grid; align-content: center; justify-items: center; gap: 8px;
  padding: 14px 12px 14px 18px; text-align: center;
  border-left: 5px solid var(--pen);
}
.cover--set .cover__title {
  font-style: italic; font-size: 15px; line-height: 1.25; font-weight: 500;
  overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden;
}
.cover--set .cover__author { font-size: 12px; color: var(--pencil); }
.cover--set .cover__rule { width: 24px; height: 1px; background: var(--ink); }

/* New arrival: an e-ink refresh flash */
.book.is-fresh .cover { animation: eink-refresh 0.42s steps(1, end); }
@keyframes eink-refresh {
  0% { filter: invert(1) grayscale(1); }
  35% { filter: brightness(2.2) grayscale(1); }
  60% { filter: invert(1) grayscale(1); }
  80% { filter: grayscale(1); }
  100% { filter: none; }
}
@media (prefers-reduced-motion: reduce) {
  .book.is-fresh .cover { animation: none; }
  .cover, .queue__bar span { transition: none; }
}

/* ---------- Dialogs ---------- */
.dialog {
  width: min(100% - 32px, 640px); max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--rule); border-radius: var(--r-panel);
  background: var(--sheet); color: var(--ink);
}
.dialog--narrow { width: min(100% - 32px, 420px); }
.dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog__body { padding: 28px; }
.dialog__title { font-size: 22px; font-weight: 500; }

.book-detail { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 28px; }
.book-detail__fields { display: grid; gap: 14px; align-content: start; }
.book-detail__meta { font-size: 14px; color: var(--pencil); overflow-wrap: anywhere; }
.book-detail__x4 { font-size: 14px; }
.book-detail__x4:empty { display: none; }
.book-detail__actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.danger { border-top: 1px solid var(--rule); padding-top: 14px; font-size: 15px; }
.danger--confirm { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; background: var(--red-soft); border: 0; border-radius: var(--r-control); padding: 14px; }
.danger--confirm p { flex-basis: 100%; font-size: 14px; }
@media (max-width: 560px) {
  .book-detail { grid-template-columns: 1fr; }
  .book-detail__cover { width: 120px; }
  .dialog__body { padding: 20px; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 10px 18px; border-radius: var(--r-control); font-size: 15px;
  max-width: calc(100% - 32px);
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.toast.is-on { opacity: 1; }
