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

:root {
  --sidebar-w: 290px;
  --bg: #f9fafb;
  --content-bg: #ffffff;
  --text: #111827;
  --text-body: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --sidebar-bg: #111827;
  --sidebar-text: #9ca3af;
  --sidebar-heading: #f3f4f6;
  --sidebar-active: #7c3aed;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-active-soft: rgba(124, 58, 237, 0.12);
  --accent: #2563eb;
  --accent-strong: #3b82f6;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --accent-border: rgba(37, 99, 235, 0.25);
  --accent-border-strong: rgba(37, 99, 235, 0.45);
  --highlight-bg: #dbeafe;
  --highlight-current: #60a5fa;
  --code-bg: #f3f4f6;
  --code-text: #1d4ed8;
  --table-head-bg: #f3f4f6;
  --font-body: Georgia, "Times New Roman", serif;
  --font-ui: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

html,
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.state-msg {
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 14px;
  padding: 48px 24px;
  text-align: center;
}

.state-msg strong {
  color: var(--text);
  display: block;
  margin-bottom: 6px;
}

.menu-page {
  min-height: 100vh;
  background:
    linear-gradient(115deg, rgba(249, 250, 251, 0.94) 0%, rgba(249, 250, 251, 0.86) 42%, rgba(238, 242, 255, 0.78) 100%),
    radial-gradient(circle at 20% 15%, rgba(37, 99, 235, 0.12), transparent 30%),
    radial-gradient(circle at 85% 20%, rgba(124, 58, 237, 0.14), transparent 28%),
    var(--menu-bg-image, linear-gradient(135deg, #f9fafb 0%, #eef2ff 100%)),
    linear-gradient(135deg, #f9fafb 0%, #eef2ff 100%);
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  padding: 56px 24px 72px;
}

.menu-page-has-bg {
  background:
    linear-gradient(115deg, rgba(249, 250, 251, 0.58) 0%, rgba(249, 250, 251, 0.42) 44%, rgba(238, 242, 255, 0.24) 100%),
    radial-gradient(circle at 20% 15%, rgba(37, 99, 235, 0.1), transparent 30%),
    radial-gradient(circle at 85% 20%, rgba(124, 58, 237, 0.1), transparent 28%),
    var(--menu-bg-image),
    linear-gradient(135deg, #f9fafb 0%, #eef2ff 100%);
  background-attachment: scroll, scroll, scroll, scroll, scroll;
  background-position: top center, top center, top center, top center, top center;
  background-repeat: no-repeat, no-repeat, no-repeat, repeat-y, no-repeat;
  background-size: 100% 100%, 100% 100%, 100% 100%, 100% auto, cover;
}

.menu-container {
  margin: 0 auto;
  max-width: 1040px;
}

.menu-kicker {
  color: var(--sidebar-active);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  margin-bottom: 14px;
  text-transform: uppercase;
}

.menu-title {
  color: var(--text);
  font-family: var(--font-ui);
  font-size: clamp(2rem, 4vw, 4rem);
  letter-spacing: -0.05em;
  line-height: 0.98;
  margin-bottom: 18px;
  max-width: 760px;
}

.menu-description {
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1.7;
  margin-bottom: 14px;
  max-width: 680px;
}

.menu-stats {
  display: flex;
  margin-bottom: 32px;
}

.menu-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.menu-card {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(17, 24, 39, 0.08);
  color: inherit;
  display: flex;
  flex-direction: column;
  min-height: 240px;
  overflow: hidden;
  padding: 24px;
  position: relative;
  text-decoration: none;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.menu-card::before {
  background: linear-gradient(90deg, var(--accent), var(--sidebar-active));
  content: "";
  height: 4px;
  inset: 0 0 auto;
  position: absolute;
}

.menu-card:hover {
  border-color: rgba(37, 99, 235, 0.28);
  box-shadow: 0 24px 70px rgba(37, 99, 235, 0.15);
  transform: translateY(-3px);
}

.menu-card-header {
  align-items: flex-start;
  display: flex;
  gap: 14px;
  margin-bottom: 12px;
}

.menu-card-icon {
  align-items: center;
  background: var(--card-icon-bg, linear-gradient(135deg, var(--accent), var(--sidebar-active)));
  border-radius: 14px;
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.22);
  color: var(--card-icon-color, #ffffff);
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 20px;
  height: 46px;
  justify-content: center;
  margin-top: -2px;
  width: 46px;
}

.menu-card h2 {
  font-family: var(--font-ui);
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin-bottom: 0;
}

.menu-card p {
  color: var(--text-body);
  font-size: 0.98rem;
  line-height: 1.65;
  margin-bottom: 18px;
}

.menu-card-footer {
  align-items: flex-end;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-top: auto;
}

.menu-card-meta {
  align-items: flex-end;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  text-align: right;
}

.menu-card-action {
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.badges {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 18px;
}

.badge {
  align-items: center;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 999px;
  color: var(--accent);
  display: inline-flex;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 5px 9px;
}

.badge-img {
  display: block;
  height: 20px;
  max-width: 180px;
}

.updated-at {
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 12px;
}

.access-counter {
  align-items: center;
  background: rgba(17, 24, 39, 0.05);
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 999px;
  color: var(--text-muted);
  display: inline-flex;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 5px 9px;
  white-space: nowrap;
}

.menu-access-counter {
  background: rgba(255, 255, 255, 0.74);
  border-color: rgba(17, 24, 39, 0.08);
  box-shadow: 0 10px 28px rgba(17, 24, 39, 0.08);
}

.reader-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  min-width: var(--sidebar-w);
  overflow: hidden;
  width: var(--sidebar-w);
  z-index: 10;
}

.sidebar-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
  padding: 22px 18px 14px;
}

.sidebar-header h1 {
  color: var(--sidebar-active);
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  margin-bottom: 3px;
  text-transform: uppercase;
}

.sidebar-header p {
  color: var(--sidebar-text);
  font-family: var(--font-ui);
  font-size: 12px;
  opacity: 0.75;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-meta {
  color: rgba(255, 255, 255, 0.42);
  font-family: var(--font-ui);
  font-size: 11px;
  padding: 10px 18px 0;
}

.reader-access-counter {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.09);
  color: rgba(255, 255, 255, 0.52);
  margin: 10px 18px 0;
}

.search-wrap {
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  flex-shrink: 0;
  padding: 12px 14px;
}

.search-box {
  align-items: center;
  display: flex;
  position: relative;
}

.search-box svg {
  color: rgba(255, 255, 255, 0.3);
  left: 9px;
  pointer-events: none;
  position: absolute;
}

.search-input {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: var(--sidebar-heading);
  font-family: var(--font-ui);
  font-size: 12px;
  outline: none;
  padding: 7px 32px 7px 30px;
  transition: border-color 0.15s, background 0.15s;
  width: 100%;
}

.search-input::placeholder {
  color: rgba(255, 255, 255, 0.25);
}

.search-input:focus {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(124, 58, 237, 0.6);
}

.search-clear {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.3);
  cursor: pointer;
  display: none;
  line-height: 1;
  padding: 2px;
  position: absolute;
  right: 7px;
}

.search-clear.visible {
  display: block;
}

.search-meta {
  color: rgba(255, 255, 255, 0.3);
  font-family: var(--font-ui);
  font-size: 10px;
  min-height: 18px;
  padding: 5px 14px 0;
}

.search-meta.has-results {
  color: var(--sidebar-active);
}

.search-results {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
}

.search-results.visible {
  display: flex;
}

.search-result-item {
  background: none;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  cursor: pointer;
  padding: 10px 16px;
  text-align: left;
  transition: background 0.12s;
  width: 100%;
}

.search-result-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.sri-heading {
  color: var(--sidebar-active);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sri-snippet {
  color: var(--sidebar-text);
  display: -webkit-box;
  font-family: var(--font-ui);
  font-size: 11px;
  line-height: 1.45;
  opacity: 0.7;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.sri-snippet mark {
  background: rgba(124, 58, 237, 0.35);
  border-radius: 2px;
  color: #ddd6fe;
  padding: 0 1px;
}

.search-no-results {
  color: rgba(255, 255, 255, 0.32);
  font-family: var(--font-ui);
  font-size: 12px;
  line-height: 1.5;
  padding: 20px 16px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0 20px;
  scrollbar-color: rgba(255, 255, 255, 0.12) var(--sidebar-bg);
  scrollbar-width: thin;
}

.sidebar-nav::-webkit-scrollbar {
  width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: var(--sidebar-bg);
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid var(--sidebar-bg);
  border-radius: 999px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.22);
}

.nav-item {
  background: none;
  border: none;
  border-left: 2px solid transparent;
  color: var(--sidebar-text);
  cursor: pointer;
  display: block;
  font-family: var(--font-ui);
  line-height: 1.35;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  width: 100%;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-heading);
}

.nav-item.active {
  background: var(--sidebar-active-soft);
  border-left-color: var(--sidebar-active);
  color: var(--sidebar-active);
}

.nav-item.h1 {
  color: var(--sidebar-heading);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-top: 4px;
  padding: 8px 18px 8px 16px;
}

.nav-item.h2 {
  font-size: 12px;
  font-weight: 400;
  padding: 5px 18px 5px 28px;
}

.nav-item.h3 {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.7;
  padding: 4px 18px 4px 40px;
}

.format-toggle {
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  flex-shrink: 0;
  gap: 6px;
  padding: 10px 14px;
}

.fmt-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: var(--sidebar-text);
  cursor: pointer;
  flex: 1;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 7px 0;
  text-transform: uppercase;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.fmt-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--sidebar-heading);
}

.fmt-btn.active {
  background: var(--sidebar-active-soft);
  border-color: rgba(124, 58, 237, 0.4);
  color: var(--sidebar-active);
}

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: grid;
  flex-shrink: 0;
  gap: 9px;
  padding: 12px 14px;
}

.sidebar-button {
  align-items: center;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
  gap: 8px;
  justify-content: center;
  letter-spacing: 0.04em;
  padding: 9px 14px;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  width: 100%;
}

.btn-menu {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--sidebar-heading);
}

