:root {
  color-scheme: light;
  --bg: #f8f2e9;
  --card: #fffefa;
  --text: #171411;
  --muted: #645d54;
  --soft: #8a8175;
  --line: #ded6ca;
  --accent: #9f3232;
  --accent-hover: #882a2a;
  --accent-soft: #fff4f2;
  --shadow: rgba(52, 38, 24, 0.055);
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 255, 255, 0.95), transparent 28%),
    linear-gradient(135deg, #fbf5ec 0%, #f5ece0 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Arial, Helvetica, sans-serif;
  font-weight: 400;
  letter-spacing: -0.01em;
}

body.modalOpen {
  overflow: hidden;
}

.page {
  width: min(1350px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 50px 0 64px;
}

.hero {
  margin-bottom: 30px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0 0 10px;
  font-size: clamp(40px, 5vw, 56px);
  font-weight: 720;
  line-height: 1.05;
  letter-spacing: -0.045em;
}

.hero p,
.notice,
.meta,
.source {
  color: var(--muted);
  font-weight: 400;
}

.searchBox,
.result {
  background: rgba(255, 254, 250, 0.82);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 16px 45px var(--shadow);
  backdrop-filter: blur(10px);
}

.fieldLabel {
  display: inline-block;
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

.queryInput {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  border: 1px solid #d7cfc4;
  border-radius: 12px;
  padding: 18px;
  font-size: 19px;
  font-weight: 400;
  line-height: 1.5;
  background: white;
  color: var(--text);
  outline: none;
}

.queryInput:focus {
  border-color: rgba(159, 50, 50, 0.55);
  box-shadow: 0 0 0 3px rgba(159, 50, 50, 0.08);
}

.stepBlock {
  margin-top: 22px;
}

.questionText {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.choiceGrid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.choiceGrid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.choiceButton {
  display: grid;
  gap: 8px;
  min-height: 92px;
  padding: 17px 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.82);
  cursor: pointer;
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    background 0.16s ease,
    transform 0.16s ease;
}

.choiceButton:hover {
  border-color: #cfc3b4;
  transform: translateY(-1px);
}

.choiceButton:has(input:checked) {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(159, 50, 50, 0.65);
  background: var(--accent-soft);
}

.choiceButton input {
  display: none;
}

.choiceButton span {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.025em;
}

.choiceButton small {
  color: var(--muted);
  font-size: 15.5px;
  font-weight: 400;
  line-height: 1.35;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 18px;
}

.button {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  padding: 12px 22px;
  font-size: 17px;
  font-weight: 650;
  cursor: pointer;
  letter-spacing: -0.01em;
  transition:
    background 0.16s ease,
    transform 0.16s ease,
    opacity 0.16s ease;
}

.button:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.button.secondary {
  background: #fbf6ee;
  border: 1px solid var(--line);
  color: var(--text);
}

.button.secondary:hover:not(:disabled) {
  background: #f5ede3;
}

.button:disabled {
  opacity: 0.7;
  cursor: wait;
}

.button.compact {
  padding: 8px 13px;
  border-radius: 8px;
  font-size: 14px;
  white-space: nowrap;
}

.results {
  display: grid;
  gap: 16px;
  margin-top: 22px;
}

.resultTitle {
  font-weight: 660;
  font-size: 18px;
  margin: 14px 0 8px;
  letter-spacing: -0.018em;
}

.source {
  font-size: 16px;
  line-height: 1.45;
}

.meta {
  font-size: 14px;
  margin-top: 5px;
  color: var(--soft);
}

.pali {
  white-space: pre-wrap;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18.5px;
  line-height: 1.65;
  font-weight: 400;
  letter-spacing: 0;
  color: #211b15;
}

.translation {
  white-space: pre-wrap;
  background: #fff8ed;
  border-left: 3px solid #d9a245;
  border-radius: 10px;
  padding: 14px 16px;
  line-height: 1.6;
  font-size: 17px;
  font-weight: 400;
}

.translationMount {
  min-height: 54px;
}

.translationLoading {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff8ed;
  border-left: 3px solid #d9a245;
  border-radius: 10px;
  padding: 14px 16px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 16px;
  animation: softPulse 1.6s ease-in-out infinite;
}

.miniSpinner {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  border: 3px solid #eadfce;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.translationDone {
  border-left-color: #4a8f4a;
  background: #f1faef;
  color: #286028;
  animation: none;
}

.translationLoading:has([data-translate-next-section]) {
  animation: none;
}

.sectionActions {
  margin: 16px 0 10px;
}

.sectionMount {
  margin-top: 14px;
}

.sectionViewer {
  border: 1px solid #ead9bc;
  border-radius: 14px;
  background: #fffaf1;
  padding: 18px;
}

.sectionViewerModal {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
}

.sectionHeader h2 {
  margin: 4px 0 8px;
  font-size: 25px;
  line-height: 1.25;
  letter-spacing: -0.03em;
}

.sectionPassage {
  border-top: 1px solid #eadfce;
  margin-top: 18px;
  padding-top: 18px;
}

.sectionColumns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.sectionColumns .sectionPassage {
  min-width: 0;
  border: 1px solid #eadfce;
  border-radius: 14px;
  margin-top: 12px;
  padding: 16px;
  background: rgba(255, 254, 250, 0.82);
}

.readerBlock {
  position: relative;
}

.readerHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.readerHeader .resultTitle,
.readerHeader .meta {
  margin-top: 0;
}

.readerBody {
  position: relative;
  max-height: none;
  overflow: visible;
  transition: max-height 0.2s ease;
}

.readerBody.collapsed {
  max-height: 62vh;
  overflow: hidden;
}

.readerBody.collapsed::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 95px;
  background: linear-gradient(to bottom, rgba(255, 250, 241, 0), #fffaf1 82%);
  pointer-events: none;
}

.sectionViewer .pali,
.sectionViewer .translation {
  margin-bottom: 0;
}

.translationNote {
  margin: 10px 0 0;
  font-style: italic;
}

.modalOverlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: rgba(25, 19, 14, 0.56);
  backdrop-filter: blur(8px);
}

.modalOverlay.hidden {
  display: none;
}

.modalPanel {
  display: flex;
  flex-direction: column;
  width: min(1540px, calc(100vw - 56px));
  max-height: calc(100vh - 56px);
  overflow: hidden;
  border: 1px solid rgba(222, 214, 202, 0.92);
  border-radius: 22px;
  background: #fffaf1;
  box-shadow: 0 30px 90px rgba(35, 24, 13, 0.32);
}

.modalTopbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid #eadfce;
  background: rgba(255, 254, 250, 0.92);
}

