/* Geekm0nkey Ebook Reader — styles */

:root {
  --accent: #00e5ff;
  --accent2: #b388ff;
  --radius: 12px;
  --tb-h: 54px;
  --font-read: "Space Grotesk", system-ui, sans-serif;
  --font-display: "Orbitron", sans-serif;
}

/* ---- Themes ---- */
body[data-theme="dark"] {
  --bg: #0d0f1a;
  --bg2: #141826;
  --panel: #181d2e;
  --panel2: #1f2540;
  --line: #2a3150;
  --text: #e8ecff;
  --muted: #8b93b8;
  --paper-bg: #131728;
  --paper-text: #dfe4f5;
  --shadow: 0 10px 40px rgba(0,0,0,.55);
}

body[data-theme="light"] {
  --bg: #eef1f7;
  --bg2: #e4e8f2;
  --panel: #ffffff;
  --panel2: #f2f4fa;
  --line: #d5dbe8;
  --text: #1a2033;
  --muted: #5c6580;
  --paper-bg: #fbf9f2;
  --paper-text: #23262e;
  --shadow: 0 10px 40px rgba(30,40,80,.18);
}
body[data-theme="sepia"] {
  --bg: #efe6d4;
  --bg2: #e7dcc6;
  --panel: #f6efe1;
  --panel2: #efe6d4;
  --line: #d8c9a9;
  --text: #3a3020;
  --muted: #7a6b4d;
  --paper-bg: #f7f0df;
  --paper-text: #3a3020;
  --shadow: 0 10px 40px rgba(80,60,20,.18);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-read);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column;
}

/* ================= Toolbar ================= */
.toolbar {
  flex: none;
  min-height: var(--tb-h);
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px;
  background: linear-gradient(180deg, var(--bg2), var(--bg));
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 40;
}
.tb-group { display: flex; align-items: center; gap: 6px; }
.tb-title {
  flex: 1; text-align: center; min-width: 0;
  font-weight: 600; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0 8px;
}
.tb-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 12px; font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; transition: .15s;
}
.tb-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.tb-btn:disabled { opacity: .38; cursor: default; }
.tb-btn.icon-only { padding: 8px 11px; }
.tb-btn .ico { font-size: 16px; }
.zoom-level {
  min-width: 48px; text-align: center; font-variant-numeric: tabular-nums;
  color: var(--muted); font-size: 13px; cursor: pointer; user-select: none;
}
.zoom-ctl { display: inline-flex; align-items: center; gap: 6px; }

/* ---- Overflow ("hamburger") menu ----
   Controls that no longer fit are moved into this panel by layoutToolbar(). */
.tb-menu {
  position: fixed; top: calc(var(--tb-h) + 6px); right: 8px;
  min-width: 210px; max-width: min(280px, 92vw);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
  padding: 6px; z-index: 70;
  display: flex; flex-direction: column; gap: 4px;
}
.tb-menu[hidden] { display: none; }
.tb-menu .tb-btn,
.tb-menu .zoom-ctl {
  width: 100%; justify-content: flex-start;
  background: transparent; border-color: transparent;
  padding: 10px 12px; font-size: 15px;
}
.tb-menu .tb-btn:hover:not(:disabled) { background: var(--panel2); }
.tb-menu .tb-btn .lbl { display: inline; }
/* icon-only buttons get their name from data-label once they're in the menu */
.tb-menu .tb-btn.icon-only::after { content: attr(data-label); font-weight: 600; }
.tb-menu .tb-btn.icon-only { gap: 10px; }
.tb-menu .zoom-ctl { justify-content: space-between; padding: 4px 12px; }
.tb-menu .zoom-ctl .tb-btn { width: auto; padding: 8px 12px; border-color: var(--line); }
.tb-menu .zoom-ctl .tb-btn::after { content: none; }
.tb-btn.open { border-color: var(--accent); color: var(--accent); }

@media (max-width: 860px) {
  .tb-btn .lbl { display: none; }
  .tb-btn { padding: 9px 11px; }
  .tb-btn.icon-only { padding: 9px 10px; font-size: 15px; }
  .toolbar { gap: 4px; padding: 5px 8px; overflow: hidden; flex-wrap: nowrap; }
  .tb-title { display: none; }
  .tb-group { flex: none; }
}
@media (max-width: 480px) {
  .zoom-level { min-width: 42px; }
  .tb-btn, .tb-btn.icon-only { padding: 8px 9px; }
}

