:root {
  --paper: #f5f0e5;
  --paper-soft: #fbf8ef;
  --ink: #1d1a16;
  --ink-soft: #5d554b;
  --line: #d7cbb8;
  --line-strong: #a58e72;
  --vermilion: #a43d2f;
  --vermilion-dark: #762a21;
  --indigo: #1c3147;
  --moss: #4d6543;
  --gold: #b48945;
  --shadow: 0 20px 45px rgba(33, 25, 16, 0.16);
  --font: "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --serif: "Noto Serif KR", "Nanum Myeongjo", "Batang", serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(164, 61, 47, 0.14), transparent 34rem),
    linear-gradient(90deg, rgba(28, 49, 71, 0.08) 0 1px, transparent 1px 100%),
    linear-gradient(var(--paper), #ede3d2);
  background-size: auto, 34px 34px, auto;
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.75;
}

a { color: var(--vermilion-dark); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--vermilion); }

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  border-bottom: 1px solid rgba(111, 91, 66, 0.32);
  background: rgba(251, 248, 239, 0.92);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fffaf0;
  background: var(--indigo);
  font-family: var(--serif);
  font-weight: 700;
}
.brand strong { display: block; line-height: 1.1; }
.brand small { display: block; color: var(--ink-soft); font-size: 12px; line-height: 1.2; }

.icon-button {
  display: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper-soft);
  color: var(--ink);
  font-size: 20px;
}

.header-actions {
  margin-left: auto;
  display: flex;
  gap: 10px;
  font-size: 14px;
}
.header-actions a {
  padding: 8px 10px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--ink);
}
.header-actions a:hover { background: rgba(164, 61, 47, 0.08); }

.site-shell {
  display: grid;
  grid-template-columns: minmax(250px, 310px) minmax(0, 1fr) minmax(190px, 250px);
  gap: 22px;
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.sidebar,
.toc {
  position: sticky;
  top: 86px;
  align-self: start;
  max-height: calc(100vh - 108px);
}
.sidebar { overflow: hidden; }
.sidebar-inner,
.toc-inner {
  border: 1px solid rgba(111, 91, 66, 0.3);
  border-radius: 8px;
  background: rgba(251, 248, 239, 0.82);
  box-shadow: 0 10px 30px rgba(33, 25, 16, 0.08);
}
.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 108px);
  min-height: 0;
  overflow: hidden;
  padding: 14px;
}
.toc-inner {
  max-height: calc(100vh - 108px);
  overflow: auto;
  padding: 16px;
}

