:root {
    --ground: #131316;
    --surface: #1c1c21;
    --raised: #26262d;
    --hairline: #32323a;

    --ink: #f2f2f5;
    --ink-dim: #9a9aa8;
    --ink-faint: #6d6d7b;

    --mint: #a9e3c8;
    --sky: #a7cdf5;
    --butter: #f2dca4;
    --peach: #f6b9a5;
    --rose: #f0b2cb;
    --sage: #c6dcab;

    --on-pastel: #16181a;

    --display: "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --body: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

    --r-lg: 20px;
    --r-md: 14px;
    --r-sm: 10px;
  }

  * { box-sizing: border-box; }

/* Must win over display rules on label/div, or [hidden] rows still render. */
[hidden] { display: none !important; }

  body {
    margin: 0;
    background: var(--ground);
    color: var(--ink);
    font-family: var(--body);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }

  button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
  :focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; }

  .wrap { max-width: 940px; margin: 0 auto; padding: 0 20px 80px; }

  /* ---------- Masthead ---------- */

  header.masthead {
    padding: 28px 0 18px;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
  }

  .wordmark {
    font-family: var(--display);
    font-weight: 600;
    font-size: 27px;
    letter-spacing: -0.02em;
    margin: 0;
    line-height: 1.1;
  }
  .wordmark .amp { color: var(--mint); font-weight: 400; }
  .subtitle { margin: 3px 0 0; color: var(--ink-faint); font-size: 13px; }

  .tallies { display: flex; gap: 24px; flex-wrap: wrap; }
  .tally-n {
    font-family: var(--display);
    font-size: 22px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
  }
  .tally-l {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--ink-faint);
    margin-top: 2px;
    white-space: nowrap;
  }
  .t-book .tally-n { color: var(--mint); }
  .t-movie .tally-n { color: var(--peach); }
  .t-other .tally-n { color: var(--sky); }
  .t-stars .tally-n { color: var(--butter); }

  /* ---------- Controls ---------- */

  .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }

  .btn-add {
    background: var(--mint);
    color: var(--on-pastel);
    border: none;
    border-radius: var(--r-md);
    padding: 10px 18px;
    font-weight: 700;
    font-family: var(--display);
    cursor: pointer;
    transition: filter .15s ease;
  }
  .btn-add:hover { filter: brightness(1.07); }

  .field {
    background: var(--surface);
    border: 1px solid transparent;
    border-radius: var(--r-md);
    padding: 9px 13px;
    transition: border-color .15s ease, background .15s ease;
    min-width: 0;
  }
  .field:focus { outline: none; border-color: var(--mint); background: var(--raised); }
  .field::placeholder { color: var(--ink-faint); }

  #q { flex: 1 1 170px; }
  select.field { cursor: pointer; }

  .chiprow {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 3px;
    background: var(--surface);
    border-radius: var(--r-md);
    margin-bottom: 20px;
    scrollbar-width: thin;
  }
  .chiprow button {
    background: none; border: none; cursor: pointer;
    color: var(--ink-dim);
    padding: 7px 15px;
    border-radius: 11px;
    white-space: nowrap;
    transition: background .15s ease, color .15s ease;
  }
  .chiprow button:hover { color: var(--ink); }
  .chiprow button[aria-pressed="true"] { background: var(--raised); color: var(--ink); font-weight: 500; }
  .chiprow .n { color: var(--ink-faint); font-size: 12px; margin-left: 5px; font-variant-numeric: tabular-nums; }

  .btn-fill {
    background: none;
    border: 1px dashed var(--hairline);
    color: var(--ink-dim);
    border-radius: var(--r-md);
    padding: 9px 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color .15s ease, color .15s ease;
  }
  .btn-fill:hover { border-color: var(--mint); color: var(--mint); }
  .btn-fill[hidden] { display: none; }

  /* ---------- Grid ---------- */

  .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(266px, 1fr)); gap: 10px; }

  .entry {
    display: flex;
    gap: 13px;
    background: var(--surface);
    border-radius: var(--r-lg);
    padding: 14px;
    cursor: pointer;
    text-align: left;
    border: none;
    width: 100%;
    transition: background .15s ease, transform .1s ease;
  }
  .entry:hover { background: var(--raised); }
  .entry:active { transform: scale(.99); }

  .tile {
    width: 52px; height: 70px;
    border-radius: var(--r-sm);
    flex-shrink: 0;
    display: grid;
    place-items: center;
    font-family: var(--display);
    font-size: 25px;
    font-weight: 600;
    color: var(--on-pastel);
    position: relative;
    overflow: hidden;
  }
  .tile .kind {
    position: absolute; bottom: 3px; right: 5px;
    font-family: var(--body);
    font-size: 8px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .06em;
    opacity: .62;
  }
  /* Real cover art, embedded in the record — the sandbox blocks remote images. */
  img.tile {
    object-fit: cover;
    display: block;
    background: var(--raised);
  }

  .entry-main { min-width: 0; flex: 1; }
  .entry-title {
    font-family: var(--display);
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.008em;
    margin: 0 0 2px;
    overflow-wrap: anywhere;
  }
  .entry-sub {
    margin: 0 0 8px;
    font-size: 12.5px;
    color: var(--ink-faint);
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
  }

  .row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

  .pill {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .02em;
    padding: 3px 9px;
    border-radius: 999px;
    color: var(--on-pastel);
    white-space: nowrap;
  }
  /* Nearly everything is Done, so Done recedes and the exceptions carry the
     colour. Highlighting the common case just makes the page shout. */
  .pill.done {
    background: none;
    color: var(--ink-faint);
    padding-left: 0;
    font-weight: 500;
    letter-spacing: .04em;
  }
  .pill.in_progress { background: var(--mint); }
  .pill.hold { background: var(--butter); }
  .pill.not_started {
    background: none;
    color: var(--ink-faint);
    padding-left: 0;
    font-weight: 500;
    box-shadow: inset 0 0 0 1px var(--hairline);
    padding: 3px 9px;
    border-radius: 999px;
  }

  .stars { font-size: 11px; letter-spacing: 1.5px; color: var(--butter); white-space: nowrap; }
  .stars .off { color: var(--hairline); }

  .entry-note {
    margin: 8px 0 0;
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--ink-faint);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .blank { text-align: center; color: var(--ink-faint); padding: 70px 20px; }

  /* ---------- Sheet ---------- */

  dialog {
    border: none;
    padding: 0;
    background: var(--surface);
    color: var(--ink);
    border-radius: 24px;
    width: min(540px, 94vw);
    max-height: 88vh;
    box-shadow: 0 30px 70px rgba(0,0,0,.6);
  }
  dialog::backdrop { background: rgba(8,8,10,.72); }
  .sheet { padding: 24px; overflow-y: auto; max-height: 88vh; }

  .sheet h2 {
    font-family: var(--display);
    font-weight: 600;
    font-size: 19px;
    letter-spacing: -0.015em;
    margin: 0 0 18px;
  }

  label.lab { display: block; margin-bottom: 14px; }
  .lab-text {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ink-faint);
    margin-bottom: 5px;
  }
  .lab .field, .sheet textarea.field { width: 100%; }
  textarea.field { resize: vertical; line-height: 1.55; min-height: 96px; }

  .duo { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

  /* A fixed slot, not just a width: catalog art ranges from a tall paperback
     scan to a landscape promo still, and letting the height follow the image
     moved every field below it by 80px depending on which title you opened.
     `contain` letterboxes the odd one instead of cropping it. */
  .cover-art {
    width: 92px;
    height: 128px;
    object-fit: contain;
    border-radius: 10px;
    display: block;
    margin: 0 auto 16px;
    background: var(--raised);
  }

  .seek { display: flex; gap: 8px; margin: 14px 0 10px; }
  .seek input { flex: 1; }
  .btn-ghost {
    background: var(--raised);
    border: none;
    border-radius: var(--r-md);
    padding: 9px 15px;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s ease;
  }
  .btn-ghost:hover { background: var(--hairline); }
  .btn-ghost:disabled { opacity: .5; cursor: default; }

  .note { font-size: 12.5px; color: var(--ink-faint); line-height: 1.5; margin: 8px 0; }

  .hits { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; max-height: 290px; overflow-y: auto; }
  .hit {
    background: var(--raised);
    border: none;
    border-radius: var(--r-md);
    padding: 11px 13px;
    cursor: pointer;
    text-align: left;
    transition: background .15s ease;
  }
  .hit:hover { background: var(--hairline); }
  .hit-t { font-family: var(--display); font-weight: 600; font-size: 14px; }
  .hit-m { font-size: 12px; color: var(--ink-faint); margin-top: 2px; font-variant-numeric: tabular-nums; }
  .hit-b { font-size: 12px; color: var(--ink-dim); margin-top: 5px; line-height: 1.45; }

  .rater { display: flex; gap: 4px; }
  .rater button {
    background: none; border: none; cursor: pointer;
    font-size: 25px; line-height: 1; padding: 0;
    color: var(--hairline);
    transition: color .12s ease, transform .12s ease;
  }
  .rater button:hover { transform: scale(1.13); }
  .rater button.on { color: var(--butter); }

  .actions { display: flex; align-items: center; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
  .actions .grow { flex: 1; }
  .btn-primary {
    background: var(--mint); color: var(--on-pastel);
    border: none; border-radius: var(--r-md);
    padding: 10px 20px; font-weight: 700; font-family: var(--display);
    cursor: pointer;
  }
  .btn-primary:hover { filter: brightness(1.07); }
  .btn-danger {
    background: none;
    border: 1px solid rgba(240,178,203,.34);
    color: var(--rose);
    border-radius: var(--r-md);
    padding: 9px 15px;
    cursor: pointer;
  }
  .btn-danger:hover { background: rgba(240,178,203,.1); }

  .meter { height: 5px; background: var(--raised); border-radius: 99px; overflow: hidden; margin: 14px 0 8px; }
  .meter i { display: block; height: 100%; background: var(--mint); width: 0; transition: width .3s ease; }

  .changed { max-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
  .changed div { font-size: 12.5px; color: var(--ink-dim); }
  .changed b { color: var(--ink); font-weight: 500; }

  .sync { font-size: 11.5px; color: var(--ink-faint); padding: 16px 0 0; text-align: center; }
  .sync b { color: var(--ink-dim); font-weight: 500; }

  @media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
  }

  @media (max-width: 560px) {
    .wrap { padding: 0 15px 60px; }
    header.masthead { padding: 20px 0 14px; }
    .tallies { gap: 18px; }
    .btn-add { flex: 1 1 100%; }
    #q { flex: 1 1 100%; }
    .duo { grid-template-columns: 1fr; }
    .grid { grid-template-columns: 1fr; }
    select.field { flex: 1 1 30%; }
    .btn-fill { flex: 1 1 100%; }
  }

/* ---------- Auth gate ---------- */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(400px, 100%);
  background: var(--surface);
  border-radius: 22px;
  padding: 30px 28px;
}
.gate-card .wordmark { font-size: 25px; margin-bottom: 4px; }
.gate-sub { color: var(--ink-faint); font-size: 13px; margin: 0 0 22px; }
.gate-card .field { width: 100%; }
.gate-card .btn-primary { width: 100%; margin-top: 4px; }
.gate-switch {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-faint);
}
.gate-msg { font-size: 13px; line-height: 1.5; margin: 12px 0 0; }
.gate-msg.bad { color: var(--rose); }
.gate-msg.good { color: var(--mint); }

