/* variables */
:root {
  --bg: #0c0c0c;
  --bg-sidebar: #111111;
  --bg-topbar: #111111;
  --bg-main: #141414;
  --bg-card: #1a1a1a;
  --bg-hover: #1e1e1e;
  --bg-input: #1a1a1a;
  --border: #ffffff0d;
  --text: #f6f6f6;
  --text-dim: rgba(246,246,246,0.55);
  --text-muted: rgba(246,246,246,0.35);
  --accent: #667eea;
  --accent2: #764ba2;
  --green: #3fb950;
  --radius: 8px;

  --content-max-width: 1500px;
}

/* reset */
* { margin: 0; padding: 0; box-sizing: border-box;-webkit-tap-highlight-color: transparent; }

html, body {
  height: 100dvh;
  font-family: "Onest", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: var(--content-max-width);
  margin-inline: auto;
  background: var(--bg);
}

.mobile-drawer-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}

.mobile-drawer-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
  color: var(--text);
}

.mobile-drawer-toggle span { font-weight: 500; }

.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  width: 300px;
  color: var(--text-dim);
}

.topbar-search input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  width: 100%;
}

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

.search-results {
  position: fixed;
  top: 48px;
  left: 40px;
  width: 400px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  display: none;
  z-index: 9999;
}

.search-results.active { display: block; }

.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-dim);
  transition: background .15s;
}

.search-result-item:hover { background: var(--bg-hover); color: var(--text); }

.search-result-item .sr-cat {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.app-layout {
  display: flex;
  height: 100dvh;
  padding-top: 48px;
  max-width: var(--content-max-width);
  margin-inline: auto;
}

/* sidebar */
.sidebar {
  width: 360px;
  min-width: 360px;
  min-height: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sidebar-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.drawer-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s;
}

.drawer-close:hover { color: var(--text); }

/* drawer overlay
   Скрыт по умолчанию везде, показывается только через .active на мобилке */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  opacity: 0;
  transition: opacity .3s ease;
}

.compact-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 12px 10px;
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-dim);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s;
}

.compact-toggle:hover { background: var(--bg-hover); }
.compact-toggle.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.sidebar-filter {
  display: block;
  margin: 0 12px 10px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.sidebar-filter:hover { border-color: var(--text-muted); }
.sidebar-filter option { background: var(--bg-card); color: var(--text-dim); }

.sidebar-tree {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}

/* sidebar tree — main categories */
.main-cat-group { margin-bottom: 4px; }

.main-cat-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  transition: background .12s;
  user-select: none;
}


.main-cat-header .arrow {
  transition: transform .2s;
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.main-cat-header .arrow.open { transform: rotate(90deg); }
.main-cat-header .main-cat-title { flex: 1; }

.main-cat-header .cat-count {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
  color: #ffffffb6;
}

.main-cat-children { display: none; padding-left: 8px; }
.main-cat-children.open { display: block; }

/* topics */
.cat-group { margin-bottom: 2px; }

.cat-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-dim);
  transition: background .12s;
  user-select: none;
}


.cat-header .arrow {
  transition: transform .2s;
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.cat-header .arrow.open { transform: rotate(90deg); }
.cat-header .cat-title { flex: 1; }
.cat-title { font-size: 15px; }

.cat-header .cat-count {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
  color: #ffffffb6;
}

.cat-children { display: none; padding-left: 14px; }
.cat-children.open { display: block; }

/* subcategories */
.subcat-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-dim);
  transition: background .12s;
  user-select: none;
}

.subcat-header .arrow {
  transition: transform .2s;
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.subcat-header .arrow.open { transform: rotate(90deg); }
.subcat-header .subcat-title { flex: 1; }
.subcat-title { font-size: 15px; }

.subcat-header .cat-count {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
  color: #ffffffb6;
}

.subcat-children { display: none; padding-left: 10px; }
.subcat-children.open { display: block; }

/* subtopics */
.subtopic-group { margin-bottom: 2px; }

.subtopic-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  transition: background .12s;
  user-select: none;
}

.subtopic-header:hover { background: var(--bg-hover); color: var(--text); }

.subtopic-header .arrow {
  transition: transform .2s;
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.subtopic-header .arrow.open { transform: rotate(90deg); }
.subtopic-header .subtopic-title { font-size: 15px; flex: 1; }

.subtopic-header .cat-count {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
  color: #ffffffb6;
}

.subtopic-children { display: none; padding-left: 10px; }
.subtopic-children.open { display: block; }

/* sidebar question item */
.sidebar-question {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 10px;
  cursor: pointer;
  border-radius: 6px;
  color: var(--text-muted);
  transition: background .12s;
  line-height: 1.4;
}

.sidebar-question:hover { background: var(--bg-hover); color: var(--text-dim); }
.sidebar-question.active { background: var(--bg-hover); color: var(--text); }

.sidebar-question .sq-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 1.5px solid var(--text-muted);
  margin-top: 6px;
  flex-shrink: 0;
  transition: background .15s, border-color .15s;
}