.search-label,
.toc-title {
  display: block;
  flex: 0 0 auto;
  color: var(--moss);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.nav-search {
  flex: 0 0 auto;
  width: 100%;
  margin: 8px 0 14px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdf7;
  color: var(--ink);
  font: inherit;
}
.nav-tree {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.nav-group { border-top: 1px solid rgba(111, 91, 66, 0.18); }
.nav-group:first-child { border-top: 0; }
.nav-group-title,
.nav-folder-title {
  width: 100%;
  border: 0;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.nav-group-title {
  padding: 10px 4px;
  color: var(--indigo);
  font-weight: 800;
}
.nav-group-title::before {
  content: "▾";
  display: inline-block;
  width: 18px;
  color: var(--gold);
}
.nav-group-title[aria-expanded="false"]::before { content: "▸"; }
.nav-group-title[aria-expanded="false"] + .nav-group-items { display: none; }
.nav-folder {
  margin: 2px 0;
}
.nav-folder-title {
  padding: 7px 8px 7px 22px;
  border-radius: 5px;
  color: #3b4b46;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.4;
}
.nav-folder-title:hover {
  background: rgba(83, 112, 96, 0.08);
  color: var(--ink);
}
.nav-folder-title.active {
  background: rgba(164, 61, 47, 0.09);
  color: var(--ink);
}
.nav-folder-title::before {
  content: "▾";
  display: inline-block;
  width: 14px;
  margin-left: -14px;
  color: var(--gold);
}
.nav-folder-title[aria-expanded="false"]::before { content: "▸"; }
.nav-folder-title[aria-expanded="false"] + .nav-folder-items { display: none; }
.nav-folder-items {
  margin-left: 8px;
  border-left: 1px solid rgba(111, 91, 66, 0.16);
}
.nav-link {
  display: block;
  padding: 7px 8px 7px 22px;
  border-radius: 5px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.nav-index-link {
  color: #74644e;
  font-style: normal;
}
.nav-index-link::before {
  content: "개요 · ";
  color: var(--gold);
  font-weight: 700;
}
.nav-link:hover,
.nav-link.active {
  color: var(--ink);
  background: rgba(164, 61, 47, 0.09);
}

.content { min-width: 0; }
.doc-card {
  max-width: 920px;
  margin: 0 auto 70px;
  padding: clamp(24px, 4vw, 54px);
  border: 1px solid rgba(111, 91, 66, 0.25);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 253, 247, 0.98), rgba(247, 241, 229, 0.96)),
    var(--paper-soft);
  box-shadow: var(--shadow);
}
.home-page .doc-card {
  border-top: 5px solid var(--vermilion);
}
.doc-kicker {
  color: var(--moss);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.source-path {
  margin-top: 4px;
  color: #8a7a66;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.markdown-body {
  margin-top: 26px;
  font-size: 17px;
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  position: relative;
  margin: 1.9em 0 0.65em;
  color: var(--ink);
  line-height: 1.35;
  letter-spacing: 0;
}
.markdown-body h1 {
  margin-top: 0;
  font-family: var(--serif);
  font-size: clamp(34px, 5vw, 54px);
  font-weight: 800;
}
.markdown-body h2 {
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--line);
  font-family: var(--serif);
  font-size: clamp(24px, 3vw, 32px);
}
.markdown-body h3 { font-size: 22px; color: var(--indigo); }
.markdown-body h4 { font-size: 18px; color: var(--vermilion-dark); }
.anchor {
  position: absolute;
  left: -24px;
  opacity: 0;
  color: var(--gold);
  text-decoration: none;
}
.markdown-body h1:hover .anchor,
.markdown-body h2:hover .anchor,
.markdown-body h3:hover .anchor,
.markdown-body h4:hover .anchor { opacity: 1; }

.markdown-body p { margin: 0.75em 0; }
.markdown-body blockquote {
  margin: 1.4em 0;
  padding: 14px 18px;
  border-left: 4px solid var(--vermilion);
  background: rgba(164, 61, 47, 0.07);
  color: #3f342a;
}
.markdown-body ul,
.markdown-body ol { padding-left: 1.5em; }
.markdown-body li { margin: 0.28em 0; }
.markdown-body hr {
  margin: 2.2em 0;
  border: 0;
  border-top: 1px solid var(--line);
}
.markdown-body code {
  padding: 0.12em 0.32em;
  border-radius: 4px;
  background: rgba(28, 49, 71, 0.09);
  color: #172c42;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.92em;
}
.markdown-body pre {
  overflow: auto;
  padding: 16px;
  border-radius: 8px;
  background: #17202a;
  color: #f6f0e5;
}
.markdown-body pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}
.markdown-body img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.4em auto;
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(33, 25, 16, 0.18);
}
.table-wrap {
  overflow-x: auto;
  margin: 1.3em 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}
th,
td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid rgba(215, 203, 184, 0.7);
  vertical-align: top;
}
th {
  background: rgba(28, 49, 71, 0.08);
  color: var(--indigo);
  font-weight: 800;
}
tr:last-child td { border-bottom: 0; }
td:last-child,
th:last-child { border-right: 0; }

.toc-link {
  display: block;
  margin-top: 9px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.45;
}
.toc-link:hover { color: var(--vermilion-dark); }
.toc-l3 { padding-left: 14px; }
.toc-empty { margin: 10px 0 0; color: var(--ink-soft); font-size: 13px; }

.sheet-app {
  margin: 1.5em 0 2em;
  border: 1px solid rgba(111, 91, 66, 0.32);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.7);
}
.sheet-toolbar {
  position: sticky;
  top: 74px;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(111, 91, 66, 0.22);
  background: rgba(246, 240, 228, 0.96);
}
.sheet-save-status {
  display: block;
  margin-top: 2px;
  color: #7c6d5a;
  font-size: 12px;
  font-weight: 600;
}
.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}
.sheet-actions button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid rgba(111, 91, 66, 0.38);
  border-radius: 6px;
  background: #fffdf7;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.sheet-actions button:hover { background: rgba(164, 61, 47, 0.08); }
