/* Bookworm. Colours taken from the cover of The House in the Cerulean Sea:
   the blue of the sea and sky, the warm sunset, the red roof, the green of the island. */
:root {
  --sea: #17769b;          /* cerulean: header, buttons, links */
  --sea-deep: #0f4c68;
  --ink: #12303f;          /* text */
  --ink-soft: #4a6472;     /* secondary text */
  --page: #fbf6ec;         /* warm paper */
  --card: #ffffff;
  --line: #e3dccd;
  --sky: #dceff4;          /* pale sea-sky wash */
  --sunset: #f5b841;       /* golden yellow */
  --coral: #ee7b55;        /* sunset orange */
  --roof: #b23a26;         /* red roof: problems, Passed and DNF */
  --island: #2f6e42;       /* green: finished and enjoyed */
  --on-sea: #ffffff;
  --shadow: 0 1px 3px rgba(18, 48, 63, .12);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tabs-h: 3.75rem;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --sea: #1d86ad;
    --sea-deep: #0c2433;
    --ink: #eaf3f6;
    --ink-soft: #a9c0cb;
    --page: #0c2433;
    --card: #14364a;
    --line: #26506a;
    --sky: #1a4660;
    --roof: #ff9d87;
    --island: #8fd3a2;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 1rem/1.5 var(--sans);
  color: var(--ink);
  background: var(--page);
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 1rem);
}
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; margin: 0; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.05rem; margin-bottom: .35rem; }
p { margin: 0 0 .6rem; }
a { color: var(--sea); }
@media (prefers-color-scheme: dark) { a { color: #7fd0ee; } }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--sunset); outline-offset: 2px; }

/* ---- Header ---- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--sea); color: var(--on-sea);
  padding: env(safe-area-inset-top) max(.75rem, env(safe-area-inset-right)) 0 max(.75rem, env(safe-area-inset-left));
  border-bottom: 4px solid var(--sunset);
}
.top-row { display: flex; align-items: center; justify-content: space-between; max-width: 46rem; margin: 0 auto; min-height: 3.25rem; }
.top h1 { font-size: 1.35rem; display: flex; align-items: center; gap: .5rem; }
.top h1 img { border-radius: 6px; }
.top-actions { display: flex; gap: .25rem; }
.icon-btn {
  width: 2.75rem; height: 2.75rem; display: inline-grid; place-items: center;
  background: none; border: 0; border-radius: 50%; color: inherit; cursor: pointer; font: inherit;
}
.icon-btn:hover { background: rgba(255, 255, 255, .18); }

/* ---- Shelf tabs: along the bottom on a phone, where a thumb reaches ---- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -1px 4px rgba(18, 48, 63, .08);
}
.tabs button {
  min-height: var(--tabs-h); padding: .35rem .15rem;
  background: none; border: 0; border-top: 3px solid transparent;
  font: 600 .9rem/1.2 var(--sans); color: var(--ink-soft); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem;
}
.tabs button.current { color: var(--sea); border-top-color: var(--coral); }
@media (prefers-color-scheme: dark) { .tabs button.current { color: #7fd0ee; } }
.count { font-weight: 400; font-size: .8rem; min-height: 1em; }

/* ---- Main column ---- */
main { max-width: 46rem; margin: 0 auto; padding: .75rem max(.75rem, env(safe-area-inset-right)) 0 max(.75rem, env(safe-area-inset-left)); }
.note { color: var(--ink-soft); font-size: .92rem; }
.banner { background: var(--sunset); color: #3a2a00; padding: .6rem .8rem; border-radius: .5rem; font-size: .95rem; }

.controls { display: grid; gap: .5rem; margin-bottom: .75rem; }
.control-row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem .75rem; }
.control-row label { display: flex; align-items: center; gap: .4rem; font-size: .9rem; color: var(--ink-soft); min-width: 0; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid #8fa3ad; border-radius: .5rem; padding: .55rem .7rem; min-height: 2.75rem; width: 100%;
}
.control-row select { flex: 1; min-width: 0; min-height: 2.75rem; padding: .35rem .5rem; }
textarea { resize: vertical; line-height: 1.4; }
label { display: block; font-weight: 600; font-size: .95rem; margin-bottom: .25rem; }
.control-row label { font-weight: 400; margin: 0; }

/* ---- Book list ---- */
.book-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.book-row {
  display: flex; gap: .75rem; align-items: flex-start; width: 100%; text-align: left;
  background: var(--card); color: inherit; font: inherit;
  border: 1px solid var(--line); border-radius: .6rem; padding: .6rem; cursor: pointer; box-shadow: var(--shadow);
}
.book-row:hover { border-color: var(--sea); }
.book-text { display: grid; gap: .1rem; min-width: 0; flex: 1; }
.book-title { font: 600 1.06rem/1.25 var(--serif); overflow-wrap: anywhere; }
.book-author { color: var(--ink-soft); font-size: .95rem; margin: 0; }
.book-tags { color: var(--ink-soft); font-size: .82rem; margin: 0; }
.book-notes, .book-why { font-size: .9rem; margin-top: .2rem; }
.book-notes { font-style: italic; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-list.discover .book-row { background: var(--sky); border-color: transparent; }

.cover {
  flex: none; width: 52px; height: 78px; object-fit: cover; border-radius: 3px;
  background: var(--sky); box-shadow: 1px 1px 3px rgba(18, 48, 63, .3);
}
.cover.large { width: 120px; height: 180px; border-radius: 4px; }
.cover.blank { display: grid; place-items: center; padding: 4px; overflow: hidden; color: #fff; text-align: center; }
.cover.blank span { font: 600 .56rem/1.15 var(--serif); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.cover.blank.large span { font-size: 1rem; }
.cover.c0 { background: #17769b; }
.cover.c1 { background: #0f4c68; }
.cover.c2 { background: #b23a26; }
.cover.c3 { background: #2f6e42; }
.cover.c4 { background: #a8541f; }

/* Outcome label. Always words, with colour as a second cue. */
.outcome {
  display: inline-block; justify-self: start; font: 600 .78rem/1 var(--sans); padding: .3rem .55rem; border-radius: 1rem;
  background: var(--sky); color: var(--ink); border: 1px solid transparent;
}
.o-good, .o-great, .o-excellent { background: transparent; border-color: var(--island); color: var(--island); }
.o-excellent { background: var(--island); color: #fff; }
@media (prefers-color-scheme: dark) { .o-excellent { color: #0c2433; } }
.o-passed, .o-dnf { background: transparent; border: 1px dashed var(--roof); color: var(--roof); }
.o-reading { background: var(--sunset); color: #3a2a00; }

/* ---- Pop-up pages ---- */
dialog.sheet {
  width: 100%; max-width: 36rem; max-height: 100dvh; height: 100dvh; margin: 0 auto;
  border: 0; padding: calc(1rem + env(safe-area-inset-top)) 1rem calc(1.5rem + env(safe-area-inset-bottom));
  background: var(--page); color: var(--ink); overflow-y: auto; overscroll-behavior: contain;
}
dialog.sheet::backdrop { background: rgba(9, 30, 42, .55); }
@media (min-width: 40rem) {
  dialog.sheet { height: auto; max-height: 92dvh; margin: auto; border-radius: .9rem; padding: 1.5rem; }
}
.close { float: right; font-size: 1.9rem; line-height: 1; margin: -.4rem -.4rem 0 .5rem; color: var(--ink); }
.close:hover { background: var(--sky); }
dialog section, dialog details { margin-top: 1.25rem; }
.detail-head { display: flex; gap: 1rem; align-items: flex-start; }
.detail-head > div { min-width: 0; display: grid; gap: .35rem; }
.detail-head p { margin: 0; }
.description { white-space: pre-line; }
.facts { margin-top: 1.25rem; }
.stack { display: grid; gap: .9rem; }

.find-links { list-style: none; margin: 0 0 .5rem; padding: 0; border: 1px solid var(--line); border-radius: .6rem; background: var(--card); }
.find-links li + li { border-top: 1px solid var(--line); }
.find-links a { display: flex; justify-content: space-between; align-items: center; gap: .75rem; min-height: 3rem; padding: .5rem .8rem; text-decoration: none; }
.find-links .place { color: var(--ink); font-weight: 600; }
.find-links .action { font-size: .9rem; text-align: right; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 2.75rem; padding: .5rem 1.1rem;
  font: 600 1rem var(--sans); text-decoration: none; cursor: pointer;
  background: var(--card); color: var(--sea-deep); border: 1.5px solid var(--sea); border-radius: .6rem;
}
@media (prefers-color-scheme: dark) { .btn { color: var(--ink); } }
.btn.primary { background: var(--sea); color: #fff; }
.btn.primary:hover { background: var(--sea-deep); }
@media (prefers-color-scheme: dark) { .btn.primary:hover { background: #17769b; } }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { min-height: 2.25rem; padding: .25rem .8rem; font-size: .9rem; }
.button-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.form-status { min-height: 1.3em; margin: 0; font-size: .95rem; color: var(--ink-soft); }
.problem { color: var(--roof); font-weight: 600; }

summary { font: 600 1.05rem var(--serif); cursor: pointer; min-height: 2.75rem; display: flex; align-items: center; }
.profile dt { font-weight: 600; margin-top: .7rem; }
.profile dd { margin: 0; color: var(--ink-soft); }

.toast {
  position: fixed; left: .75rem; right: .75rem; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + .75rem); z-index: 20;
  max-width: 30rem; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  background: var(--ink); color: var(--page); padding: .65rem .9rem; border-radius: .6rem; box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
}
@media (prefers-color-scheme: dark) { .toast { background: #eaf3f6; color: #12303f; } }

/* ---- Sign-in page ---- */
.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(#f5b841 0, #ee7b55 22%, #17769b 60%, #0f4c68 100%); }
.login-card { width: 100%; max-width: 22rem; background: var(--page); border-radius: 1rem; padding: 1.75rem 1.5rem; text-align: center; box-shadow: 0 8px 30px rgba(9, 30, 42, .35); }
.login-card h1 { margin: .5rem 0 1.25rem; }
.login-card form { display: grid; gap: .8rem; text-align: left; }
.login-card img { border-radius: 16px; }

/* ---- Wider screens: tabs move up under the header, list in two columns ---- */
@media (min-width: 50rem) {
  body { padding-bottom: 2rem; }
  .tabs { position: sticky; top: calc(3.25rem + 4px); bottom: auto; max-width: none; justify-content: center; grid-template-columns: repeat(4, minmax(0, 11.5rem)); box-shadow: none; border-top: 0; border-bottom: 1px solid var(--line); }
  .tabs button { flex-direction: row; gap: .4rem; min-height: 3rem; border-top: 0; border-bottom: 3px solid transparent; font-size: 1rem; }
  .tabs button.current { border-bottom-color: var(--coral); }
  main, .top-row { max-width: 62rem; }
  .book-list { grid-template-columns: 1fr 1fr; }
  .controls { grid-template-columns: minmax(0, 1fr) 24rem; align-items: center; }
  .toast { bottom: 1.5rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .book-row, .btn, .icon-btn { transition: background-color .15s, border-color .15s; }
}