.sidebar-question.active .sq-dot { border-color: var(--text); }
.sidebar-question .sq-dot.status-learned { background: #3fb950; border-color: #3fb950; }
.sidebar-question .sq-dot.status-repeat { background: #f85149; border-color: #f85149; }

.sq-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.sq-grade { font-size: 10px; font-weight: 500; line-height: 1; }
.sq-grade-trainee { color: #81c784; }
.sq-grade-junior { color: #64b5f6; }
.sq-grade-middle { color: #ffb74d; }
.sq-grade-senior { color: #e57373; }

.sq-popular {
  font-size: 9px;
  font-weight: 500;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1px 6px;
  line-height: 1.4;
  white-space: nowrap;
}

.sq-info { display: flex; flex-direction: column; min-width: 0; }
.sq-title { font-size: 15px; }

/* compact mode */
.sidebar.compact .sidebar-question { padding: 3px 10px; }
.sidebar.compact .sidebar-question .sq-title { font-size: 14px; }
.sidebar.compact .sidebar-question .sq-meta { display: none; }
.sidebar.compact .sidebar-question .sq-dot { width: 6px; height: 6px; margin-top: 5px; }
.sidebar.compact .cat-header { padding: 5px 10px; }
.sidebar.compact .cat-header .cat-title { font-size: 14px; }
.sidebar.compact .cat-header .cat-count { font-size: 10px; }
.sidebar.compact .subcat-header { padding: 4px 10px; }
.sidebar.compact .subcat-header .subcat-title { font-size: 14px; }
.sidebar.compact .subcat-header .cat-count { font-size: 10px; }
.sidebar.compact .main-cat-header { padding: 6px 10px; }
.sidebar.compact .main-cat-header .main-cat-title { font-size: 14px; }
.sidebar.compact .main-cat-header .cat-count { font-size: 10px; }
.sidebar.compact .subtopic-header { padding: 4px 10px; }
.sidebar.compact .subtopic-header .subtopic-title { font-size: 14px; }
.sidebar.compact .subtopic-header .cat-count { font-size: 10px; }

/* main content */
.main-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 30px 50px;
  background: var(--bg-main);
}

.loading {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.welcome-inner {
  text-align: center;
  padding: 100px 20px;
  color: var(--text-muted);
}

.welcome-inner h2 { color: var(--text-dim); margin-bottom: 10px; font-size: 26px; }

/* breadcrumb & badges */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.breadcrumb span { color: var(--text-dim); }
.breadcrumb .bc-sep { color: var(--text-muted); }

.question-grade { margin-bottom: 8px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.grade-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.grade-trainee { background: rgba(76,175,80,0.15); color: #81c784; }
.grade-junior { background: rgba(33,150,243,0.15); color: #64b5f6; }
.grade-middle { background: rgba(255,152,0,0.15); color: #ffb74d; }
.grade-senior { background: rgba(244,67,54,0.15); color: #e57373; }

.popular-badge {
  background: rgba(255,213,79,0.12);
  color: #ffd54f;
  border: 1px solid rgba(255,213,79,0.25);
}

/* question */
.question-title {
  font-size: 29px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.3;
}

.question-subtitle {
  font-size: 16px;
  color: var(--text);
  margin-bottom: 16px;
}

/* status bar */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
}

.status-label { font-size: 13px; color: var(--text-muted); }

.status-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: transparent;
  cursor: pointer;
  transition: all .15s;
  color: var(--text-muted);
}


.status-btn-repeat.active { background: rgba(248,81,73,0.15); border-color: #f85149; color: #f85149; }
.status-btn-learned.active { background: rgba(63,185,80,0.15); border-color: #3fb950; color: #3fb950; }

/* explanation */
.explanation-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  overflow: hidden;
}

.explanation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  cursor: pointer;
}

.explanation-label {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.explanation-label::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.expand-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color .15s;
}

.expand-btn:hover { color: var(--text); }
.expand-btn svg { transition: transform .2s; }
.expand-btn.open svg { transform: rotate(180deg); }

.explanation-content {
  display: none;
  padding: 0 20px 20px;
  color: var(--text-dim);
  line-height: 1.7;
  font-size: 15px;
}

.explanation-content.open { display: block; }
.explanation-content p { color: var(--text); margin-bottom: 8px; }

/* prev/next nav */
.question-nav { display: flex; justify-content: space-between; gap: 12px; }

.nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.nav-btn:active {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

.nav-btn:disabled { opacity: 0.3; cursor: default; }
.nav-btn:disabled:hover { background: var(--bg-card); border-color: var(--border); }

/* typography */
code.inline-code {
  background: #1e1e2e;
  color: #79c0ff;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
}

pre {
  background: #1a1b26;
  color: #c9d1d9;
  padding: 10px;
  border-radius: 6px;
  margin: 12px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

pre code {
  font-family: 'JetBrains Mono', monospace;
  background: transparent;
  color: inherit;
  font-size: 13px;
  line-height: 1.6;
  border: none;
  white-space: pre-wrap;
  word-break: break-word;
}

blockquote {
  border-left: 3px solid var(--accent);
  margin: 16px 0;
  color: var(--text-dim);
  font-style: italic;
  background: rgba(255,255,255,0.02);
  padding: 12px 18px;
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  background: rgba(0,0,0,0.2);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

th, td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 14px;
}

th:last-child,
td:last-child {
  border-right: none;
}

th {
  background: rgba(255,255,255,0.03);
  color: var(--text);
  font-weight: 600;
  border-bottom: 2px solid var(--accent);
}

tr:hover { background: rgba(255,255,255,0.02); }
tr:last-child td { border-bottom: none; }

hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }

h3, h4, h5 { color: var(--text); margin: 16px 0; }
h3 { font-size: 21px; }
h4 { font-size: 18px; }
h5 { font-size: 17px; }
h6 { font-size: 14px; }

ul, ol { margin: 12px 0; padding-left: 28px; color: var(--text-dim); }
li { margin: 6px 0; }
strong { color: var(--text); }

/* scroll to top */
.scroll-to-top {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 48px;
  height: 48px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-dim);
  transition: all .3s ease;
  opacity: 0;
  visibility: hidden;
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.scroll-to-top.visible { opacity: 1; visibility: visible; }

.scroll-to-top:hover {
  background: var(--accent);
  color: var(--text);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(102,126,234,0.4);
}

.scroll-to-top:active { transform: translateY(0); }

/* scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* ─── responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .sidebar { width: 260px; min-width: 260px; }
  .main-content { padding: 20px 24px; }
  .topbar-search { width: 220px; }
}

@media (max-width: 768px) {
  .topbar { padding-inline: 16px; }
  .app-layout { padding-inline: 0; }
  .main-content { padding: 20px 16px; }

  .mobile-drawer-toggle { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    bottom: 0;
    width: 85%;
    max-width: 340px;
    min-width: 0;
    z-index: 300;
    transition: left .3s ease;
    border-right: none;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.7);
  }

  .sidebar.open { left: 0; }

  .sidebar-header { display: flex; }

  /* Оверлей — только когда активен */
  .drawer-overlay {
    display: none;
    z-index: 200;
  }

  .drawer-overlay.active {
    display: block;
    opacity: 1;
  }

  .topbar-search { flex: 1; width: auto; }

  .search-results {
    left: 16px;
    right: 16px;
    width: auto;
  }

  .explanation-content table,
  .main-content table {
    table-layout: fixed;
    word-wrap: break-word;
    max-width: 100%;
    overflow-wrap: anywhere;
    min-width: 0;
    overflow: hidden;
  }

  .explanation-content table td,
  .explanation-content table th {
    white-space: normal;
    min-width: 100px;
  }
}

@media (max-width: 640px) {
  .main-content { padding: 16px 12px; }
  .question-title { font-size: 22px; line-height: 1.25; }
  .question-subtitle { font-size: 14px; }
  .breadcrumb { font-size: 11px; margin-bottom: 16px; flex-wrap: wrap; }
  .explanation-section { margin-bottom: 20px; }
  .explanation-header { padding: 12px 14px; }
  .explanation-label { font-size: 16px; }
  .explanation-content { padding: 0 14px 16px; font-size: 14px; line-height: 1.6; }
  .question-nav { flex-direction: column; gap: 8px; }
  .nav-btn { width: 100%; justify-content: center; }
  .scroll-to-top { bottom: 20px; right: 20px; width: 44px; height: 44px; }
  .status-bar { margin-bottom: 20px; }
  .grade-badge { font-size: 10px; padding: 2px 8px; }
  code.inline-code { font-size: 12px; padding: 1px 4px; }
  pre { padding: 8px; font-size: 12px; margin: 10px 0; }
  pre code { font-size: 12px; }
  table { font-size: 13px; }
  th, td { padding: 8px; font-size: 12px; }
  h3 { font-size: 18px; }
  h4 { font-size: 16px; }
  h5 { font-size: 15px; }
}

@media (max-width: 375px) {
  .topbar { padding-inline: 12px; gap: 8px; }
  .app-layout { padding-inline: 0; }
  .main-content { padding: 12px 10px; }
  .mobile-drawer-toggle { padding: 6px 10px; font-size: 12px; }
  .mobile-drawer-toggle svg { width: 18px; height: 18px; }
  .topbar-search { font-size: 12px; }
  .question-title { font-size: 20px; }
  .sidebar { width: 90%; max-width: 300px; }
  .sidebar-title { font-size: 16px; }
}

@media (hover: hover) {
  .sidebar-question:hover {
    background: var(--bg-hover);
    color: var(--text-dim);
  }

  .cat-header:hover {
    background: var(--bg-hover);
    color: var(--text);
  }

  .subcat-header:hover {
    background: var(--bg-hover);
    color: var(--text);
  }

  .subtopic-header:hover {
    background: var(--bg-hover);
    color: var(--text);
  }

  .nav-btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
  }

  .status-btn:hover { border-color: var(--text-dim); color: var(--text-dim); }
}
