:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #eef5f7;
  --ink: #18222f;
  --muted: #5f6b7a;
  --line: #d7dfe7;
  --line-strong: #aeb9c6;
  --blue: #2468b2;
  --teal: #008fa3;
  --green: #4d9a63;
  --orange: #d97821;
  --red: #c84b42;
  --shadow: 0 12px 34px rgba(24, 34, 47, 0.09);
  --radius: 8px;
  font-family: "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(220px, 340px) minmax(280px, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, var(--blue) 0 30%, transparent 30% 100%),
    linear-gradient(45deg, transparent 0 46%, var(--orange) 46% 56%, transparent 56% 100%),
    linear-gradient(135deg, transparent 0 55%, var(--teal) 55% 68%, transparent 68% 100%),
    #e9f3f5;
  border: 1px solid #cfe0e5;
  flex: 0 0 auto;
}

.brand strong,
.brand small {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 1px;
}

.search-wrap {
  position: relative;
  min-width: 0;
}

.search-wrap svg {
  position: absolute;
  left: 14px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  color: var(--muted);
}

.search-wrap input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfd;
  color: var(--ink);
  padding: 0 14px 0 42px;
  outline: none;
}

.search-wrap input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 143, 163, 0.14);
  background: #fff;
}

.top-actions,
.page-jump {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.round-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
  border-radius: 8px;
  min-height: 38px;
  padding: 0 12px;
}

.icon-button svg,
.round-button svg {
  width: 18px;
  height: 18px;
}

.icon-button:hover,
.round-button:hover,
.chip:hover,
.segmented button:hover {
  border-color: var(--line-strong);
  background: #f7fafc;
}

