/* ── RESET & BASE ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Fix: [hidden] must win over any explicit display: rule.
   Without this, CSS display:flex on #spinner overrides the browser's
   built-in [hidden]{display:none} rule because #id specificity beats it. */
[hidden] { display: none !important; }

:root {
  --chrome-bg:      #1a1a2e;
  --chrome-border:  #2e2e50;
  --chrome-text:    #c8c8e0;
  --accent:         #6c63ff;
  --accent-hover:   #857dff;
  --bar-height:     52px;
  --bottom-height:  60px;
}

html, body {
  height: 100%;
  background: #0f0f1a;
  color: var(--chrome-text);
  font-family: system-ui, sans-serif;
  font-size: 14px;
  overflow: hidden;
}


/* ── HOME SCREEN ───────────────────────────────────────────── */
#home-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 48px;
  background: #0f0f1a;
}

#home-title {
  font-size: 26px;
  font-weight: 300;
  letter-spacing: 0.12em;
  color: var(--chrome-text);
  opacity: 0.7;
}

#book-grid {
  display: flex;
  gap: 52px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
}

.book-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.book-tile:hover {
  transform: translateY(-5px);
}

.book-tile canvas {
  display: block;
  border-radius: 2px;
  box-shadow: 0 8px 36px rgba(0, 0, 0, 0.65), 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Shown while cover canvas is still loading */
.cover-placeholder {
  background: #1f1f38;
  border-radius: 2px;
  box-shadow: 0 8px 36px rgba(0, 0, 0, 0.65);
}

.book-tile-title {
  font-size: 14px;
  color: var(--chrome-text);
  opacity: 0.65;
  text-align: center;
}

.book-tile-style {
  font-size: 11px;
  color: var(--chrome-text);
  opacity: 0.35;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}


/* ── READER SCREEN ─────────────────────────────────────────── */
#reader-screen {
  position: fixed;
  inset: 0;
}


/* ── TOP BAR ───────────────────────────────────────────────── */
#top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--bar-height);
  background: var(--chrome-bg);
  border-bottom: 1px solid var(--chrome-border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  z-index: 100;
}

#library-btn {
  background: transparent;
  color: var(--chrome-text);
  border: 1px solid var(--chrome-border);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}

#library-btn:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
}

/* Custom-styled select: removes the browser's native chevron (which is hard
   to control) and replaces it with our own SVG arrow, precisely positioned. */
#book-select {
  appearance: none;
  -webkit-appearance: none;
  background-color: #2a2a45;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23c8c8e0'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  color: var(--chrome-text);
  border: 1px solid var(--chrome-border);
  border-radius: 6px;
  padding: 6px 28px 6px 10px; /* right padding reserves space for the arrow */
  font-size: 14px;
  cursor: pointer;
  width: auto;
}

#book-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#download-btn {
  margin-left: auto;
  background: transparent;
  color: var(--chrome-text);
  border: 1px solid var(--chrome-border);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}

#download-btn:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
}


/* ── MAIN AREA ─────────────────────────────────────────────── */
#main-area {
  position: fixed;
  top: var(--bar-height);
  bottom: var(--bottom-height);
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f0f1a;
}

/* StPageFlip mounts into this div; JS sets width + height.
   Three shadow layers: a crisp close shadow, a mid diffuse, and a wide ambient.
   Together they give the impression of a physical book sitting on the surface. */
#book-container {
  position: relative;
  box-shadow:
    0 2px 6px  rgba(0, 0, 0, 0.45),
    0 10px 28px rgba(0, 0, 0, 0.45),
    0 32px 72px rgba(0, 0, 0, 0.30);
}

/* Spine crease: a soft gradient line at the horizontal centre of the book.
   Represents the binding — the point where the two pages meet.
   z-index keeps it above StPageFlip's canvases; pointer-events:none
   means it never blocks clicks or drags on the pages. */
#book-container::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  background: linear-gradient(
    to right,
    transparent,
    rgba(0, 0, 0, 0.18) 50%,
    transparent
  );
  pointer-events: none;
  z-index: 20;
}


/* ── LOADING SPINNER ───────────────────────────────────────── */
/* Default: hidden. JS uses style.display = 'flex'/'none' to toggle. */
#spinner {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.spinner-ring {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(108, 99, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}


/* ── BOTTOM BAR ────────────────────────────────────────────── */
#bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-height);
  background: var(--chrome-bg);
  border-top: 1px solid var(--chrome-border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  z-index: 100;
}

#spread-indicator {
  white-space: nowrap;
  min-width: 120px;
  font-size: 13px;
  color: var(--chrome-text);
  opacity: 0.75;
}

#spread-slider {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}


/* ── MODAL ─────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#modal {
  background: #1f1f38;
  border: 1px solid var(--chrome-border);
  border-radius: 12px;
  padding: 32px 36px;
  max-width: 380px;
  width: 90%;
  text-align: center;
}

#modal-message {
  font-size: 16px;
  line-height: 1.5;
  margin-bottom: 24px;
  color: var(--chrome-text);
}

#modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

#modal-buttons button {
  padding: 10px 22px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}

#modal-buttons button:hover { opacity: 0.85; }

#modal-continue { background: var(--accent); color: #fff; }
#modal-restart  { background: #2e2e50; color: var(--chrome-text); }


/* ── MOBILE OVERLAY ────────────────────────────────────────── */
/* Hidden on desktop; shown on screens ≤ 768px via media query. */
#mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #0f0f1a;
  z-index: 999;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
  text-align: center;
}

@media (max-width: 768px) {
  #mobile-overlay { display: flex; }
}

#mobile-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 300px;
}

#mobile-icon   { font-size: 48px; }

#mobile-title  {
  font-size: 22px;
  font-weight: 600;
  color: var(--chrome-text);
}

#mobile-body {
  font-size: 15px;
  line-height: 1.7;
  color: var(--chrome-text);
  opacity: 0.65;
}

#mobile-body strong {
  color: var(--chrome-text);
  opacity: 1;
  font-weight: 600;
}