/* ================= Stage ================= */
/* --progress-h reserves a band at the bottom for the progress bar so page
   text never slides underneath it, however far the reader zooms in. */
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; --progress-h: 0px; }
.stage.has-progress { --progress-h: 58px; }
.viewport {
  position: absolute; inset: 0 0 var(--progress-h) 0;
  display: flex; justify-content: center;
  overflow: auto; padding: 0;
}
.reader-surface {
  width: 100%; height: 100%;
  display: flex; justify-content: center;
}

/* Rotation: rotate the whole surface; JS sets --rot and swaps dimensions */
.stage.rotated .viewport {
  transform: rotate(90deg);
  transform-origin: center center;
}

/* ---- TXT / plain reader (paginated) ---- */
.txt-reader {
  max-width: 44rem; width: 100%; height: 100%;
  background: var(--paper-bg); color: var(--paper-text);
  padding: clamp(20px, 5vw, 52px) clamp(22px, 6vw, 60px);
  overflow: hidden; position: relative;
  box-shadow: var(--shadow);
}
.txt-cols {
  height: 100%;
  column-width: 100%; column-gap: 0; column-fill: auto;
  line-height: 1.8; font-size: calc(1.25rem * var(--zoom, 1));
  transition: transform .22s ease; will-change: transform;
}
.txt-cols h2.txt-chapter {
  font-family: var(--font-display); font-size: 1.2em;
  margin: 0 0 .6em; color: var(--accent); break-after: avoid;
}
.txt-cols h2.txt-chapter:not(:first-child) { margin-top: 1.4em; }
.txt-cols p { margin: 0 0 1em; white-space: pre-wrap; }

/* ---- EPUB host ---- */
.epub-host { width: 100%; height: 100%; background: var(--paper-bg); box-shadow: var(--shadow); }

/* ---- PDF host ---- */
.pdf-host {
  width: 100%; height: 100%; overflow: auto;
  display: flex; flex-direction: column; align-items: center;
  gap: 14px; padding: 16px; background: var(--bg2);
}
.pdf-page { box-shadow: var(--shadow); background: #fff; max-width: 100%; }

/* ================= Pagers ================= */
.pager {
  position: absolute; top: 0; bottom: var(--progress-h); width: 8%; min-width: 44px; max-width: 90px;
  border: none; background: transparent; color: var(--muted);
  font-size: 34px; cursor: pointer; z-index: 20; opacity: .55; transition: .15s;
}
.pager:hover { opacity: 1; color: var(--accent); background: rgba(0,229,255,.06); }
.pager-prev { left: 0; }
.pager-next { right: 0; }

/* ================= Progress ================= */
.progressbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 25;
  height: var(--progress-h);
  padding: 8px 16px 10px; background: var(--bg2); border-top: 1px solid var(--line);
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
}
.progressbar input[type=range] { width: 100%; accent-color: var(--accent); cursor: pointer; }
.progress-meta { text-align: center; font-size: 12px; color: var(--muted); }