.btn-menu:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-pdf {
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent-strong);
}

.btn-pdf:hover {
  background: rgba(37, 99, 235, 0.2);
  border-color: var(--accent-border-strong);
}

.reader-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.html-frame {
  border: none;
  flex: 1;
  height: 100%;
  width: 100%;
}

.html-mode-msg {
  padding: 16px 18px;
  text-align: left;
}

.content-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 52px 64px 80px;
}

.content {
  margin: 0 auto;
  max-width: 760px;
}

.content .badges {
  margin-bottom: 20px;
}

.content h1,
.content h2,
.content h3,
.content h4 {
  color: var(--text);
  font-family: var(--font-ui);
  scroll-margin-top: 36px;
}

.content h1 {
  border-bottom: 2px solid var(--border);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.5rem;
}

.content h1:first-child {
  margin-top: 0;
}

.content h2 {
  color: var(--accent);
  font-size: 1.3rem;
  font-weight: 600;
  margin: 2.2rem 0 0.75rem;
}

.content h3 {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  margin: 1.8rem 0 0.6rem;
  text-transform: uppercase;
}

.content p {
  color: var(--text-body);
  font-size: 1rem;
  line-height: 1.8;
  margin-bottom: 1.1rem;
  text-wrap: pretty;
}

.content ul,
.content ol {
  margin-bottom: 1.1rem;
  padding-left: 1.5rem;
}