.who {
  display: flex; align-items: center; gap: 10px;
  font-size: 12.5px; color: var(--ink-faint);
}
.who button {
  background: var(--surface); border: none; color: var(--ink-dim);
  border-radius: 10px; padding: 7px 12px; cursor: pointer; font-size: 12.5px;
}
.who button:hover { background: var(--raised); color: var(--ink); }

.hit img.hit-art {
  width: 40px; height: 60px; object-fit: cover;
  border-radius: 6px; background: var(--raised); flex-shrink: 0;
}
.hit { align-items: flex-start; gap: 10px; }
.hit-body { min-width: 0; }
.hit-b {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.saving { opacity: .55; pointer-events: none; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--raised); color: var(--ink);
  padding: 11px 18px; border-radius: 999px;
  font-size: 13px; z-index: 50;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.toast.bad { background: var(--rose); color: var(--on-pastel); }

/* ---------- Inline text link buttons + field hints ---------- */

.link-btn {
  background: none;
  border: none;
  color: var(--mint);
  cursor: pointer;
  padding: 4px 0;
  font-size: 13px;
  text-align: left;
}
.link-btn:hover { text-decoration: underline; }
.link-btn[hidden] { display: none !important; }

.hint {
  display: block;
  font-size: 12px;
  color: var(--ink-faint);
  line-height: 1.5;
  margin-top: 5px;
}

/* Inside a dialog the page surface and the field surface were the same colour,
   which made input boxes invisible. Lift fields onto the raised tone there. */
dialog .field,
.gate-card .field {
  background: var(--raised);
}
dialog .field:focus,
.gate-card .field:focus {
  background: var(--hairline);
  border-color: var(--mint);
}

/* Catalog-supplied fields sit behind a disclosure: prefilled, rarely touched. */
.catalog-fields {
  border-top: 1px solid var(--hairline);
  margin: 4px 0 16px;
  padding-top: 14px;
}
.catalog-fields > summary {
  cursor: pointer;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-faint);
  list-style: none;
  padding: 4px 0 12px;
}
.catalog-fields > summary::-webkit-details-marker { display: none; }
.catalog-fields > summary::before { content: "▸ "; }
.catalog-fields[open] > summary::before { content: "▾ "; }
.catalog-fields > summary:hover { color: var(--ink-dim); }