/* ================= Welcome ================= */
.welcome {
  position: absolute; inset: 0; display: grid; place-items: center;
  padding: 24px; z-index: 15;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(0,229,255,.08), transparent),
              var(--bg);
}
.welcome[hidden] { display: none; }
.welcome-card {
  max-width: 520px; text-align: center;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 40px 32px; box-shadow: var(--shadow);
}
.welcome-logo { font-size: 56px; }
.welcome-card h1 { font-family: var(--font-display); margin: 8px 0 12px; letter-spacing: 1px; }
.welcome-card p { color: var(--muted); line-height: 1.6; }
.welcome-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 22px 0 10px; }
.cta {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #05121a; border: none; border-radius: 10px;
  padding: 12px 20px; font: 600 15px var(--font-read); cursor: pointer;
}
.cta.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.cta.danger { background: transparent; color: #ff5470; border: 1px solid #ff5470; }
.cta.continue { box-shadow: 0 0 0 3px rgba(0,229,255,.18); }
.cta:hover { filter: brightness(1.08); }
.hint { font-size: 12px; margin-top: 14px; }

/* ================= Drawers ================= */
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(420px, 88vw);
  background: var(--panel); border-right: 1px solid var(--line);
  z-index: 60; display: flex; flex-direction: column;
  box-shadow: var(--shadow); animation: slideIn .18s ease;
}
.drawer[hidden] { display: none; }
@keyframes slideIn { from { transform: translateX(-16px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 17px; font-family: var(--font-display); }
.x { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.x:hover { color: var(--accent); }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 55; }
.scrim[hidden] { display: none; }

/* ---- Library ---- */
.lib-toolbar { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.lib-search {
  width: 100%; padding: 9px 12px; margin-bottom: 10px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 14px;
}
.lib-search:focus { outline: none; border-color: var(--accent); }
.lib-item .path { font-size: 11px; color: var(--muted); opacity: .8; }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; font-size: 13px; margin-bottom: 8px; }
.crumbs .crumb { color: var(--accent); cursor: pointer; }
.crumbs .crumb.current { color: var(--muted); cursor: default; }
.crumbs .sep { color: var(--muted); }
.lib-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.mini {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 11px; font: 600 13px var(--font-read); cursor: pointer;
}
.mini:hover { border-color: var(--accent); color: var(--accent); }
.mini.primary { background: var(--accent); color: #05121a; border-color: var(--accent); }
.mini.ghost { background: transparent; }

.dropzone { flex: 1; overflow: auto; position: relative; }
.dropzone.drag { outline: 2px dashed var(--accent); outline-offset: -8px; background: rgba(0,229,255,.05); }
.dz-hint {
  position: absolute; left: 0; right: 0; bottom: 8px; text-align: center;
  color: var(--muted); font-size: 12px; pointer-events: none; opacity: .0; transition: .15s;
}
.dropzone.drag .dz-hint { opacity: 1; }

.lib-list { padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.lib-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 9px; cursor: pointer;
  border: 1px solid transparent;
}
.lib-item:hover { background: var(--panel2); border-color: var(--line); }
.lib-item .ic { font-size: 20px; width: 24px; text-align: center; flex: none; }
.lib-item .meta { flex: 1; min-width: 0; }
.lib-item .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-item .sub { font-size: 12px; color: var(--muted); }
.lib-item .badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  padding: 2px 6px; border-radius: 5px; background: var(--panel2);
  border: 1px solid var(--line); color: var(--muted); flex: none;
}
.lib-item .row-actions { display: flex; gap: 2px; opacity: 0; transition: .12s; flex: none; }
.lib-item:hover .row-actions { opacity: 1; }
.row-actions button {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 15px; padding: 4px; border-radius: 6px;
}
.row-actions button:hover { color: var(--accent); background: var(--panel); }
.lib-empty { color: var(--muted); text-align: center; padding: 40px 20px; font-size: 14px; }
.lib-status { padding: 8px 14px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); min-height: 14px; }
.progress-inline { height: 4px; background: var(--panel2); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.progress-inline > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---- TOC ---- */
.toc-list, .bm-list { overflow: auto; flex: 1; padding: 8px; }
.toc-item {
  display: block; padding: 9px 12px; border-radius: 8px; cursor: pointer;
  color: var(--text); border: 1px solid transparent; line-height: 1.35;
}
.toc-item:hover { background: var(--panel2); border-color: var(--line); }
.toc-item.active { color: var(--accent); border-color: var(--accent); }
.toc-item.lvl-1 { padding-left: 26px; font-size: .93em; color: var(--muted); }
.toc-item.lvl-2 { padding-left: 40px; font-size: .9em; color: var(--muted); }

/* ---- Bookmarks ---- */
.bm-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px;
  border-radius: 9px; cursor: pointer; border: 1px solid transparent;
}
.bm-item:hover { background: var(--panel2); border-color: var(--line); }
.bm-item .bm-ic { color: var(--accent); }
.bm-item .bm-meta { flex: 1; min-width: 0; }
.bm-item .bm-label { font-weight: 600; }
.bm-item .bm-sub { font-size: 12px; color: var(--muted); }
.bm-item .bm-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; }
.bm-item .bm-del:hover { color: #ff5470; }
.bm-empty { color: var(--muted); text-align: center; padding: 40px 20px; }

/* ---- Reading profile / sync ---- */
.profile-body { padding: 16px; overflow: auto; flex: 1; }
.profile-lead { margin: 0 0 10px; line-height: 1.55; }
.profile-sub, .profile-note { color: var(--muted); font-size: 13px; line-height: 1.6; }
.profile-sub { margin: 0 0 18px; }
.profile-note { margin: 16px 0 0; }
.profile-note.warn {
  color: var(--warn, #ffb454);
  border: 1px solid currentColor;
  border-radius: 8px;
  padding: 8px 10px;
  opacity: .9;
}
.profile-actions { display: flex; flex-direction: column; gap: 10px; }
.profile-actions .cta { width: 100%; }

.profile-who {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel2); margin-bottom: 16px;
}
.profile-avatar { font-size: 26px; }
.profile-who > div { flex: 1; min-width: 0; }
.profile-name { font-weight: 700; font-size: 16px; }
.profile-books { font-size: 12px; color: var(--muted); }

.code-block {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; text-align: center; margin-bottom: 14px;
  background: radial-gradient(400px 120px at 50% 0, rgba(0,229,255,.08), transparent), var(--panel2);
}
.code-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.code-value {
  font-family: var(--font-display); font-size: clamp(20px, 6vw, 26px);
  letter-spacing: 2px; color: var(--accent); margin: 8px 0 6px;
  cursor: pointer; word-break: break-all;
}
.code-hint { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.code-actions { display: flex; gap: 8px; justify-content: center; }

.sync-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0 16px; border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.sync-status { font-size: 12px; color: var(--muted); flex: 1; min-width: 0; }
.tb-btn.signed-in .ico { color: var(--accent); }

/* ---- In-book search ---- */
.search-box { padding: 12px 14px 6px; }
.search-box .lib-search { margin-bottom: 0; }
.search-status { padding: 6px 16px; font-size: 12px; color: var(--muted); }
.search-list { flex: 1; overflow-y: auto; padding: 4px 10px 16px; }
.search-item {
  padding: 9px 12px; border-radius: 9px; cursor: pointer;
  border: 1px solid transparent; margin-bottom: 3px;
}
.search-item:hover { background: var(--panel2); border-color: var(--line); }
.search-item.active { border-color: var(--accent); background: var(--panel2); }
.search-ex { font-size: 13px; line-height: 1.5; color: var(--text); }
.search-ex b { color: var(--accent); font-weight: 700; }
.search-page { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* highlighted hits inside the TXT reader */
mark.search-hit {
  background: rgba(0, 229, 255, .32); color: inherit;
  border-radius: 3px; padding: 0 1px;
}

/* ================= Modal ================= */
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 80; background: rgba(0,0,0,.55); }
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px; width: min(400px, 90vw); box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 8px; font-family: var(--font-display); }
.modal-msg { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.modal-input {
  width: 100%; padding: 10px 12px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font: inherit; margin-bottom: 14px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ================= Toast ================= */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  padding: 11px 18px; border-radius: 10px; z-index: 90; box-shadow: var(--shadow);
  font-size: 14px; max-width: 90vw;
}
.toast[hidden] { display: none; }
.toast.err { border-color: #ff5470; color: #ff8095; }

/* ================= Mobile ================= */
@media (max-width: 640px) {
  .drawer { width: 100vw; border-right: none; }
  .pager { width: 14%; min-width: 40px; font-size: 40px; opacity: .35; }
  .welcome-card { padding: 30px 22px; }
  .welcome-card h1 { font-size: 22px; }
  .txt-reader { padding: clamp(16px, 5vw, 40px) clamp(16px, 6vw, 40px); }
  .lib-item { padding: 11px 10px; }          /* bigger touch targets */
  .lib-item .row-actions { opacity: 1; }     /* no hover on touch */
  .row-actions button { padding: 7px; font-size: 17px; }
  .stage.has-progress { --progress-h: calc(58px + env(safe-area-inset-bottom)); }
  .progressbar { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}
@media (hover: none) {
  .lib-item .row-actions { opacity: 1; }
}

/* selection */
::selection { background: rgba(0,229,255,.28); }
