@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Spline+Sans+Mono:wght@400;500&display=swap');

:root {
  --topbar-offset: 120px;
  --bg: #f7f1e8;
  --bg-2: #f0e8dd;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-2: rgba(251, 248, 243, 0.9);
  --surface-3: rgba(255, 255, 255, 0.65);
  --text: #1c1b20;
  --muted: #5f5c67;
  --border: rgba(24, 23, 29, 0.12);
  --accent-h: 210;
  --accent: hsl(var(--accent-h) 75% 55%);
  --accent-2: hsl(calc(var(--accent-h) + 24) 70% 54%);
  --accent-3: hsl(calc(var(--accent-h) - 18) 85% 64%);
  --glow: hsla(var(--accent-h) 75% 55% / 0.25);
  --shadow: 0 30px 80px rgba(25, 24, 30, 0.18);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
}

body.theme-night {
  --bg: #0d1118;
  --bg-2: #111826;
  --surface: rgba(17, 21, 31, 0.88);
  --surface-2: rgba(19, 24, 36, 0.9);
  --surface-3: rgba(18, 24, 32, 0.7);
  --text: #edf0f7;
  --muted: #9aa3b2;
  --border: rgba(229, 232, 240, 0.1);
  --shadow: 0 30px 70px rgba(0, 0, 0, 0.45);
  --glow: hsla(var(--accent-h) 85% 60% / 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Space Grotesk', 'Outfit', 'Fira Sans', sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
}

.bg-layer {
  position: fixed;
  inset: -20% -10% -20% -10%;
  background: radial-gradient(circle at 20% 20%, rgba(248, 148, 117, 0.35), transparent 55%),
    radial-gradient(circle at 80% 10%, rgba(99, 163, 255, 0.35), transparent 50%),
    radial-gradient(circle at 50% 80%, rgba(255, 198, 110, 0.3), transparent 60%),
    linear-gradient(135deg, var(--bg), var(--bg-2));
  z-index: 0;
  pointer-events: none;
  filter: blur(0px);
  animation: drift 18s ease-in-out infinite alternate;
}

body.theme-night .bg-layer {
  background: radial-gradient(circle at 20% 20%, rgba(66, 150, 255, 0.35), transparent 55%),
    radial-gradient(circle at 80% 10%, rgba(238, 126, 255, 0.3), transparent 50%),
    radial-gradient(circle at 50% 80%, rgba(255, 179, 96, 0.25), transparent 60%),
    linear-gradient(135deg, var(--bg), var(--bg-2));
}

@keyframes drift {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  100% {
    transform: translate3d(2%, -3%, 0) scale(1.03);
  }
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.15;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/></filter><rect width='120' height='120' filter='url(%23n)' opacity='0.45'/></svg>");
  z-index: 1;
}

.app {
  position: relative;
  z-index: 2;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 18px;
  align-items: center;
  padding: 18px 28px;
  margin: 18px 18px 0;
  border-radius: var(--radius-lg);
  background: var(--surface);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  font-size: 28px;
  color: var(--accent);
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.4px;
}

.brand-sub {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.icon-btn {
  border: none;
  background: var(--surface-2);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  gap: 4px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  cursor: pointer;
}

.icon-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 99px;
  transition: transform 0.2s ease;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.search-wrap input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  width: clamp(140px, 22vw, 280px);
  color: var(--text);
}

.search-wrap input::placeholder {
  color: var(--muted);
}

.chip,
.pill {
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.chip:hover,
.pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
}

.top-actions {
  display: flex;
  gap: 10px;
}

.shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 240px;
  gap: 24px;
  padding: 24px;
}

.sidebar {
  position: sticky;
  top: var(--topbar-offset);
  height: calc(100vh - var(--topbar-offset) - 20px);
  overflow: auto;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.sidebar::-webkit-scrollbar,
.markdown::-webkit-scrollbar,
.toc::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-thumb,
.markdown::-webkit-scrollbar-thumb,
.toc::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 999px;
}

.nav-section {
  margin-bottom: 16px;
}

.nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border 0.2s ease, transform 0.2s ease;
}

.nav-header:hover {
  border-color: var(--border);
  transform: translateY(-1px);
}

.nav-header span {
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.nav-items {
  display: grid;
  gap: 8px;
  margin: 10px 0 0;
}

.nav-item {
  border: none;
  background: transparent;
  text-align: left;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  border: 1px solid transparent;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.nav-item small {
  color: var(--muted);
  font-size: 11px;
}

.nav-item:hover {
  border-color: var(--border);
  background: var(--surface-2);
}

.nav-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--glow);
  background: rgba(255, 255, 255, 0.6);
}

body.theme-night .nav-item.active {
  background: rgba(30, 36, 48, 0.8);
}

.nav-section.collapsed .nav-items {
  display: none;
}

.content {
  min-height: 50vh;
  padding: 16px 24px 40px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.doc-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

.doc-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.breadcrumbs {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.doc-meta {
  flex: 1;
}

.doc-title {
  font-size: clamp(26px, 4vw, 38px);
  font-weight: 700;
  margin-bottom: 8px;
}

.doc-stats {
  display: flex;
  gap: 8px;
}

.progress-ring {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) 0%, rgba(0, 0, 0, 0.08) 0%);
  display: grid;
  place-items: center;
  position: relative;
}

