/* ============================================================
   Reusable textbook components
   ============================================================ */

/* ---- Chapter title ---- */
.chapter-title {
  margin: 0 0 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 3px solid var(--navy);
}

.chapter-title .chapter-label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

.chapter-title h1 {
  color: var(--navy);
  font-size: clamp(1.4rem, 3.5vw, 1.85rem);
  margin: 0 0 0.4rem;
  letter-spacing: -0.02em;
}

.chapter-title .chapter-desc {
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  font-weight: 400;
}

.chapter-title-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

/* ---- Frequency badge ---- */
.frequency {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem;
  font-size: var(--fs-xs);
  font-weight: 700;
  border-radius: 2px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.frequency--high {
  background: #c01c28;
  color: #fff;
}

.frequency--mid {
  background: #e6a817;
  color: #1a1a1a;
}

.frequency--low {
  background: var(--gray-pale);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.frequency::before {
  content: "출제";
  font-weight: 600;
  opacity: 0.9;
}

/* ---- Timeline ---- */
.timeline {
  list-style: none;
  padding: 0.5rem 0 0.5rem 0;
  margin: 0.75rem 0 1rem;
  border-left: 3px solid var(--blue-muted);
  position: relative;
}

.timeline li {
  position: relative;
  padding: 0.35rem 0 0.35rem 1.15rem;
  margin: 0;
  font-size: var(--fs-sm);
}

.timeline li::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 0.65rem;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--blue);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--blue-muted);
}

.timeline .tl-year {
  display: inline-block;
  min-width: 4.5em;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
  margin-right: 0.35rem;
}

.timeline .tl-event {
  color: var(--text-secondary);
}

/* ---- King / Person cards ---- */
.king-card,
.person-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.75rem 1rem;
  padding: 0.85rem 1rem;
  margin: 0.75rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--navy);
  border-radius: var(--radius);
}

.king-card .card-thumb,
.person-card .card-thumb {
  width: 112px;
  height: 112px;
  border-radius: var(--radius-sm);
  background: #111;
  object-fit: cover;
  object-position: center top;
  align-self: start;
  border: 1px solid var(--border);
}

.king-card .card-thumb.placeholder,
.person-card .card-thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--blue);
  font-weight: 700;
}

.king-card h4,
.person-card h4 {
  margin: 0 0 0.2rem;
  font-size: var(--fs-lg);
  color: var(--navy);
}

.king-card .reign,
.person-card .role {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.king-card ul,
.person-card ul {
  margin: 0;
  padding-left: 1.1rem;
  font-size: var(--fs-sm);
}

.king-card .card-body,
.person-card .card-body {
  min-width: 0;
}

@media (max-width: 480px) {
  .king-card,
  .person-card {
    grid-template-columns: 1fr;
  }

  .king-card .card-thumb,
  .person-card .card-thumb {
    width: 88px;
    height: 88px;
    margin: 0 auto;
  }
}

/* ---- War flow ---- */
.war-flow {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.4rem;
  margin: 0.75rem 0 1rem;
  padding: 0.75rem;
  background: var(--blue-pale);
  border-radius: var(--radius);
}

.war-flow .wf-step {
  flex: 1 1 120px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.65rem;
  font-size: var(--fs-sm);
  position: relative;
}

.war-flow .wf-step strong {
  display: block;
  color: var(--navy);
  font-size: var(--fs-xs);
  margin-bottom: 0.2rem;
}

.war-flow .wf-arrow {
  display: flex;
  align-items: center;
  color: var(--blue);
  font-weight: 700;
  flex: 0 0 auto;
  padding: 0 0.1rem;
}

@media (max-width: 600px) {
  .war-flow {
    flex-direction: column;
  }

  .war-flow .wf-arrow {
    transform: rotate(90deg);
    justify-content: center;
    padding: 0.1rem 0;
  }
}

/* ---- Memory / Trap / Tip boxes ---- */
.memory-box,
.trap-box,
.tip-box {
  margin: 0.85rem 0;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius);
  border-left: 4px solid;
  font-size: var(--fs-sm);
}

.memory-box {
  background: var(--memory-bg);
  border-left-color: var(--memory-border);
  color: var(--memory-text);
}

.trap-box {
  background: var(--trap-bg);
  border-left-color: var(--trap-border);
  color: var(--trap-text);
}

.tip-box {
  background: var(--tip-bg);
  border-left-color: var(--tip-border);
  color: var(--tip-text);
}

.memory-box .box-label,
.trap-box .box-label,
.tip-box .box-label {
  display: block;
  font-weight: 800;
  font-size: var(--fs-xs);
  letter-spacing: 0.04em;
  margin-bottom: 0.3rem;
}

.memory-box p,
.trap-box p,
.tip-box p {
  margin: 0.25rem 0;
}

.memory-box ul,
.trap-box ul,
.tip-box ul {
  margin: 0.25rem 0 0;
}

/* ---- Comparison table ---- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.75rem 0 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.comparison-table {
  width: 100%;
  min-width: 480px;
  font-size: var(--fs-sm);
  background: var(--surface);
}

.comparison-table th,
.comparison-table td {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.comparison-table thead th {
  background: var(--table-header);
  color: var(--navy);
  font-weight: 700;
  white-space: nowrap;
}

.comparison-table tbody tr:nth-child(even) {
  background: var(--table-stripe);
}

.comparison-table tbody th {
  background: var(--blue-pale);
  font-weight: 600;
  color: var(--navy);
  white-space: nowrap;
}

/* ---- Artifact card ---- */
.artifact-card {
  display: grid;
  grid-template-columns: minmax(120px, 38%) 1fr;
  gap: 0.85rem;
  margin: 0.85rem 0;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  align-items: center;
}

