/* =========================================================
   처음 만나는 초보자의 경제 공부 - 스타일
   - 라이트/다크 테마
   - 위키처럼: 목차, 분류, 같이 보기, 빨간 링크(아직 없는 단어)
   - 휴대폰 우선, PC에서는 오른쪽에 메뉴
   ========================================================= */

/* ---------- 색상(라이트) ---------- */
:root {
  --bg: #faf8f4;
  --bg-elev: #ffffff;
  --bg-sunk: #f3efe8;
  --text: #2e2a26;
  --text-soft: #6b635b;
  --border: #e7e1d8;
  --accent: #3f7d5e;
  --accent-soft: #e8f0ea;
  --accent-text: #ffffff;
  --missing: #b9442f;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.06);
  --serif: "Gowun Batang", "Nanum Myeongjo", serif;
  --sans: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

/* ---------- 색상(다크) ---------- */
[data-theme="dark"] {
  --bg: #15130f;
  --bg-elev: #1f1c17;
  --bg-sunk: #1a1814;
  --text: #ece7df;
  --text-soft: #a9a29a;
  --border: #35302a;
  --accent: #7fc59e;
  --accent-soft: #24322a;
  --accent-text: #10201a;
  --missing: #f08a74;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

/* ---------- 기본 ---------- */
* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 90px; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  font-size: 16px;
  word-break: keep-all;
  overflow-wrap: break-word;
  transition: background 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
}

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

button { font-family: inherit; }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- 머리글 ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-top: 12px;
  padding-bottom: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
}

.brand-icon { font-size: 1.25rem; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- 검색 ---------- */
.search-wrap {
  position: relative;
  flex: 1;
  max-width: 420px;
  margin-left: auto;
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: border-color 0.2s ease;
}

.search-box:focus-within { border-color: var(--accent); }

.search-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 10px 4px 10px 14px;
  font-size: 0.95rem;
  font-family: var(--sans);
  color: var(--text);
  outline: none;
}

.search-input::placeholder { color: var(--text-soft); opacity: 0.8; }

.search-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-soft);
  padding: 8px 12px;
  cursor: pointer;
}

.search-btn:hover { color: var(--accent); }

.suggest {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 60vh;
  overflow-y: auto;
}

.suggest[hidden] { display: none; }

.suggest a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
}

.suggest a:hover,
.suggest a:focus { background: var(--accent-soft); outline: none; }

.suggest a strong { display: block; font-size: 0.95rem; }

.suggest a span { display: block; font-size: 0.82rem; color: var(--text-soft); line-height: 1.5; }

.suggest-empty { padding: 10px; font-size: 0.88rem; color: var(--text-soft); }

/* ---------- 본문 + 옆 메뉴 배치 ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 40px;
  padding-top: 28px;
  align-items: start;
}

.content { min-width: 0; outline: none; }

.sidebar { position: sticky; top: 84px; }

.side-box {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
  padding: 14px 16px;
  margin-bottom: 16px;
}

.side-title {
  margin: 0 0 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-soft);
  letter-spacing: 0.04em;
}

.side-list { list-style: none; margin: 0; padding: 0; }

.side-list li { margin: 2px 0; }

.side-list a,
.side-link-btn {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 4px 0;
  border: none;
  background: none;
  font-size: 0.95rem;
  color: var(--text);
  text-decoration: none;
  text-align: left;
  cursor: pointer;
}

.side-list a:hover,
.side-link-btn:hover { color: var(--accent); }

.side-list .count { color: var(--text-soft); font-size: 0.85rem; }

/* ---------- 대문 ---------- */
.hero { padding: 16px 0 8px; }

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.85rem;
}

.hero-title {
  font-family: var(--serif);
  font-size: 2rem;
  line-height: 1.4;
  margin: 0 0 14px;
  letter-spacing: -0.02em;
}

.hero-desc { margin: 0 0 6px; color: var(--text); max-width: 560px; }

.hero-hint { margin: 0; color: var(--text-soft); font-size: 0.9rem; }

.block { margin-top: 36px; }

.block-title {
  font-family: var(--serif);
  font-size: 1.3rem;
  margin: 0 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

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

.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--text);
  text-decoration: none;
  font-size: 0.92rem;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.cat-chip span { color: var(--text-soft); font-size: 0.82rem; }

.cat-chip:hover { border-color: var(--accent); color: var(--accent); }

.cat-chip.small { padding: 2px 10px; font-size: 0.82rem; margin-left: 6px; }

/* 가나다 바로가기 */
.jump-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 20px;
}

.jump-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.jump-btn:hover { border-color: var(--accent); color: var(--accent); }

