/* ========================================
   DTV Book Reader - Styles
   Designed with UI/UX principles from userinterface.wiki
   ======================================== */

/* CSS Variables for theming */
:root {
  /* Typography */
  --font-serif: 'Cormorant Garamond', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Spacing */
  --content-max-width: 680px;
  --content-padding: clamp(1.5rem, 5vw, 3rem);

  /* Animation timing - following UI principles */
  --ease-out: cubic-bezier(0.215, 0.61, 0.355, 1);
  --ease-in: cubic-bezier(0.55, 0.055, 0.675, 0.19);
  --ease-in-out: cubic-bezier(0.455, 0.03, 0.515, 0.955);

  /* Timing - keep under 300ms for interactions */
  --duration-fast: 150ms;
  --duration-normal: 220ms;
  --duration-slow: 300ms;
}

/* Light theme (default and explicit) */
:root,
[data-theme="light"] {
  color-scheme: light;
  --bg-primary: #faf9f7;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f5f4f2;
  --text-primary: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #8a8a8a;
  --accent: #2c2c2c;
  --accent-light: rgba(44, 44, 44, 0.1);
  --border: rgba(0, 0, 0, 0.08);
  --shadow: rgba(0, 0, 0, 0.06);
  --shadow-strong: rgba(0, 0, 0, 0.12);
}

/* Dark theme */
[data-theme="dark"] {
  color-scheme: dark;
  --bg-primary: #121212;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #242424;
  --text-primary: #e8e6e3;
  --text-secondary: #b8b5b0;
  --text-muted: #6a6a6a;
  --accent: #e8e6e3;
  --accent-light: rgba(232, 230, 227, 0.1);
  --border: rgba(255, 255, 255, 0.08);
  --shadow: rgba(0, 0, 0, 0.3);
  --shadow-strong: rgba(0, 0, 0, 0.5);
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.8;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  transition: background-color var(--duration-slow) var(--ease-out),
              color var(--duration-slow) var(--ease-out);
  overflow-x: hidden;
}

/* ========================================
   Cover Screen
   ======================================== */
.cover-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  z-index: 100;
  transition: opacity var(--duration-slow) var(--ease-in),
              transform var(--duration-slow) var(--ease-in);
}

.cover-screen.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.98);
}

.cover-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.5rem;
  max-width: 420px;
  min-height: 100vh;
  min-height: 100dvh;
  text-align: center;
  animation: fadeInUp 600ms var(--ease-out) both;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.cover-image-wrapper {
  position: relative;
  width: 100%;
  max-width: 240px;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 16px 48px var(--shadow-strong),
              0 6px 16px var(--shadow);
  transition: transform var(--duration-normal) var(--ease-out),
              box-shadow var(--duration-normal) var(--ease-out);
}

.cover-image-wrapper:hover {
  transform: translateY(-4px);
  box-shadow: 0 28px 80px var(--shadow-strong),
              0 12px 30px var(--shadow);
}

.cover-image {
  display: block;
  width: 100%;
  height: auto;
}

.cover-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  animation: fadeInUp 600ms var(--ease-out) 150ms both;
}

.cover-title {
  font-family: var(--font-serif);
  font-size: clamp(2.5rem, 8vw, 3.5rem);
  font-weight: 300;
  letter-spacing: 0.15em;
  color: var(--text-primary);
  margin: 0;
}

.cover-signature {
  max-width: 220px;
  width: 60%;
  height: auto;
  opacity: 0.85;
  filter: var(--signature-filter, none);
  transition: opacity var(--duration-normal) var(--ease-out);
}

[data-theme="dark"] .cover-signature {
  filter: invert(1) brightness(0.85);
}

.cover-author {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-variant: small-caps;
  letter-spacing: 0.12em;
  color: var(--text-secondary);
  margin: 0;
}

.start-button {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.75rem;
  margin-top: 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--bg-primary);
  background: var(--text-primary);
  border: none;
  border-radius: 100px;
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out),
              background-color var(--duration-fast) var(--ease-out);
  animation: fadeInUp 600ms var(--ease-out) 300ms both;
}

.start-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--shadow-strong);
}

.start-button:active {
  transform: translateY(0) scale(0.98);
}

.start-button svg {
  transition: transform var(--duration-fast) var(--ease-out);
}

.start-button:hover svg {
  transform: translateX(3px);
}

/* ========================================
   Reader Layout
   ======================================== */
.reader {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  transition: opacity var(--duration-slow) var(--ease-out),
              transform var(--duration-slow) var(--ease-out);
}

.reader.hidden {
  display: none;
}

.reader.entering {
  animation: fadeIn var(--duration-slow) var(--ease-out) both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Reader Header */
.reader-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0.875rem var(--content-padding);
  background: var(--bg-secondary);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.reader-header > .icon-button {
  justify-self: end;
}

/* Chapter Navigation */
.chapter-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chapter-title {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-primary);
  text-align: center;
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}