.artifact-card .art-img {
  width: 100%;
  max-width: 420px;
  aspect-ratio: 4 / 3;
  height: auto;
  object-fit: cover;
  object-position: center;
  border-radius: var(--radius-sm);
  background: #1a1a1a;
  display: block;
  border: 1px solid var(--border);
}

.artifact-card .art-img.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-align: center;
  padding: 0.5rem;
}

/* Chapter hero + edu figures */
.chapter-hero {
  margin: 0 0 1.1rem;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
}

.chapter-hero img {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 1;
  object-fit: cover;
  display: block;
}

.chapter-hero figcaption {
  padding: 0.45rem 0.75rem 0.55rem;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-align: center;
  word-break: keep-all;
  overflow-wrap: break-word;
}

/* 구버전 자동 삽입 edu-figure는 사용 중단 — 남아 있으면 숨김 */
.edu-figure {
  display: none !important;
}

@media (max-width: 720px) {
  .artifact-card {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .artifact-card .art-img {
    max-width: 100%;
    margin: 0 auto;
  }

  .king-card,
  .person-card {
    text-align: center;
    justify-items: center;
  }

  .king-card ul,
  .person-card ul {
    text-align: left;
    display: inline-block;
  }
}


.artifact-card h4 {
  margin: 0 0 0.25rem;
  font-size: var(--fs-base);
}

.artifact-card p {
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

@media (max-width: 480px) {
  .artifact-card {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .artifact-card .art-img {
    width: 100%;
    max-width: 100%;
    height: auto;
    aspect-ratio: 8 / 5;
    margin: 0 auto 0.5rem;
  }

  .artifact-card .art-body,
  .artifact-card > div:last-child {
    text-align: center;
  }

  .artifact-card p {
    word-break: keep-all;
    overflow-wrap: break-word;
  }
}

/* ---- OX list ---- */
.ox-list {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 1rem;
}

.ox-list li {
  display: grid;
  grid-template-columns: 2rem 1fr;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  margin: 0 0 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
}

.ox-list .ox-mark {
  font-weight: 800;
  text-align: center;
  font-size: 1rem;
  line-height: 1.4;
}

.ox-list .ox-mark.is-o {
  color: var(--blue);
}

.ox-list .ox-mark.is-x {
  color: var(--trap-border);
}

.ox-list .ox-explain {
  display: block;
  margin-top: 0.25rem;
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

/* ---- Question list ---- */
.question-list {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 1rem;
  counter-reset: q;
}

.question-list > li {
  counter-increment: q;
  margin: 0 0 0.75rem;
  padding: 0.75rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--fs-sm);
}

.question-list > li::before {
  content: "Q" counter(q);
  display: inline-block;
  font-weight: 800;
  color: var(--blue);
  margin-right: 0.5rem;
  font-size: var(--fs-xs);
}

.question-list .q-stem {
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.question-list .q-choices {
  list-style: none;
  padding: 0;
  margin: 0.35rem 0;
}

.question-list .q-choices li {
  margin: 0.15rem 0;
  padding-left: 0.25rem;
}

.question-list .q-answer {
  margin-top: 0.5rem;
  padding-top: 0.45rem;
  border-top: 1px dashed var(--border);
  font-size: var(--fs-xs);
  color: var(--tip-text);
}

.question-list .q-answer strong {
  color: var(--tip-border);
}

/* ---- Summary card (aside + inline) ---- */
.summary-card {
  background: var(--blue-pale);
  border: 1px solid var(--blue-muted);
  border-radius: var(--radius);
  padding: 0.85rem;
  margin: 0.75rem 0 1rem;
  font-size: var(--fs-sm);
}

.summary-card h4 {
  margin: 0 0 0.45rem;
  font-size: var(--fs-sm);
  color: var(--navy);
}

.summary-card ul {
  margin: 0;
  padding-left: 1.1rem;
}

.summary-card li {
  margin: 0.2rem 0;
}

.aside-panel .summary-card {
  margin: 0;
  border: none;
  background: transparent;
  padding: 0;
}

/* ---- Chapter nav (prev / next) ---- */
.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 2rem 0 1rem;
  padding-top: 1rem;
  border-top: 2px solid var(--border);
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  padding: 0.7rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  font-size: var(--fs-sm);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
  min-height: 3.5rem;
}

.chapter-nav a:hover {
  border-color: var(--blue);
  background: var(--blue-pale);
  text-decoration: none;
  color: var(--text);
}

.chapter-nav a.is-disabled {
  visibility: hidden;
  pointer-events: none;
}

.chapter-nav .nav-dir {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.chapter-nav .nav-title {
  font-weight: 600;
  color: var(--navy);
  line-height: 1.3;
}

.chapter-nav .nav-next {
  text-align: right;
  grid-column: 2;
}

.chapter-nav .nav-prev {
  grid-column: 1;
}

/* ---- Body content helpers ---- */
.lead {
  font-size: var(--fs-lg);
  color: var(--text-secondary);
  margin: 0 0 1rem;
}

.content-block {
  margin-bottom: 1.25rem;
}

.content-block > p {
  margin: 0.4rem 0;
}

.key-term {
  font-weight: 700;
  color: var(--navy);
}

.mark-check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.75rem;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.mark-check input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--blue);
}

/* Section anchors offset for sticky header */
.main-content section[id],
.main-content h2[id],
.main-content h3[id] {
  scroll-margin-top: calc(var(--header-h) + 0.75rem);
}
