/* Reading Archive — "card catalogue" design.
   Manila cards on a bankers-lamp green desk; review state is an ink stamp. */

:root {
  --desk: #1f3b2c;        /* deep green — header band, login field */
  --page: #e6decb;        /* the desk blotter the cards sit on */
  --card: #f4ecd9;        /* manila card stock */
  --edge: #d5c8a8;        /* card edge */
  --ink: #2a2620;         /* warm near-black text */
  --dim: #7d745f;         /* pencil grey-brown */
  --stamp: #b8402c;       /* red ink pad */
  --pen: #2b4a73;         /* fountain-pen blue: links, focus */
  --leaf: #33684b;        /* green ink: keep verdict, buttons */
  --cream: #f0e8d4;       /* text on green */
  --shadow: 0 1px 3px rgba(58, 48, 22, 0.14);
}
@media (prefers-color-scheme: dark) {
  :root {
    --desk: #142019;
    --page: #191e19;
    --card: #262b22;
    --edge: #3b4033;
    --ink: #e7dfca;
    --dim: #9a947e;
    --stamp: #e0674c;
    --pen: #92b4dc;
    --leaf: #8cb496;
    --cream: #e7dfca;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.serif {
  font-family: "Fraunces", Georgia, serif;
  font-optical-sizing: auto;
}
.mono {
  font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace;
}

main {
  max-width: 40rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 5rem;
}

/* ---- header: the ledger binding ---- */
header { background: var(--desk); }
nav {
  max-width: 40rem;
  margin: 0 auto;
  padding: 0.9rem 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.2rem;
  align-items: baseline;
}
.brand {
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-weight: 500;
  font-size: 1.15rem;
  color: var(--cream);
  text-decoration: none;
  margin-right: auto;
}
.navlink {
  font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cream);
  opacity: 0.75;
  text-decoration: none;
}
.navlink:hover, .navlink.here { opacity: 1; }
.navlink.here { border-bottom: 2px solid var(--stamp); padding-bottom: 2px; }

/* ---- page heading ---- */
h1 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.7rem;
  line-height: 1.2;
  margin: 1.2rem 0 0.2rem;
}
.count {
  color: var(--dim);
  font-size: 0.85rem;
  margin: 0 0 1.4rem;
}
h2 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.15rem;
  margin: 2.2rem 0 0.6rem;
}

a { color: var(--pen); }
.dim { color: var(--dim); }
.error { color: var(--stamp); font-weight: 600; }
.note { font-style: italic; }

/* ---- the cards ---- */
.item-list { list-style: none; padding: 0; margin: 0; }
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 0.8rem 1rem 0.75rem;
  margin-bottom: 0.7rem;
}
@media (prefers-reduced-motion: no-preference) {
  .card { transition: transform 0.12s ease; }
  .card:hover { transform: translateY(-1px); }
}

.eyebrow {
  font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  font-size: 0.66rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 0.25rem;
}

.item-title {
  display: block;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.06rem;
  line-height: 1.35;
  color: var(--ink);
  text-decoration: none;
  word-break: break-word;
  padding-right: 6.5rem;   /* room for the stamp */
}
.item-title:hover { color: var(--pen); }

.meta {
  color: var(--dim);
  font-size: 0.82rem;
  margin-top: 0.3rem;
}
.meta a { word-break: break-all; }

/* ---- the signature: the ink stamps (a card can wear several) ---- */
.stamp-stack {
  position: absolute;
  top: 0.75rem;
  right: 0.8rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  z-index: 1;
}
.stamp {
  font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--stamp);
  border: 2px solid currentColor;
  border-radius: 4px;
  padding: 0.14em 0.5em 0.1em;
  opacity: 0.88;
  white-space: nowrap;
}
/* hand-stamped look: each sits at a slightly different angle */
.stamp-stack .stamp:nth-child(odd)  { transform: rotate(-3deg); }
.stamp-stack .stamp:nth-child(even) { transform: rotate(2.5deg); }
.stamp-review { color: var(--stamp); }
.stamp-keep { color: var(--leaf); }
.stamp-skim-later { color: var(--pen); }
.stamp-discard { color: var(--stamp); }
.stamp-watch-again { color: var(--leaf); }
.stamp-skim { color: var(--pen); }
.stamp-skip { color: var(--stamp); }

