/* 기억해봐요 — 공통 스타일 (목차·상세 공용) */

/* ── 토큰 ─────────────────────────────────────────── */
:root {
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --line: #E1E6EC;
  --line-strong: #C9D3DF;
  --ink: #1B2430;
  --muted: #51606F;
  --accent: #1F5FD0;
  --accent-dark: #143F8F;
  --chip-bg: #E4EDFC;
  --chip-ink: #1B4590;
  --mark: #FFE98A;
  --panel: #14202E;
  --panel-head: #1E2F42;

  --code-ink: #E6EDF5;
  --code-comment: #9FB0C2;
  --code-string: #9EE0B0;
  --code-keyword: #F5A8C0;
  --code-prompt: #8FB4F5;

  --tab-off-bg: #F4F6F9;
  --tab-off-ink: #5E6B79;
  --tab-off-line: #D5DCE5;

  --sans: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ── 기본 ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.75;
  overflow-wrap: break-word;
}

a { color: var(--accent); }
a:hover { color: var(--accent-dark); }

h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding-left: 1.2em; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.wrap {
  max-width: 960px;
  margin: 0 auto;
  /* 아이폰의 노치·홈 인디케이터 영역(safe area)을 피해 여백을 줍니다. */
  padding-left: calc(24px + env(safe-area-inset-left, 0px));
  padding-right: calc(24px + env(safe-area-inset-right, 0px));
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

mark {
  background: var(--mark);
  color: inherit;
  padding: 0 4px;
  border-radius: 4px;
}

/* ── 사이트 헤더 ───────────────────────────────────── */
.site-head {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.site-head__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding-top: calc(32px + env(safe-area-inset-top, 0px));
  padding-bottom: 28px;
}

.site-head__title {
  font-size: clamp(28px, 8vw, 40px);
  font-weight: 900;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.site-head__sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.site-head__count {
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

/* ── 목차 화면 ─────────────────────────────────────── */
.index-main {
  padding-top: 24px;
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  line-height: 1.6;
}

.search { margin-bottom: 20px; }

.search__label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
}

.search__input {
  width: 100%;
  min-height: 48px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
}
.search__input::placeholder { color: #8894A3; }

.group-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

/* 칩·탭 공통 버튼 */
.pill {
  min-height: 44px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  cursor: pointer;
}
.pill:hover { border-color: var(--accent); color: var(--accent-dark); }

.pill--tab { min-width: 52px; padding: 8px 12px; text-align: center; }

/* 개념이 없는 탭 — 클릭은 가능 */
.pill--empty {
  background: var(--tab-off-bg);
  color: var(--tab-off-ink);
  border-color: var(--tab-off-line);
  font-weight: 400;
}

.pill[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
  font-weight: 700;
}

.result {
  margin: 4px 0 20px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
}

.section-head {
  margin: 28px 0 14px;
  padding-bottom: 8px;
  font-size: 28px;
  font-weight: 900;
  color: var(--accent);
  border-bottom: 2px solid var(--line-strong);
}
.section-head:first-child { margin-top: 0; }

/* 카드 (전체가 하나의 링크) */
.card {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 20px;
  margin-bottom: 12px;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  color: inherit;
  text-decoration: none;
}
.card:hover {
  border-color: var(--accent);
  color: inherit;
}

.card__main { flex: 1 1 220px; display: block; }

.card__title {
  display: block;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.4;
}

.card__sub {
  margin-left: 8px;
  font-size: 14px;
  font-weight: 400;
  color: var(--muted);
}

.card__summary {
  display: block;
  margin-top: 4px;
  font-size: 15px;
  color: var(--muted);
}

.card__meta {
  flex: 0 1 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
}

.card__go { font-weight: 700; color: var(--accent); white-space: nowrap; }

.chip {
  display: inline-block;
  padding: 3px 12px;
  background: var(--chip-bg);
  color: var(--chip-ink);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.empty {
  padding: 40px 24px;
  border: 2px dashed var(--line-strong);
  border-radius: 16px;
  text-align: center;
  color: var(--muted);
}

/* ── 상세 페이지 헤더 ──────────────────────────────── */
.page-head {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.page-head__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: 16px;
}

.crumbs {
  flex: 1 1 200px;
  font-size: 14px;
  color: var(--muted);
}
.crumbs a { font-weight: 700; text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs__sep { margin: 0 6px; color: var(--line-strong); }

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 18px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--accent);
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.back-link:hover { border-color: var(--accent); background: var(--chip-bg); }

/* ── 상세 본문 ─────────────────────────────────────── */
.detail-main {
  padding-top: 28px;
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}

.sect {
  margin-bottom: 20px;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
}

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

.title {
  margin-top: 16px;
  font-size: clamp(40px, 13vw, 64px);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.reading {
  margin-top: 10px;
  font-size: 20px;
  color: var(--muted);
}

.define {
  margin-top: 24px;
  padding: 24px;
  background: var(--surface);
  border: 2px solid var(--line-strong);
  border-radius: 14px;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.6;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 20px;
  font-size: 14px;
  color: var(--muted);
}

.sect__head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  background: var(--accent);
  color: #FFFFFF;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 900;
}

.sect__title { font-size: 26px; font-weight: 700; line-height: 1.35; }

.sect p + p { margin-top: 14px; }

/* 핵심 3가지 카드 */
.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.fact {
  flex: 1 1 180px;
  padding: 16px 18px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.fact__label {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}

.fact__value {
  margin-top: 4px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.5;
}
.fact__value--mono { font-family: var(--mono); font-size: 16px; }

/* ── 다이어그램 (모바일 우선: 세로 흐름) ───────────── */
.flow {
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
}

.node {
  flex: 0 0 auto;
  padding: 18px;
  background: var(--surface);
  border: 2px solid var(--line-strong);
  border-radius: 14px;
  text-align: center;
}

.node--accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}

.node__title { font-size: 18px; font-weight: 700; line-height: 1.4; }

.node__note {
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}
.node--accent .node__note { color: #D8E4F8; }

.chip-mono {
  display: inline-block;
  padding: 2px 10px;
  margin: 4px 3px 0;
  background: var(--chip-bg);
  color: var(--chip-ink);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 13px;
}
.node--accent .chip-mono { background: #FFFFFF; color: var(--accent-dark); }

.arrow {
  flex: 0 0 auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 0;
}

.arrow__line {
  position: relative;
  flex: 0 0 auto;
  width: 2px;
  height: 34px;
  background: var(--line-strong);
}
/* 세로 화살표 머리 (아래 방향) */
.arrow__line::after {
  content: '';
  position: absolute;
  left: -5px;
  bottom: -9px;
  width: 0; height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 10px solid var(--line-strong);
}

.arrow__label {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  line-height: 1.4;
}

.arrow__note {
  display: block;
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
}

@media (min-width: 720px) {
  .flow { flex-direction: row; align-items: stretch; gap: 0; }
  .node { flex: 1 1 200px; }
  .arrow { flex: 0 0 104px; flex-direction: column; gap: 6px; align-self: center; padding: 0 4px; }
  .arrow__line { width: 100%; height: 2px; }
  .arrow__line::after {
    left: auto; bottom: auto;
    right: -9px; top: -5px;
    border-left: 10px solid var(--line-strong);
    border-right: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
  }
}

/* 단계 설명 */
.steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 26px;
}

.step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 16px;
  line-height: 1.6;
}

.step__no {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  margin-top: 2px;
  background: var(--mark);
  color: var(--ink);
  border-radius: 999px;
  font-size: 15px;
  font-weight: 900;
}

/* ── 코드 패널 ─────────────────────────────────────── */
.code {
  margin-top: 16px;
  background: var(--panel);
  border-radius: 14px;
  overflow: hidden;
}

.code__head {
  padding: 10px 18px;
  background: var(--panel-head);
  color: var(--code-comment);
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
}

.code pre {
  margin: 0;
  padding: 18px;
  overflow-x: auto;
  color: var(--code-ink);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.7;
  white-space: pre;
}

.c-comment { color: var(--code-comment); }
.c-string { color: var(--code-string); }
.c-keyword { color: var(--code-keyword); }
.c-prompt { color: var(--code-prompt); }

.callout {
  margin-top: 16px;
  padding: 14px 18px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 15px;
  color: var(--muted);
}

.case {
  margin-top: 16px;
  padding: 20px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.case__title { font-size: 18px; font-weight: 700; }
.case p { margin-top: 6px; font-size: 16px; line-height: 1.7; }

/* ── 한 줄 정리 ────────────────────────────────────── */
.wrapup {
  margin-bottom: 20px;
  padding: 32px;
  background: var(--panel);
  border-radius: 20px;
}

.wrapup__label {
  font-size: 14px;
  font-weight: 700;
  color: var(--mark);
  letter-spacing: 0.04em;
}

.wrapup__text {
  margin-top: 10px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.5;
  color: #FFFFFF;
}

/* ── 이전/다음 ─────────────────────────────────────── */
.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.pager__link {
  flex: 1 1 220px;
  min-height: 44px;
  padding: 18px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  color: inherit;
  text-decoration: none;
}
.pager__link:hover { border-color: var(--accent); color: inherit; }
.pager__link[hidden] { display: none; }
.pager__link--next { text-align: right; }

.pager__label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
}

.pager__title {
  display: block;
  margin-top: 4px;
  font-size: 18px;
  font-weight: 700;
}

/* ── 상세 푸터 ─────────────────────────────────────── */
.page-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
}
.page-foot a { font-weight: 700; text-decoration: none; }
.page-foot a:hover { text-decoration: underline; }

/* ── 좁은 화면 ─────────────────────────────────────── */
@media (max-width: 479px) {
  .wrap {
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
  }
  .sect, .wrapup { padding: 22px 18px; }
  .define { padding: 18px; font-size: 20px; }
  .card { padding: 16px 18px; }
  .wrapup__text { font-size: 22px; }
  .section-head { font-size: 24px; }
  .sect__title { font-size: 22px; }
}
