@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable.min.css");
@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&display=swap");

:root {
  --ink-900: #0b1220;
  --ink-800: #111a2e;
  --ink-700: #1b2640;
  --ink-600: #2a3760;
  --ink-500: #33436d;
  --ink-400: #707fa3;
  --ink-300: #a3adc9;
  --ink-200: #cfd7ee;
  --ink-100: #e6eaf6;
  --ink-050: #f4f6fb;
  --accent-600: #FD312E;
  --accent-500: #ff524f;
  --accent-200: #ffd3c2;
  --mint-500: #2fb3a3;
  --sun-500: #ffd166;
  --shadow-lg: 0 22px 70px rgba(11, 18, 32, 0.12);
  --shadow-md: 0 12px 30px rgba(11, 18, 32, 0.12);
  --shadow-sm: 0 6px 16px rgba(11, 18, 32, 0.1);
  --surface: #ffffff;
  --surface-alt: #f9fbff;
  --surface-raised: #ffffff;
  --bg-accent-1: #fff6f0;
  --bg-accent-2: #f0fbff;
  --bg-base-1: #f8f7fb;
  --bg-base-2: #ffffff;
  --topbar-bg: rgba(255, 255, 255, 0.92);
  --input-bg: #ffffff;
  --hero-bg-start: #fff7f2;
  --hero-bg-end: #f9fbff;
  --callout-bg: #fff5f0;
  --code-bg: #0b1220;
  --code-text: #ffffff;
  --btn-primary-bg: #0b1220;
  --btn-primary-text: #ffffff;
  --btn-outline-bg: #ffffff;
  --btn-outline-text: #0b1220;
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --grid-max: 1520px;
  --sidebar-width: 250px;
  --toc-width: 220px;
}

:root[data-theme="dark"] {
  --ink-900: #f2f5ff;
  --ink-800: #dbe2ff;
  --ink-700: #c2cae6;
  --ink-600: #a4afcf;
  --ink-500: #8894b8;
  --ink-200: #2a3147;
  --ink-100: #1d2334;
  --ink-050: #141926;
  --accent-600: #ff8b5d;
  --accent-500: #ff9a72;
  --accent-200: #5a3326;
  --shadow-lg: 0 22px 70px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 6px 16px rgba(0, 0, 0, 0.35);
  --surface: #121826;
  --surface-alt: #161d2e;
  --surface-raised: #151b2a;
  --bg-accent-1: #2a1d16;
  --bg-accent-2: #10202a;
  --bg-base-1: #0c111b;
  --bg-base-2: #0f1420;
  --topbar-bg: rgba(12, 16, 26, 0.92);
  --input-bg: #121826;
  --hero-bg-start: #1f1a20;
  --hero-bg-end: #111827;
  --callout-bg: #2a1d16;
  --code-bg: #0d111b;
  --code-text: #e7ebff;
  --btn-primary-bg: #f2f5ff;
  --btn-primary-text: #0b1220;
  --btn-outline-bg: transparent;
  --btn-outline-text: #f2f5ff;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  margin: 0;
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, "Helvetica Neue", "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  color: var(--ink-900);
  background: radial-gradient(circle at 20% 20%, var(--bg-accent-1) 0%, transparent 40%),
              radial-gradient(circle at 80% 0%, var(--bg-accent-2) 0%, transparent 30%),
              linear-gradient(180deg, var(--bg-base-1) 0%, var(--bg-base-2) 70%);
  min-height: 100vh;
  text-rendering: optimizeLegibility;
}

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
.page-shell { display: flex; min-height: 100vh; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--ink-100);
}

.topbar-inner {
  max-width: var(--grid-max);
  margin: 0 auto;
  padding: 16px 20px;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  align-items: center;
  gap: 20px;
}

.topbar-logo-area {
  display: flex;
  align-items: center;
  padding-left: 20px;
}

.topbar-content-area {
  display: flex;
  align-items: center;
  padding-left: 36px;
}

.brand-title {
  font-size: 32px;
  font-weight: 800;
  color: #A50034;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #A50034 0%, #FD312E 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-logo {
  height: 32px;
  width: auto;
}

.brand-logo-swap {
  display: flex;
  align-items: center;
}

.brand-logo-dark {
  display: none;
}