/* inline row — for the item-page heading */
.stamp-stack-inline {
  position: static;
  display: inline-flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.4rem;
  vertical-align: 0.2em;
  margin-left: 0.3rem;
}
.stamp-stack-inline .stamp:nth-child(n) { transform: rotate(-2deg); }

/* ---- forms ---- */
textarea, input[type="text"], input[type="search"],
input[type="password"], select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
}
textarea { resize: vertical; }
select, input[type="search"] { width: auto; }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 1px; }

button {
  padding: 0.55rem 1.15rem;
  border: none;
  border-radius: 6px;
  background: var(--leaf);
  color: var(--cream);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.5rem;
}
button:hover { filter: brightness(1.08); }
button.secondary {
  background: transparent;
  border: 1px solid var(--edge);
  color: var(--dim);
  font-weight: 400;
}
button.danger { color: var(--stamp); border-color: var(--stamp); }

.add-form { margin-bottom: 2rem; }
.add-form textarea {
  background: var(--card);
  border-color: var(--edge);
}

.filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1.4rem;
}
.filter-form input[type="search"] { flex: 1; min-width: 9rem; }
.filter-form button { margin-top: 0; }

/* ---- item page ---- */
.review {
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 0.35rem 1.2rem 1rem;
  overflow-x: auto;
}
.review h2:first-child { margin-top: 0.8rem; }
.review pre { overflow-x: auto; }

.notes-log {
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 0.8rem 1rem;
  margin-bottom: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.doc-page { margin-top: 1.4rem; }
.doc-page .mermaid { display: flex; justify-content: center; overflow-x: auto; background: transparent; }

.verdict-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0.75rem 0;
}
.verdict-opt { white-space: nowrap; }

.danger-zone {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--edge);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}
.danger-zone .inline { display: flex; gap: 0.5rem; align-items: center; }
.danger-zone input[type="text"] { width: 13rem; }
.danger-zone button { margin-top: 0; }

/* ---- shelf chips: the drawer labels ---- */
.shelf-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: -0.4rem 0 1.2rem;
}
.chip {
  font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  text-decoration: none;
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 0.25em 0.8em;
  background: var(--card);
}
.chip:hover { color: var(--pen); border-color: var(--pen); }
.chip.here {
  color: var(--cream);
  background: var(--desk);
  border-color: var(--desk);
}

.saved-tick { color: var(--leaf); }

/* ---- the watch side: video cards wear their thumbnail ---- */
.video-card { display: flex; gap: 0.9rem; }
.video-card .thumb {
  flex: 0 0 8.5rem;
  align-self: flex-start;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--edge);
}
.video-card .thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}
.video-card .video-body { min-width: 0; flex: 1; position: relative; }
@media (max-width: 30rem) {
  .video-card .thumb { flex-basis: 6rem; }
}

/* video reading room: the thumbnail is the doorway to YouTube */
.video-lead {
  position: relative;
  display: block;
  max-width: 30rem;
  margin: 0 0 1.4rem;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--edge);
  box-shadow: var(--shadow);
}
.video-lead img { display: block; width: 100%; }
.play-badge {
  position: absolute;
  left: 0.7rem;
  bottom: 0.7rem;
  font-size: 0.66rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: #fff;
  background: rgba(0, 0, 0, 0.65);
  border-radius: 4px;
  padding: 0.35em 0.7em;
}
.transcript-label {
  font-size: 0.66rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 0.5rem;
}