.nav-arrow:hover:not(:disabled) {
  background: var(--accent-light);
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.nav-arrow:active:not(:disabled) {
  transform: scale(0.92);
}

.nav-arrow:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background-color var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}

/* Only apply hover styles on devices that support hover */
@media (hover: hover) {
  .icon-button:hover {
    background: var(--accent-light);
    color: var(--text-primary);
  }
}

.icon-button:active {
  transform: scale(0.95);
}

/* Theme toggle icons */
.sun-icon { display: block; }
.moon-icon { display: none; }

[data-theme="dark"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: block; }

/* Progress Bar - integrated into header */
.progress-container {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--border);
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--text-primary);
  transition: width var(--duration-normal) var(--ease-out);
}

/* Reader Content */
.reader-content {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: clamp(2rem, 6vw, 4rem) var(--content-padding);
}

.chapter {
  width: 100%;
  max-width: var(--content-max-width);
  animation: contentFadeIn var(--duration-slow) var(--ease-out) both;
}

@keyframes contentFadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chapter.transitioning {
  animation: contentFadeOut var(--duration-normal) var(--ease-in) both;
}

@keyframes contentFadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-12px);
  }
}

/* Typography Styles */
.chapter h2 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-align: center;
  text-transform: uppercase;
  color: var(--text-primary);
  margin: 2em 0 3em;
}

.chapter p {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  line-height: 1.85;
  color: var(--text-primary);
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  margin-bottom: 0;
}

.chapter p + p {
  text-indent: 2em;
}

.chapter p.section-start {
  text-indent: 0;
  margin-top: 3em;
}

.chapter p.section-start::first-line {
  font-variant: small-caps;
  letter-spacing: 0.05em;
}

.chapter .signature-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 4rem 0;
  text-align: center;
}

.chapter .signature-img {
  max-width: 280px;
  width: 70%;
  margin-bottom: 1rem;
}

[data-theme="dark"] .chapter .signature-img {
  filter: invert(1) brightness(0.85);
}

/* Next Chapter Button */
.chapter {
  display: flex;
  flex-direction: column;
  padding-bottom: 3rem;
}

.next-chapter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  gap: 0.5rem;
  margin-top: 4rem;
  padding: 0.875rem 1.5rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 100px;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}

.next-chapter-btn:hover {
  background: var(--accent-light);
  border-color: var(--text-muted);
}

.next-chapter-btn:active {
  transform: scale(0.97);
}

.next-chapter-label {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.next-chapter-btn svg {
  color: var(--text-secondary);
  transition: transform var(--duration-fast) var(--ease-out);
}

.next-chapter-btn:hover svg {
  transform: translateX(3px);
}


/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 768px) {
  body {
    font-size: 16px;
  }

  .cover-image-wrapper {
    max-width: 260px;
  }

  .cover-title {
    font-size: 2.5rem;
  }

  .reader-header {
    padding: 0.5rem 1rem;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .icon-button svg {
    width: 20px;
    height: 20px;
  }

  .chapter-nav {
    gap: 0.5rem;
  }

  .chapter-title {
    font-size: 0.75rem;
    max-width: 180px;
  }

  .nav-arrow {
    width: 28px;
    height: 28px;
  }

  .nav-arrow svg {
    width: 14px;
    height: 14px;
  }

  .chapter p {
    font-size: 1.0625rem;
    text-align: left;
  }
}

@media (max-width: 480px) {
  .cover-content {
    gap: 0.75rem;
  }

  .start-button {
    padding: 0.875rem 1.5rem;
    font-size: 0.875rem;
  }

  .book-info {
    display: none;
  }
}

/* Small viewport height - compact cover */
@media (max-height: 700px) {
  .cover-content {
    gap: 0.75rem;
    padding: 1rem;
  }

  .cover-image-wrapper {
    max-width: 180px;
  }

  .cover-title {
    font-size: 2rem;
  }

  .cover-signature {
    max-width: 160px;
  }

  .cover-author {
    font-size: 0.875rem;
  }

  .start-button {
    padding: 0.75rem 1.5rem;
    margin-top: 0.25rem;
  }
}

@media (max-height: 550px) {
  .cover-content {
    gap: 0.5rem;
    padding: 0.75rem;
  }

  .cover-image-wrapper {
    max-width: 140px;
  }

  .cover-title {
    font-size: 1.75rem;
  }

  .cover-signature {
    max-width: 130px;
  }

  .start-button {
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
  }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
  .cover-screen,
  .reader-header {
    display: none !important;
  }

  .reader {
    display: block !important;
  }

  .chapter {
    max-width: none;
  }
}

/* ========================================
   Accessibility
   ======================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus styles */
:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

button:focus:not(:focus-visible) {
  outline: none;
}

/* Selection */
::selection {
  background: var(--accent-light);
  color: var(--text-primary);
}