:root[data-theme="dark"] .brand-logo-light {
  display: none;
}

:root[data-theme="dark"] .brand-logo-dark {
  display: inline-block;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-icon-moon {
  display: none;
}

:root[data-theme="dark"] .theme-icon-sun {
  display: none;
}

:root[data-theme="dark"] .theme-icon-moon {
  display: inline;
}

/* Layout */
.layout {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(200px, var(--sidebar-width)) minmax(0, 1fr) minmax(160px, var(--toc-width));
  gap: 20px;
  max-width: var(--grid-max);
  margin: 0 auto;
  padding: 28px 20px 72px;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 92px;
  align-self: start;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--ink-100);
  padding: 24px 12px;
  box-shadow: var(--shadow-sm);
}

.sidebar-section {
  margin-bottom: 24px;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-400);
  margin-bottom: 12px;
  padding-left: 12px;
}

.sidebar-link {
  display: block;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 400;
  color: var(--ink-700);
  transition: all 0.15s ease;
  border-left: 3px solid transparent;
  margin-bottom: 2px;
}

.sidebar-link:hover {
  background: var(--ink-050);
  color: var(--ink-900);
}

.sidebar-link.active {
  background: rgba(253, 49, 46, 0.06);
  color: var(--accent-600);
  font-weight: 700;
  border-left: 3px solid var(--accent-600);
  border-radius: 0 8px 8px 0;
}

/* Unified Sidebar Levels */
.sidebar-link.level-0 {
  font-weight: 500;
  color: var(--ink-900);
  font-size: 15px;
  margin-top: 14px;
  padding-left: 12px;
}

.sidebar-link.level-1 { padding-left: 28px; font-size: 14.5px; }
.sidebar-link.level-2 { padding-left: 40px; font-size: 13.5px; }

.sidebar-link.external-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-link p.secondary {
  margin: 2px 0 0 0;
  font-size: 11px;
  color: var(--ink-500);
  font-weight: 400;
  line-height: 1.2;
}

/* Main Content Area */
.content {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 32px 36px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--ink-100);
  animation: fadeUp 0.6s ease both;
  width: 100%;
}

/* TOC */
.toc {
  position: sticky;
  top: 92px;
  align-self: start;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--ink-100);
  padding: 32px 20px;
  box-shadow: var(--shadow-sm);
}

.toc strong {
  display: block;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-500);
  margin-bottom: 12px;
}

.toc a {
  display: block;
  padding: 6px 0;
  color: var(--ink-600);
  font-size: 14px;
  transition: color 0.2s ease;
}

.toc a.active {
  color: var(--accent-600);
  font-weight: 600;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Footer */
.footer {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--ink-100);
  display: flex;
  justify-content: space-between;
  color: var(--ink-500);
  font-size: 13px;
}

/* Responsive */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr); }
  .toc { display: none; }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: relative; top: 0; }
  .sidebar.collapsed { display: none; }
  .topbar-inner { display: flex; justify-content: space-between; padding: 12px 16px; }
  .topbar-logo-area { padding-left: 0; }
  .topbar-content-area { padding-left: 0; flex-grow: 1; justify-content: space-between; }
}

/* Wide Layout Mode */
[data-layout="wide"] .layout { max-width: 100%; padding: 0; gap: 0; }
[data-layout="wide"] .sidebar {
  border-right: 1px solid var(--ink-100);
  height: calc(100vh - 65px);
  position: sticky;
  top: 65px;
  overflow-y: auto;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
}
[data-layout="wide"] .content {
  padding: 40px 60px;
  max-width: 2000px;
  margin: 0 auto;
  background: transparent;
  border: none;
  box-shadow: none;
}

/* Auth FAB */
.auth-fab { position: fixed; bottom: 24px; right: 24px; z-index: 100; }
.btn-fab {
  display: flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; background-color: var(--surface);
  border: 1px solid var(--ink-200); border-radius: 50%;
  box-shadow: var(--shadow-md); transition: all 0.2s ease;
  cursor: pointer; background-repeat: no-repeat;
  background-position: center; background-size: 20px;
}
.btn-fab.login { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%230b1220' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='11' width='18' height='11' rx='2' ry='2'%3E%3C/rect%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'%3E%3C/path%3E%3C/svg%3E"); }
