:root {
  --bg: #0d0f12;
  --ink: #c9cdd4;
  --dim: #6f7681;
  --line: #2a2f38;
  --accent: #9effc5;
  --glass: rgba(17, 20, 25, 0.72);
  --blur: 6px;
  --pad: 0.75rem;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg) url('/assets/standardbackground.jpg') center/cover fixed; color: var(--ink); font-family: ui-monospace, monospace; }
body { overflow: hidden; }

.glass {
  background: var(--glass);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--line);
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-template-rows: auto 1fr auto;
  gap: var(--pad);
  height: 100%;
  padding: var(--pad);
  max-width: 1400px;
  margin: 0 auto;
}

.top-banner {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  position: relative;
  min-height: 64px;
}

.master-logo {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}
.master-logo img { max-height: 56px; width: auto; display: block; }
.master-logo:hover img { filter: drop-shadow(0 0 8px var(--accent)); }

.drawer {
  position: absolute;
  top: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  z-index: 40;
  min-width: 160px;
}
.drawer-start { left: 0; }
.drawer-end { right: 0; }

.shelf-pane {
  grid-column: 1 / -1;
  grid-row: 2;
  overflow: auto;
  padding: 16px;
}

.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}

.shelf-card {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  text-align: left;
  padding: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
}
.shelf-card:hover { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 12px rgba(158, 255, 197, 0.25); }
.shelf-card img, .note-glyph {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
  margin-bottom: 8px;
  background: #111419;
}
.note-glyph {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--dim);
}
.shelf-card .title { display: block; margin-bottom: 4px; font-size: 12px; }
.shelf-card .meta { color: var(--dim); line-height: 1.4; }

.footer-pane {
  grid-column: 1 / -1;
  grid-row: 3;
  padding: 10px 14px;
  font-size: 12px;
}
.footer-text { color: var(--dim); }

.error-report {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 50;
  background: none;
  border: 1px solid var(--line);
  color: var(--dim);
  font-family: inherit;
  font-size: 11px;
  padding: 6px 10px;
  opacity: 0.4;
  cursor: pointer;
}
.error-report:hover { opacity: 1; color: var(--accent); border-color: var(--accent); }

.reader-pane {
  grid-column: 1 / -1;
  grid-row: 2 / 4;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--glass);
  border: 1px solid var(--line);
}
.reader-chrome {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.text-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
  padding: 6px 10px;
  cursor: pointer;
}
.text-btn:hover { border-color: var(--accent); color: var(--accent); }
.book-title { max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#readerMount { flex: 1; min-height: 0; position: relative; }

.reader-surface { position: absolute; inset: 0; display: flex; flex-direction: column; }
.reader-viewport { position: relative; flex: 1; overflow: hidden; }
.reader-content {
  height: 100%;
  padding: 24px 0 40px;
  column-gap: var(--reader-gap, 56px);
  transition: transform 220ms ease;
  will-change: transform;
  font-family: Georgia, 'Times New Roman', serif;
}
.reader-content.mono { font-family: ui-monospace, monospace; }
.reader-content p { margin: 0 0 0.9em; text-indent: 1.5em; text-align: justify; hyphens: auto; }
.reader-content p:first-child, .reader-content h1 + p, .reader-content h2 + p { text-indent: 0; }
.reader-content h1 { font-size: 1.5em; margin: 2.2em 0 1.1em; font-weight: normal; text-align: center; break-before: column; }
.reader-content h1:first-child { margin-top: 0.2em; }
.reader-content h2 { font-size: 1.05em; margin: 1.8em 0 0.8em; font-weight: normal; text-align: center; color: var(--dim); letter-spacing: 0.12em; text-transform: uppercase; }
.reader-content h3 { font-size: 1em; margin: 1.2em 0 0.6em; color: var(--dim); }

.reader-tapzones { position: absolute; inset: 0; display: flex; z-index: 5; }
.reader-tapzones div { flex: 1; cursor: pointer; }

.reader-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--dim);
}
.reader-footer input[type=range] { flex: 1; accent-color: var(--accent); height: 4px; }

.overlay {
  position: fixed;
  z-index: 60;
  padding: 24px;
  max-width: 480px;
}
.overlay.fullscreen {
  inset: 0;
  max-width: none;
  background: rgba(13, 15, 18, 0.92);
  overflow-y: auto;
}
.drawer-start.overlay { left: 0; top: 0; bottom: 0; width: min(50vw, 360px); }
.drawer-end.overlay { right: 0; top: 0; bottom: 0; width: min(50vw, 360px); }
.overlay-title { font-size: 12px; color: var(--dim); letter-spacing: 0.2em; margin-bottom: 16px; font-weight: normal; }
.overlay button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  padding: 12px 8px;
  font-family: inherit;
  cursor: pointer;
}
.overlay button:hover { color: var(--accent); }
.overlay button.cur { color: var(--accent); }
.overlay button:disabled { opacity: 0.35; cursor: default; }
.close-overlay { margin-top: 16px; border: 1px solid var(--line) !important; text-align: center !important; }

.font-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; font-size: 12px; }
.font-controls .lbl { color: var(--dim); }

.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-panel { padding: 32px; width: min(360px, 90vw); }
.login-panel h1 { letter-spacing: 0.3em; margin-bottom: 8px; }
.login-panel label { display: block; font-size: 12px; color: var(--dim); margin: 16px 0 6px; }
.login-panel input {
  width: 100%;
  padding: 10px;
  background: #111419;
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: inherit;
}
.login-panel button {
  margin-top: 16px;
  width: 100%;
  padding: 10px;
  background: none;
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
}
.login-panel button:hover { border-color: var(--accent); color: var(--accent); }
.error { color: #ff8a8a; font-size: 12px; margin-top: 8px; }
.dim { color: var(--dim); }

@media (max-width: 720px) {
  .app-grid { padding: 0.5rem; }
  .shelf-pane { grid-row: 2; }
  .footer-pane { grid-row: 3; }
  .reader-pane { grid-row: 2 / 4; }
  .drawer-start.overlay, .drawer-end.overlay { width: 50vw; }
}
