:root {
  --ground: #f3f5f1; --sheet: #ffffff; --ink: #16211f; --soft: #56635f; --line: #d5dcd6;
  --accent: #123f3a; --on-accent: #ffffff; --accent-soft: #dfeae6; --gold: #8a5a00; --gold-soft: #fbecc8;
  --red: #9c2b1e; --red-soft: #f9e0dc; --focus: #c07a00;
  --serif: Charter, 'Iowan Old Style', 'Noto Serif', 'Sinhala MN', 'Noto Serif Sinhala', Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Sinhala Sangam MN', 'Noto Sans Sinhala', 'Nirmala UI', sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #101716; --sheet: #192321; --ink: #e8eeea; --soft: #a3b1ac; --line: #31403c;
    --accent: #8fd0c0; --on-accent: #08211d; --accent-soft: #21403a; --gold: #f0c675; --gold-soft: #3f3213;
    --red: #f0a195; --red-soft: #45201b; --focus: #f0c675;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--ground); color: var(--ink); font: 1rem/1.5 var(--sans); -webkit-text-size-adjust: 100%; }
main { max-width: 60rem; margin: 0 auto; padding: 1rem 1rem calc(6rem + env(safe-area-inset-bottom)); }
main:focus, main:focus-visible { outline: none; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.25; margin: 0; text-wrap: balance; }
h1 { font-size: 1.7rem; margin-bottom: .75rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.1rem; }
section { margin-top: 1.75rem; }
p { margin: .4rem 0; }
[lang=si] { line-height: 1.6; }
a { color: var(--accent); }
h3 a, .gallery a, .menu a, .brand, .who { color: inherit; text-decoration: none; }
h3 a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--soft); }
.fine { font-size: .85rem; }
.hint { margin-top: .4rem; font-size: .9rem; }
.due { color: var(--red); font-weight: 600; }
.note { white-space: pre-line; overflow-wrap: anywhere; }
.place { overflow-wrap: anywhere; }
.grow { flex: 1; min-width: 0; }
.empty { padding: 1.25rem; border: 1px dashed var(--line); border-radius: .6rem; color: var(--soft); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Controls */
button, .button { display: inline-flex; align-items: center; justify-content: center; min-height: 2.75rem; padding: .45rem .95rem; border: 1px solid var(--line); border-radius: .5rem; background: var(--sheet); color: var(--ink); font: inherit; font-weight: 550; text-decoration: none; cursor: pointer; text-align: center; }
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: default; }
.button:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.danger { color: var(--red); }
.plain { border-color: transparent; background: none; color: var(--accent); padding-inline: .4rem; }
.small { min-height: 2.4rem; padding: .25rem .7rem; font-size: .92rem; }
.wide { width: 100%; margin-top: .75rem; }
input, select, textarea { width: 100%; min-height: 2.75rem; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: .5rem; background: var(--sheet); color: var(--ink); font: inherit; }
input[type=checkbox], input[type=radio] { width: 1.25rem; height: 1.25rem; min-height: 0; accent-color: var(--accent); flex: none; }
input[type=file].visually-hidden { min-height: 0; padding: 0; }
.field { display: block; margin: .75rem 0; }
.field > span { display: block; font-weight: 600; font-size: .92rem; margin-bottom: .2rem; }
.check { display: flex; gap: .6rem; align-items: center; min-height: 2.75rem; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; align-items: center; }
.pair { display: flex; gap: .5rem; align-items: end; flex-wrap: wrap; }
.pair .field { flex: 1 1 9rem; margin-bottom: 0; min-width: 0; }
.inline { display: flex; gap: .5rem; align-items: center; margin-top: .5rem; }
.inline select { width: auto; max-width: 100%; }
.setting { display: flex; flex-wrap: wrap; gap: .25rem 1rem; align-items: center; justify-content: space-between; }
.setting select { width: auto; }
.panel { background: var(--sheet); border: 1px solid var(--line); border-radius: .75rem; padding: 1rem; margin: 1rem 0; }
.panel.warn { border-color: var(--gold); }
.panel.chosen { background: var(--accent-soft); border-color: transparent; display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
details summary { cursor: pointer; padding: .6rem 0; font-weight: 600; color: var(--accent); }
.section-head { display: flex; flex-wrap: wrap; gap: .25rem 1rem; align-items: baseline; justify-content: space-between; margin-bottom: .6rem; }
.section-head h1 { margin: 0; }

/* Frame */
#bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: calc(.5rem + env(safe-area-inset-top)) 1rem .5rem; border-bottom: 1px solid var(--line); background: var(--sheet); }
.brand { font: 600 1.1rem var(--serif); white-space: nowrap; }
.who { display: flex; gap: .5rem; align-items: center; min-width: 0; min-height: 2.4rem; padding: .2rem .8rem; border-radius: 2rem; background: var(--accent-soft); font-weight: 600; }
.who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--red); color: var(--ground); border-radius: 1rem; padding: 0 .5rem; font-size: .8rem; font-weight: 700; }
#nav { position: fixed; inset: auto 0 0; z-index: 5; display: flex; background: var(--sheet); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#nav a { flex: 1; padding: .95rem .2rem; text-align: center; text-decoration: none; color: var(--soft); font-size: .88rem; font-weight: 600; border-top: 3px solid transparent; }
#nav a[aria-current] { color: var(--accent); border-color: var(--accent); }
@media (min-width: 48rem) {
  #bar { padding-inline: 2rem; }
  #nav { position: absolute; inset: 0 auto auto 50%; transform: translateX(-50%); border: 0; background: none; padding-top: env(safe-area-inset-top); }
  #nav a { padding: .95rem 1rem; border-top: 0; white-space: nowrap; font-size: .95rem; }
  #nav a[aria-current] { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: .4em; }
  main { padding-top: 1.75rem; }
}
#toast { position: fixed; left: 50%; top: calc(4rem + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 20; max-width: min(32rem, calc(100vw - 2rem)); width: max-content; padding: .7rem 1rem; border-radius: .6rem; background: var(--ink); color: var(--ground); visibility: hidden; }
#toast.show { visibility: visible; }
#toast.error { background: var(--red); color: var(--ground); }
dialog { width: min(34rem, calc(100vw - 1.5rem)); max-height: calc(100dvh - 2rem); overflow: auto; padding: 1rem; border: 1px solid var(--line); border-radius: .9rem; background: var(--ground); color: var(--ink); }
dialog::backdrop { background: rgb(0 0 0 / .55); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.scanner { width: 100%; max-height: 60dvh; background: #000; border-radius: .5rem; object-fit: cover; }
.full-photo { max-width: 100%; max-height: 75dvh; display: block; margin: .5rem auto; }

/* Covers. Books awaiting a photo get a cloth binding with the title stamped on it. */
.cover { display: block; flex: none; align-self: flex-start; width: 4rem; aspect-ratio: 2 / 3; object-fit: cover; border-radius: .15rem .35rem .35rem .15rem; box-shadow: 0 1px 3px rgb(0 0 0 / .3); }
.cover.large { width: 100%; }
.cloth { overflow: hidden; padding: 12% 8% 8% 14%; color: #f6ecd2; font: 600 .62rem/1.3 var(--serif); border-left: .3rem solid rgb(0 0 0 / .22); overflow-wrap: anywhere; text-align: left; }
.cloth.large { font-size: .95rem; }
.cloth-0 { background: #24504a; } .cloth-1 { background: #6b2f2a; } .cloth-2 { background: #2d4268; } .cloth-3 { background: #5a4a1f; }
.cloth-4 { background: #4b3157; } .cloth-5 { background: #38552c; } .cloth-6 { background: #7a4420; } .cloth-7 { background: #39434a; }

.searchbar { display: flex; gap: .5rem; }
.searchbar input { font-size: 1.1rem; min-height: 3.1rem; }
.result, .member, .suggestion { display: flex; gap: .9rem; background: var(--sheet); border: 1px solid var(--line); border-radius: .75rem; padding: .85rem; margin: .65rem 0; }
.member { flex-wrap: wrap; align-items: center; }
.result p { margin: 0; }
.copies { list-style: none; margin: .35rem 0 0; padding: 0; }
.copies li { padding: .45rem 0; border-top: 1px solid var(--line); }
.suggestions { display: grid; gap: .65rem; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
.suggestion { margin: 0; }
.tag { display: inline-block; padding: .05rem .5rem; border-radius: .3rem; font-size: .85rem; font-weight: 650; }
.lent, .caution { background: var(--gold-soft); color: var(--gold); }
.missing { background: var(--red-soft); color: var(--red); }
.verdict { padding: .7rem .9rem; border-radius: .6rem; font-weight: 600; }
.verdict.have { background: var(--accent-soft); color: var(--accent); }
.verdict.maybe { background: var(--gold-soft); color: var(--gold); }
.verdict.none { background: var(--sheet); border: 1px solid var(--line); }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 0 .75rem; }
.gallery { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr)); gap: 1.1rem .9rem; }
@media (min-width: 48rem) { .gallery { grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); } }
.gallery a { display: block; }
.gallery-title { display: block; margin-top: .35rem; font-size: .92rem; line-height: 1.35; overflow-wrap: anywhere; }
.gallery.selecting .cover { opacity: .6; }
.gallery .selected .cover { opacity: 1; outline: 4px solid var(--accent); outline-offset: 2px; }
.selection { position: sticky; bottom: calc(4.5rem + env(safe-area-inset-bottom)); display: flex; gap: .6rem; align-items: center; padding: .7rem 1rem; margin-top: 1rem; background: var(--sheet); border: 1px solid var(--accent); border-radius: .75rem; }
.selection span { flex: 1; font-weight: 600; }

.work-head { display: flex; gap: 1rem; align-items: flex-start; }
.work-head .cover { width: 7.5rem; }
.reading fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.reading legend { padding: 0; margin-bottom: .5rem; }
.segments { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: .4rem; }
.segments label { position: relative; }
.segments input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.segments span { display: flex; align-items: center; justify-content: center; min-height: 2.75rem; padding: .3rem .5rem; border: 1px solid var(--line); border-radius: .5rem; text-align: center; font-size: .95rem; }
.segments input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.segments input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.copy { background: var(--sheet); border: 1px solid var(--line); border-radius: .75rem; padding: .9rem; margin: .65rem 0; scroll-margin: 5rem; }
.copy.highlight { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.copy-head { display: flex; gap: .9rem; }
.photos { list-style: none; display: flex; flex-wrap: wrap; gap: .75rem; padding: 0; margin: .75rem 0 0; }
.photos li { width: 8rem; display: grid; gap: .35rem; justify-items: start; }
.photos img { width: 100%; height: 8rem; object-fit: cover; border-radius: .4rem; display: block; }
.photos button.plain { flex-direction: column; padding: 0; width: 100%; }

.tabs { display: flex; gap: .4rem; overflow-x: auto; padding: .25rem; margin: 0 -.25rem .75rem; }
.tabs a { flex: none; padding: .5rem .85rem; border-radius: 2rem; border: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.tabs a[aria-current] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tabs a[aria-current] .muted { color: inherit; }
.menu { list-style: none; padding: 0; margin: 1rem 0; }
.menu a, .menu button { display: flex; align-items: center; gap: .5rem; width: 100%; justify-content: flex-start; min-height: 3.2rem; padding: .5rem .25rem; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: none; font-weight: 550; }
.plain-list, .notes { list-style: none; padding: 0; }
.plain-list li { padding: .35rem 0; }
.notes li { padding: .75rem 0 .75rem .9rem; border-left: 3px solid var(--line); margin-bottom: .5rem; }
.notes li.new { border-color: var(--gold); }
.tree { list-style: none; padding: 0; margin: 0; }
.tree .tree { margin-left: .5rem; padding-left: .8rem; border-left: 2px solid var(--line); }
.place-row { display: flex; gap: .5rem; align-items: center; padding: .35rem 0; }
.welcome { max-width: 28rem; margin: 12vh auto 0; }
.welcome h1 { font-size: 2.4rem; }
form[inert] { opacity: .55; }
