:root {
  color-scheme: dark;
  --bg: #17120d;
  --panel: rgba(28, 22, 16, 0.86);
  --panel-solid: #1f1812;
  --line: rgba(217, 178, 106, 0.28);
  --text: #f1e6d0;
  --muted: #b6a487;
  --accent: #d9b26a;
  --accent-strong: #e8c47c;
  --danger: #e2786a;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Noto Serif", serif;
}

* { box-sizing: border-box; }
/* Author `display` rules (e.g. .ov-loading's flex) would otherwise override the hidden attribute. */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }
#app, #app canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.noscript { padding: 2rem; text-align: center; }

#overlay { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
/* Zero specificity, so class rules like `.ov-loading.done { pointer-events: none }` can win:
   an ID selector here once left the faded-out loading screen swallowing every click. */
:where(#overlay) > * { pointer-events: auto; }
#overlay.ov-hidden > :not(.ov-toasts) { display: none !important; }
#overlay .ov-card, #overlay .ov-search, #overlay .ov-hint, #overlay .ov-bottom { transition: opacity .35s ease; }
#overlay.ov-reading .ov-card, #overlay.ov-reading .ov-search, #overlay.ov-reading .ov-hint,
#overlay.ov-reading .ov-vr { opacity: 0; pointer-events: none !important; }
/* While reading, the help (and its "Copy debug info") stays, dimmed and in the corner, clear of the
   book's toolbar: a problem seen while reading must be reportable without closing the book. */
#overlay.ov-reading .ov-bottom { left: auto; right: max(16px, env(safe-area-inset-right)); transform: none; }
#overlay.ov-reading .ov-help-btn { opacity: .55; }
#overlay.ov-reading .ov-help-btn:hover { opacity: 1; }

/* Loading */
.ov-loading { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(ellipse at center, #2a1f15 0%, #120d09 70%); transition: opacity .5s ease; z-index: 5; }
.ov-loading.done { opacity: 0; pointer-events: none; }
.ov-loading.error .ov-loading-text { color: var(--danger); max-width: 34rem; text-align: center; padding: 0 16px; }
.ov-logo { font: 600 44px/1 var(--serif); letter-spacing: .06em; color: var(--accent); text-shadow: 0 2px 18px rgba(217,178,106,.35); }
.ov-loading-text { color: var(--muted); }
.ov-progress { width: min(320px, 70vw); height: 4px; border-radius: 2px; background: rgba(255,255,255,.08); overflow: hidden; }
.ov-progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .25s ease; }
.ov-progress-bar.indeterminate { width: 35%; animation: ov-slide 1.2s ease-in-out infinite; }
@keyframes ov-slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

/* Library card */
.ov-card { position: fixed; top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); width: min(360px, calc(100vw - 24px));
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px 12px; backdrop-filter: blur(8px); box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.ov-card header { display: flex; align-items: center; justify-content: space-between; }
.ov-brand { font: 600 20px/1.2 var(--serif); letter-spacing: .05em; color: var(--accent); }
.ov-tools { display: flex; gap: 6px; }
/* Gamepad aim point (xr/controls.js), centred on the canvas. */
.pad-crosshair { position: fixed; left: 50%; top: 50%; width: 14px; height: 14px; margin: -9px 0 0 -9px; border: 2px solid rgba(255, 241, 208, 0.85); border-radius: 50%; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45); pointer-events: none; z-index: 5; transition: transform 0.12s, background 0.12s; }
.pad-crosshair.hover { transform: scale(1.35); background: rgba(255, 210, 122, 0.55); }
.ov-version { flex: 1; margin: 0 8px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ov-collapse, .ov-rescan { background: none; border: 1px solid var(--line); border-radius: 8px; width: 28px; height: 28px; line-height: 1; color: var(--muted); }
.ov-rescan:hover, .ov-collapse:hover { color: var(--accent); border-color: var(--accent); }
.ov-card.collapsed .ov-libs, .ov-card.collapsed .ov-open { display: none; }
.ov-open { margin-top: 10px; }
.ov-open-btn { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--accent); }
.ov-open-btn:hover { border-color: var(--accent); }
.ov-open-hint { margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.ov-reopen { margin-top: 6px; font-size: 12px; line-height: 1.6; color: var(--muted); }
.ov-reopen-names { color: var(--text); }
.ov-reopen button { margin-left: 6px; padding: 1px 8px; font-size: 12px; }
.ov-open-hint a { color: var(--accent); }
/* Shown while ZIM files are dragged over the page. */
.ov-drop { position: fixed; inset: 16px; z-index: 30; display: flex; align-items: center; justify-content: center; border: 3px dashed var(--accent); border-radius: 18px; background: rgba(20, 16, 10, 0.72); color: var(--accent); font: 600 24px/1.3 var(--serif); pointer-events: none; }
.ov-drop[hidden] { display: none; }
.ov-libs { margin-top: 8px; display: grid; gap: 10px; max-height: 40vh; overflow: auto; }
.ov-lib { display: flex; gap: 10px; align-items: flex-start; }
.ov-lib img { border-radius: 8px; flex: none; image-rendering: auto; }
.ov-lib-title { font: 600 16px/1.25 var(--serif); }
.ov-lib-desc { color: var(--muted); font-size: 13px; margin-top: 2px; }
.ov-lib-meta { color: var(--muted); font-size: 12px; margin-top: 4px; opacity: .85; }

/* Search */
.ov-search { position: fixed; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); width: min(380px, calc(100vw - 24px)); }
.ov-search input { width: 100%; padding: 10px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; backdrop-filter: blur(8px); }
.ov-search input::placeholder { color: var(--muted); }
.ov-results { list-style: none; margin: 6px 0 0; padding: 6px; background: var(--panel-solid); border: 1px solid var(--line); border-radius: var(--radius); max-height: min(60vh, 520px); overflow: auto; box-shadow: 0 12px 30px rgba(0,0,0,.45); }
.ov-results li { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 10px; cursor: pointer; }
.ov-results li.sel, .ov-results li:hover { background: rgba(217,178,106,.16); }
.ov-results img, .ov-nocover { width: 34px; height: 48px; object-fit: cover; border-radius: 3px; background: #3a2e22; flex: none; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.ov-results img.ov-r-icon { height: 34px; object-fit: contain; background: none; box-shadow: none; }
.ov-r-title { font: 600 14px/1.25 var(--serif); }
.ov-r-sub { color: var(--muted); font-size: 12px; }
.ov-empty { color: var(--muted); cursor: default !important; }

/* Bottom bar */
.ov-bottom { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 12px; align-items: center; }
.ov-vr { padding: 12px 30px; border-radius: 999px; border: 0; background: linear-gradient(180deg, var(--accent-strong), #b98a3c); color: #24170a; font-weight: 700; letter-spacing: .03em;
  box-shadow: 0 8px 24px rgba(217,178,106,.3); }
.ov-vr:hover { filter: brightness(1.07); }
.ov-help-btn { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-weight: 700; color: var(--accent); backdrop-filter: blur(8px); }
.ov-hint { position: fixed; left: max(14px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom)); color: var(--muted); font-size: 12px;
  background: rgba(20,15,10,.55); padding: 4px 10px; border-radius: 999px; pointer-events: none !important; }

/* Help dialog */
.ov-help { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 6; /* above the loading screen: its error offers the debug report */ }
.ov-help[hidden] { display: none; }
.ov-help-inner { background: var(--panel-solid); border: 1px solid var(--line); border-radius: var(--radius); max-width: 560px; width: 100%; max-height: 85vh; overflow: auto; padding: 14px 20px 18px; }
.ov-help-inner header { display: flex; justify-content: space-between; align-items: center; }
.ov-help h2 { font: 600 20px var(--serif); margin: 4px 0; color: var(--accent); }
.ov-help h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 0 6px; }
.ov-help dl { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 6px 14px; margin: 0; }
.ov-help dt { font-weight: 600; }
.ov-help dd { margin: 0; color: var(--muted); }
.ov-view { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 14px; }
.ov-view-book, .ov-view-reset { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--accent); }
.ov-view-book[hidden] { display: none; }
.ov-view-note { color: var(--muted); font-size: 13px; }
.ov-debug { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); }
.ov-debug > div { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.ov-debug > div + div { margin-top: 8px; }
.ov-scene-save, .ov-scene-restore, .ov-scene-paste, .ov-scene-restore-text { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--accent); }
.ov-scene-restore:disabled { opacity: .45; cursor: default; }
.ov-scene-note { color: var(--muted); font-size: 13px; }
.ov-scene-text { margin-top: 8px; }
.ov-debug-btn, .ov-loading-debug, .ov-shot-btn, .ov-reset-btn, .ov-reset-go, .ov-reset-cancel { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--accent); }
.ov-reset-go:disabled { opacity: .45; cursor: default; }
.ov-reset-note { color: var(--muted); font-size: 13px; }
/* "Reset stored data…": the parts to clear, one per line, then the buttons. */
.ov-reset { display: grid; gap: 6px; margin: 8px 0 0; padding: 8px 12px 10px; border: 1px solid var(--line); border-radius: 8px; }
.ov-reset legend { padding: 0 6px; color: var(--muted); font-size: 13px; }
.ov-reset label { display: flex; gap: 8px; align-items: baseline; }
.ov-reset > div { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 4px; }
.ov-debug-note { color: var(--muted); font-size: 13px; }
.ov-debug-text { display: block; width: 100%; height: 12em; margin-top: 10px; resize: vertical; font: 12px/1.4 ui-monospace, Consolas, monospace; color: inherit; background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 8px; padding: 8px; box-sizing: border-box; }
.ov-help-close { background: none; border: 0; font-size: 26px; line-height: 1; color: var(--muted); }

