@import url("https://fonts.googleapis.com/css2?family=Cinzel:wght@600;700&family=Manrope:wght@500;700&display=swap");

:root {
  --bg: #141414;
  --bg-surface: #1e1e1e;
  --bg-surface2: #2a2a2a;
  --text: #e8e8e8;
  --text-muted: #999999;
  --line: #3a3a3a;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  --font-cover-heading: "Cinzel", Georgia, "Times New Roman", serif;
  --font-cover-ui: "Manrope", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-surface: #ffffff;
  --bg-surface2: #f5f5f5;
  --text: #111111;
  --text-muted: #5f5f5f;
  --line: #d9d9d9;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.site {
  max-width: 1500px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

h1 {
  margin: 0 0 18px;
  font-size: 1.8rem;
  font-weight: 700;
  text-align: center;
}

#homeView h1 {
  font-family: var(--font-cover-heading);
  letter-spacing: 0.02em;
}

.hidden {
  display: none !important;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 320px));
  justify-content: center;
  gap: 18px;
}

.home-notice {
  max-width: 900px;
  margin: 28px auto 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.55;
  text-align: center;
  font-family: var(--font-cover-ui);
}

.home-kofi {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(92vw, 560px);
}

.kofi-note {
  font-family: var(--font-cover-ui);
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  line-height: 1.3;
}

.kofi-image {
  border: 0;
  height: 36px;
  display: block;
}

.book-card {
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
}

.book-cover-btn {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.book-cover {
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  background: transparent;
  border: 0;
  box-shadow: var(--shadow);
  border-radius: 0;
}

.book-title {
  margin: 10px 0;
  font-size: 0.98rem;
  font-weight: 600;
  min-height: 40px;
  font-family: var(--font-cover-ui);
}

#homeView .primary-btn {
  font-family: var(--font-cover-ui);
}

.primary-btn,
.secondary-btn,
.nav-btn {
  border: 1px solid var(--line);
  background: var(--bg-surface);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
}

.primary-btn,
.secondary-btn {
  padding: 10px 12px;
  font-size: 0.95rem;
}

.primary-btn {
  border-color: var(--line);
  font-weight: 600;
}

.primary-btn:hover,
.secondary-btn:hover,
.nav-btn:hover {
  background: var(--bg-surface2);
}

.reader-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}

.book-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  min-height: 0;
}

body.reading .site {
  max-width: none;
  padding: 8px 10px;
}

body.reading {
  overflow: hidden;
}

body.reading #readerView {
  min-height: calc(100vh - 16px);
}

body.reading .reader-layout {
  height: calc(100vh - 16px);
  align-items: stretch;
}

body.reading .spread {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: calc((100vh - 140px) * 1.45);
}

.reader-loading-notice {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  border: 1px solid #3a5a8a;
  background: #1a2d4a;
  color: #a8c8f8;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.95rem;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  text-align: center;
}

[data-theme="light"] .reader-loading-notice {
  border-color: #cfe0ff;
  background: #f4f8ff;
  color: #103b78;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.14);
}

.back-arrow-btn {
  position: fixed;
  top: 14px;
  left: 14px;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-surface);
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  z-index: 25;
  box-shadow: var(--shadow);
}

.floating-tools {
  position: fixed;
  right: 14px;
  top: 96px;
  display: grid;
  gap: 10px;
  z-index: 25;
}

.tool-fab {
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-surface);
  color: var(--text);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.tool-fab.active {
  background: #1a3a5a;
  border-color: #4a7ac0;
}

[data-theme="light"] .tool-fab.active {
  background: #eaf2ff;
  border-color: #8fb4ff;
}

.spread {
  position: relative;
  height: min(76vh, 980px);
  border: 0;
  border-radius: 0;
  background: transparent;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 0;
  overflow: visible;
  perspective: 1200px;
}

.page-slot {
  background: transparent;
  border: 0;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  position: relative;
}