.modalTopbar h2 {
  margin: 2px 0 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.modalEyebrow {
  margin-bottom: 4px;
}

.modalClose {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fffaf1;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.modalClose:hover {
  background: #f5ede3;
}

.modalBody {
  overflow: auto;
  padding: 20px 22px 24px;
}

.loadMoreForm {
  margin: 18px 0 0;
}

.error {
  margin-top: 14px;
  border: 1px solid #e3a5a5;
  background: #fff0f0;
  color: #8a1f1f;
  padding: 12px;
  border-radius: 8px;
  font-weight: 400;
}

.loading {
  margin-top: 22px;
  padding: 18px;
  color: var(--muted);
}

.searchLoading {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid #eadfce;
  border-radius: 14px;
  background: rgba(255, 254, 250, 0.9);
  box-shadow: 0 16px 45px var(--shadow);
}

.spinner {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border: 3px solid #eadfce;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loadingTitle {
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
}

.loadingText {
  margin-top: 3px;
  color: var(--muted);
  font-size: 15px;
}

.aiWarning {
  display: inline-block;
  margin-top: 16px;
  border: 1px solid #d9a245;
  border-radius: 10px;
  background: #fff2d4;
  color: #6e3d00;
  padding: 10px 12px;
  font-weight: 750;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes softPulse {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(217, 162, 69, 0);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(217, 162, 69, 0.12);
  }
}

@media (max-width: 900px) {
  .choiceGrid,
  .choiceGrid.three {
    grid-template-columns: 1fr;
  }

  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .sectionColumns {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .page {
    width: min(100% - 28px, 1350px);
    padding-top: 28px;
  }

  .searchBox,
  .result {
    padding: 18px;
  }

  .readerHeader {
    flex-direction: column;
  }

  .button.compact {
    width: 100%;
  }

  .readerBody.collapsed {
    max-height: 430px;
  }

  .modalOverlay {
    padding: 10px;
  }

  .modalPanel {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    border-radius: 16px;
  }

  .modalTopbar {
    padding: 14px 16px;
  }

  .modalBody {
    padding: 14px 16px 18px;
  }
}
