:root {
  --bg: #eff0e6;
  --surface: #fbfaf4;
  --surface-2: #f2f1e4;
  --ink: #262a22;
  --ink-dim: #5b6153;
  --line: #c9cbb8;
  --accent: #7c5cbf;
  --accent-soft: #ece6f7;
  --moss: #3f7a4b;
  --moss-soft: #e1ebde;
  --clay: #b87438;
  --clay-soft: #f1e4d2;
  --font-display: "Do Hyeon", "Noto Sans KR", sans-serif;
  --font-brand: "Jua", "Noto Sans KR", sans-serif;
  --font-body: "Noto Sans KR", -apple-system, "Malgun Gothic", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1d18;
    --surface: #23261f;
    --surface-2: #2a2d24;
    --ink: #e9e7da;
    --ink-dim: #a7ac98;
    --line: #3a3e32;
    --accent: #bba1ea;
    --accent-soft: #332c46;
    --moss: #8fc496;
    --moss-soft: #263426;
    --clay: #e0ae79;
    --clay-soft: #3a3123;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.7;
}

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

/* ---- brand header ---- */
.brand {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 18px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand img {
  width: 56px;
  height: 72px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid var(--line);
  flex-shrink: 0;
}
.brand-title {
  font-family: var(--font-brand);
  font-size: 34px;
  line-height: 1;
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
}
.brand-title span:nth-child(1) { color: #3f7a4b; }
.brand-title span:nth-child(2) { color: #d99a2b; }
.brand-title span:nth-child(3) { color: #3a8fc7; }
.brand-title span:nth-child(4) { color: #c65a8f; }
.brand-sub {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--ink-dim);
  margin-top: 4px;
  letter-spacing: .02em;
}

/* ---- layout ---- */
.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: calc(100vh - 108px);
}

.sidebar {
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  padding: 16px 10px;
  overflow-y: auto;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar > ul > li { margin-bottom: 2px; }

.tab-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14.5px;
  font-weight: 500;
  text-align: left;
  border-radius: 10px;
  cursor: pointer;
}
.tab-btn:hover { background: var(--surface); }
.tab-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.tab-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
}
.tab-icon.tab-icon-emoji {
  font-size: 16px;
  width: 20px;
  text-align: center;
  display: inline-block;
  image-rendering: auto;
}

.sub-list { padding-left: 10px; margin-top: 2px; }
.sub-list .tab-btn { font-size: 13.5px; padding: 6px 10px; }
.sub-list .tab-icon { width: 42px; height: 42px; }
.badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--clay-soft);
  color: var(--clay);
  margin-left: auto;
}

/* ---- content ---- */
.content {
  padding: 32px 40px;
  max-width: 760px;
  overflow-y: auto;
}
.content h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 30px;
  margin: 0 0 18px;
}
.content h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 21px;
  margin: 32px 0 10px;
  color: var(--moss);
}
.content p { color: var(--ink); }
.content strong { color: var(--ink); }
.content table {
  border-collapse: collapse;
  width: 100%;
  margin: 14px 0;
  font-size: 14px;
}
.content th, .content td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
}
.content th { background: var(--surface-2); }
.content code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: .92em;
}
.content ul, .content ol { padding-left: 22px; }
.content li { margin: 4px 0; }

.content figure.inline-shot {
  margin: 18px 0 24px;
  max-width: 420px;
}
.content figure.inline-shot img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: block;
}
.content figure.inline-shot figcaption {
  font-size: 12.5px;
  color: var(--ink-dim);
  margin-top: 6px;
}
.content figure.inline-shot figcaption a { color: var(--ink-dim); text-decoration: underline; }

.gallery {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 20px;
}
.gallery figure {
  margin: 0;
  flex-shrink: 0;
  width: 200px;
}
.gallery img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  display: block;
}
.gallery figcaption {
  font-size: 12px;
  color: var(--ink-dim);
  margin-top: 4px;
}
.gallery figcaption a { color: var(--ink-dim); text-decoration: underline; }

.sources {
  margin-top: 36px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-dim);
}
.sources summary { cursor: pointer; font-weight: 600; }
.sources ul { padding-left: 18px; }

/* ---- chat fab button ---- */
.chat-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--line);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  z-index: 60;
  transition: transform .15s ease;
}
.chat-fab:hover { transform: scale(1.06); }
.chat-fab img { width: 58px; height: 58px; object-fit: contain; image-rendering: pixelated; }
.chat-fab.hidden { display: none; }

/* ---- chat slide-in panel ---- */
.chat-panel {
  position: fixed;
  top: 0;
  right: -380px;
  width: 340px;
  max-width: 92vw;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -6px 0 24px rgba(0, 0, 0, 0.16);
  z-index: 70;
  display: flex;
  flex-direction: column;
  transition: right .25s ease;
}
.chat-panel.open { right: 0; }

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  background: var(--surface);
  position: relative;
  z-index: 2;
}
.chat-panel-header h3 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 18px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-title-icon {
  width: 44px;
  height: 44px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
}
.chat-title-brand {
  font-family: var(--font-brand);
  font-size: 21px;
  line-height: 1;
  display: inline-flex;
  gap: 1px;
}
.chat-title-brand span:nth-child(1) { color: #3f7a4b; }
.chat-title-brand span:nth-child(2) { color: #d99a2b; }
.chat-title-brand span:nth-child(3) { color: #3a8fc7; }
.chat-title-brand span:nth-child(4) { color: #c65a8f; }
.chat-title-sub {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--ink-dim);
}
.chat-close {
  border: none;
  background: transparent;
  color: var(--ink-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.chat-close:hover { background: var(--surface-2); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background-image:
    linear-gradient(rgba(18, 15, 10, .38), rgba(18, 15, 10, .58)),
    url('assets/branding/box-art.png');
  background-size: cover;
  background-position: top center;
}
.chat-msg {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
}
.chat-msg p { margin: 0 0 7px; }
.chat-msg p:last-child { margin-bottom: 0; }
.chat-msg ul, .chat-msg ol { margin: 2px 0 8px; padding-left: 20px; }
.chat-msg ul:last-child, .chat-msg ol:last-child { margin-bottom: 0; }
.chat-msg li { margin: 3px 0; }
.chat-msg strong { color: inherit; font-weight: 700; }
.chat-msg code {
  background: rgba(127, 127, 127, .18);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: .92em;
}
.chat-msg.bot {
  align-self: flex-start;
  background: var(--surface-2);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--accent-soft);
  color: var(--accent);
  border-bottom-right-radius: 4px;
}
.chat-msg.error {
  align-self: flex-start;
  background: var(--clay-soft);
  color: var(--clay);
}
.chat-msg.pending { color: var(--ink-dim); font-style: italic; }
.chat-sources {
  font-size: 11px;
  color: var(--ink-dim);
  margin-top: 6px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
  background: var(--surface);
  position: relative;
  z-index: 2;
}
.chat-input-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 13.5px;
}
.chat-input-row input:focus { outline: 2px solid var(--accent-soft); }
.chat-input-row button {
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 13.5px;
  padding: 0 16px;
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-input-row button:disabled { opacity: .5; cursor: default; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 220px;
  }
  .content { padding: 22px 18px; max-width: none; }
  .chat-panel { width: 100vw; max-width: 100vw; right: -100vw; }
  .chat-fab { right: 16px; bottom: 16px; }
}
