:root {
  color-scheme: light;
  --paper: #faf6ed;
  --panel: #f0e9da;
  --ink: #292b25;
  --muted: #5d6154;
  --accent: #35604e;
  --line: #d9d1c1;
  --reading-size: 20px;
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #1d221e;
  --panel: #282f28;
  --ink: #f1eadb;
  --muted: #c0c4b4;
  --accent: #add2b6;
  --line: #444d43;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
.masthead { background: var(--panel); border-bottom: 1px solid var(--line); }
.toolbar {
  max-width: 68rem;
  margin: auto;
  padding: .75rem clamp(1rem, 4vw, 2.5rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .55rem 1rem;
}
.brand { color: inherit; font: bold 1.35rem Georgia, serif; text-decoration: none; white-space: nowrap; }
.brand span, footer span { color: var(--accent); }
.catalog-link { color: var(--accent); font-weight: 600; }
.site-nav { display: flex; flex-wrap: wrap; gap: .5rem 1rem; }
.site-nav [aria-current="page"] { text-decoration-thickness: .15em; text-underline-offset: .25em; }
.settings { display: flex; flex-wrap: wrap; gap: .35rem; }
button {
  min-height: 44px;
  min-width: 44px;
  padding: .45rem .65rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: .875rem;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
main { max-width: 46rem; margin: auto; padding: 0 clamp(1.15rem, 5vw, 2rem); }
.story-header { text-align: center; padding: clamp(2rem, 7vw, 4.5rem) 0 1.5rem; }
.eyebrow, .chapter-count, footer {
  color: var(--muted);
  font-size: .8rem;
}
.eyebrow { letter-spacing: .13em; color: var(--accent); }
.story-name { margin: .35rem 0 1.5rem; font: bold clamp(2rem, 7vw, 3.2rem) Georgia, serif; }
.chapter-count { margin-bottom: .4rem; }
h1 { margin: 0; font: bold clamp(1.4rem, 5vw, 2rem) Georgia, serif; }
article { font: var(--reading-size)/1.8 Georgia, serif; overflow-wrap: break-word; }
article p { margin: 0 0 1em; }
.chapter-nav {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  border-top: 1px solid var(--line);
  padding: 1.25rem 0;
}
.chapter-nav button { background: var(--panel); }
.chapter-nav button { flex: 1 1 auto; }
#chapter-picker, #chapter-report {
  width: min(36rem, calc(100% - 2rem));
  max-height: 80dvh;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: .85rem;
  background: var(--paper);
  color: var(--ink);
}
#chapter-picker::backdrop, #chapter-report::backdrop { background: #151a16b3; }
.reader-tools { display: flex; justify-content: flex-end; padding-bottom: 1rem; }
.picker-header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.picker-header h2 { margin: 0; font: bold 1.5rem Georgia, serif; }
footer { padding: 1.25rem 1rem 2rem; text-align: center; }

#catalog { max-width: 68rem; }
#catalog h2, #catalog h3 { font-family: Georgia, serif; }
.welcome { padding: clamp(2.5rem, 9vw, 6rem) 0 2rem; }
.welcome h1 { font-size: clamp(2.3rem, 8vw, 4.7rem); max-width: 13ch; }
.search-field { display: grid; gap: .4rem; max-width: 28rem; margin: 1rem 0; font-weight: 600; }
.search-field input, .search-field textarea {
  width: 100%;
  min-height: 44px;
  padding: .6rem .8rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 400;
}
.search-field textarea { resize: vertical; }
.page-heading { padding: clamp(2rem, 6vw, 4rem) 0 1rem; }
.page-heading p, .shelf-list p { color: var(--muted); }
.shelf-list { list-style: none; margin: 0; padding: 0; }
.shelf-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem 1rem;
  border-top: 1px solid var(--line);
  padding: .75rem 0;
}
.shelf-list p { margin: .3rem 0 0; }
.shelf-list a, #catalog section > p a, footer a { color: var(--accent); }
#save-story[aria-pressed="true"] { border-color: var(--accent); background: var(--panel); }
#save-status:empty, #shelf-status:empty, #report-status:empty { display: none; }
.updates { margin-bottom: 2rem; }
.updates-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr)); gap: .75rem; }
.update-card {
  display: grid;
  grid-template-columns: 4.75rem 1fr;
  align-items: center;
  gap: .85rem;
  padding: .75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: .75rem;
  color: var(--ink);
  text-decoration: none;
}
.update-card:hover { border-color: var(--accent); }
.update-card .cover { display: block; border-radius: .35rem; padding: 0; }
.update-card .cover span { display: none; }
.update-card h3, .update-card p { margin: 0; }
.update-card p { margin-top: .3rem; color: var(--muted); }
.welcome > p:last-child, .card-text > p:last-child, .detail p { color: var(--muted); line-height: 1.55; }
.resume {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem 1rem;
  margin-bottom: 2rem;
  padding: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: .85rem;
}
.resume h2, .resume p { margin: 0 0 .35rem; }
.action, .secondary-action {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: .55rem 1rem;
  border-radius: .5rem;
  font-weight: 600;
  text-decoration: none;
}
.action { background: var(--accent); color: var(--paper); }
.secondary-action { border: 1px solid var(--line); color: var(--ink); }
.moods, .detail-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.categories { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.categories a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: .4rem .85rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  color: var(--ink);
  text-decoration: none;
}
.categories a:hover { border-color: var(--accent); }
.categories a[aria-current] { background: var(--accent); color: var(--paper); }
.moods button[aria-pressed="true"] { background: var(--accent); color: var(--paper); }
.result-count { color: var(--muted); font-size: .85rem; }
.story-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); gap: 1rem; }
.story-card {
  border: 1px solid var(--line);
  border-radius: .85rem;
  background: var(--panel);
  font: inherit;
}
.story-card:hover { border-color: var(--accent); }
.story-card a { display: block; height: 100%; border-radius: inherit; color: inherit; text-decoration: none; }
.cover {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  place-items: center;
  gap: .4rem;
  aspect-ratio: 4 / 5;
  padding: clamp(1rem, 3vw, 1.5rem);
  border-radius: .8rem .8rem 0 0;
  background-size: cover;
  background-position: center;
  text-align: center;
  font-family: Georgia, serif;
}
.cover-category, .cover-author { font: 600 .75rem system-ui, sans-serif; }
.cover-category { letter-spacing: .1em; text-transform: uppercase; }
.cover-symbol { font-size: 3.5rem; line-height: 1; }
.cover-title { font-size: clamp(1.1rem, 3vw, 1.6rem); line-height: 1.2; font-weight: bold; }
.amber { background: #e4c791; color: #694923; }
.green { background: #c6d7bf; color: #355744; }
.blue { background: #c8d3e4; color: #344866; }
.court { background-color: #441b28; background-image: url("covers/court.svg"); color: #ffe2b3; }
.apartment { background-color: #17353e; background-image: url("covers/apartment.svg"); color: #e1f4eb; }
.court .cover-symbol, .apartment .cover-symbol { visibility: hidden; }
.card-text { padding: 1rem; }
.card-text h3, .card-text p { margin: 0 0 .45rem; }
.back-link { display: inline-block; margin-top: 1.25rem; color: var(--accent); }
.detail { display: grid; grid-template-columns: minmax(8rem, 14rem) 1fr; align-items: center; gap: clamp(1.25rem, 5vw, 3rem); margin: 2rem 0; }
.detail .cover { border-radius: .85rem; }
.detail .eyebrow a { color: var(--accent); }
.detail #intro-title { margin: 1rem 0 .35rem; font-size: 1.25rem; }
.detail section p { margin-top: 0; max-width: 60ch; }
.contents { list-style: none; margin: 0; padding: 0; }
.contents a { display: block; padding: 1rem 0; border-top: 1px solid var(--line); color: var(--ink); }
.contents span { margin-right: .75rem; color: var(--muted); }
.contents a[aria-current] { background: var(--panel); padding-inline: .65rem; }
.badge {
  display: inline-block;
  padding: .15rem .45rem;
  border: 1px solid var(--line);
  border-radius: .4rem;
  color: var(--accent);
  font: 600 .75rem system-ui, sans-serif;
  letter-spacing: normal;
}
@media (max-width: 30rem) {
  .detail { grid-template-columns: 1fr; }
  .detail .cover { width: min(100%, 13rem); justify-self: center; }
}