.page-slot.empty {
  background: #1e1e1e;
}

[data-theme="light"] .page-slot.empty {
  background: #f1f1f1;
}

.page-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  filter: drop-shadow(0 14px 28px rgba(0, 0, 0, 0.28));
}

.page-slot.left .page-image {
  object-position: right center;
}

.page-slot.right .page-image {
  object-position: left center;
}

.page-image.selectable {
  cursor: pointer;
  outline: 3px solid #1f6feb;
  outline-offset: -3px;
}

.spread.flip-next .page-slot.right {
  transform-origin: left center;
  animation: pageflip-next 320ms ease;
}

.spread.flip-prev .page-slot.left {
  transform-origin: right center;
  animation: pageflip-prev 320ms ease;
}

@keyframes pageflip-next {
  from {
    transform: rotateY(0deg);
    opacity: 1;
  }
  to {
    transform: rotateY(-45deg);
    opacity: 0.75;
  }
}

@keyframes pageflip-prev {
  from {
    transform: rotateY(0deg);
    opacity: 1;
  }
  to {
    transform: rotateY(45deg);
    opacity: 0.75;
  }
}

.magnifier {
  position: absolute;
  width: 350px;
  height: 350px;
  border: 2px solid #666666;
  border-radius: 50%;
  pointer-events: none;
  z-index: 20;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  background-repeat: no-repeat;
  background-color: #1a1a1a;
}

[data-theme="light"] .magnifier {
  border-color: #3a3a3a;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.24);
  background-color: #fff;
}

body.reading.magnifier-on .spread,
body.reading.magnifier-on .spread * {
  cursor: none !important;
}

.bottom-controls {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.download-hint-box {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  border: 1px solid #3a5a8a;
  background: #1a2d4a;
  color: #a8c8f8;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.95rem;
  width: fit-content;
  max-width: min(90vw, 520px);
  z-index: 35;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

[data-theme="light"] .download-hint-box {
  border-color: #cfe0ff;
  background: #f4f8ff;
  color: #103b78;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.14);
}

.nav-btn {
  width: 44px;
  height: 44px;
  font-size: 1.25rem;
  line-height: 1;
}

.page-status {
  min-width: 150px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--bg-surface);
  color: var(--text);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 50;
}

.modal-card {
  width: min(640px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--bg-surface);
  color: var(--text);
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 16px;
}

.modal-card h2 {
  margin-top: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.preview-card {
  width: min(1100px, 100%);
  display: flex;
  flex-direction: column;
  max-height: 85vh;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 8px;
  overflow-y: auto;
  min-height: 0;
}

.preview-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-surface);
  color: var(--text);
  padding: 6px;
  cursor: pointer;
}

.preview-item:hover {
  background: var(--bg-surface2);
}

.preview-item img {
  width: 100%;
  height: 150px;
  object-fit: contain;
}

.preview-thumb.loading {
  background: linear-gradient(90deg, #2a2a2a 25%, #333333 37%, #2a2a2a 63%);
  background-size: 400% 100%;
  animation: previewShimmer 1.2s ease-in-out infinite;
}

[data-theme="light"] .preview-thumb.loading {
  background: linear-gradient(90deg, #f1f1f1 25%, #ececec 37%, #f1f1f1 63%);
  background-size: 400% 100%;
}

@keyframes previewShimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

.preview-item div {
  text-align: center;
  font-size: 0.85rem;
}

@media (max-width: 1100px) {
  .floating-tools {
    right: 10px;
    top: 84px;
  }
}

.theme-toggle-btn {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-surface);
  color: var(--text);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  z-index: 30;
  box-shadow: var(--shadow);
}

.site-footer {
  margin-top: 40px;
  padding-top: 20px;
  text-align: center;
}

.site-footer p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

@media (max-width: 760px) {
  .spread {
    height: min(70vh, 820px);
  }

  .home-kofi {
    right: 10px;
    bottom: 10px;
  }
}