.content li {
  color: var(--text-body);
  font-size: 1rem;
  line-height: 1.75;
  margin-bottom: 0.25rem;
}

.content li::marker {
  color: var(--accent);
}

.content code {
  background: var(--code-bg);
  border-radius: 3px;
  color: var(--code-text);
  font-family: Menlo, "Courier New", monospace;
  font-size: 0.85em;
  padding: 0.1em 0.35em;
}

.content pre {
  background: var(--code-bg);
  border-radius: 6px;
  margin-bottom: 1.3rem;
  overflow-x: auto;
  padding: 1.2rem 1.4rem;
}

.content pre code {
  background: none;
  color: var(--text);
  padding: 0;
}

.content blockquote {
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
  font-style: italic;
  margin: 1.3rem 0;
  padding: 0.5rem 0 0.5rem 1.2rem;
}

.content table {
  border-collapse: collapse;
  font-size: 0.92rem;
  margin-bottom: 1.3rem;
  width: 100%;
}

.content th {
  background: var(--table-head-bg);
  border-bottom: 2px solid var(--border);
  font-family: var(--font-ui);
  font-weight: 600;
  padding: 8px 12px;
  text-align: left;
}

.content td {
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
}

.content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

.content a {
  border-bottom: 1px solid var(--accent-border-strong);
  color: var(--accent);
  text-decoration: none;
}

.content mark.search-hl {
  background: var(--highlight-bg);
  border-radius: 2px;
  color: inherit;
  padding: 0 1px;
}

.content mark.search-hl.current {
  background: var(--highlight-current);
  outline: 2px solid var(--accent);
}

.progress-bar {
  background: linear-gradient(90deg, var(--accent), var(--sidebar-active));
  height: 2px;
  left: var(--sidebar-w);
  position: fixed;
  right: 0;
  top: 0;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.1s;
  z-index: 100;
}

.search-nav {
  align-items: center;
  background: var(--sidebar-bg);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  bottom: 24px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  display: none;
  gap: 4px;
  padding: 6px 10px;
  position: fixed;
  right: 24px;
  z-index: 200;
}

.search-nav.visible {
  display: flex;
}

.search-nav-count {
  color: var(--sidebar-active);
  font-family: var(--font-ui);
  font-size: 11px;
  min-width: 60px;
  padding: 0 6px;
  text-align: center;
}

.search-nav-btn,
.search-nav-close {
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  line-height: 1;
  padding: 4px 6px;
}

.search-nav-btn:hover,
.search-nav-close:hover {
  color: var(--sidebar-heading);
}

.search-nav-close {
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.3);
  font-size: 14px;
  margin-left: 4px;
}

@media (max-width: 760px) {
  .menu-page {
    padding: 34px 16px 48px;
  }

  .reader-layout {
    display: block;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    min-width: 0;
    position: relative;
    width: 100%;
  }

  .sidebar-nav {
    max-height: 240px;
  }

  .menu-card-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .menu-card-meta {
    align-items: flex-start;
    text-align: left;
  }

  .reader-main {
    height: auto;
    overflow: visible;
  }

  .html-frame {
    height: 80vh;
    min-height: 400px;
  }

  .content-wrap {
    overflow: visible;
    padding: 34px 20px 72px;
  }

  .progress-bar {
    left: 0;
  }
}