.jump-btn.is-empty { opacity: 0.35; cursor: default; background: transparent; }

.idx-group { margin-bottom: 18px; }

.idx-head {
  margin: 0 0 4px;
  font-size: 1rem;
  color: var(--accent);
}

/* 단어 목록 (대문/분류/검색/같이 보기 공통) */
.row-list { list-style: none; margin: 0; padding: 0; }

.row-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
}

.row-list li:last-child { border-bottom: none; }

.row-list .row-name,
.row-list .wlink { font-weight: 700; text-decoration: none; min-width: 80px; }

.row-list .row-name:hover,
.row-list .wlink:hover { text-decoration: underline; }

.row-sum { color: var(--text-soft); font-size: 0.92rem; flex: 1; min-width: 200px; }

/* ---------- 단어 문서 ---------- */
.crumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-soft);
  margin-bottom: 12px;
}

.crumb a { color: var(--text-soft); text-decoration: none; }

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

.crumb strong { color: var(--text); font-weight: 600; }

.doc-head {
  border-bottom: 2px solid var(--text);
  padding-bottom: 10px;
  margin-bottom: 18px;
}

.doc-title {
  font-family: var(--serif);
  font-size: 2.1rem;
  line-height: 1.3;
  margin: 0;
  letter-spacing: -0.02em;
}

.doc-aka { margin: 6px 0 0; color: var(--text-soft); font-size: 0.9rem; }

.doc-summary {
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 20px;
}

.doc-summary-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}

.doc-summary p { margin: 0; font-size: 1.05rem; font-weight: 500; }

/* 목차 */
.toc {
  display: inline-block;
  min-width: 220px;
  border: 1px solid var(--border);
  background: var(--bg-sunk);
  border-radius: 10px;
  padding: 12px 18px;
  margin-bottom: 8px;
}

.toc-title { margin: 0 0 4px; font-weight: 700; font-size: 0.9rem; }

.toc ol { margin: 0; padding-left: 20px; }

.toc button {
  border: none;
  background: none;
  padding: 2px 0;
  color: var(--accent);
  font-size: 0.92rem;
  cursor: pointer;
  text-align: left;
}

.toc button:hover { text-decoration: underline; }

.doc-sec { margin-top: 28px; }

.doc-sec h2 {
  font-family: var(--serif);
  font-size: 1.3rem;
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.doc-sec p { margin: 0 0 12px; }

.doc-sec ul:not(.row-list) { margin: 0; padding-left: 20px; }

.doc-sec li { margin-bottom: 6px; }

.doc-example {
  background: var(--bg-sunk);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

/* 단어 링크 */
.wlink {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.wlink.is-missing {
  color: var(--missing);
  text-decoration-style: dashed;
}

.doc-foot {
  margin-top: 36px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.doc-cats { font-size: 0.85rem; color: var(--text-soft); }

.pager {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 20px 0;
}

.pager a {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elev);
  text-decoration: none;
  color: var(--text);
  font-size: 0.92rem;
}

.pager a:hover { border-color: var(--accent); color: var(--accent); }

.doc-note { font-size: 0.82rem; color: var(--text-soft); margin: 0; }

.notice {
  background: var(--bg-sunk);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 20px;
}

.back-link { margin-top: 20px; }

/* ---------- 하단 ---------- */
.site-footer {
  margin-top: 60px;
  border-top: 1px solid var(--border);
  padding: 24px 0 40px;
  text-align: center;
  color: var(--text-soft);
  font-size: 0.85rem;
}

.site-footer p { margin: 0; }

.footer-small { font-size: 0.78rem; opacity: 0.8; margin-top: 4px !important; }

/* ---------- 태블릿 이하: 옆 메뉴를 아래로 ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .sidebar { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .side-box { margin-bottom: 0; }
}

/* ---------- 휴대폰 ---------- */
@media (max-width: 600px) {
  body { font-size: 15px; }

  .container { padding: 0 16px; }

  .header-inner { flex-wrap: wrap; gap: 10px; }

  .brand { font-size: 0.95rem; flex: 1; min-width: 0; }

  .brand-text { overflow: hidden; text-overflow: ellipsis; }

  .theme-label { display: none; }

  .theme-toggle { padding: 7px 10px; }

  .search-wrap { order: 3; flex-basis: 100%; max-width: none; }

  html { scroll-padding-top: 130px; }

  .hero-title { font-size: 1.6rem; }

  .doc-title { font-size: 1.75rem; }

  .toc { display: block; }

  .row-sum { min-width: 0; flex-basis: 100%; }

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