:root {
  --base-surface: rgba(255, 249, 238, 0.9);
  --base-border: rgba(129, 97, 64, 0.25);
  --text-main: #3c2f24;
  --text-subtle: #6b5644;
  --accent: #b66d3a;
  --accent-strong: #965126;
  --shadow: 0 18px 38px rgba(83, 51, 22, 0.15);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Source Sans 3", sans-serif;
  background: radial-gradient(circle at 20% 10%, #ffe9c6 0%, #f5e4ca 35%, #efddbf 100%);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
}

.ambient {
  position: fixed;
  pointer-events: none;
  border-radius: 50%;
  filter: blur(42px);
  opacity: 0.35;
}

.ambient-one {
  width: 320px;
  height: 320px;
  background: #e9b47d;
  top: -80px;
  left: -100px;
}

.ambient-two {
  width: 360px;
  height: 360px;
  background: #d89f67;
  bottom: -130px;
  right: -120px;
}

.site-nav,
.app-shell,
.site-footer {
  width: min(1200px, 94vw);
  position: relative;
  z-index: 2;
}

.site-nav {
  margin: 1.1rem auto 0;
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.app-shell {
  margin: 1.2rem auto 2rem;
  display: grid;
  gap: 1.2rem;
}

.site-footer {
  margin: 0 auto 1.1rem;
  padding: 0.8rem 1rem;
  text-align: center;
  color: #6a4b31;
}

.site-footer p {
  margin: 0;
}

.brand-logo {
  font-family: "Fraunces", serif;
  font-size: 1.35rem;
  color: #7e4823;
  text-decoration: none;
  font-weight: 700;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.nav-links a {
  color: #5e3e25;
  text-decoration: none;
  font-weight: 600;
}

.nav-links a:hover {
  color: #8a4f29;
}

.panel {
  background: var(--base-surface);
  border: 1px solid var(--base-border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
}

.hero h1 {
  font-family: "Fraunces", serif;
  font-size: clamp(1.6rem, 3.8vw, 3.1rem);
  margin: 0.3rem 0 0.7rem;
  line-height: 1.1;
}

.kicker {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  margin: 0;
  color: #8e5a33;
}

.subtitle {
  color: var(--text-subtle);
  max-width: 74ch;
  margin: 0;
}

.controls-panel,
.viewer-panel,
.reader-panel,
.ai-panel {
  padding: 1rem;
}

.input-row,
.audio-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
}

.audio-controls {
  margin-top: 0.8rem;
}

.file-label {
  font-weight: 600;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 0.62rem 1rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.btn.secondary {
  background: #f1d4b4;
  color: #56391f;
}

.btn.small {
  padding: 0.45rem 0.75rem;
  font-size: 0.92rem;
}

.btn:hover {
  transform: translateY(-1px);
  opacity: 0.95;
}

.status {
  margin: 0.7rem 0;
  color: #6d4f32;
  min-height: 1.25rem;
}

.reading-controls {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.reading-controls label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.hint {
  margin: 0.2rem 0 0;
  color: #7a624d;
  font-size: 0.92rem;
}

.split-layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr 1fr;
}

.panel-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

.viewer-panel h2,
.reader-panel h2,
.ai-panel h2 {
  margin: 0;
  font-family: "Fraunces", serif;
}

.reader-head-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

#pdfPreview {
  width: 100%;
  height: 62vh;
  border-radius: 12px;
  border: 1px solid rgba(98, 63, 31, 0.24);
  background: #fff;
}

.reader-note {
  margin-top: -0.3rem;
  color: #725b47;
}

.reader-content {
  border-radius: 12px;
  padding: 1.1rem;
  min-height: 62vh;
  max-height: 62vh;
  overflow: auto;
  line-height: 1.85;
  font-size: 18px;
}

.reader-panel[data-theme="1"] .reader-content {
  background: #fff8ea;
  color: #3f2f20;
}

.reader-panel[data-theme="2"] .reader-content {
  background: #f9efd6;
  color: #433325;
}

.reader-panel[data-theme="3"] .reader-content {
  background: #f0e0bf;
  color: #3d2e21;
}

.reader-panel[data-theme="4"] .reader-content {
  background: #ead5ae;
  color: #352618;
}

.ai-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.7rem;
  align-items: start;
  margin-top: 0.7rem;
}

.ai-audio-controls {
  margin-top: 0.8rem;
}

#aiQuestion {
  width: 100%;
  border: 1px solid rgba(130, 90, 55, 0.34);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  font: inherit;
  resize: vertical;
  background: #fff9ef;
  color: #473322;
}

.ai-answer {
  margin-top: 0.85rem;
  border-radius: 12px;
  border: 1px solid rgba(130, 90, 55, 0.3);
  background: #fdf2de;
  padding: 0.8rem;
  line-height: 1.65;
  min-height: 70px;
}

.word {
  cursor: pointer;
  border-radius: 4px;
  padding: 0 1px;
}

.word:hover {
  background: rgba(184, 112, 59, 0.2);
}

.word.last-read {
  background: rgba(145, 84, 36, 0.36);
  border-bottom: 2px solid #6e3d15;
}

.word-menu {
  position: fixed;
  width: min(360px, calc(100vw - 24px));
  background: rgba(255, 249, 239, 0.98);
  border: 1px solid rgba(139, 92, 54, 0.3);
  border-radius: 14px;
  box-shadow: 0 14px 32px rgba(64, 36, 12, 0.2);
  padding: 0.8rem;
  z-index: 20;
}

.hidden {
  display: none;
}

.word-title {
  margin: 0.1rem 0 0.5rem;
  font-family: "Fraunces", serif;
  font-size: 1.2rem;
}

.word-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.word-output {
  margin: 0.75rem 0 0;
  color: #5e452f;
  min-height: 1.3rem;
}

.split-layout:fullscreen,
.viewer-panel:fullscreen,
.reader-panel:fullscreen {
  background: #f7ebd6;
  padding: 1rem;
  overflow: auto;
}

.split-layout:fullscreen {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  height: 100vh;
}

.split-layout:fullscreen #pdfPreview,
.split-layout:fullscreen .reader-content {
  min-height: calc(100vh - 170px);
  max-height: calc(100vh - 170px);
}

.viewer-panel:fullscreen #pdfPreview {
  min-height: calc(100vh - 110px);
  max-height: calc(100vh - 110px);
}

.reader-panel:fullscreen .reader-content {
  min-height: calc(100vh - 145px);
  max-height: calc(100vh - 145px);
}

@media (max-width: 980px) {
  .split-layout {
    grid-template-columns: 1fr;
  }

  .panel-actions {
    justify-content: flex-start;
  }

  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  #pdfPreview,
  .reader-content {
    min-height: 50vh;
    max-height: 50vh;
  }
}

@media (max-width: 760px) {
  .site-nav {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.7rem;
  }

  .nav-links {
    gap: 0.65rem;
  }

  .input-row,
  .audio-controls {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .input-row input,
  .btn,
  .btn.secondary {
    width: 100%;
    text-align: center;
  }

  .reader-head-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .ai-row {
    grid-template-columns: 1fr;
  }

  .reader-content,
  #pdfPreview {
    min-height: 44vh;
    max-height: 44vh;
  }
}

@media (max-width: 480px) {
  .app-shell,
  .site-nav,
  .site-footer {
    width: 95vw;
  }

  .reader-head-actions {
    grid-template-columns: 1fr;
  }
}
