/* Fonts are bundled with the app (SIL Open Font License), so no request leaves the
   device. Literata, made for long reading on screens, is used for words and sentences;
   Atkinson Hyperlegible, designed so similar letters are easy to tell apart, for the UI. */
@font-face { font-family: "Literata"; src: url("fonts/literata-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Literata"; src: url("fonts/literata-latin-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Literata"; src: url("fonts/literata-latin-600-normal.woff2") format("woff2"); font-weight: 600 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2"); font-weight: 600 700; font-display: swap; }

/* Reading themes, as in e-readers (Kindle and Apple Books offer white, sepia and dark
   pages): Paper, Sepia and Night, plus Auto (Paper by day, Night when the phone is in
   dark mode). The accent is a bookmark-ribbon red. No pure white or black text on its
   opposite: body text contrast is 10-16:1, muted text at least 4.5:1. */
:root, :root[data-theme="paper"] {
  --soft: #f1eee8;
  --bg: #fbfaf7;
  --card: #ffffff;
  --ink: #1d1c1a;
  --muted: #625d55;
  --line: #e6e1d8;
  --accent: #a3322a;
  --accent-ink: #ffffff;
  --accent-soft: #f7e8e5;
  --warn: #8a5a12;
  --warn-soft: #fbefd5;
  --danger: #a3322a;
  --mark: #ffe9a6;
  --shadow: 0 1px 2px rgba(40, 30, 20, .08), 0 6px 18px rgba(40, 30, 20, .10);
  --shadow-lift: 0 2px 4px rgba(40, 30, 20, .10), 0 14px 30px rgba(40, 30, 20, .18);
  color-scheme: light;
}
:root[data-theme="sepia"] {
  --soft: #eadfc6;
  --bg: #f3ead7;
  --card: #f9f2e3;
  --ink: #4b3a2c;
  --muted: #73604e;
  --line: #e0d2b6;
  --accent: #9a3b22;
  --accent-ink: #fff8ee;
  --accent-soft: #eedac6;
  --warn: #7d5310;
  --warn-soft: #f0e0bb;
  --danger: #9a3b22;
  --mark: #ecd18a;
  color-scheme: light;
}
:root[data-theme="night"] {
  --soft: #262626;
  --bg: #141414;
  --card: #1e1e1e;
  --ink: #dedad3;
  --muted: #a19c94;
  --line: #2f2f2f;
  --accent: #e88b7f;
  --accent-ink: #141414;
  --accent-soft: #3a2421;
  --warn: #e5c07a;
  --warn-soft: #3a3020;
  --danger: #f09b8f;
  --mark: #5c4a1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 6px 18px rgba(0, 0, 0, .45);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, .5), 0 14px 30px rgba(0, 0, 0, .6);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --soft: #262626;
    --bg: #141414;
    --card: #1e1e1e;
    --ink: #dedad3;
    --muted: #a19c94;
    --line: #2f2f2f;
    --accent: #e88b7f;
    --accent-ink: #141414;
    --accent-soft: #3a2421;
    --warn: #e5c07a;
    --warn-soft: #3a3020;
    --danger: #f09b8f;
    --mark: #5c4a1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 6px 18px rgba(0, 0, 0, .45);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, .5), 0 14px 30px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root {
  --read: "Literata", Charter, "Sitka Text", Georgia, serif;
  --ui: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 12px;
  --tap: 48px;
  font-size: 17px;
}
:root[data-font="atkinson"] { --read: "Atkinson Hyperlegible", system-ui, sans-serif; }
:root[data-font="system"] { --read: Charter, "Iowan Old Style", "Sitka Text", Georgia, "Noto Serif", serif; }
:root[data-size="s"] { font-size: 15px; }
:root[data-size="l"] { font-size: 19.5px; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1rem/1.5 var(--ui);
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}
main { max-width: 640px; margin: 0 auto; padding: 12px 16px 24px; outline: none; }
h1 { font-family: var(--read); font-weight: 600; font-size: 1.45rem; margin: 8px 0 12px; }
h2 { font-size: 1.05rem; margin: 20px 0 8px; color: var(--muted); font-weight: 600; }
a { color: var(--accent); }
p { margin: 6px 0; }
.muted { color: var(--muted); font-size: .92rem; }
.small { font-size: .85rem; }

label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 4px; }
input, textarea, select {
  width: 100%; font: inherit; color: inherit; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: var(--tap);
}
textarea { min-height: 96px; resize: vertical; font-family: var(--read); line-height: 1.5; }
#word, #edit-headword { font-family: var(--read); }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row > .grow { flex: 1; min-width: 0; }
.row > .page { width: 96px; flex: none; }

button, .button {
  font: inherit; font-weight: 600; min-height: var(--tap); padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
button.primary, .button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--accent); padding: 0 4px; min-height: 36px; }
button:disabled { opacity: .55; cursor: default; }
.block { width: 100%; margin-top: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 8px 0; }
.book-bar { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.book-bar .title { font-weight: 700; overflow-wrap: anywhere; }

.senses { list-style: none; padding: 0; margin: 8px 0 0; }
.sense {
  display: block; width: 100%; text-align: left; font-weight: 400; padding: 10px 12px; margin: 6px 0;
  min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); background: var(--card); line-height: 1.35;
}
.sense[aria-pressed="true"] { border: 2px solid var(--accent); background: var(--accent-soft); }
.pos { font-style: italic; color: var(--muted); font-size: .85rem; margin-right: 4px; }
.example { display: block; color: var(--muted); font-size: .85rem; margin-top: 2px; }
.notice { border-radius: 10px; padding: 10px 12px; margin: 10px 0; background: var(--soft); }
.notice.warn { background: var(--warn-soft); color: var(--ink); }
.notice.warn strong { color: var(--warn); }
.phonetic { color: var(--muted); }

.list { list-style: none; padding: 0; margin: 0; }
.list a.item { display: block; color: inherit; text-decoration: none; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.list a.item:active { background: var(--accent-soft); }
.item .head { font-family: var(--read); font-weight: 600; font-size: 1.05rem; }
.item .meta { color: var(--muted); font-size: .85rem; }
.item .def { font-size: .92rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sentence { font-family: var(--read); line-height: 1.6; overflow-wrap: anywhere; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.empty { text-align: center; color: var(--muted); padding: 32px 8px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 10;
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 60px; color: var(--muted); text-decoration: none; font-size: .78rem; font-weight: 600;
}
.tabs a span { font-size: 1.3rem; line-height: 1; }
.tabs a[aria-current="page"] { color: var(--accent); }

.banner { position: sticky; top: 0; z-index: 11; background: var(--warn-soft); padding: 8px 16px; font-size: .9rem; text-align: center; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: calc(100% - 32px);
  z-index: 12; font-size: .95rem;
}
.hint { color: var(--muted); font-size: .9rem; margin: 12px 0 0; }
.field-error { color: var(--danger); font-size: .85rem; margin-top: 4px; }
.spinner { color: var(--muted); font-size: .9rem; padding: 8px 0; }
details summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; color: var(--accent); font-weight: 600; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); max-width: min(92vw, 480px); }
dialog::backdrop { background: rgba(0,0,0,.4); }

/* photo of the page */
.label-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.label-row label { margin-bottom: 4px; }
#photo-panel progress { width: 100%; accent-color: var(--accent); }
.page-text { max-height: 50vh; overflow-y: auto; }
.page-sentence { margin: 0; padding: 6px 4px; border-radius: 8px; cursor: pointer; }
.page-sentence.chosen { background: var(--accent-soft); }
.page-word {
  font: inherit; color: inherit; background: none; border: 0; border-radius: 4px; padding: 2px 1px; margin: 0;
  min-height: 0; display: inline; cursor: pointer; font-weight: 400; text-decoration: underline dotted var(--muted);
  text-underline-offset: 3px;
}
.page-word:active, .page-word:focus-visible { background: var(--mark); }
/* keep the photo box small so the sentence and meanings stay in view on a phone */
#photo-panel { padding: 8px 12px; }
#photo-status { margin: 0; font-size: .9rem; color: var(--muted); }
#photo-panel details summary { min-height: 34px; font-size: .9rem; }
#photo-panel .actions { margin-top: 0; gap: 4px; }
#photo-panel .actions .link { min-height: 34px; font-size: .9rem; }

/* -- shelves and covers ------------------------------------------------------------ */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.back { display: inline-block; margin: 4px 0 8px; text-decoration: none; font-weight: 600; }
.hero { display: flex; gap: 16px; align-items: center; margin: 12px 0 8px; }
.hero-text { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.hero-title { font-family: var(--read); font-weight: 600; font-size: 1.2rem; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
.hero .button { margin-top: 8px; align-self: flex-start; }
.shelf-section { margin-top: 18px; }
.shelf-head { display: flex; align-items: center; justify-content: space-between; }
.shelf-head h2 { margin: 0; color: var(--ink); font-size: 1.05rem; }
.shelf-head .count { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: .9rem; }
.shelf-add { min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; text-decoration: none; font-size: 1.3rem; color: var(--muted); }
.shelf-add:hover, .shelf-add:focus-visible { background: var(--accent-soft); color: var(--accent); }
.shelf-empty { margin: 6px 0 0; }
.shelf {
  display: grid; grid-auto-flow: column; grid-auto-columns: 112px; gap: 16px; overflow-x: auto;
  padding: 14px 4px 18px; margin: 0 -4px; scroll-snap-type: x proximity; scrollbar-width: thin;
}
@media (min-width: 640px) { .shelf { grid-auto-flow: row; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); overflow: visible; } }
.book { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--ink); scroll-snap-align: start; outline: none; }
.book-name { font-family: var(--read); font-weight: 600; font-size: .9rem; line-height: 1.25; overflow-wrap: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-meta { font-size: .75rem; color: var(--muted); }

.cover { position: relative; width: 100%; aspect-ratio: 2 / 3; border-radius: 3px 6px 6px 3px; overflow: hidden;
  box-shadow: var(--shadow); background: var(--line); transform-origin: left center; }
.cover::after { /* the spine: a soft fold near the left edge, like a real paperback */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,.22) 0, rgba(255,255,255,.18) 3%, rgba(0,0,0,.08) 6%, transparent 12%); }
.cover-art { width: 100%; height: 100%; object-fit: cover; display: block; }
.drawn { display: flex; flex-direction: column; justify-content: space-between; padding: 12% 10% 10% 16%;
  background: linear-gradient(160deg, hsl(var(--hue) 34% 40%), hsl(var(--hue) 38% 25%)); color: #fbf6ec; }
.drawn-title { font-family: var(--read); font-weight: 600; font-size: calc(.85rem * var(--fit, 1)); line-height: 1.2; overflow-wrap: break-word; hyphens: auto;
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.drawn-author { font-size: .65rem; opacity: .85; text-transform: uppercase; letter-spacing: .06em; }
.cover.thumb { width: 40px; flex: none; }
.cover.thumb .drawn { padding: 8% 6% 6% 14%; }
.cover.thumb .drawn-title { display: none; }
.cover.thumb .drawn-author { display: none; }
.cover.hero-cover { width: 96px; flex: none; }
.cover.large { width: 120px; flex: none; }
.cover.large .drawn-title { font-size: calc(.95rem * var(--fit, 1)); }
.cover.hero-cover .drawn-title { font-size: calc(.68rem * var(--fit, 1)); }
.cover.hero-cover .drawn-author { font-size: .55rem; }

/* The hover: the book lifts a little off the shelf and turns a few degrees, as if
   being picked up. Short, eased, and only on devices that hover; a tap presses it. */
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .book .cover { transition: transform .28s cubic-bezier(.2,.7,.3,1), box-shadow .28s ease; }
  .book:hover .cover, .book:focus-visible .cover { transform: translateY(-6px) perspective(700px) rotateY(-8deg); box-shadow: var(--shadow-lift); }
}
@media (prefers-reduced-motion: no-preference) {
  .book:active .cover { transform: scale(.97); transition: transform .1s ease; }
}
.book:focus-visible .book-name { text-decoration: underline; }

.book-bar-link { display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit; min-width: 0; }
.book-head { display: flex; gap: 16px; align-items: flex-start; margin: 4px 0 12px; }
.book-head-text { min-width: 0; flex: 1; }
.book-head h1 { margin-top: 0; overflow-wrap: anywhere; }
.manage { margin-top: 24px; }

.segmented { display: flex; flex-wrap: wrap; gap: 4px; padding: 3px; border-radius: 10px; background: var(--line); width: fit-content; max-width: 100%; }
.segmented button { min-height: 36px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 600; font-size: .85rem; }
.segmented button[aria-checked="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.appearance label { margin-top: 14px; }
.appearance label:first-child { margin-top: 0; }
.sample { margin: 16px 0 0; color: var(--muted); }

/* -- camera ---------------------------------------------------------------------- */
.camera { position: fixed; inset: 0; z-index: 50; background: #000; color: #fff; display: flex; flex-direction: column; }
.camera-top { display: flex; align-items: center; gap: 12px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; }
.camera-title { font-size: .95rem; opacity: .9; }
.camera-close { background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 999px; width: 44px; min-height: 44px; padding: 0; font-size: 1.1rem; }
.camera-view { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.camera-view video { width: 100%; height: 100%; object-fit: cover; }
.camera-guide { position: absolute; inset: 8% 7%; border: 2px solid rgba(255,255,255,.7); border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.25); pointer-events: none; }
.camera-status { text-align: center; margin: 8px 16px; min-height: 1.4em; font-size: .95rem; }
.camera-failed .camera-guide, .camera-failed .shutter { display: none; }
.camera-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 12px 16px calc(20px + env(safe-area-inset-bottom)); }
.camera-gallery { justify-self: start; background: rgba(255,255,255,.12); color: #fff; border: 0; font-size: .85rem; }
.camera-failed .camera-gallery { grid-column: 1 / -1; justify-self: center; background: #fff; color: #111; }
.shutter { width: 72px; height: 72px; border-radius: 50%; border: 4px solid #fff; background: rgba(255,255,255,.85); padding: 0; box-shadow: 0 0 0 3px rgba(0,0,0,.4) inset; }
.shutter:disabled { opacity: .4; }
.shutter:active { transform: scale(.94); }
.camera.flash::after { content: ""; position: fixed; inset: 0; background: #fff; animation: flash .25s ease-out forwards; }
@keyframes flash { from { opacity: .8; } to { opacity: 0; } }

.link-box { font-size: .85rem; }
#people-list li { list-style: none; }
