:root {
  --ink: #1f2328; --muted: #5b6470; --line: #e6e6e6; --bg: #ffffff; --accent: #345b7d;
  --mark: #ffe9a8; --link: #2f5d7c; --flag: #b45309;
}
* { box-sizing: border-box; }
body {
  font: 16.5px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
  max-width: 820px; margin: 0 auto; padding: 1.5rem 1rem 4rem;
}
header h1 { font-size: 1.4rem; margin: .2rem 0 .8rem; }
form[role=search] { display: block; }
.searchrow { display: flex; gap: .5rem; }
input[type=search] {
  flex: 1; font: inherit; padding: .6rem .8rem;
  border: 1px solid #ccc; border-radius: 8px; background: #fff;
}

/* corpus toggles */
.scopes { display: flex; flex-wrap: wrap; gap: 1rem; margin: .7rem 0 .2rem; }
.scope { font-size: .92rem; display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; }
.tag {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .03em;
  padding: .05rem .35rem; border-radius: 4px; border: 1px solid transparent;
}
.tag.word { background: #e7f3e7; color: #275; border-color: #cbe3cb; }
.tag.asr  { background: #f3eee2; color: #856404; border-color: #e6dcc2; }
.tag.doc  { background: #e9edf6; color: #345; border-color: #cdd6e6; }

/* chapter toggle panel */
details.chapters { margin: .5rem 0 .2rem; font-size: .92rem; }
details.chapters summary { cursor: pointer; user-select: none; display: flex; align-items: center; gap: .6rem; }
.chcount { color: var(--muted); font-size: .85rem; }
.chbtns { margin-left: auto; }
.chbtns button {
  font: inherit; font-size: .8rem; padding: .15rem .6rem; background: #e9e9e2;
  color: #333; border: 1px solid #d3d3c8; border-radius: 6px; cursor: pointer;
}
.chgrid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: .1rem .8rem; margin: .6rem 0 .2rem; max-height: 240px; overflow-y: auto;
  padding: .5rem; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.chgrid label {
  display: flex; align-items: baseline; gap: .4rem; font-size: .84rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
.chgrid label span { overflow: hidden; text-overflow: ellipsis; }
button {
  font: inherit; padding: .6rem 1.1rem; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; cursor: pointer;
}
button:hover { filter: brightness(1.05); }
.hint, .empty, .count, .error { color: var(--muted); font-size: .92rem; }
.hint { margin: .6rem 0 0; }
.error { color: #b00; }
.count { margin: 1.2rem 0 .4rem; }
a { color: var(--link); }

ol.results { list-style: none; padding: 0; margin: .5rem 0; }
ol.results li {
  display: flex; gap: .7rem; align-items: flex-start;
  padding: .7rem 0; border-top: 1px solid var(--line);
}
.play {
  flex: 0 0 auto; display: grid; place-items: center;
  width: 2.1rem; height: 2.1rem; margin-top: .1rem;
  border-radius: 50%; background: var(--accent); color: #fff;
  text-decoration: none; font-size: .8rem;
}
.play:hover { filter: brightness(1.08); }
.hit { min-width: 0; }
.meta { display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; font-size: .85rem; }
.vid { font-weight: bold; }
.sub { color: var(--muted); }
.ts { color: var(--muted); font-family: ui-monospace, monospace; }
.play.book { background: #558; }
.flag {
  color: var(--flag); border: 1px solid currentColor; border-radius: 4px;
  padding: 0 .35rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .03em;
}
.snippet { display: block; margin-top: .2rem; text-decoration: none; color: var(--ink); }
.snippet:hover { color: #000; }
mark { background: var(--mark); padding: 0 .1em; border-radius: 2px; }

/* watch page */
.watch main { display: block; }
.back { display: inline-block; margin-bottom: .4rem; font-size: .9rem; text-decoration: none; }
video { width: 100%; border-radius: 10px; background: #000; position: sticky; top: 0; }
.jumped { font-size: .92rem; color: var(--muted); margin: .8rem 0; }
.transcript {
  border-top: 1px solid var(--line); padding-top: .8rem; color: #333;
}
.transcript .seg { cursor: pointer; padding: 1px 2px; border-radius: 3px; }
.transcript .seg:hover { background: #eef; }
.transcript .seg.active { background: var(--mark); }

/* book read-along player */
body.read main.doc { line-height: 1.85; }
.doc .seg { cursor: pointer; padding: 1px 2px; border-radius: 3px; }
.doc .seg:hover { background: #eef; }
.doc .seg.active { background: var(--mark); }
audio { width: 100%; position: sticky; top: 0; }

/* loader / front door */
.libstats { color: var(--muted); font-size: .9rem; }
.toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin: 1rem 0; }
.toolbar #processbtn { background: var(--accent); color: #fff; }
.sel-actions { display: inline-flex; gap: .3rem; }
.sel-actions button, #rebuildbtn {
  font: inherit; font-size: .82rem; padding: .35rem .7rem; border-radius: 7px; cursor: pointer;
  background: #e9e9e2; color: #333; border: 1px solid #d3d3c8;
}
#rebuildbtn { margin-left: auto; }
.matgroup { margin: 1.2rem 0; }
.matgroup h3 { font-size: 1rem; margin: .3rem 0; }
.mkind { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .03em; border: 1px solid var(--line); padding: 0 .3rem; border-radius: 4px; }
.gcount { color: var(--muted); font-size: .8rem; font-weight: normal; }
.matlist { list-style: none; padding: 0; margin: .3rem 0; }
.matlist li { border-top: 1px solid var(--line); }
.matlist label { display: flex; align-items: center; gap: .6rem; padding: .45rem .2rem; cursor: pointer; }
.mname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msize { color: var(--muted); font-size: .8rem; font-family: ui-monospace, monospace; }
.status { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; padding: .05rem .4rem; border-radius: 4px; }
.status.ok { background: #e7f3e7; color: #275; }
.status.todo { background: #eef; color: #34a; }
.status.part { background: #f3eee2; color: #856404; }
.matlist li.done .mname { color: var(--muted); }

.jobpanel { border: 1px solid var(--line); border-radius: 8px; padding: .7rem .9rem; margin: 1rem 0; background: #fff; }
.jobpanel.hidden { display: none; }
.jobhead { display: flex; align-items: center; gap: .5rem; font-size: .9rem; font-weight: bold; }
.jobpanel pre { max-height: 260px; overflow: auto; background: #111; color: #cde; padding: .6rem; border-radius: 6px; font-size: .78rem; margin: .5rem 0 0; white-space: pre-wrap; }
.spinner { width: .9rem; height: .9rem; border: 2px solid #ccc; border-top-color: var(--accent); border-radius: 50%; display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.topnav { float: right; font-size: .85rem; margin-left: 1rem; }

/* uploader (front door "take in files") */
.uploader, .process { border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem; margin: 1rem 0; background: #fff; }
.uploader h2, .process h2 { font-size: 1.05rem; margin: .1rem 0 .7rem; }
.uprow { display: flex; gap: .8rem; align-items: flex-end; flex-wrap: wrap; margin: .5rem 0; }
.uplabel { display: flex; flex-direction: column; font-size: .78rem; color: var(--muted); gap: .2rem; }
.uplabel select, .uplabel input[type=text] { font: inherit; font-size: .9rem; padding: .35rem .5rem; border: 1px solid #ccc; border-radius: 7px; background: #fff; color: var(--ink); }
input[type=file] { font: inherit; font-size: .85rem; }
.uphint { color: var(--muted); font-size: .8rem; flex: 1; min-width: 12rem; }
.uplist { list-style: none; padding: 0; margin: .6rem 0 0; }
.uplist li { display: flex; align-items: center; gap: .6rem; padding: .3rem 0; font-size: .82rem; border-top: 1px solid var(--line); }
.uplist .un { flex: 1 1 40%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uplist .ub { flex: 1 1 40%; height: .5rem; background: #eee; border-radius: 4px; overflow: hidden; }
.uplist .ub i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.uplist .us { flex: 0 0 auto; color: var(--muted); font-family: ui-monospace, monospace; font-size: .75rem; min-width: 4rem; text-align: right; }
.uplist li.ok .us { color: #275; }
.uplist li.err .us { color: #b00; }
.uplist li.err .ub i { background: #b00; }

/* inventory */
.inventory table.inv { width: 100%; border-collapse: collapse; font-size: .82rem; margin: .8rem 0; }
.inventory .inv th, .inventory .inv td { text-align: left; padding: .35rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.inventory .inv th { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.inventory .inv td.num { text-align: right; font-family: ui-monospace, monospace; }
.inventory .inv td.built { color: var(--muted); font-family: ui-monospace, monospace; white-space: nowrap; }
.inventory .dl { font-size: .82rem; margin-left: .6rem; }
.inventory h2 { font-size: 1.05rem; margin: 1.4rem 0 .3rem; }
ul.pending { list-style: none; padding: 0; margin: .3rem 0; }
ul.pending li { display: flex; gap: .6rem; align-items: baseline; padding: .3rem 0; border-top: 1px solid var(--line); font-size: .85rem; }
ul.pending .pf { color: var(--muted); font-size: .78rem; }
ul.pending .pn { flex: 1; }
ul.pending .ps { color: var(--muted); font-family: ui-monospace, monospace; font-size: .78rem; }

/* text document reader */
body.read.text main.doc { line-height: 1.75; }
.doc .passage { padding: .3rem .5rem; border-radius: 6px; margin: .1rem -.5rem; }
.doc .passage.active { background: var(--mark); }

@media (prefers-color-scheme: dark) {
  :root { --ink: #ddd; --muted: #9a9a90; --line: #333; --bg: #16160f; --link: #9cf; }
  input[type=search], .uplabel select, .uplabel input[type=text] { background: #222; color: #eee; border-color: #444; }
  .snippet { color: var(--ink); }
  .transcript .seg:hover { background: #223; }
  .uploader, .process, .inventory .inv td { background: #1c1c14; }
  .uplist .ub { background: #333; }
  .tag.doc { background: #1e2634; color: #9db4d6; border-color: #33415a; }
}

/* Les Feldick masthead (demo restyle: clean, sans, understated) */
.brand { margin: .2rem 0 1.1rem; }
.brand .wordmark { font-size: 1.95rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.1; color: var(--ink); }
.brand .brandsub { color: var(--muted); font-size: .95rem; margin-top: .25rem; }