.progress-ring::after {
  content: '';
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.markdown {
  font-size: 16px;
  line-height: 1.7;
}

.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4 {
  scroll-margin-top: calc(var(--topbar-offset) + 20px);
  margin-top: 32px;
  margin-bottom: 12px;
}

.markdown h1 {
  font-size: 32px;
}

.markdown h2 {
  font-size: 26px;
}

.markdown h3 {
  font-size: 20px;
}

.markdown p {
  margin: 12px 0;
}

.markdown a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  border-bottom: 1px solid transparent;
}

.markdown a:hover {
  border-bottom-color: var(--accent);
}

.markdown ul,
.markdown ol {
  padding-left: 20px;
  margin: 12px 0;
}

.markdown li {
  margin: 6px 0;
}

.markdown code {
  font-family: 'Spline Sans Mono', 'JetBrains Mono', monospace;
  background: rgba(255, 255, 255, 0.6);
  padding: 2px 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.9em;
}

body.theme-night .markdown code {
  background: rgba(24, 30, 42, 0.7);
}

.code-block {
  position: relative;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(246, 239, 228, 0.8));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  margin: 18px 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

body.theme-night .code-block {
  background: linear-gradient(135deg, rgba(20, 26, 38, 0.95), rgba(15, 19, 31, 0.9));
}

.code-block::before {
  content: attr(data-lang);
  position: absolute;
  top: -10px;
  right: 18px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  letter-spacing: 1px;
  padding: 4px 8px;
  border-radius: 999px;
  text-transform: uppercase;
}

.code-block pre {
  margin: 0;
  overflow: auto;
  font-family: 'Spline Sans Mono', 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.6;
}

.copy-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid var(--border);
}

.markdown blockquote {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  color: var(--muted);
}

.markdown hr {
  border: none;
  border-top: 1px dashed var(--border);
  margin: 20px 0;
}

.markdown table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 14px;
}

.markdown img {
  max-width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin: 12px 0;
}

.markdown th,
.markdown td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
}

.markdown th {
  background: var(--surface-2);
}

.toc {
  position: sticky;
  top: var(--topbar-offset);
  height: calc(100vh - var(--topbar-offset) - 20px);
  overflow: auto;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 16px;
  box-shadow: var(--shadow);
}

.toc h3 {
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
}

.toc-item {
  display: block;
  padding: 6px 8px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  border: 1px solid transparent;
}

.toc-item:hover,
.toc-item.active {
  border-color: var(--border);
  background: var(--surface-2);
}

.doc-footer {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px dashed var(--border);
}

.error-card {
  padding: 20px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
  background: var(--surface-2);
}

.error-card h2 {
  margin-top: 0;
}

.pager {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.radar {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 260px;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.radar-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
}

.radar-title {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.6px;
}

.radar-sub {
  font-size: 12px;
  color: var(--muted);
}

#radarCanvas {
  width: 100%;
  height: 180px;
  display: block;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.85), rgba(246, 239, 228, 0.7));
  border: 1px solid var(--border);
}

body.theme-night #radarCanvas {
  background: linear-gradient(135deg, rgba(19, 24, 36, 0.9), rgba(15, 19, 30, 0.95));
}

.radar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.legend-pill {
  font-size: 10px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.palette {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 100;
}

.palette.open {
  opacity: 1;
  pointer-events: auto;
}

.palette-card {
  width: min(640px, 90vw);
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 16px;
}

.palette-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.palette-head input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 16px;
  outline: none;
  color: var(--text);
}

.palette-hint {
  font-size: 12px;
  color: var(--muted);
}

.palette-results {
  margin-top: 16px;
  display: grid;
  gap: 8px;
  max-height: 50vh;
  overflow: auto;
}

.palette-item {
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.palette-item strong {
  font-size: 14px;
}

.palette-item span {
  font-size: 12px;
  color: var(--muted);
}

.hidden {
  display: none;
}

.focus-mode .sidebar,
.focus-mode .toc,
.focus-mode .radar {
  display: none;
}

.focus-mode .shell {
  grid-template-columns: minmax(0, 1fr);
}

.focus-mode .content {
  max-width: 960px;
  margin: 0 auto;
}

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

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
  }
  .search-wrap {
    grid-column: 1 / -1;
  }
  .top-actions {
    justify-content: flex-end;
  }
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: fixed;
    top: var(--topbar-offset);
    left: 24px;
    width: min(320px, 85vw);
    height: calc(100vh - var(--topbar-offset) - 20px);
    transform: translateX(calc(-100% - 24px));
    transition: transform 0.25s ease;
    z-index: 60;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .radar {
    position: static;
    margin: 0 24px 24px;
    width: auto;
  }
}

@media (max-width: 720px) {
  .topbar {
    margin: 12px 12px 0;
    padding: 14px;
  }
  .shell {
    padding: 16px;
  }
  .content {
    padding: 16px;
  }
  .pager {
    flex-direction: column;
  }
  .radar {
    margin: 0 12px 16px;
  }
}
