/* Master PDF — styles */
:root {
  --teal: #013541;
  --teal-2: #0b4a58;
  --teal-3: #1d6676;
  --cream: #fcf1d9;
  --cream-2: #f3e3bd;
  --bg: #fbf7ee;
  --card: #ffffff;
  --ink: #102a30;
  --muted: #5d6f74;
  --line: #e6dcc6;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --bad: #c0392b;
  --hl-yellow: rgba(255, 214, 64, .45);
  --hl-green: rgba(90, 210, 120, .40);
  --hl-blue: rgba(80, 170, 255, .38);
  --hl-pink: rgba(255, 110, 170, .38);
  --radius: 14px;
  --shadow: 0 6px 24px rgba(1, 53, 65, .12);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Malayalam", "Nirmala UI", "Kartika", sans-serif;
  --ml: "Noto Sans Malayalam", "Nirmala UI", "Kartika", "Manjari", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #0d181b;
  --card: #132429;
  --ink: #e6eeef;
  --muted: #9db0b4;
  --line: #24393f;
  --cream: #f6e7c3;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.ml { font-family: var(--ml); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; align-items: center; gap: .5rem; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- shell ---------- */
#app { display: flex; height: 100%; }
.rail {
  width: 220px; flex: none; background: var(--teal); color: var(--cream);
  display: flex; flex-direction: column; gap: 4px; padding: calc(12px + var(--safe-t)) 10px 12px;
}
.rail-brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; font-weight: 700; font-size: 1.15rem; letter-spacing: .2px; }
.rail-brand img { border-radius: 10px; }
.nav-btn {
  display: flex; align-items: center; gap: 12px; border: 0; background: transparent; color: inherit;
  padding: 11px 12px; border-radius: 12px; text-align: left; font-size: .98rem; opacity: .85;
}
.nav-btn .ico { font-size: 1.2rem; width: 1.6rem; text-align: center; }
.nav-btn:hover { background: rgba(252, 241, 217, .08); opacity: 1; }
.nav-btn.active { background: var(--cream); color: var(--teal); opacity: 1; font-weight: 600; }
#main { flex: 1; min-width: 0; overflow: auto; height: 100%; }
.view { display: none; padding: calc(16px + var(--safe-t)) 20px 32px; max-width: 1200px; margin: 0 auto; }
.view.active { display: block; }

@media (max-width: 860px) {
  #app { flex-direction: column-reverse; }
  .rail { width: 100%; flex-direction: row; justify-content: space-around; padding: 6px 4px calc(6px + var(--safe-b)); gap: 0; }
  .rail-brand { display: none; }
  .nav-btn { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: .72rem; flex: 1; align-items: center; text-align: center; }
  .nav-btn .ico { font-size: 1.25rem; }
  .view { padding: calc(12px + var(--safe-t)) 14px 24px; }
}

