  :root {
    --bg: #f6f1e7;
    --surface: #fffdf8;
    --surface-2: #efe8da;
    --text: #27241f;
    --muted: #6d665b;
    --line: #e2d9c8;
    --accent: #2f5bd3;
    --accent-soft: #e4ebfb;
    --callout: #fbf6ea;
    --callout-line: #d9b45a;
    --shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 4px 16px rgba(60, 45, 20, .05);
    --radius: 12px;
    --radius-sm: 10px;
    --serif: "Noto Serif KR", "Nanum Myeongjo", Georgia, serif;
    --sans: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color-scheme: light;
  }
  @media (prefers-color-scheme: dark) {
    :root[data-theme="auto"] {
      --bg: #16161a; --surface: #1f1f24; --surface-2: #26262c; --text: #e8e4dc; --muted: #a39c90;
      --line: #34343b; --accent: #7c9cf5; --accent-soft: #232b45; --callout: #232019; --callout-line: #b8954a;
      --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); color-scheme: dark;
    }
  }
  :root[data-theme="white"] { --bg: #ffffff; --surface: #ffffff; --surface-2: #f2f3f5; --text: #1f2328; --muted: #5f6670; --line: #e3e5e8; --callout: #f7f7f8; }
  :root[data-theme="sepia"] { --bg: #f1e7d0; --surface: #f8f1e1; --surface-2: #e8dcc0; --text: #3b2f20; --muted: #6e5d45; --line: #dccca8; --callout: #f4ead2; }
  :root[data-theme="gray"]  { --bg: #eceef1; --surface: #f8f9fa; --surface-2: #e2e5ea; --text: #23262b; --muted: #5d636c; --line: #d5d9df; --callout: #f3f4f6; }
  :root[data-theme="mint"]  { --bg: #e8f1ea; --surface: #f6fbf7; --surface-2: #dbe8de; --text: #1f2b23; --muted: #55665a; --line: #cddfd2; --callout: #eff6f0; }
  :root[data-theme="black"] {
    --bg: #000000; --surface: #111114; --surface-2: #1a1a1f; --text: #e8e4dc; --muted: #a39c90;
    --line: #2a2a30; --accent: #7c9cf5; --accent-soft: #1b2238; --callout: #15130f; --callout-line: #b8954a;
    --shadow: none; color-scheme: dark;
  }
  :root[data-theme="dark"] {
    --bg: #16161a; --surface: #1f1f24; --surface-2: #26262c; --text: #e8e4dc; --muted: #a39c90;
    --line: #34343b; --accent: #7c9cf5; --accent-soft: #232b45; --callout: #232019; --callout-line: #b8954a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); color-scheme: dark;
  }

  * { box-sizing: border-box; }
  html { scroll-behavior: smooth; scroll-padding-top: 72px; }
  @media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
  body {
    margin: 0; background: var(--bg); color: var(--text);
    font-family: var(--sans); font-size: 16.5px; line-height: 1.75; letter-spacing: -0.005em;
    -webkit-font-smoothing: antialiased; word-break: keep-all; overflow-wrap: anywhere;
  }
  a { color: var(--accent); text-decoration: none; text-underline-offset: 3px; }
  a:hover { text-decoration: underline; }

  #progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--accent); z-index: 50; transition: width .1s linear; }

  .topbar {
    position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 8px;
    padding: 10px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(140%) blur(10px); -webkit-backdrop-filter: saturate(140%) blur(10px);
    border-bottom: 1px solid var(--line);
  }
  .brand { font-family: var(--serif); font-weight: 700; font-size: 15px; color: var(--text); margin-right: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand span { color: var(--accent); }
  .btn {
    font: inherit; font-size: 13.5px; line-height: 1; padding: 8px 12px; border-radius: var(--radius-sm);
    border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap;
  }
  .btn:hover { border-color: var(--accent); color: var(--accent); }
  .btn:focus-visible, summary:focus-visible, .zoom:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

  .layout { display: grid; grid-template-columns: 1fr minmax(0, 780px) 1fr; gap: 0 40px; padding: 0 20px; }
  .toc { grid-column: 1; justify-self: end; width: 250px; position: sticky; top: 72px; align-self: start; max-height: calc(100vh - 92px); overflow: auto; padding: 28px 0 40px; font-size: 13.5px; }
  .toc h2 { font-family: var(--sans); font-size: 12px; font-weight: 600; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; text-transform: uppercase; }
  .toc ol { list-style: none; margin: 0; padding: 0; counter-reset: none; }
  .toc li a { display: block; padding: 5px 10px; border-left: 2px solid transparent; color: var(--muted); line-height: 1.45; }
  .toc li a:hover { color: var(--text); text-decoration: none; }
  .toc li a.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; }
  main { grid-column: 2; min-width: 0; padding: 36px 0 80px; }
  .mobile-toc { display: none; }

  @media (max-width: 1180px) {
    .layout { grid-template-columns: minmax(0, 780px); justify-content: center; }
    .toc { display: none; }
    main { grid-column: 1; }
    .mobile-toc { display: block; margin: 0 0 28px; }
    .mobile-toc ol { margin: 8px 0 4px; padding-left: 22px; font-size: 15px; }
    .mobile-toc li { margin: 4px 0; }
  }

  h1, h2, h3 { font-family: var(--serif); line-height: 1.35; letter-spacing: -0.015em; }
  h1 { font-size: clamp(28px, 4.4vw, 40px); margin: 8px 0 12px; }
  h2 { font-size: clamp(22px, 3vw, 28px); margin: 64px 0 14px; padding-top: 8px; }
  h3 { font-size: 20px; margin: 36px 0 10px; }
  h1 + p { font-size: 18px; color: var(--muted); }
  p, ul, ol { margin: 0 0 14px; }
  ul, ol { padding-left: 22px; }
  li { margin: 4px 0; }
  li > ul, li > ol { margin: 4px 0; }
  hr { border: 0; border-top: 1px solid var(--line); margin: 56px 0 0; }
  code { font-family: var(--mono); font-size: .86em; background: var(--surface-2); padding: .12em .4em; border-radius: 6px; }
  strong { font-weight: 650; }
  .meta { font-size: 13.5px; color: var(--muted); margin-bottom: 20px; }

  blockquote { margin: 18px 0; padding: 14px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
  blockquote p:last-child, blockquote ul:last-child { margin-bottom: 0; }
  .callout.meaning { background: var(--callout); border-color: color-mix(in srgb, var(--callout-line) 45%, var(--line)); border-left: 4px solid var(--callout-line); }
  .callout.meaning strong:first-child { display: inline-block; font-size: 12px; letter-spacing: .06em; color: var(--callout-line); margin-right: 6px; }
  .callout.guide { border-left: 4px solid var(--accent); }
  .callout.note { margin: -12px 0 26px; padding: 12px 16px; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line)); border-left: 4px solid var(--accent); box-shadow: none; font-size: 15px; }
  details .callout.note { margin-left: 18px; margin-right: 18px; }
  .callout.note > p:first-child strong, .callout.summary > p:first-child strong { font-size: 12px; letter-spacing: .06em; color: var(--accent); }
  .callout.note > p:first-child, .callout.summary > p:first-child { margin: 0 0 4px; }
  .callout.summary { border-left: 4px solid var(--callout-line); background: var(--callout); }
  .callout.summary > p:first-child strong { color: var(--callout-line); }
  .callout.summary ol { margin: 0; padding-left: 20px; }

  details { margin: 14px 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
  details > summary {
    list-style: none; cursor: pointer; padding: 13px 44px 13px 18px; position: relative; font-weight: 600; font-size: 15.5px; border-radius: var(--radius);
  }
  details > summary::-webkit-details-marker { display: none; }
  details > summary::after {
    content: ""; position: absolute; right: 18px; top: 50%; width: 8px; height: 8px; margin-top: -6px;
    border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .2s;
  }
  details[open] > summary::after { transform: rotate(-135deg); margin-top: -2px; }
  details > summary:hover { background: var(--surface-2); }
  details[open] > summary { border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
  details > :not(summary) { margin-left: 18px; margin-right: 18px; }
  details > :nth-child(2) { margin-top: 14px; }
  details > :last-child { margin-bottom: 16px; }
  details details { box-shadow: none; }

  .table-wrap { overflow-x: auto; margin: 12px 0 18px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
  details .table-wrap { margin-left: 18px; margin-right: 18px; }
  table { border-collapse: collapse; width: 100%; font-size: 14px; line-height: 1.55; }
  th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
  th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
  tr:last-child td { border-bottom: 0; }
  td { min-width: 72px; overflow-wrap: normal; word-break: keep-all; }

  .fig { margin: 22px 0 26px; }
  .zoom { display: block; width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; cursor: zoom-in; box-shadow: var(--shadow); }
  .zoom img { display: block; width: 100%; height: auto; border-radius: 6px; }
  .fig figcaption { font-size: 13.5px; color: var(--muted); margin-top: 8px; line-height: 1.55; }
  details .fig { margin-left: 18px; margin-right: 18px; }

  #lightbox { position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center; padding: 3vh 3vw; background: rgba(10, 10, 12, .88); cursor: zoom-out; }
  #lightbox.open { display: flex; }
  #lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; background: #fff; border-radius: 8px; padding: 8px; }
  #lightbox .cap { position: fixed; left: 0; right: 0; bottom: 10px; text-align: center; color: #ddd; font-size: 13px; padding: 0 16px; }

  /* 배경색 메뉴 */
  .menu-wrap { position: relative; }
  .bg-menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 60; width: 236px; padding: 12px; display: none;
    background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(0,0,0,.18); }
  .bg-menu.open { display: block; }
  .bg-menu .label { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
  .swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .swatch { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 0; border: 0; background: none; color: var(--text); font: inherit; font-size: 11.5px; cursor: pointer; }
  .swatch i { display: block; width: 34px; height: 34px; border-radius: 50%; border: 1px solid rgba(127,127,127,.45); }
  .swatch[aria-pressed="true"] i { outline: 2px solid var(--accent); outline-offset: 2px; }
  .swatch:focus-visible i { outline: 2px solid var(--accent); outline-offset: 2px; }
  .custom-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; }
  .custom-row input[type=color] { width: 40px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }

  /* 용어 사전 */
  #glossary { width: min(860px, 94vw); max-height: 86vh; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); color: var(--text); box-shadow: 0 12px 48px rgba(0,0,0,.3); }
  #glossary::backdrop { background: rgba(10,10,12,.55); }
  #glossary .g-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
  #glossary .g-head h2 { margin: 0; font-family: var(--serif); font-size: 18px; }
  #glossary .g-body { padding: 6px 18px 18px; overflow: auto; }

  /* 비교표 추이 그래프 */
  .trend-trigger { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; text-align: left; border-bottom: 1px dashed var(--accent); }
  .trend-trigger svg { flex: none; color: var(--accent); }
  .trend-trigger:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  #trendPop { position: absolute; z-index: 70; width: 340px; max-width: calc(100vw - 24px); padding: 12px 14px 10px; display: none;
    background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(0,0,0,.18); }
  #trendPop.open { display: block; }
  #trendPop .t-title { font-weight: 600; font-size: 14px; margin: 0 0 2px; }
  #trendPop .t-note { font-size: 12px; color: var(--muted); margin: 6px 0 0; line-height: 1.5; }
  #trendPop svg { display: block; width: 100%; height: auto; overflow: visible; }
  #trendPop .t-tip { font-size: 12.5px; min-height: 18px; color: var(--muted); }
  #trendPop .t-tip b { color: var(--text); }
  .trend-hint { font-size: 13px; color: var(--muted); margin: -6px 0 10px; }

  #totop { position: fixed; right: 18px; bottom: 18px; z-index: 30; opacity: 0; pointer-events: none; transition: opacity .2s; }
  #totop.show { opacity: 1; pointer-events: auto; }

  footer { grid-column: 1 / -1; text-align: center; font-size: 13px; color: var(--muted); padding: 24px 0 40px; border-top: 1px solid var(--line); }

  @media (max-width: 640px) {
    body { font-size: 16px; }
    .topbar { padding: 8px 12px; }
    .btn { padding: 7px 9px; font-size: 12.5px; }
    .btn .long { display: none; }
    .layout { padding: 0 14px; }
    details > :not(summary), details .table-wrap, details .fig { margin-left: 12px; margin-right: 12px; }
    details > summary { padding-left: 14px; }
    th, td { padding: 8px 9px; }
    .table-wrap table { min-width: 620px; }
  }
  @media print {
    .topbar, .toc, #totop, #progress, .mobile-toc { display: none !important; }
    details > summary::after { display: none; }
    .layout { display: block; }
  }