/* type chips: checkable, wrap freely */
.type-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.2rem 0 0.5rem;
}
.type-chip {
  font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 0.25em 0.7em;
  cursor: pointer;
  user-select: none;
}
.type-chip:has(input:checked) {
  color: var(--cream);
  background: var(--desk);
  border-color: var(--desk);
}
.type-chip input { accent-color: var(--leaf); margin-right: 0.25em; }
.type-add { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.type-add input { flex: 1; }
.type-add button { margin-top: 0; white-space: nowrap; }
.read-link { font-weight: 600; }

.shelf-pick {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}
.shelf-pick select { width: auto; }

/* ---- the reading room: paper on the desk, notepad beside it ---- */
body.reading main {
  max-width: 74rem;
  padding-bottom: 6rem;
}
.reading-room { position: relative; }
@media (min-width: 62rem) {
  .reading-room {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 20rem;
    gap: 1.6rem;
    align-items: start;
  }
  .margin {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
  }
  .drawer-toggle { display: none; }
}

.paper {
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 1.6rem clamp(1rem, 4vw, 2.6rem) 2.4rem;
  margin-top: 1.2rem;
  overflow-wrap: break-word;
}
.paper-title {
  margin: 0.3rem 0 1.2rem;
  font-size: clamp(1.5rem, 3vw, 2rem);
}
.byline {
  color: var(--dim);
  font-size: 0.85rem;
  font-style: italic;
  margin: -0.7rem 0 1.6rem;
}
.paper-body {
  font-family: Charter, Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
  line-height: 1.65;
  max-width: 42rem;
}
.paper-body img { max-width: 100%; height: auto; }
.paper-body pre {
  overflow-x: auto;
  background: var(--page);
  border: 1px solid var(--edge);
  border-radius: 6px;
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
}
.paper-body h1, .paper-body h2, .paper-body h3 {
  font-family: "Fraunces", Georgia, serif;
  line-height: 1.25;
  margin: 1.6em 0 0.5em;
}
.paper-body blockquote {
  margin: 1em 0;
  padding-left: 1em;
  border-left: 3px solid var(--edge);
  color: var(--dim);
}
.paper-body table { display: block; overflow-x: auto; border-collapse: collapse; }
.paper-body td, .paper-body th { border: 1px solid var(--edge); padding: 0.3em 0.6em; }

.snap-warn {
  color: var(--dim);
  font-style: italic;
  border: 1px dashed var(--edge);
  border-radius: 6px;
  padding: 0.6rem 0.9rem;
}

/* the notepad */
.margin {
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem 1.2rem;
  margin-top: 1.2rem;
}
.margin-label {
  font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  font-size: 0.66rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 1.1rem 0 0.35rem;
}
.margin-links { display: flex; gap: 1rem; font-size: 0.75rem; }
.margin .notes-log { margin-top: 0; font-size: 0.9rem; }
.margin .notes-log.hidden { display: none; }
.margin textarea { font-size: 0.95rem; }
.margin .review { padding: 0 0.9rem 0.6rem; font-size: 0.9rem; box-shadow: none; }
.margin-review summary { cursor: pointer; }
.margin-review summary.margin-label { display: list-item; }
.note-saved { color: var(--leaf); font-size: 0.75rem; margin-left: 0.6rem; }
.file-away {
  margin-top: 1.4rem;
  padding-top: 0.9rem;
  border-top: 1px dashed var(--edge);
}
.file-away .margin-label { margin-top: 0; }
.shelf-form select { width: 100%; }

/* mobile: the notepad becomes a slide-up drawer */
@media (max-width: 61.99rem) {
  .drawer-toggle {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 30;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    margin: 0;
  }
  .margin {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    margin: 0;
    max-height: 72vh;
    overflow-y: auto;
    border-radius: 12px 12px 0 0;
    transform: translateY(105%);
    visibility: hidden;
  }
  @media (prefers-reduced-motion: no-preference) {
    .margin { transition: transform 0.22s ease, visibility 0.22s; }
  }
  body.drawer-open .margin {
    transform: translateY(0);
    visibility: visible;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.25);
  }
}

/* ---- login: a card on the desk ---- */
.login-body { background: var(--desk); }
.login-box {
  max-width: 21rem;
  margin: 16vh auto 0;
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 1.8rem 1.6rem 1.6rem;
  text-align: center;
}
.login-box h1 { margin: 0 0 1rem; font-size: 1.4rem; }
.login-box input { margin-bottom: 0.75rem; }
.login-box button { width: 100%; }