/* Toasts */
.ov-update { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 12px; max-width: calc(100vw - 24px); width: max-content; padding: 8px 10px 8px 16px; border-radius: 22px; border: 1px solid var(--accent); background: var(--panel-solid); box-shadow: 0 6px 20px rgba(0,0,0,.35); z-index: 4; }
.ov-update-never, .ov-update-close { background: none; border: none; color: var(--muted); padding: 2px 4px; }
.ov-update-never { text-decoration: underline; font-size: 13px; }
.ov-update-close { font-size: 20px; line-height: 1; }
.ov-update-pref { display: flex; align-items: center; gap: 8px; margin-top: 16px; color: var(--muted); font-size: 13px; }
.ov-update-btn { padding: 4px 14px; border-radius: 999px; border: 1px solid var(--accent); background: var(--accent); color: #1a120a; font-weight: 600; }
/* width: max-content, or a box at left: 50% shrinks to the half of the page right of its start: on
   a phone each toast wrapped into a tall oval over the search field. */
.ov-toasts { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); width: max-content; max-width: min(720px, calc(100vw - 24px)); display: grid; gap: 8px; justify-items: center; pointer-events: none !important; }
.ov-toast { background: var(--panel-solid); border: 1px solid var(--line); padding: 8px 16px; border-radius: 20px; box-shadow: 0 8px 20px rgba(0,0,0,.4); transition: opacity .4s, transform .4s; max-width: 100%; }
.ov-toast.error { border-color: var(--danger); color: #ffd9d3; }
.ov-toast.out { opacity: 0; transform: translateY(6px); }
.ov-toast.busy::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 10px; vertical-align: -2px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: ov-spin .9s linear infinite; }
@keyframes ov-spin { to { transform: rotate(360deg); } }
.ov-toast-bar { height: 4px; margin: 7px 0 2px; border-radius: 2px; background: var(--line); overflow: hidden; }
.ov-toast-bar > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
/* What the local library is doing (files opening, index builds): one box at the foot of the page, out of the view's middle. */
.ov-status { position: fixed; right: 16px; bottom: 84px; width: min(340px, calc(100vw - 32px)); padding: 8px 12px; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 20px rgba(0,0,0,.4); font-size: 13px; }
.ov-status-head { display: flex; align-items: center; gap: 8px; }
.ov-status-head::before { content: ""; flex: none; width: 11px; height: 11px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: ov-spin .9s linear infinite; }
.ov-status-text { flex: 1; min-width: 0; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.ov-status-toggle, .ov-status-stop { flex: none; padding: 0 8px; font-size: 13px; line-height: 1.6; }
.ov-status-rows { list-style: none; margin: 8px 0 0; padding: 0; max-height: 40vh; overflow-y: auto; overflow-x: hidden; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.ov-status-rows li.waiting { color: var(--muted); }
.ov-status-row { display: flex; align-items: baseline; gap: 8px; }
.ov-status-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ov-status-line { flex: none; color: var(--muted); font-size: 12px; }
.ov-status-cancel { flex: none; padding: 0 7px; line-height: 1.4; }
.ov-status-rows .ov-toast-bar { margin: 4px 0 0; height: 3px; }

@media (max-width: 640px) {
  .ov-card { width: calc(100vw - 24px); }
  .ov-search { top: auto; bottom: 74px; left: 12px; right: 12px; width: auto; }
  .ov-toasts, .ov-status { bottom: 128px; } /* above the search field */
  .ov-results { position: absolute; bottom: 48px; width: 100%; }
  .ov-hint { display: none; }
}

/* A ZIM's web address (milestone 3), the example read online, and a local library's × */
.ov-url { display: flex; gap: 6px; margin-top: 8px; }
.ov-url-input { flex: 1; min-width: 0; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 13px; }
.ov-url-input:focus { outline: none; border-color: var(--accent); }
.ov-url button { padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--accent); }
.ov-url button:hover { border-color: var(--accent); }
.ov-try-btn { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
.ov-lib-body { flex: 1; min-width: 0; }
.ov-lib-close { flex: none; width: 24px; height: 24px; padding: 0; border-radius: 6px; border: 1px solid transparent; background: none; color: var(--muted); font-size: 16px; line-height: 1; }
.ov-lib-close:hover { border-color: var(--line); color: var(--text); }

/* Kiwix's library (ui/kiwix-dialog.js, milestone 3 step 5) */
.ov-kiwix-btn { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--accent); }
.ov-kiwix-btn:hover { border-color: var(--accent); }
/* Kiwix's library first, on a line of its own (what a new visitor most likely wants), then the
   device's files on the next. */
.ov-kiwix-btn, .ov-open-btn { display: block; }
.ov-kiwix-btn:not([hidden]) + .ov-open-btn { margin-top: 8px; }
.ov-kiwix { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 6; }
.ov-kiwix[hidden] { display: none; }
.ov-kiwix-inner { background: var(--panel-solid); border: 1px solid var(--line); border-radius: var(--radius); max-width: 680px; width: 100%; height: min(85vh, 760px); display: flex; flex-direction: column; padding: 14px 20px 16px; }
.ov-kiwix-inner header { display: flex; justify-content: space-between; align-items: center; }
.ov-kiwix h2 { font: 600 20px var(--serif); margin: 4px 0; color: var(--accent); }
.ov-kiwix-close { background: none; border: 0; font-size: 26px; line-height: 1; color: var(--muted); }
.ov-kiwix-note { margin: 4px 0 10px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.ov-kiwix-note a { color: var(--accent); }
.ov-kiwix-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.ov-kiwix-kinds { display: flex; gap: 4px; }
.ov-kiwix-kinds button { padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.ov-kiwix-kinds button[aria-selected="true"] { border-color: var(--accent); color: var(--accent); }
.ov-kiwix-lang, .ov-kiwix-find { padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 13px; }
.ov-kiwix-lang { max-width: 180px; }
.ov-kiwix-find { flex: 1; min-width: 120px; }
.ov-kiwix-state { color: var(--muted); font-size: 13px; padding: 6px 2px; }
.ov-kiwix-state[hidden] { display: none; }
.ov-kiwix-state.error { color: #e8a87c; }
.ov-kiwix-retry { margin-left: 8px; padding: 2px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--accent); }
.ov-kiwix-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; min-height: 0; }
.ov-kiwix-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 4px; border-top: 1px solid var(--line); }
.ov-kiwix-item img, .ov-kiwix-noimg { flex: none; width: 40px; height: 40px; border-radius: 8px; background: rgba(255,255,255,.05); }
.ov-kiwix-body { flex: 1; min-width: 0; }
.ov-kiwix-title { font: 600 15px/1.25 var(--serif); }
.ov-kiwix-summary { color: var(--muted); font-size: 13px; margin-top: 2px; }
.ov-kiwix-meta { color: var(--muted); font-size: 12px; margin-top: 3px; opacity: .85; }
.ov-kiwix-warn { color: #e8a87c; font-size: 12px; margin-top: 3px; }
.ov-kiwix-open { flex: none; padding: 5px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--accent); }
.ov-kiwix-open:hover:not(:disabled) { border-color: var(--accent); }
.ov-kiwix-open:disabled { color: var(--muted); opacity: .7; }
/* Where an entry's index comes from (kiwix.js indexLabel) */
.ov-kiwix-index { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px; border: 1px solid var(--line); font-size: 11px; line-height: 17px; color: var(--muted); }
.ov-kiwix-index.here, .ov-kiwix-index.site { border-color: #6f8f4e; color: #a9c98a; }
.ov-kiwix-index.build { border-style: dashed; }
