:root {
  --ink: #161817;
  --muted: #69716b;
  --paper: #f4efe4;
  --sheet: #fffdf7;
  --sheet-strong: #fbf4e7;
  --line: #d7cbbb;
  --green: #173b33;
  --red: #b94331;
  --blue: #28556f;
  --ochre: #c4902e;
  --shadow: 0 22px 70px rgba(22, 24, 23, 0.13);
  --reader-size: 17px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(23, 59, 51, 0.05) 1px, transparent 1px) 0 0 / 36px 36px,
    linear-gradient(0deg, rgba(23, 59, 51, 0.045) 1px, transparent 1px) 0 0 / 36px 36px,
    var(--paper);
  font-family: "Avenir Next", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.reader-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: 100vh;
}

.library-panel {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.84);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 58px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px solid var(--green);
  border-radius: 8px;
  color: var(--sheet);
  background: var(--green);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 32px;
  box-shadow: 0 16px 30px rgba(23, 59, 51, 0.22);
}

.brand strong {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  line-height: 1;
}

.brand span,
.eyebrow,
.search-box span,
.result-meta,
.chapter-button small,
.section-card header span {
  color: var(--muted);
}

.book-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.book-tabs button,
.icon-button,
.text-button,
.section-tabs button,
.chapter-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--sheet);
}

.book-tabs button {
  min-height: 44px;
  font-weight: 800;
}

.book-tabs button.active,
.section-tabs button.active {
  border-color: var(--green);
  color: var(--sheet);
  background: var(--green);
}

.search-box {
  display: grid;
  gap: 8px;
}

.search-box span,
.eyebrow {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.search-box input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--sheet);
  outline: 0;
}

.search-box input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 85, 111, 0.15);
}

.result-meta {
  min-height: 18px;
  font-size: 13px;
  font-weight: 700;
}

.chapter-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.chapter-button {
  width: 100%;
  padding: 13px 14px;
  text-align: left;
}

.chapter-button strong {
  display: block;
  margin-bottom: 4px;
  line-height: 1.25;
}

.chapter-button small {
  display: block;
  font-weight: 800;
}

.chapter-button.active {
  border-color: var(--red);
  background: #fff2eb;
  box-shadow: inset 5px 0 0 var(--red);
}

.reader-main {
  padding: 28px;
}

.reader-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 8px;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(38px, 5vw, 76px);
  line-height: 0.96;
  letter-spacing: 0;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-button,
.text-button {
  min-height: 44px;
  padding: 0 14px;
  font-weight: 800;
}

.text-button {
  color: var(--sheet);
  border-color: var(--red);
  background: var(--red);
}

.text-button.is-on {
  color: var(--ink);
  border-color: var(--line);
  background: var(--sheet);
}

.section-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.section-tabs button {
  min-width: 112px;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 900;
}

.content-stack {
  display: grid;
  gap: 16px;
}

.section-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.94);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.section-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--sheet-strong);
}

.section-card h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 26px;
}

.section-body {
  padding: 22px;
  font-size: var(--reader-size);
  line-height: 1.82;
  white-space: pre-line;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.section-body mark {
  padding: 0 3px;
  border-radius: 4px;
  background: rgba(196, 144, 46, 0.34);
}

.answer-body {
  border-top: 1px dashed var(--line);
  background: #f8f0e3;
}

.empty {
  padding: 24px;
  color: var(--muted);
  font-weight: 700;
}

@media (max-width: 900px) {
  .reader-shell {
    grid-template-columns: 1fr;
  }

  .library-panel {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chapter-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: 260px;
  }

  .reader-main {
    padding: 18px;
  }

  .reader-toolbar {
    display: grid;
  }

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

@media (max-width: 560px) {
  .library-panel {
    padding: 16px;
  }

  .chapter-list {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 38px;
  }

  .section-card header {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-body {
    padding: 18px;
    line-height: 1.75;
  }
}
