/* noolagam: musigold's gold-on-dark look, sized in rem so the hub TV
   (html.tv, or any big screen) gets the same layout, only larger. */
:root {
  --bg: #0e0d0b;
  --bg2: #15130f;
  --panel: #1c1914;
  --panel2: #262219;
  --line: #322c21;
  --text: #f3ede0;
  --muted: #a39a87;
  --faint: #6f6757;
  --gold: #e3b54a;
  --gold2: #f5d27a;
  --gold-ink: #1a1305;
  --danger: #e66a5a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --radius: 12px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #faf7f0; --bg2: #f3eee2; --panel: #ffffff; --panel2: #f1ebdc; --line: #e4dccb;
    --text: #221d12; --muted: #6d6452; --faint: #a39a87; --gold: #b5851c; --gold2: #8f6610;
    --gold-ink: #fffaf0; --shadow: 0 10px 30px rgba(60, 45, 10, .15); color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #faf7f0; --bg2: #f3eee2; --panel: #ffffff; --panel2: #f1ebdc; --line: #e4dccb;
  --text: #221d12; --muted: #6d6452; --faint: #a39a87; --gold: #b5851c; --gold2: #8f6610;
  --gold-ink: #fffaf0; --shadow: 0 10px 30px rgba(60, 45, 10, .15); color-scheme: light;
}