/* ---------- common ---------- */
.page-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; }
.page-head h1 { font-size: 1.45rem; margin: 0; }
.page-head .logo { width: 40px; height: 40px; border-radius: 10px; }
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 9px 14px; border-radius: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover { border-color: var(--teal-3); }
.btn.primary { background: var(--teal); color: var(--cream); border-color: var(--teal); }
.btn.primary:hover { background: var(--teal-2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 6px 10px; font-size: .85rem; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 12px; font-size: 1.2rem;
  display: inline-grid; place-items: center; color: inherit; flex: none;
}
.icon-btn:hover { background: rgba(127, 127, 127, .14); }
.icon-btn.on { background: var(--cream); color: var(--teal); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .75rem;
  background: var(--cream); color: var(--teal); font-weight: 600; white-space: nowrap;
}
.chip.ok { background: #dff3e6; color: var(--ok); }
.chip.warn { background: #fbecd2; color: var(--warn); }
.chip.bad { background: #f8dcd8; color: var(--bad); }
html[data-theme="dark"] .chip { background: #1e3a40; color: var(--cream); }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 12px;
}
.input:focus { outline: 2px solid var(--teal-3); border-color: transparent; }
.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--teal-3); width: 0; transition: width .3s; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty img { width: 84px; opacity: .9; margin-bottom: 8px; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
kbd { font-size: .8em; border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; }

/* ---------- library ---------- */
.lib-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.lib-actions .input { max-width: 320px; }
.dropzone {
  border: 2px dashed var(--teal-3); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted);
  margin-bottom: 16px; background: rgba(252, 241, 217, .35);
}
.dropzone.drag { background: var(--cream); color: var(--teal); }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.doc-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; position: relative; }
.doc-card .cover { aspect-ratio: 3 / 4; background: #ece4d2 center/cover no-repeat; display: grid; place-items: center; cursor: pointer; position: relative; }
.doc-card .cover .ph { font-size: 2.4rem; opacity: .5; }
.doc-card .cover .badge { position: absolute; left: 8px; top: 8px; display: flex; gap: 4px; flex-wrap: wrap; }
.doc-card .meta { padding: 10px 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.doc-card .title { font-weight: 600; font-size: .92rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-card .sub { font-size: .75rem; color: var(--muted); }
.doc-card .more { position: absolute; right: 6px; top: 6px; background: rgba(255, 255, 255, .85); color: var(--teal); }
.storage-bar { font-size: .8rem; color: var(--muted); }

/* ---------- sheets / modals ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 20, 26, .45); z-index: 60; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--card); color: var(--ink); width: min(680px, 100%); max-height: 88vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 10px 18px calc(18px + var(--safe-b)); box-shadow: var(--shadow); animation: up .18s ease-out;
}
.sheet .grab { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 2px auto 10px; }
.sheet h2 { margin: 4px 0 12px; font-size: 1.15rem; }
@media (min-width: 861px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; max-height: 84vh; }
}
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }
.menu-list { display: flex; flex-direction: column; }
.menu-list button { border: 0; background: transparent; text-align: left; padding: 12px 8px; border-radius: 10px; display: flex; gap: 12px; align-items: center; font-size: .98rem; }
.menu-list button:hover { background: rgba(127, 127, 127, .1); }
.menu-list button .ico { width: 1.6rem; text-align: center; }
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-row label { font-weight: 600; font-size: .9rem; }
.form-row .hint { font-size: .8rem; color: var(--muted); }
.switch-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch-row:last-child { border-bottom: 0; }
.switch-row .grow b { display: block; font-size: .95rem; }
.switch-row .grow span { font-size: .8rem; color: var(--muted); }
.toggle { appearance: none; width: 46px; height: 28px; border-radius: 99px; background: var(--line); position: relative; flex: none; cursor: pointer; transition: background .15s; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.toggle:checked { background: var(--teal-3); }
.toggle:checked::after { left: 21px; }

/* ---------- toast ---------- */
#toast-root { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--safe-b)); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--teal); color: var(--cream); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: .92rem; max-width: 92vw; animation: up .2s; pointer-events: auto; }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------- reader ---------- */
.reader { position: fixed; inset: 0; z-index: 40; background: #5d666a; display: flex; flex-direction: column; }
html[data-theme="dark"] .reader { background: #050b0d; }
.reader.sepia-bg { background: #8d7f63; }
.r-bar {
  flex: none; display: flex; align-items: center; gap: 2px; padding: calc(4px + var(--safe-t)) 6px 4px; background: var(--teal); color: var(--cream);
  transition: transform .2s; z-index: 5; min-height: 52px;
}
.r-bar .r-title { flex: 1; min-width: 0; font-weight: 600; font-size: .95rem; padding: 0 6px; }
.r-bar .r-title small { display: block; font-weight: 400; opacity: .75; font-size: .72rem; }
.reader.immersive .r-bar { transform: translateY(-110%); position: absolute; left: 0; right: 0; }
.reader.immersive .r-foot { transform: translateY(110%); position: absolute; left: 0; right: 0; bottom: 0; }
.r-scroll { flex: 1; overflow: auto; position: relative; touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; }
.r-pages { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 8px 80px; transform-origin: 0 0; }
.r-page { position: relative; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .25); flex: none; }
.r-page canvas.pdf { position: absolute; inset: 0; width: 100%; height: 100%; }
.r-page .pnum { position: absolute; bottom: -18px; right: 0; font-size: .7rem; color: rgba(255, 255, 255, .7); }
.r-page .hl-layer, .r-page .hit-layer { position: absolute; inset: 0; pointer-events: none; }
.r-page .hl-layer > i { position: absolute; display: block; mix-blend-mode: multiply; border-radius: 2px; }
.r-page .hit-layer > i { position: absolute; display: block; background: rgba(255, 140, 0, .45); outline: 2px solid rgba(255, 120, 0, .9); border-radius: 2px; }
.r-page .word-flash { position: absolute; border-radius: 3px; background: rgba(29, 102, 118, .28); outline: 2px solid rgba(29, 102, 118, .8); pointer-events: none; z-index: 3; }
.r-page .loading { position: absolute; inset: 0; display: grid; place-items: center; color: #999; font-size: .85rem; }
.reader.mode-night canvas.pdf { filter: invert(.92) hue-rotate(180deg) brightness(.95) contrast(.95); }
.reader.mode-night .r-page { background: #111; }
.reader.mode-sepia canvas.pdf { filter: sepia(.55) brightness(.97); }
.reader.enhance canvas.pdf { filter: contrast(1.45) brightness(1.06) saturate(.85); }
.reader.mode-night.enhance canvas.pdf { filter: invert(.92) hue-rotate(180deg) contrast(1.4); }

/* pdf.js text layer (from pdf_viewer.css, trimmed) */
.textLayer { position: absolute; text-align: initial; inset: 0; overflow: clip; opacity: 1; line-height: 1; letter-spacing: normal; word-spacing: normal; -webkit-text-size-adjust: none; text-size-adjust: none; forced-color-adjust: none; transform-origin: 0 0; caret-color: CanvasText; z-index: 2; color-scheme: only light; }
.textLayer :is(span, br) { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; user-select: text; -webkit-user-select: text; }
.textLayer { --min-font-size: 1; --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size)); --min-font-size-inv: calc(1 / var(--min-font-size)); }
.textLayer > :not(.markedContent), .textLayer .markedContent span:not(.markedContent) { z-index: 1; --font-height: 0; font-size: calc(var(--text-scale-factor) * var(--font-height)); --scale-x: 1; --rotate: 0deg; transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv)); }
.textLayer .markedContent { display: contents; }
.textLayer ::selection { background: rgba(0, 110, 255, .28); color: transparent; }
.textLayer .endOfContent { display: block; position: absolute; inset: 100% 0 0; z-index: 0; cursor: default; user-select: none; }
.textLayer.selecting .endOfContent { top: 0; }
.ocrLayer { position: absolute; inset: 0; z-index: 2; }
.ocrLayer span { position: absolute; color: transparent; white-space: pre; transform-origin: 0 0; cursor: text; line-height: 1; user-select: text; -webkit-user-select: text; }
.ocrLayer ::selection { background: rgba(0, 110, 255, .28); color: transparent; }
.reader.tapmode .textLayer span, .reader.tapmode .ocrLayer span { cursor: pointer; }

.r-foot {
  flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 10px calc(6px + var(--safe-b)); background: var(--card); color: var(--ink);
  border-top: 1px solid var(--line); transition: transform .2s; z-index: 5;
}
.r-foot input[type=range] { flex: 1; accent-color: var(--teal-3); }
.r-foot .pg { font-variant-numeric: tabular-nums; font-size: .85rem; min-width: 82px; text-align: center; }
.r-side {
  position: absolute; top: 0; bottom: 0; left: 0; width: min(360px, 88vw); background: var(--card); color: var(--ink); z-index: 20;
  box-shadow: var(--shadow); display: flex; flex-direction: column; transform: translateX(-102%); transition: transform .2s;
}
.r-side.open { transform: none; }
.r-side .tabs { display: flex; border-bottom: 1px solid var(--line); padding-top: var(--safe-t); }
.r-side .tabs button { flex: 1; border: 0; background: transparent; padding: 12px 4px; font-weight: 600; font-size: .85rem; border-bottom: 3px solid transparent; }
.r-side .tabs button.on { border-color: var(--teal-3); color: var(--teal-3); }
.r-side .body { flex: 1; overflow: auto; padding: 10px; }
.thumbs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.thumbs .t { border: 2px solid transparent; border-radius: 8px; cursor: pointer; text-align: center; font-size: .75rem; color: var(--muted); }
.thumbs .t.cur { border-color: var(--teal-3); }
.thumbs canvas { width: 100%; background: #fff; display: block; border-radius: 6px; box-shadow: 0 1px 4px rgba(0, 0, 0, .2); }
.outline a { display: block; padding: 7px 6px; color: inherit; text-decoration: none; border-radius: 8px; font-size: .9rem; }
.outline a:hover { background: rgba(127, 127, 127, .12); }
.outline .lvl1 { padding-left: 18px; } .outline .lvl2 { padding-left: 30px; font-size: .85rem; } .outline .lvl3 { padding-left: 42px; font-size: .82rem; }
.list-item { padding: 9px 8px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: .88rem; }
.list-item:hover { background: rgba(127, 127, 127, .08); }
.list-item mark { background: #ffe58a; color: inherit; border-radius: 3px; }
.sel-menu {
  position: absolute; z-index: 30; display: flex; gap: 2px; background: var(--teal); color: var(--cream); border-radius: 12px; padding: 4px; box-shadow: var(--shadow);
}
.sel-menu button { border: 0; background: transparent; color: inherit; padding: 7px 10px; border-radius: 9px; font-size: .85rem; white-space: nowrap; }
.sel-menu button:hover { background: rgba(252, 241, 217, .15); }
.sel-menu .sw { width: 18px; height: 18px; border-radius: 50%; display: inline-block; vertical-align: middle; border: 2px solid rgba(255, 255, 255, .8); }
.ocr-pill { position: absolute; right: 12px; top: 64px; z-index: 6; background: var(--card); color: var(--ink); border-radius: 99px; padding: 6px 12px; font-size: .78rem; box-shadow: var(--shadow); }
.tts-bar { position: absolute; left: 50%; transform: translateX(-50%); bottom: 64px; z-index: 6; background: var(--teal); color: var(--cream); border-radius: 99px; display: flex; gap: 4px; padding: 4px 8px; box-shadow: var(--shadow); align-items: center; font-size: .85rem; }
.tts-bar button { border: 0; background: transparent; color: inherit; font-size: 1.1rem; padding: 6px 8px; border-radius: 99px; }

/* ---------- word popup ---------- */
.wp-backdrop { position: fixed; inset: 0; z-index: 70; }
.wp {
  position: fixed; z-index: 71; background: var(--card); color: var(--ink); box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
  border: 1px solid var(--line); overflow: auto; overscroll-behavior: contain;
}
@media (max-width: 860px) {
  .wp { left: 0; right: 0; bottom: 0; max-height: 72vh; border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + var(--safe-b)); animation: up .16s ease-out; }
}
@media (min-width: 861px) {
  .wp { width: 420px; max-height: 70vh; border-radius: 16px; padding: 14px 16px 16px; }
}
.wp .grab { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 2px auto 8px; }
.wp-head { display: flex; align-items: flex-start; gap: 8px; }
.wp-word { font-size: 1.45rem; font-weight: 700; line-height: 1.2; word-break: break-word; }
.wp-sub { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; font-size: .85rem; color: var(--muted); }
.wp-ipa { font-family: "Charis SIL", "Doulos SIL", "Gentium Plus", "Segoe UI", "Noto Sans", sans-serif; color: var(--teal-3); font-size: .98rem; }
html[data-theme="dark"] .wp-ipa { color: #8fd3e0; }
.play { border: 0; background: var(--teal); color: var(--cream); width: 44px; height: 44px; border-radius: 50%; font-size: 1.15rem; display: grid; place-items: center; flex: none; box-shadow: 0 3px 10px rgba(1, 53, 65, .3); }
.play.slow { width: 36px; height: 36px; font-size: .78rem; background: var(--cream); color: var(--teal); box-shadow: none; font-weight: 700; }
.play.speaking { animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.wp-sec { margin-top: 12px; }
.wp-sec h4 { margin: 0 0 6px; font-size: .78rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.wp-ml-main { font-family: var(--ml); font-size: 1.3rem; font-weight: 700; color: var(--teal); line-height: 1.45; }
html[data-theme="dark"] .wp-ml-main { color: var(--cream); }
.wp-ml-list { font-family: var(--ml); font-size: 1.02rem; line-height: 1.6; }
.wp-ml-list span { display: inline-block; background: rgba(252, 241, 217, .7); border: 1px solid var(--line); padding: 1px 9px; border-radius: 99px; margin: 0 4px 6px 0; }
html[data-theme="dark"] .wp-ml-list span { background: #1c3237; }
.wp-ai { border-radius: 14px; padding: 12px; background: linear-gradient(135deg, rgba(1, 53, 65, .06), rgba(252, 241, 217, .7)); border: 1px solid var(--line); }
html[data-theme="dark"] .wp-ai { background: #172e33; }
.wp-ai .lbl { font-size: .72rem; font-weight: 700; color: var(--teal-3); letter-spacing: .4px; }
.wp-ai .mlbig { font-family: var(--ml); font-size: 1.32rem; font-weight: 700; margin: 4px 0; color: var(--teal); }
html[data-theme="dark"] .wp-ai .mlbig { color: var(--cream); }
.wp-ai p { margin: 6px 0; font-size: .95rem; line-height: 1.55; }
.wp-ctx { font-size: .92rem; line-height: 1.55; background: rgba(127, 127, 127, .08); border-radius: 10px; padding: 8px 10px; }
.wp-ctx b { background: rgba(255, 214, 64, .6); color: inherit; border-radius: 3px; padding: 0 2px; }
.wp-def { font-size: .92rem; line-height: 1.5; margin: 0 0 6px; }
.wp-def .ex { color: var(--muted); font-style: italic; display: block; font-size: .85rem; }
.wp-def.best::before { content: "★ "; color: var(--warn); }
.wp-note { font-family: var(--ml); font-size: .95rem; line-height: 1.6; background: #fff7e3; border-left: 4px solid var(--warn); padding: 8px 10px; border-radius: 8px; }
html[data-theme="dark"] .wp-note { background: #2a2416; }
.wp-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.wp-tabs { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.wp-tabs button { border: 1px solid var(--line); background: transparent; border-radius: 99px; padding: 4px 12px; font-size: .85rem; }
.wp-tabs button.on { background: var(--teal); color: var(--cream); border-color: var(--teal); }
.spin { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--teal-3); border-radius: 50%; display: inline-block; animation: rot .8s linear infinite; vertical-align: -3px; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ---------- words ---------- */
.word-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 6px; border-bottom: 1px solid var(--line); }
.word-row .w { font-weight: 700; font-size: 1.05rem; }
.word-row .m { font-family: var(--ml); font-size: 1rem; color: var(--teal); }
html[data-theme="dark"] .word-row .m { color: var(--cream); }
.word-row .c { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.flash { max-width: 460px; margin: 20px auto; text-align: center; }
.flash .cardf { min-height: 220px; display: grid; place-items: center; font-size: 1.8rem; font-weight: 700; cursor: pointer; padding: 24px; }
.flash .cardf .ml { font-size: 1.4rem; color: var(--teal); }

/* ---------- tools ---------- */
.tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.tool { text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.tool:hover { border-color: var(--teal-3); }
.tool .ico { font-size: 1.6rem; }
.tool b { font-size: 1rem; }
.tool span { font-size: .8rem; color: var(--muted); }
.pick-list { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow: auto; margin: 8px 0; }
.pick-list label { display: flex; gap: 10px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 10px; font-size: .9rem; }
.org-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; max-height: 55vh; overflow: auto; padding: 4px; }
.org-grid .pg { border: 2px solid var(--line); border-radius: 8px; padding: 4px; text-align: center; font-size: .75rem; background: var(--card); position: relative; user-select: none; }
.org-grid .pg canvas { width: 100%; display: block; background: #fff; }
.org-grid .pg.sel { border-color: var(--teal-3); }
.org-grid .pg.del { opacity: .35; }
.org-grid .pg .ctl { display: flex; justify-content: center; gap: 2px; margin-top: 4px; }
.org-grid .pg .ctl button { border: 0; background: rgba(127, 127, 127, .12); border-radius: 6px; padding: 2px 6px; font-size: .8rem; }
.sig-pad { width: 100%; height: 180px; border: 1px dashed var(--teal-3); border-radius: 12px; background: #fff; touch-action: none; }

/* ---------- AI panel ---------- */
.ai-out { font-size: .95rem; line-height: 1.65; }
.ai-out h3 { font-size: 1rem; margin: 14px 0 6px; }
.ai-out .ml { font-size: 1.02rem; }
.ai-out ul { padding-left: 20px; margin: 6px 0; }
.qa-msg { padding: 10px 12px; border-radius: 12px; margin: 8px 0; font-size: .93rem; line-height: 1.6; }
.qa-msg.q { background: var(--cream); color: var(--teal); align-self: flex-end; }
.qa-msg.a { background: rgba(127, 127, 127, .1); }
.qa-msg a.cite { color: var(--teal-3); font-weight: 600; cursor: pointer; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- additions ---------- */
.r-pages { min-width: 100%; width: max-content; }
.r-page { --scale-round-x: 1px; --scale-round-y: 1px; --user-unit: 1; contain: layout paint; }
.link-layer { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.link-layer a.lnk { position: absolute; pointer-events: auto; border-radius: 2px; }
.link-layer a.lnk:hover { background: rgba(29, 102, 118, .12); outline: 1px dashed rgba(29, 102, 118, .6); }
.r-page .hit-layer > i.tts { background: rgba(80, 170, 255, .25); outline: none; border-radius: 3px; }
.r-page .hl-layer > i.note-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); mix-blend-mode: normal; box-shadow: 0 0 0 2px #fff; }
.sw-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.r-bar .icon-btn { color: var(--cream); }
.r-bar .icon-btn.on { background: var(--cream); color: var(--teal); }
.r-side .tabs button { padding: 12px 2px; }
.r-side .tabs .tab-l { display: none; }
.r-side h4 { margin: 4px 0 8px; font-size: .9rem; }
.outline-a { display: block; padding: 8px 6px; color: inherit; text-decoration: none; border-bottom: 1px solid var(--line); }
.card.continue { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; cursor: pointer; }
.card.continue img, .card.continue .ph { width: 54px; height: 72px; object-fit: cover; border-radius: 8px; background: #ece4d2; display: grid; place-items: center; flex: none; box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }
.card.continue:hover { border-color: var(--teal-3); }
.wp details summary, .r-side details summary { cursor: pointer; }
.wp-head .icon-btn { font-size: 1.35rem; }
.wp-head .icon-btn.on { color: var(--warn); background: transparent; }
.tool .ico { line-height: 1; }
.empty h3 { color: var(--ink); }
.reader .loading { color: #9aa; }
html[data-theme="dark"] .r-page .pnum { color: rgba(255, 255, 255, .5); }
html[data-theme="dark"] .doc-card .more { background: rgba(19, 36, 41, .85); color: var(--cream); }
html[data-theme="dark"] .dropzone { background: rgba(29, 102, 118, .12); }
html[data-theme="dark"] .wp-ctx b { background: rgba(255, 214, 64, .35); }
html[data-theme="dark"] .qa-msg.q { background: #1e3a40; color: var(--cream); }
html[data-theme="dark"] .list-item mark { background: #6b5a12; }
body.reading { overflow: hidden; }
@media (min-width: 861px) {
  .r-side .tabs .tab-l { display: inline; font-size: .72rem; }
}
@media (max-width: 860px) {
  .r-bar .r-title { font-size: .85rem; }
  .r-foot .icon-btn { width: 36px; }
  .lib-actions .input { max-width: none; flex: 1; min-width: 150px; }
  .lib-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
}
@media print { #rail, .r-bar, .r-foot { display: none !important; } }
/* side panel: never catch taps when closed; tabs = icon + short label */
.r-side { overflow: hidden; visibility: hidden; transition: transform .2s, visibility 0s .2s; }
.r-side.open { visibility: visible; transition: transform .2s; }
.r-side .tabs { overflow: hidden; }
.r-side .tabs button { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; flex: 1 1 0; font-size: 1.05rem; padding: 8px 2px 6px; }
.r-side .tabs .tab-l { display: block !important; font-size: .62rem; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* text view (reflow) */
.rf { max-width: 760px; margin: 0 auto; padding: 14px 20px 110px; background: var(--card); color: var(--ink); min-height: 100%; font-size: var(--rf-font, 1.15rem); line-height: 1.75; font-family: Georgia, "Noto Serif", "Times New Roman", serif; -webkit-user-select: text; user-select: text; }
.rf-page { padding-bottom: 6px; }
.rf-pn { text-align: center; font: 600 .72rem var(--font); color: var(--muted); margin: 18px 0 10px; letter-spacing: .3px; }
.rf p { margin: 0 0 .85em; overflow-wrap: anywhere; }
.rf p.rf-title { font-weight: 700; font-size: 1.2em; line-height: 1.4; margin-top: .4em; }
.rf-sentinel { height: 1px; }
.reader.mode-night .rf { background: #121a1c; color: #d9e2e4; }
.reader.mode-sepia .rf { background: #f4ecd8; color: #3b2f1e; }
::highlight(mp-word) { background-color: rgba(29, 102, 118, .30); }
::highlight(mp-tts) { background-color: rgba(80, 170, 255, .30); }
::highlight(mp-hit) { background-color: rgba(255, 140, 0, .45); }
::highlight(hl-yellow) { background-color: rgba(255, 214, 64, .55); }
::highlight(hl-green) { background-color: rgba(90, 210, 120, .45); }
::highlight(hl-blue) { background-color: rgba(80, 170, 255, .40); }
::highlight(hl-pink) { background-color: rgba(255, 110, 170, .40); }
input[type=range], input[type=checkbox], input[type=radio] { accent-color: var(--teal-3); }