/* ---------- Reading now ---------- */

.reading-now { margin-bottom: 26px; }
.reading-now h2 {
  font-family: var(--display);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--mint);
  margin: 0 0 10px;
}
.reading-now .grid { grid-template-columns: repeat(auto-fill, minmax(266px, 1fr)); }
.reading-now .entry { background: var(--raised); }
.reading-now .entry:hover { background: var(--hairline); }

/* ---------- Search results (Content) ---------- */
/* `.hit` carried flex properties but never `display: flex`, so the poster
   stacked above the text and every row was ~170px of mostly empty space. */

.hit {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
}
.hit img.hit-art {
  width: 46px;
  height: 69px;
  border-radius: 6px;
}
.hit-body { flex: 1; min-width: 0; }
.hit-t {
  font-size: 14px;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.hit-m { margin-top: 1px; }
.hit-b {
  margin-top: 4px;
  font-size: 11.5px;
  line-height: 1.4;
  -webkit-line-clamp: 2;
}
/* The dialog scrolls anyway; a short inner scroller just fights it. */
.hits { max-height: 46vh; gap: 4px; }

/* Dialogs need a dismiss on every step — the search step had none, so the
   only way out was Escape, which isn't discoverable. */
.sheet { position: relative; }
.sheet-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--ink-faint);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s ease, color .15s ease;
}
.sheet-close:hover { background: var(--raised); color: var(--ink); }
.sheet h2 { padding-right: 38px; }

