*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #ffffff;
  --bg-card: #f8f8f8;
  --bg-header: #1a1a1a;
  --text-primary: #1a1a1a;
  --text-secondary: #666;
  --text-on-dark: #ffffff;
  --border: #e0e0e0;
  --border-dark: #ccc;
  --accent: #000000;
  --topbar-h: 48px;
  --sidebar-w: 280px;
}

html { scroll-behavior: auto; scroll-padding-top: var(--topbar-h); }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.4;
}
body.sidebar-lock {
  position: fixed;
  width: 100%;
  overflow: hidden;
}

/* ── Topbar ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--topbar-h);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
}
.topbar-title {
  font-size: 15px; font-weight: 600; letter-spacing: 0.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.topbar-btn {
  width: 36px; height: 36px; border: none; background: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-primary); flex-shrink: 0;
}
.topbar-right {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.mode-toggle {
  min-width: 52px; height: 28px; padding: 0 12px;
  border: 1px solid var(--border-dark);
  background: var(--bg-primary);
  color: var(--text-primary);
  font: 600 12px/1 "Segoe UI", "Noto Sans SC", sans-serif;
  text-transform: lowercase;
  letter-spacing: .6px;
  cursor: pointer;
}
.mode-toggle:hover { background: var(--bg-card); }
.mode-toggle[data-mode="part"] {
  background: #1a1a1a;
  border-color: #1a1a1a;
  color: #fff;
}
.maint-badge {
  display: inline-flex; align-items: center; justify-content: center;
  height: 28px; padding: 0 10px;
  border: 1px solid var(--border-dark);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 12px; font-weight: 600; letter-spacing: .5px;
  white-space: nowrap;
}
.maint-badge[hidden] { display: none; }
.topbar-btn:hover { background: var(--bg-card); }

/* ── Search Panel ── */
.search-panel {
  position: fixed; top: var(--topbar-h); left: 0; right: 0; z-index: 99;
  background: var(--bg-primary); border-bottom: 1px solid var(--border);
  transform: translateY(-100%); opacity: 0; transition: transform .2s, opacity .2s;
  pointer-events: none;
}
.search-panel.open { transform: translateY(0); opacity: 1; pointer-events: auto; }
.search-inner {
  max-width: 800px; margin: 0 auto; padding: 8px 16px;
  display: flex; align-items: center; gap: 8px;
}
.search-results {
  max-width: 800px; margin: 0 auto; padding: 0 16px 16px;
}
.search-results[hidden] { display: none; }
.search-results-list {
  border: 1px solid var(--border);
  background: var(--bg-primary);
}
.search-result-item {
  width: 100%; border: none; border-top: 1px solid var(--border);
  background: var(--bg-primary); padding: 12px 16px; text-align: left; cursor: pointer;
}
.search-result-item:first-child { border-top: none; }
.search-result-item:hover { background: var(--bg-card); }
.search-result-path {
  display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 4px;
}
.search-result-title {
  display: block; font-size: 14px; font-weight: 600; color: var(--text-primary); margin-bottom: 4px;
}
.search-result-excerpt {
  display: block; font-size: 13px; color: var(--text-secondary); line-height: 1.5;
}
.search-empty {
  border: 1px solid var(--border);
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--bg-primary);
}
#search-input {
  flex: 1; height: 36px; border: 1px solid var(--border);
  padding: 0 12px; font-size: 14px; outline: none;
}
#search-input:focus { border-color: var(--accent); }
.search-count { font-size: 13px; color: var(--text-secondary); white-space: nowrap; }
.search-nav-btn {
  width: 32px; height: 32px; border: 1px solid var(--border);
  background: var(--bg-primary); cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.search-nav-btn:hover { background: var(--bg-card); }

/* ── Sidebar ── */
.sidebar-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.3);
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.sidebar-overlay.open { opacity: 1; pointer-events: auto; }
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 201;
  width: var(--sidebar-w); background: var(--bg-primary);
  border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform .25s;
  overflow-y: auto; padding-bottom: 32px;
}
.sidebar.open { transform: translateX(0); }
.sidebar-header {
  height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; font-weight: 600; font-size: 15px;
  border-bottom: 1px solid var(--border);
}
.sidebar-toggle {
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}
.sidebar-toggle:hover {
  color: var(--text-primary);
}
.sidebar-toggle[data-collapsed="true"] {
  transform: rotate(-90deg);
}
.toc { list-style: none; padding: 12px 0; }
.toc-item {
  display: block; padding: 8px 20px; font-size: 14px; font-weight: 600;
  color: var(--text-secondary); text-decoration: none; cursor: pointer;
  transition: background .15s, color .15s;
}
.toc-item:hover { background: var(--bg-card); color: var(--text-primary); }
.toc-item.active { color: #fff; font-weight: 600; background: #1a1a1a; }
.toc-item.toc-read { color: var(--text-primary); background: #f7f7f7; }
.toc-item.toc-ancestor.toc-h3 { color: var(--text-primary); background: #dddddd; }
.toc-item.toc-ancestor.toc-h4 { color: var(--text-primary); background: #e4e4e4; }
.toc-item.toc-ancestor.toc-h5 { color: var(--text-primary); background: #eaeaea; }
.toc-item.toc-ancestor.toc-h6 { color: var(--text-primary); background: #f0f0f0; }
.toc-item.active-sub.toc-h3 { color: var(--text-primary); background: #e8e8e8; }
.toc-item.active-sub.toc-h4 { color: var(--text-primary); background: #f0f0f0; }
.toc-item.active-sub.toc-h5 { color: var(--text-primary); background: #f5f5f5; }
.toc-item.active-sub.toc-h6 { color: var(--text-primary); background: #f8f8f8; }
.toc-item.toc-current.toc-h3 { color: var(--text-primary); background: #d6d6d6; }
.toc-item.toc-current.toc-h4 { color: var(--text-primary); background: #dcdcdc; }
.toc-item.toc-current.toc-h5 { color: var(--text-primary); background: #e4e4e4; }
.toc-item.toc-current.toc-h6 { color: var(--text-primary); background: #eaeaea; }
.toc-item.toc-h3 { padding-left: 40px; font-weight: 400; font-size: 13px; }
.toc-item.toc-h4 { padding-left: 56px; font-weight: 400; font-size: 13px; }
.toc-item.toc-h5 { padding-left: 72px; font-weight: 400; font-size: 12px; }
.toc-item.toc-h6 { padding-left: 88px; font-weight: 400; font-size: 11px; }
.toc.collapsed .toc-h4,
.toc.collapsed .toc-h5,
.toc.collapsed .toc-h6 {
  display: none;
}

/* ── Content ── */
.content {
  max-width: 840px; margin: 0 auto;
  padding: calc(var(--topbar-h) + 16px) 8px 32px;
}

/* ── Site Footer ── */
.site-footer {
  display: flex;
  flex-direction: column;
  gap: 22px;
  max-width: 840px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .45s ease, transform .45s ease;
  pointer-events: none;
}
.site-footer.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.site-footer-divider {
  display: flex;
  align-items: center;
  width: 100%;
}
.site-footer-divider-half {
  flex: 1;
  height: 2px;
}
.site-footer-divider-red { background: #B22936; }
.site-footer-divider-blue { background: #1F4FA8; }
.site-footer-divider-center {
  width: 12px;
  height: 12px;
  background: #1a1a1a;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.site-footer-divider-dot {
  width: 4px;
  height: 4px;
  background: #fff;
  border-radius: 50%;
}
.site-footer-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.site-footer-flag {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  object-fit: cover;
  display: block;
  flex-shrink: 0;
  user-select: none;
  -webkit-user-drag: none;
}
.site-footer-text {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .4px;
  line-height: 1;
  white-space: nowrap;
}
.site-footer-sakyvo {
  color: #1F4FA8;
  text-decoration: none;
  transition: opacity .15s;
  position: relative;
  padding-right: 11px;
}
.site-footer-sakyvo:hover { opacity: .75; }
.site-footer-arrow {
  position: absolute;
  top: -3px;
  right: 0;
  width: 9px;
  height: 9px;
  display: block;
  pointer-events: none;
  user-select: none;
}
.site-footer-project { color: #B22936; }
@media (min-width: 769px) {
  .site-footer { margin-left: var(--sidebar-w); max-width: none; }
}

/* ── Floor ── */
.floor {
  margin-bottom: 24px; border: 1px solid var(--border);
  overflow: hidden; background: var(--bg-primary);
}
.floor.floor-part {
  border-color: var(--border);
}
.floor-header {
  background: var(--bg-header); color: var(--text-on-dark);
  padding: 10px 20px; font-size: 14px; font-weight: 600;
}
.floor-body {
  padding: 20px 24px; background: var(--bg-primary);
}
.part-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  padding: 0;
}
.part-nav-card {
  display: block;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  text-decoration: none;
  padding: 16px;
  transition: background .15s, border-color .15s;
}
.part-nav-card:hover {
  border-color: #b9b9b9;
  background: var(--bg-card);
}
.part-grid .part-nav-card,
.part-grid .part-nav-card:hover,
.part-grid .part-nav-card:visited {
  text-decoration: none;
}
.part-nav-index {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: .8px;
  margin-bottom: 6px;
}
.part-nav-title {
  display: block;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
}
.part-section {
  padding: 0;
  border-top: 1px solid var(--border);
}
.part-section:first-of-type { border-top: none; }
.part-section-title {
  margin: 0 0 12px;
  font-size: 18px;
}
.part-section-title a {
  color: inherit;
  text-decoration: none;
}
.part-submodule {
  border: 1px solid var(--border);
  background: var(--bg-primary);
  margin-top: 18px;
}
.part-submodule-header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 13px;
  font-weight: 700;
}
.part-submodule-body {
  padding: 18px;
}
.part-pager {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}
.part-pager-link,
.part-pager-spacer {
  flex: 1;
  min-height: 72px;
}
.part-pager-link {
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  text-decoration: none;
  padding: 14px 16px;
}
.part-pager-spacer {
  border: 1px solid var(--border);
  background: var(--bg-primary);
  padding: 14px 16px;
}
.part-pager-link:hover { background: var(--bg-card); }
.part-pager-dir {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.part-pager-name {
  display: block;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
}
.part-pager-spacer .part-pager-name {
  min-height: 1.4em;
}

/* ── Markdown content styling ── */
.floor-body { font-size: 14px; }
.floor-body h1 { font-size: 1.6em; margin: 0 0 .6em; }
.floor-body h2 { font-size: 1.3em; margin: 1.2em 0 .5em; }
.floor-body h3 { font-size: 1.15em; margin: 1em 0 .4em; }
.floor-body h4 { font-size: 1.05em; margin: .8em 0 .3em; }
.floor-body h5 { font-size: 1em; margin: .6em 0 .2em; }
.floor-body h6 { font-size: 1em; margin: .6em 0 .2em; font-weight: 600; }
.floor-body p { margin: 0; }
.floor-body br { display: block; margin-bottom: 3px; }
.floor-body .bl { height: calc(0.8em + 2px); }
.floor-body ul, .floor-body ol { margin: 0; padding-left: 1.5em; }
.floor-body blockquote {
  margin: 0 0 .8em; padding: 12px 16px;
  border-left: 3px solid var(--border-dark); background: var(--bg-card);
  color: var(--text-secondary);
}
.floor-body img,
.floor-body video,
.floor-body iframe,
.floor-body canvas,
.floor-body svg {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 8px 0;
}
.floor-body a { color: #00bcd4; text-decoration: underline; overflow-wrap: break-word; word-break: break-all; }
.floor-body code {
  font-family: "JetBrains Mono", "Fira Code", monospace;
  background: var(--bg-card); padding: 2px 6px; font-size: .9em;
}
.floor-body pre {
  margin: 0 0 .8em; padding: 16px;
  background: #f6f8fa; overflow-x: auto;
}
.floor-body pre code { background: none; padding: 0; }
.code-copy-wrap { position: relative; margin: 0 0 .8em; }
.code-copy-wrap pre { margin-bottom: 0; padding-right: 48px; }
.code-copy-btn {
  position: absolute; top: 8px; right: 8px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid #d0d7de; background: #fff; color: #57606a;
  cursor: pointer; opacity: .72;
  transition: opacity .15s, color .15s, border-color .15s, background .15s;
}
.code-copy-btn:hover,
.code-copy-btn:focus-visible {
  opacity: 1; color: #24292f; border-color: #8c959f; background: #f6f8fa;
}
.code-copy-btn.is-copied { color: #1a7f37; border-color: #7ac68c; }
.code-copy-btn.is-error { color: #cf222e; border-color: #ff8182; }
.floor-body .code-copy-btn svg {
  display: block; width: 16px; height: 16px; margin: 0;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.floor-body table { width: 100%; border-collapse: collapse; margin: 0 0 .8em; }
.floor-body th, .floor-body td {
  border: 1px solid var(--border); padding: 8px 12px; text-align: left; font-size: 14px;
}
.floor-body th { background: var(--bg-card); font-weight: 600; }
.floor-body hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }

.jump-flash {
  animation: jump-flash 1.35s ease-out;
}
@keyframes jump-flash {
  0%, 42% { background-color: #fff1a8; box-shadow: 0 0 0 4px #fff1a8; }
  100% { background-color: transparent; box-shadow: 0 0 0 0 transparent; }
}

/* ── Search highlight ── */
mark.search-hl { background: #fff3a8; padding: 0; }
mark.search-hl.current { background: #ff9632; }

/* ── Maintenance Overlay ── */
.maint-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: #fff;
  display: flex; align-items: center; justify-content: center;
}
.maint-card { text-align: center; }
.maint-title {
  font-size: 28px; font-weight: 700; letter-spacing: 2px;
  color: #1a1a1a; margin-bottom: 12px;
}
.maint-sub { font-size: 14px; color: #999; letter-spacing: 1px; }

/* ── Responsive ── */
@media (min-width: 769px) {
  #menu-btn { display: none; }
  .sidebar-overlay { display: none; }
  .sidebar {
    transform: translateX(0);
    top: var(--topbar-h);
    z-index: 1;
  }
  .topbar { justify-content: center; }
  .topbar-right { margin-left: auto; }
  .content {
    margin-left: var(--sidebar-w);
    max-width: none;
  }
}
@media (max-width: 768px) {
  .content { padding-left: 4px; padding-right: 4px; }
  .floor-body { padding: 16px; }
  .topbar-title { font-size: 13px; }
  .maint-badge { padding: 0 8px; font-size: 11px; }
  .topbar-right { gap: 6px; }
  .mode-toggle { min-width: 46px; padding: 0 10px; }
  .search-inner { padding-left: 8px; padding-right: 8px; }
  .search-results { padding-left: 8px; padding-right: 8px; padding-bottom: 12px; }
  .part-grid { grid-template-columns: 1fr; }
  .part-submodule-body { padding: 14px; }
  .part-pager { flex-direction: column; }
  .floor-body img,
  .floor-body video,
  .floor-body iframe,
  .floor-body canvas,
  .floor-body svg {
    width: 100%;
  }
}
