:root {
  --font-sans: "Outfit", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 10px;
  --sidebar-w: 280px;
  --topbar-h: 56px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="dark"] {
  --bg: #0c0c0c;
  --bg-elevated: #141414;
  --bg-muted: #1a1a1a;
  --border: #2a2a2a;
  --text: #f2f2f2;
  --text-muted: #9a9a9a;
  --accent: #f5f5f5;
  --accent-soft: rgba(245, 245, 245, 0.08);
  --link: #e8e8e8;
  --code-bg: #101010;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --sidebar-bg: linear-gradient(180deg, #101010 0%, #0b0b0b 100%);
  --hero-glow: radial-gradient(ellipse at top left, rgba(255, 255, 255, 0.06), transparent 55%);
  --scroll-track: #101010;
  --scroll-thumb: #3a3a3a;
  --scroll-thumb-hover: #555555;
}

[data-theme="light"] {
  --bg: #f7f6f3;
  --bg-elevated: #ffffff;
  --bg-muted: #efeee9;
  --border: #ddd9d0;
  --text: #141414;
  --text-muted: #5c5c5c;
  --accent: #111111;
  --accent-soft: rgba(17, 17, 17, 0.06);
  --link: #1a1a1a;
  --code-bg: #f0efe9;
  --shadow: 0 12px 36px rgba(20, 20, 20, 0.08);
  --sidebar-bg: linear-gradient(180deg, #ffffff 0%, #f4f3ef 100%);
  --hero-glow: radial-gradient(ellipse at top left, rgba(0, 0, 0, 0.04), transparent 55%);
  --scroll-track: #efeee9;
  --scroll-thumb: #c8c4ba;
  --scroll-thumb-hover: #a9a59c;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

html {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: var(--scroll-track);
}

*::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 999px;
  border: 2px solid var(--scroll-track);
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
}

*::-webkit-scrollbar-corner {
  background: var(--scroll-track);
}

a {
  color: var(--link);
}

button,
input {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.app {
  display: flex;
  min-height: 100vh;
  background: var(--hero-glow), var(--bg);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  z-index: 40;
  transform: translateX(0);
  transition: transform 0.28s var(--ease);
}

.sidebar-brand {
  padding: 1rem 1.1rem 0.75rem;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #000;
  box-shadow: 0 0 0 1px var(--border);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-name {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.sidebar-search {
  position: relative;
  padding: 0.5rem 0.9rem 0.75rem;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
}

.search-field input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  min-width: 0;
}

.search-field kbd {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 0.15rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  white-space: nowrap;
}

.search-results {
  position: absolute;
  left: 0.9rem;
  right: 0.9rem;
  top: calc(100% - 0.35rem);
  max-height: 320px;
  overflow: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 50;
}

.search-hit {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.7rem 0.85rem;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.search-hit:last-child {
  border-bottom: 0;
}

.search-hit:hover,
.search-hit:focus-visible {
  background: var(--accent-soft);
  outline: none;
}

.search-hit strong {
  display: block;
  font-size: 0.92rem;
  margin-bottom: 0.15rem;
}

.search-hit span {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.sidebar-nav {
  flex: 1;
  overflow: auto;
  padding: 0.25rem 0.65rem 1rem;
}

.nav-section {
  margin-bottom: 0.75rem;
}

.nav-section-title {
  padding: 0.45rem 0.55rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
}

.nav-link {
  display: block;
  padding: 0.45rem 0.65rem;
  border-radius: 7px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.nav-link.active {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--accent);
}

.sidebar-footer {
  padding: 0.85rem;
  border-top: 1px solid var(--border);
}

.main-wrap {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--accent-soft);
}

#btn-menu {
  display: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0.45rem 0.85rem;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--accent-soft);
}

.btn-danger {
  background: transparent;
  border-color: #8a3030;
  color: #d06060;
}

.btn-block {
  width: 100%;
}

.content {
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 1.75rem 1.35rem 4rem;
  animation: fadeIn 0.35s var(--ease);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.loading,
.empty {
  color: var(--text-muted);
  padding: 2rem 0;
}

.doc-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.doc-header h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.doc-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.page-welcome .welcome-header {
  border-bottom: 0;
  margin-bottom: 0.5rem;
  padding-bottom: 0;
}

.welcome-kicker {
  margin: 0 0 0.55rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.page-welcome .welcome-header h1 {
  margin: 0;
  font-size: clamp(2rem, 4.5vw, 2.75rem);
  letter-spacing: -0.04em;
}

.welcome-subtitle {
  margin: 0.75rem 0 0;
  max-width: 34rem;
  font-size: 1.05rem;
  line-height: 1.5;
  color: var(--text-muted);
  font-weight: 450;
}

.page-welcome .markdown-body > p:first-of-type {
  font-size: 1.05rem;
  line-height: 1.65;
  color: color-mix(in srgb, var(--text) 88%, var(--text-muted));
}

.page-welcome .markdown-body h2 {
  margin-top: 2.4rem;
}

.welcome-link-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 1rem 0 0.5rem;
}

.welcome-link-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1rem 1.05rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background:
    linear-gradient(160deg, var(--accent-soft), transparent 55%),
    var(--bg-elevated);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.18s ease, transform 0.18s var(--ease), background 0.18s ease;
}

.welcome-link-card:hover {
  border-color: color-mix(in srgb, var(--text) 28%, var(--border));
  transform: translateY(-2px);
}

.welcome-link-card strong {
  font-size: 0.98rem;
  letter-spacing: -0.02em;
}

.welcome-link-card span {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.welcome-scripts {
  margin-top: 2.75rem;
  padding-top: 0.25rem;
}

.welcome-scripts h2 {
  margin: 0 0 0.45rem;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

.welcome-scripts-lead {
  margin: 0.85rem 0 1.1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.welcome-script-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.welcome-script-card {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: -0.01em;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s var(--ease);
}

.welcome-script-card:hover {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--text) 22%, var(--border));
  transform: translateY(-1px);
}

.page-welcome .markdown-body ol {
  padding-left: 1.2rem;
}

.page-welcome .markdown-body ol li {
  margin: 0.4rem 0;
}

.page-welcome .markdown-body ol li strong {
  color: var(--text);
}

@media (max-width: 900px) {
  .welcome-link-grid {
    grid-template-columns: 1fr;
  }

  .welcome-script-grid {
    grid-template-columns: 1fr;
  }
}

.markdown-body > *:first-child {
  margin-top: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  letter-spacing: -0.02em;
  line-height: 1.25;
  scroll-margin-top: 80px;
}

.markdown-body h1 {
  font-size: 1.9rem;
}

.markdown-body h2 {
  margin-top: 2rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
  font-size: 1.35rem;
}

.markdown-body h3 {
  margin-top: 1.5rem;
  font-size: 1.1rem;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body table {
  color: color-mix(in srgb, var(--text) 92%, var(--text-muted));
}

.markdown-body a {
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.1em 0.35em;
}

.markdown-body pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  overflow: auto;
}

.markdown-body pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: 0.84rem;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  margin: 1.25rem 0;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 0.55rem 0.75rem;
  text-align: left;
}

.markdown-body th {
  background: var(--bg-muted);
  font-weight: 600;
}

.markdown-body blockquote {
  margin: 1rem 0;
  padding: 0.35rem 0 0.35rem 1rem;
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
}

.markdown-body img {
  max-width: 100%;
  border-radius: 8px;
}

.editor-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.editor-toolbar .spacer {
  flex: 1;
}

.editor-area {
  width: 100%;
  min-height: 60vh;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.55;
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
}

.modal {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
  width: min(420px, calc(100vw - 2rem));
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.25rem;
}

.modal h2 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.modal label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.modal input {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-weight: 500;
}

.hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.overlay {
  display: none;
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-105%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-wrap {
    margin-left: 0;
  }

  #btn-menu {
    display: inline-flex;
  }

  .overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 35;
  }

  .overlay[hidden] {
    display: none;
  }

  .search-field kbd {
    display: none;
  }

  .content {
    padding: 1.25rem 1rem 3rem;
  }
}