.fillable-sheet {
  padding: 16px;
}
.fillable-sheet fieldset {
  margin: 18px 0;
  padding: 16px;
  border: 1px solid rgba(111, 91, 66, 0.28);
  border-radius: 8px;
  background: rgba(251, 248, 239, 0.72);
}
.fillable-sheet legend {
  padding: 0 8px;
  color: var(--indigo);
  font-weight: 850;
}
.sheet-note {
  color: var(--ink-soft);
  font-size: 14px;
}
.sheet-grid,
.sheet-repeat-row {
  display: grid;
  gap: 10px;
}
.sheet-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.sheet-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.sheet-derived-grid { margin-top: 12px; }
.sheet-repeat { display: grid; gap: 12px; }
.sheet-repeat-row { grid-template-columns: 1.25fr 0.55fr 0.75fr 1.5fr; }
.sheet-field {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: #2b261f;
  font-size: 13px;
  font-weight: 750;
}
.sheet-field span {
  line-height: 1.25;
}
.sheet-field small {
  color: #7e715f;
  font-weight: 500;
  line-height: 1.3;
}
.sheet-field input,
.sheet-field select,
.sheet-field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(111, 91, 66, 0.34);
  border-radius: 6px;
  background: #fffefa;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}
.sheet-field input,
.sheet-field select {
  min-height: 36px;
  padding: 7px 9px;
}
.sheet-field textarea {
  resize: vertical;
  padding: 8px 9px;
  line-height: 1.45;
}
.sheet-field input[readonly] {
  background: rgba(28, 49, 71, 0.07);
  color: var(--indigo);
  font-weight: 800;
}
.sheet-field-wide { grid-column: 1 / -1; }
.sheet-check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 12px;
}
.sheet-check-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 750;
}
.skill-sheet-grid,
.squad-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.skill-group,
.squad-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(111, 91, 66, 0.2);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.76);
}
.skill-group h4,
.squad-card h3 {
  margin: 0 0 10px;
}
.skill-group {
  display: grid;
  gap: 8px;
}
.squad-card {
  display: grid;
  gap: 8px;
}
.sheet-line-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.scrim { display: none; }

@media (max-width: 1180px) {
  .site-shell { grid-template-columns: minmax(230px, 280px) minmax(0, 1fr); }
  .toc { display: none; }
}

@media (max-width: 820px) {
  .site-header { height: 58px; padding: 0 12px; }
  .icon-button { display: grid; place-items: center; }
  .brand small { display: none; }
  .header-actions { display: none; }
  .site-shell {
    display: block;
    padding: 12px;
  }
  .sidebar {
    position: fixed;
    z-index: 50;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(86vw, 340px);
    max-height: none;
    overflow: hidden;
    transform: translateX(-104%);
    transition: transform 0.2s ease;
  }
  body.nav-open { overflow: hidden; }
  body.nav-open .sidebar { transform: translateX(0); }
  .sidebar-inner {
    height: 100dvh;
    max-height: none;
    border-radius: 0;
  }
  body.nav-open .scrim {
    display: block;
    position: fixed;
    z-index: 40;
    inset: 0;
    background: rgba(23, 20, 16, 0.42);
  }
  .doc-card {
    padding: 22px 17px 34px;
    border-radius: 6px;
  }
  .markdown-body { font-size: 16px; }
  .markdown-body h1 { font-size: 32px; }
  .sheet-toolbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
  }
  .sheet-actions { justify-content: flex-start; }
  .fillable-sheet { padding: 11px; }
  .fillable-sheet fieldset { padding: 12px; }
  .sheet-grid-4,
  .sheet-grid-3,
  .sheet-repeat-row,
  .skill-sheet-grid,
  .squad-grid,
  .sheet-line-list {
    grid-template-columns: 1fr;
  }
  .anchor { display: none; }
  table { min-width: 620px; }
}

@media print {
  .site-header,
  .sidebar,
  .toc,
  .scrim,
  .source-path,
  .doc-kicker,
  .sheet-toolbar {
    display: none !important;
  }
  body {
    background: #fff;
    color: #000;
  }
  .site-shell {
    display: block;
    padding: 0;
  }
  .doc-card {
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
    background: #fff;
  }
  .sheet-app,
  .fillable-sheet fieldset,
  .skill-group,
  .squad-card {
    background: #fff;
    box-shadow: none;
  }
  .sheet-field input,
  .sheet-field select,
  .sheet-field textarea {
    border-color: #999;
    background: #fff;
  }
}