/* Layout: sticky command bar on top; on wide screens a sticky section index on the left and the rulebook column on the right. */
:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --fg: #1a2130;
  --muted: #5c6577;
  --line: #d9dde6;
  --accent: #a3620c;
  --accent-soft: #f6e8d2;
  --warn-bg: #fff4e0;
  --bar: #1c2433;
  --bar-fg: #eef1f6;
  --bar-muted: #9aa5b8;
  --font-display: "Chakra Petch", "Noto Sans TC", system-ui, sans-serif;
  --font-body: "Noto Sans TC", "Noto Sans KR", "Noto Sans JP", system-ui, -apple-system, "Microsoft JhengHei", sans-serif;
  --font-num: "Chakra Petch", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11161f; --surface: #182030; --fg: #e4e8ef; --muted: #9aa4b6; --line: #2a3446;
    --accent: #f0b04a; --accent-soft: #33291a; --warn-bg: #2a2416;
    --bar: #0b0f16; --bar-fg: #eef1f6; --bar-muted: #8994a8; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11161f; --surface: #182030; --fg: #e4e8ef; --muted: #9aa4b6; --line: #2a3446;
  --accent: #f0b04a; --accent-soft: #33291a; --warn-bg: #2a2416;
  --bar: #0b0f16; --bar-fg: #eef1f6; --bar-muted: #8994a8; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--font-body); font-size: 15px; line-height: 1.75;
}
:lang(ko) body, body:lang(ko) { --font-body: "Noto Sans KR", system-ui, "Malgun Gothic", sans-serif; }
:lang(ja) body, body:lang(ja) { --font-body: "Noto Sans JP", system-ui, "Hiragino Sans", "Yu Gothic", sans-serif; }
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  z-index: 10; background: var(--bar);
}

/* Top bar */
.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: var(--bar); color: var(--bar-fg);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.bar-inner {
  max-width: 1120px; margin: 0 auto; min-height: 56px;
  display: flex; align-items: center; gap: 12px 20px; flex-wrap: wrap; padding-block: 8px;
}
.brand { display: flex; align-items: baseline; gap: 10px; color: inherit; text-decoration: none; margin-right: auto; }
.brand b { font-family: var(--font-display); font-weight: 700; font-size: 20px; letter-spacing: .04em; }
.brand span { color: var(--bar-muted); font-size: 13px; }
.nav { display: flex; gap: 4px; }
.nav a, .langs button {
  font: inherit; font-size: 13px; color: var(--bar-muted); background: none; border: 1px solid transparent;
  padding: 4px 10px; border-radius: 6px; text-decoration: none; cursor: pointer;
}
.nav a:hover, .langs button:hover { color: var(--bar-fg); }
.nav a[aria-current="page"] { color: var(--bar-fg); border-color: #3a4560; }
.langs { display: flex; border: 1px solid #3a4560; border-radius: 8px; padding: 2px; }
.langs button[aria-pressed="true"] { background: var(--accent); color: #1a1205; font-weight: 700; }
a:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Page */
.wrap {
  max-width: 1120px; margin: 0 auto; padding-block: 28px 64px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 40px; align-items: start;
}
.wrap.single { grid-template-columns: minmax(0, 1fr); max-width: 780px; }
@media (max-width: 860px) { .wrap { grid-template-columns: minmax(0, 1fr); gap: 20px; } }

.toc { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 76px); font-size: 13.5px; }
.toc summary { font-weight: 700; color: var(--muted); cursor: pointer; list-style: none; letter-spacing: .06em; font-size: 12px; text-transform: uppercase; }
.toc summary::-webkit-details-marker { display: none; }
.toc ol { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 2px; border-left: 2px solid var(--line); }
.toc a { display: block; padding: 3px 0 3px 12px; margin-left: -2px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; line-height: 1.45; }
.toc a:hover, .toc a.on { color: var(--fg); border-left-color: var(--accent); }
@media (max-width: 860px) {
  .toc { position: static; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
}

/* Version header */
.vhead { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 8px; }
.vhead h1 { font-family: var(--font-display); font-size: 30px; line-height: 1.2; margin: 0; letter-spacing: .02em; text-wrap: balance; }
.chip { font-family: var(--font-num); font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.chip.old { background: var(--warn-bg); color: var(--muted); }
.meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 20px; }
.meta a { color: var(--accent); }
.notice { background: var(--warn-bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 20px; font-size: 14px; }
.notice a { color: var(--accent); font-weight: 700; }

/* Rule content */
.doc { max-width: 72ch; min-width: 0; }
.doc h2 {
  font-size: 21px; line-height: 1.35; margin: 44px 0 12px; padding-top: 14px; border-top: 1px solid var(--line);
  scroll-margin-top: 80px; text-wrap: balance;
}
.doc h2:first-child { margin-top: 0; border-top: 0; padding-top: 0; }
.doc h3 { font-size: 17px; margin: 28px 0 8px; scroll-margin-top: 80px; }
.doc h4 { font-size: 15px; margin: 20px 0 6px; color: var(--muted); }
.doc p, .doc ul, .doc ol { margin: 0 0 12px; }
.doc ul, .doc ol { padding-left: 1.4em; }
.doc li + li { margin-top: 4px; }
.doc strong { color: var(--fg); }
.doc blockquote {
  margin: 12px 0; padding: 8px 14px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; color: var(--muted); font-size: 14px;
}
.doc blockquote p { margin: 0; }
.doc blockquote p + p { margin-top: 6px; }
.tbl { overflow-x: auto; margin: 12px 0 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.tbl table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 7px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th { font-size: 12.5px; color: var(--muted); font-weight: 700; background: var(--bg); white-space: nowrap; }
.tbl td:last-child { font-family: var(--font-num); font-weight: 600; white-space: nowrap; }
.tbl tbody tr:hover td { background: var(--accent-soft); }

/* History */
.hist { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 0; }
.hist > li { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 16px; padding: 16px 0; border-top: 1px solid var(--line); }
.hist > li:first-child { border-top: 0; }
.hist .d { font-family: var(--font-num); font-weight: 600; font-size: 15px; }
.hist .tag { display: inline-block; margin-top: 4px; font-size: 12px; }
.hist ul { margin: 0 0 8px; padding-left: 1.2em; }
.hist .links { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 13.5px; }
.hist .links a { color: var(--accent); font-weight: 600; }
.hist .na { color: var(--muted); font-size: 13px; }
@media (max-width: 520px) { .hist > li { grid-template-columns: minmax(0, 1fr); gap: 4px; } }

.foot { color: var(--muted); font-size: 12.5px; margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--line); }
.err { color: var(--muted); padding: 40px 0; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
:lang(ko) .doc, :lang(ko) .hist, :lang(ko) .meta, :lang(ko) h1 { word-break: keep-all; overflow-wrap: anywhere; }
.toc summary::after { content: " ▾"; }
.toc[open] summary::after { content: " ▴"; }
@media (min-width: 861px) { .toc summary { pointer-events: none; } .toc summary::after { content: none; } }
