@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700&family=Lora:ital,wght@0,400;0,500;1,400&family=Montserrat:wght@300;400;500;600&display=swap');

/* Color Themes & Variables */
:root {
  --font-title: 'Cinzel', serif;
  --font-body: 'Lora', serif;
  --font-ui: 'Montserrat', sans-serif;
  
  /* Transition values */
  --transition-smooth: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
  --shadow-premium: 0 15px 35px rgba(0, 0, 0, 0.15), 0 5px 15px rgba(0, 0, 0, 0.08);
}

/* Light / Cream Theme */
[data-theme="light"] {
  --bg-app: linear-gradient(135deg, #f5f2eb 0%, #e6dfd3 100%);
  --bg-book: #fbf9f5;
  --bg-page-left: linear-gradient(to right, #fbf9f5 95%, #eadecc 100%);
  --bg-page-right: linear-gradient(to left, #fbf9f5 95%, #eadecc 100%);
  --text-main: #2c251e;
  --text-muted: #6b5e51;
  --accent: #8e7256;
  --accent-hover: #705840;
  --border-color: rgba(142, 114, 86, 0.2);
  --spine-shadow: linear-gradient(to right, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0.2) 30%, rgba(0,0,0,0.2) 70%, rgba(0,0,0,0.1) 100%);
  --shadow-book: 0 30px 70px rgba(44, 37, 30, 0.2);
}

/* Sepia / Vintage Theme */
[data-theme="sepia"] {
  --bg-app: linear-gradient(135deg, #dfd0bb 0%, #cbb79b 100%);
  --bg-book: #f3e8d7;
  --bg-page-left: linear-gradient(to right, #f3e8d7 95%, #dfceb7 100%);
  --bg-page-right: linear-gradient(to left, #f3e8d7 95%, #dfceb7 100%);
  --text-main: #433422;
  --text-muted: #7c6850;
  --accent: #a37546;
  --accent-hover: #83592f;
  --border-color: rgba(163, 117, 70, 0.25);
  --spine-shadow: linear-gradient(to right, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.25) 30%, rgba(0,0,0,0.25) 70%, rgba(0,0,0,0.15) 100%);
  --shadow-book: 0 30px 70px rgba(67, 52, 34, 0.35);
}

/* Dark / Midnight Theme */
[data-theme="dark"] {
  --bg-app: linear-gradient(135deg, #0f111a 0%, #171b2a 100%);
  --bg-book: #1e2235;
  --bg-page-left: linear-gradient(to right, #1e2235 95%, #131622 100%);
  --bg-page-right: linear-gradient(to left, #1e2235 95%, #131622 100%);
  --text-main: #e2e6f0;
  --text-muted: #959ebd;
  --accent: #bf9f62;
  --accent-hover: #d9b87c;
  --border-color: rgba(191, 159, 98, 0.2);
  --spine-shadow: linear-gradient(to right, rgba(0,0,0,0.3) 0%, rgba(0,0,0,0.5) 30%, rgba(0,0,0,0.5) 70%, rgba(0,0,0,0.3) 100%);
  --shadow-book: 0 30px 70px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  overflow-x: hidden;
  transition: var(--transition-smooth);
}

/* Header & Controls bar */
header {
  width: 100%;
  max-width: 1200px;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  flex-wrap: wrap;
  gap: 15px;
}

.brand {
  font-family: var(--font-title);
  font-size: 1.5rem;
  letter-spacing: 2px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  color: var(--accent);
}

.controls {
  display: flex;
  align-items: center;
  gap: 15px;
}

/* Custom Select & Button elements */
button, select, input {
  font-family: var(--font-ui);
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  outline: none;
  cursor: pointer;
  transition: var(--transition-smooth);
  font-size: 0.9rem;
}

button:hover, select:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

input[type="text"] {
  background: rgba(255, 255, 255, 0.08);
  padding: 8px 20px;
  width: 200px;
}

input[type="text"]:focus {
  border-color: var(--accent);
  width: 250px;
}

/* App Container */
main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  width: 100%;
  max-width: 1300px;
  perspective: 1500px; /* Perspective for physical book feel */
}

/* Book Container */
.book-wrapper {
  position: relative;
  width: 100%;
  max-width: 960px;
  aspect-ratio: 3 / 2;
  box-shadow: var(--shadow-book);
  border-radius: 8px;
  transition: var(--transition-smooth);
  background: transparent;
  display: flex;
  overflow: hidden;
}

@media (max-width: 850px) {
  .book-wrapper {
    aspect-ratio: 3 / 4.5;
    max-width: 500px;
  }
}

.book {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
}

/* Pages Styling */
.page {
  flex: 1;
  height: 100%;
  padding: 50px 60px;
  position: relative;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: var(--transition-smooth);
  background: var(--bg-book);
}

/* Left & Right Pages */
.page-left {
  background: var(--bg-page-left);
  border-radius: 8px 0 0 8px;
  border-right: 1px solid rgba(0, 0, 0, 0.15);
}

.page-right {
  background: var(--bg-page-right);
  border-radius: 0 8px 8px 0;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
}

@media (max-width: 850px) {
  .page-left {
    display: none; /* In portrait mode, only show the active page */
  }
  .page-right {
    border-radius: 8px;
    border-left: none;
  }
}

/* Spine detailing */
.book-spine {
  position: absolute;
  left: 50%;
  top: 0;
  width: 16px;
  height: 100%;
  transform: translateX(-50%);
  background: var(--spine-shadow);
  z-index: 5;
}

@media (max-width: 850px) {
  .book-spine {
    display: none;
  }
}

/* Content Animations & Layouts */
.cover-page {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  height: 100%;
  padding: 40px;
  background-size: cover;
  background-position: center;
  position: relative;
  border-radius: 8px;
}

.cover-page::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 17, 26, 0.45);
  border-radius: 8px;
  z-index: 1;
}

.cover-content {
  position: relative;
  z-index: 2;
  color: #fff;
}

.cover-title {
  font-family: var(--font-title);
  font-size: 3rem;
  margin-bottom: 20px;
  text-shadow: 0 4px 10px rgba(0,0,0,0.5);
  letter-spacing: 3px;
  line-height: 1.2;
}

.cover-subtitle {
  font-family: var(--font-ui);
  font-size: 1.1rem;
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-bottom: 40px;
  color: #d9b87c;
  font-weight: 400;
}

.cover-author {
  font-family: var(--font-title);
  font-size: 1.2rem;
  letter-spacing: 2px;
  border-top: 1px solid rgba(255, 255, 255, 0.3);
  display: inline-block;
  padding-top: 15px;
}

/* Table of Contents Styling */
.toc-title {
  font-family: var(--font-title);
  font-size: 1.8rem;
  margin-bottom: 30px;
  text-align: center;
  color: var(--accent);
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 10px;
}

.toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.toc-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.toc-item:hover {
  color: var(--accent);
  transform: translateX(5px);
}

.toc-name {
  font-weight: 500;
}

.toc-dots {
  flex-grow: 1;
  border-bottom: 1px dotted var(--border-color);
  margin: 0 10px;
}

.toc-page-num {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Poem Content layout */
.poem-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  margin: auto;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.poem-title {
  font-family: var(--font-title);
  font-size: 1.8rem;
  margin-bottom: 15px;
  color: var(--accent);
  letter-spacing: 2px;
}

.poem-theme {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 25px;
  color: var(--text-muted);
}

.poem-body {
  font-size: 1.1rem;
  line-height: 1.8;
  white-space: pre-line;
  margin-bottom: 30px;
  font-style: italic;
}

.poem-illustration {
  font-size: 2rem;
  color: var(--accent);
  opacity: 0.5;
  margin-top: 15px;
}

/* Page footer numbers & metadata */
.page-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  padding-top: 15px;
  margin-top: 20px;
  width: 100%;
}

.favorite-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-muted);
  font-size: 1.1rem;
}

.favorite-btn.active {
  color: #e25c5c;
}

/* Navigation Overlay */
.nav-buttons {
  display: flex;
  gap: 20px;
  margin-top: 25px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Footer Section */
footer {
  width: 100%;
  text-align: center;
  padding: 20px;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  max-width: 1200px;
}

/* Toast alert styling */
.toast {
  position: fixed;
  bottom: 30px;
  background: var(--accent);
  color: white;
  padding: 12px 24px;
  border-radius: 30px;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 100;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}