/* ---------- Mobile pass ---------- */
/* Installed to a home screen the page runs under the status bar (viewport-fit
   is cover), so every top edge needs the safe-area inset or the title collides
   with the clock. The side insets matter in landscape on notched phones. */

body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

@media (max-width: 620px) {
  .wrap, .hub { padding-left: 16px; padding-right: 16px; }

  header.masthead {
    padding-top: calc(18px + env(safe-area-inset-top));
    padding-bottom: 14px;
    gap: 12px;
  }
  .hub-head { padding-top: calc(34px + env(safe-area-inset-top)); }

  /* The app name is the one piece of text that should not shrink on a
     phone — it is the whole header. Sign-out is out of flow above, so
     there is nothing left for it to collide with. */
  .wordmark { font-size: 28px; }
  .subtitle { font-size: 13.5px; }

  /* Counts read as one compact row rather than three oversized columns.
     The numbers themselves keep their desktop size — the space came from
     the gap, not from shrinking anything. */
  .tallies { gap: 20px; width: 100%; }

  /* Filters in a fixed grid stop them reflowing into ragged rows. */
  .controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
  }
  .btn-add { grid-column: 1 / -1; padding: 12px 16px; font-size: 16px; }
  #q { grid-column: 1 / -1; }
  /* Native selects reserve ~20px on the right for the UA arrow that the
     computed padding does not account for, and "Recently finished" at
     16px needs every pixel of a 168px column. Tighten the right side. */
  .controls select.field { width: 100%; padding: 10px 4px 10px 10px; }
  .btn-fill { grid-column: 1 / -1; }

  /* Anything below 16px makes iOS zoom the page when the field takes
     focus, so every input and select sits at 16px on a phone. */
  .field, input.field, select.field, textarea.field { font-size: 16px; }

  /* Identity belongs in the corner, not in a full-width band between the
     filters and the list. Lifted out of the grid entirely and pinned to the
     top right, level with the wordmark — it is out of flow, so the filter
     row closes up behind it. */
  .wrap { position: relative; }
  .who {
    position: absolute;
    top: calc(20px + env(safe-area-inset-top));
    right: 16px;
    gap: 7px;
    font-size: 12.5px;
  }
  .who button { padding: 5px 10px; font-size: 12.5px; border-radius: 9px; }

  .chiprow { margin-bottom: 16px; }
  .chiprow button { padding: 8px 14px; }
  .chiprow .n { font-size: 13px; }

  /* Secondary text was sized against a 940px three-column grid. On a phone
     it is the only text on the line and needs to be read at arm's length,
     so it goes up here rather than down. */
  .entry { padding: 13px; gap: 12px; }
  .entry-title { font-size: 16.5px; }
  .entry-sub { font-size: 13.5px; }
  .entry-note { font-size: 13.5px; }
  .pill { font-size: 11px; padding: 4px 10px; }
  .stars { font-size: 12.5px; }
  .tile, img.tile { width: 50px; height: 70px; }

  /* The sheet was spaced for a 540px desktop dialog. On a phone the same
     margins plus a six-row textarea push Save off the first screen. */
  .sheet h2 { font-size: 21px; margin-bottom: 14px; }
  label.lab, .sheet .lab { margin-bottom: 12px; }
  .lab-text { font-size: 11.5px; margin-bottom: 4px; }
  .cover-art { width: 84px; height: 116px; margin-bottom: 14px; }
  /* rows="6" wins over min-height, so the notes box was 169px and pushed
     Save off the bottom of the dialog. Set the height outright. */
  textarea.field { min-height: 0; height: 104px; }
  .actions { margin-top: 16px; gap: 7px; }

  /* Safari centres the value in a date input and leaves it looking unanchored
     next to the left-aligned select above it. */
  input[type="date"].field { text-align: left; }
  .hit-t { font-size: 15px; }
  .hit-m, .hit-b { font-size: 13px; }
  .note, .gate-sub, .gate-msg { font-size: 13.5px; }

  dialog { width: 94vw; }
  .sheet { padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); }
}