.icon-button.solid {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.content-grid {
  display: grid;
  grid-template-columns: 258px minmax(0, 1fr);
  gap: 0;
}

.sidebar {
  position: sticky;
  top: 71px;
  height: calc(100vh - 71px);
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  overflow: auto;
}

.toc-group,
.filter-panel,
.search-results {
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
  margin-bottom: 18px;
}

.toc-link {
  display: block;
  padding: 9px 10px;
  border-radius: 8px;
  color: #334153;
  font-weight: 700;
  font-size: 14px;
}

.toc-link.is-active,
.toc-link:hover {
  color: var(--teal);
  background: #eaf7f9;
}

.panel-title {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.chip-set {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip,
.segmented button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  min-height: 34px;
  padding: 0 12px;
  font-weight: 800;
}

.chip.is-active,
.segmented button.is-active {
  color: #fff;
  border-color: var(--ink);
  background: var(--ink);
}

main {
  min-width: 0;
  padding: 28px;
}

.overview-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 204px;
  gap: 28px;
  align-items: stretch;
  padding: 28px;
  background:
    linear-gradient(90deg, rgba(232, 244, 247, 0.92), rgba(255, 255, 255, 0.86)),
    #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.overview-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
  letter-spacing: 0;
}

h1 {
  max-width: 780px;
  font-size: 32px;
}

h2 {
  font-size: 24px;
}

h3 {
  font-size: 18px;
}

.overview-copy p {
  max-width: 760px;
  margin: 14px 0 0;
  color: #3f4b5a;
  font-size: 16px;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.meta-row span {
  border: 1px solid #cbdce2;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: #324151;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 800;
}

.cover-button {
  overflow: hidden;
  width: 204px;
  min-height: 288px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 20px rgba(24, 34, 47, 0.12);
}

.cover-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.stats-strip article,
.diagnosis-card,
.focus-card,
.subject-item,
.page-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.stats-strip article {
  padding: 16px;
}

.stats-strip span,
.stats-strip small {
  display: block;
  color: var(--muted);
}

.stats-strip span {
  font-size: 13px;
  font-weight: 800;
}

.stats-strip strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

.stats-strip small {
  margin-top: 2px;
  font-size: 12px;
}

.section-band {
  padding-top: 34px;
  scroll-margin-top: 90px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.section-heading:not(.with-controls) {
  display: block;
}

.section-heading.with-controls {
  align-items: center;
}

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.segmented button {
  min-height: 32px;
  border-color: transparent;
  background: transparent;
}

.diagnosis-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.diagnosis-card {
  position: relative;
  min-height: 248px;
  padding: 18px;
  overflow: hidden;
}

.diagnosis-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--accent, var(--teal));
}

.diagnosis-card .label,
.focus-card .label,
.subject-item .label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.diagnosis-card p,
.focus-card p,
.subject-item p {
  color: #3f4b5a;
}

.diagnosis-card ul,
.focus-card ul,
.subject-item ul {
  margin: 12px 0 0;
  padding-left: 18px;
}

.diagnosis-card li,
.focus-card li,
.subject-item li {
  margin: 6px 0;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 8px;
  background: #eef2f5;
  color: #3d4a59;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 800;
}

.focus-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.focus-card {
  display: flex;
  min-height: 312px;
  flex-direction: column;
  padding: 16px;
}

.focus-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 8px;
  background: var(--accent-soft, #edf7f8);
  color: var(--accent, var(--teal));
  padding: 0 9px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.focus-card dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.focus-card dt {
  color: var(--ink);
  font-weight: 900;
}

.focus-card dd {
  margin: 0;
  color: #3f4b5a;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  padding-top: 14px;
}

.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  font-weight: 900;
}

.text-button.primary {
  border-color: var(--accent, var(--teal));
  color: var(--accent, var(--teal));
  background: var(--accent-soft, #edf7f8);
}

.text-button svg {
  width: 16px;
  height: 16px;
}

.subject-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.subject-item {
  padding: 16px;
}

.subject-item strong {
  color: var(--ink);
}

.subject-item .page-range {
  display: inline-flex;
  align-items: center;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

table {
  width: 100%;
  min-width: 880px;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eff4f6;
  color: #263241;
  font-weight: 900;
}

tbody tr:hover {
  background: #fbfdfe;
}

tbody tr.total-row {
  background: #f0f2f4;
  font-weight: 900;
}

.page-jump input {
  width: 76px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
}

.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
  gap: 12px;
}

.page-card {
  padding: 8px;
  text-align: left;
  cursor: pointer;
}

.page-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1240 / 1753;
  object-fit: cover;
  object-position: top center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f2f4f6;
}

.page-card span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.search-results {
  min-height: 40px;
}

.empty-state {
  grid-column: 1 / -1;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  padding: 22px;
  text-align: center;
  font-weight: 800;
}

.result-button {
  display: block;
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px;
  color: var(--ink);
  text-align: left;
}

.result-button strong {
  display: block;
  margin-bottom: 3px;
  font-size: 13px;
}

.result-button small {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.page-dialog {
  width: min(1000px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: #151a20;
  color: #fff;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
  overflow: auto;
}

.page-dialog::backdrop {
  background: rgba(18, 25, 33, 0.64);
}

.dialog-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 40px 1fr 40px 40px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  background: rgba(21, 26, 32, 0.96);
}

.dialog-bar strong {
  text-align: center;
}

.round-button {
  min-width: 38px;
  width: 38px;
  padding: 0;
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.round-button.close {
  color: #ffd8d5;
}

.dialog-pages {
  display: grid;
  gap: 14px;
  padding-bottom: 14px;
}

.dialog-page {
  display: block;
  width: min(100%, 900px);
  height: auto;
  margin: 0 auto;
  background: #fff;
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: minmax(190px, 260px) minmax(220px, 1fr);
  }

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

  .content-grid {
    grid-template-columns: 1fr;
  }

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

  .toc-group {
    display: flex;
    gap: 6px;
    overflow: auto;
  }

  .toc-link {
    white-space: nowrap;
  }

  .focus-grid,
  .diagnosis-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions .icon-button {
    flex: 1;
  }

  main {
    padding: 16px;
  }

  .overview-band {
    grid-template-columns: 1fr;
    padding: 18px;
  }

  .cover-button {
    width: min(100%, 220px);
    min-height: 300px;
  }

  h1 {
    font-size: 25px;
  }

  h2 {
    font-size: 21px;
  }

  .stats-strip,
  .focus-grid,
  .diagnosis-grid,
  .subject-panel {
    grid-template-columns: 1fr;
  }

  .section-heading,
  .section-heading.with-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented {
    overflow: auto;
  }

  .segmented button {
    flex: 1;
    white-space: nowrap;
  }

  .page-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