html { font-size: 15px; }
@media (min-width: 1600px) { html { font-size: clamp(15px, 0.95vw, 30px); } }
html.tv { font-size: clamp(16px, 1.15vw, 34px); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 1rem/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Tamil", sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden; overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
svg { display: block; }
.ic { width: 1.35rem; height: 1.35rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible, html.tv [data-f]:focus { outline: .18rem solid var(--gold); outline-offset: .18rem; }
::selection { background: color-mix(in srgb, var(--gold) 40%, transparent); }

/* ------------------------------------------------------------ library */
.app { display: grid; grid-template-rows: auto 1fr; height: 100dvh; }
.top {
  display: flex; align-items: center; gap: .9rem; padding: .7rem 1.2rem; padding-top: max(.7rem, env(safe-area-inset-top));
  background: var(--bg2); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.35rem; letter-spacing: -.02em; border-radius: 10px; }
.brand .logo { width: 2.1rem; height: 2.1rem; }
.brand b { color: var(--gold); font-weight: 800; }
.tabs { display: flex; gap: .25rem; background: var(--panel); border-radius: 999px; padding: .25rem; }
.tabs button { padding: .45rem 1rem; border-radius: 999px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabs button.on { background: var(--gold); color: var(--gold-ink); }
.search { flex: 1; min-width: 12rem; display: flex; align-items: center; gap: .5rem; background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 0 .9rem; height: 2.6rem; color: var(--muted); }
.search:focus-within { border-color: var(--gold); }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: 0; height: 100%; color: var(--text); }
.iconbtn { display: inline-grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 999px; color: var(--muted); flex: none; }
.iconbtn:hover { background: var(--panel2); color: var(--text); }
.iconbtn.spinning .ic { animation: spin 1s linear infinite; }

.main { overflow-y: auto; padding: 1.2rem 1.2rem 3rem; scrollbar-width: thin; }
.main h2 { margin: .2rem 0 1rem; font-size: 1.5rem; letter-spacing: -.02em; display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.main h2 .muted { font-size: 1rem; font-weight: 500; }
.crumbs { display: flex; flex-wrap: wrap; gap: .2rem; align-items: center; margin-bottom: 1rem; color: var(--muted); }
.crumbs button { padding: .3rem .6rem; border-radius: 8px; font-weight: 600; }
.crumbs button:hover { background: var(--panel2); color: var(--text); }
.crumbs button:last-child { color: var(--text); }
.empty { color: var(--muted); padding: 3rem 1rem; text-align: center; }
.note { color: var(--muted); font-size: .9rem; margin: -.5rem 0 1rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: 1.4rem 1.1rem; }
@media (max-width: 520px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 1rem .7rem; } .main { padding: .9rem .8rem 3rem; } }
.card { text-align: left; display: flex; flex-direction: column; gap: .35rem; border-radius: var(--radius); padding: .35rem; margin: -.35rem; transition: transform .15s ease, background .15s ease; }
.card:hover { background: var(--panel); }
html.tv .card:focus { transform: scale(1.06); background: var(--panel); }
.cover {
  position: relative; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden; box-shadow: var(--shadow);
  background: linear-gradient(160deg, hsl(var(--h) 45% 32%), hsl(calc(var(--h) + 40) 50% 16%));
  display: flex; flex-direction: column; justify-content: space-between; padding: .7rem .6rem; color: #f6efdf;
}
.cover .ct { font-weight: 700; font-size: .9rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.cover .ext { align-self: flex-start; font-size: .65rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; background: rgba(0, 0, 0, .35); padding: .1rem .4rem; border-radius: 4px; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #fff; }
.cover .prog { position: absolute; left: 0; bottom: 0; height: .3rem; background: var(--gold); box-shadow: 0 0 6px rgba(0, 0, 0, .5); }
.card .t { font-weight: 650; font-size: .92rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.card .a { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.rows { display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: .6rem; margin-bottom: 1.6rem; }
.row { display: flex; align-items: center; gap: .8rem; padding: .8rem 1rem; border-radius: var(--radius); background: var(--panel); text-align: left; min-height: 3.6rem; }
.row:hover, html.tv .row:focus { background: var(--panel2); }
.row .ic { color: var(--gold); }
.row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.row small { color: var(--muted); }
.more { height: 1px; }

.settings { max-width: 26rem; display: flex; flex-direction: column; gap: .7rem; }
.settings h3 { margin: 0; font-size: 1.1rem; }
.settings .note { margin: 0 0 .3rem; }
.settings input { height: 3rem; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); padding: 0 1rem; outline: 0; }
.settings input:focus { border-color: var(--gold); }
.settings button { height: 3rem; border-radius: 12px; background: var(--gold); color: var(--gold-ink); font-weight: 700; }
.settings .msg { min-height: 1.4rem; color: var(--danger); }
.settings .msg.ok { color: var(--gold); }

/* ------------------------------------------------------------ reader */
.reader { position: fixed; inset: 0; z-index: 10; background: var(--rbg, #0e0d0b); color: var(--rfg, #f3ede0); }
.reader.light { --rbg: #faf7f0; --rfg: #221d12; }
.reader.sepia { --rbg: #f4ecd8; --rfg: #3b2f1e; }
.stage { position: absolute; inset: 0; overflow: hidden; }
.pdfwrap { position: absolute; inset: 0; overflow: auto; display: grid; place-items: center; touch-action: pan-x pan-y pinch-zoom; scrollbar-width: thin; }
.pdfwrap img { display: block; background: #fff; box-shadow: 0 6px 30px rgba(0, 0, 0, .5); user-select: none; -webkit-user-drag: none; }
.pdfwrap.page img { max-width: 100%; max-height: 100%; width: auto; height: auto; }
.pdfwrap.width { place-items: start center; }
.pdfwrap.width img { width: calc(100% * var(--zoom, 1)); max-width: none; height: auto; }
.reader iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--rbg); }
.spin { position: absolute; left: 50%; top: 50%; width: 2.6rem; height: 2.6rem; margin: -1.3rem; border-radius: 50%;
  border: .25rem solid rgba(128, 128, 128, .3); border-top-color: var(--gold); animation: spin .8s linear infinite; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.rmsg { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 1rem; padding: 2rem; color: var(--muted); }
.rmsg a { color: var(--gold); font-weight: 700; }

.rbar { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: .6rem; padding: .6rem 1rem; z-index: 2;
  background: color-mix(in srgb, #0e0d0b 88%, transparent); color: #f3ede0; backdrop-filter: blur(10px);
  transition: transform .2s ease, opacity .2s ease; }
.rbar .iconbtn { color: #e6dcc6; }
.rbar .iconbtn:hover { background: rgba(255, 255, 255, .1); }
.rtop { top: 0; padding-top: max(.6rem, env(safe-area-inset-top)); }
.rbottom { bottom: 0; padding-bottom: max(.6rem, env(safe-area-inset-bottom)); }
.reader.bare .rtop { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.reader.bare .rbottom { transform: translateY(100%); opacity: 0; pointer-events: none; }
.rtitle { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.rtitle b, .rtitle span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rtitle span { color: #a39a87; font-size: .85rem; }
.rbottom input { flex: 1; accent-color: var(--gold); height: 2rem; }
.rpage { min-width: 6rem; text-align: center; font-variant-numeric: tabular-nums; color: #d8cdb5; font-size: .9rem; }

.panel { position: absolute; z-index: 3; right: .8rem; top: 4rem; width: min(24rem, calc(100% - 1.6rem)); max-height: calc(100% - 9rem); overflow-y: auto;
  background: #1c1914; color: #f3ede0; border: 1px solid #322c21; border-radius: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, .6); padding: .8rem; }
.panel h3 { margin: .3rem .4rem .7rem; font-size: 1rem; color: #a39a87; font-weight: 600; }
.panel .opts { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.panel .opts button { padding: .5rem .9rem; border-radius: 999px; background: #262219; font-weight: 600; min-width: 3rem; }
.panel .opts button.on { background: var(--gold); color: #1a1305; }
.panel .toc button { display: block; width: 100%; text-align: left; padding: .55rem .7rem; border-radius: 8px; line-height: 1.3; }
.panel .toc button:hover, .panel .toc button:focus { background: #262219; }
.panel .toc button.cur { color: var(--gold); font-weight: 700; }
