/* ===========================================================
   JavaScript.info — O'zbekcha variant
   Umumiy uslublar (stylesheet)
   =========================================================== */

:root {
  --brand: #f0db4f;          /* JavaScript sariq rangi */
  --brand-dark: #d9c43e;
  --ink: #1a1a2e;
  --ink-soft: #3d3d5c;
  --muted: #6b7280;
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --bg-code: #1e1e2e;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 8px 24px rgba(0, 0, 0, .04);
  --max: 1180px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--ink);
  color: #fff;
  border-bottom: 3px solid var(--brand);
}
.site-header .inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  color: #fff;
}
.logo:hover { text-decoration: none; }
.logo .mark {
  background: var(--brand);
  color: var(--ink);
  font-weight: 900;
  padding: 4px 8px;
  border-radius: 6px;
  font-family: var(--mono);
  letter-spacing: -1px;
}
.site-nav a {
  color: #d1d5db;
  margin-inline-start: 22px;
  font-weight: 500;
  font-size: .95rem;
}
.site-nav a:hover { color: #fff; text-decoration: none; }

/* ---------- Layout ---------- */
.layout {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 20px;
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 36px;
  align-items: start;
}
.sidebar {
  position: sticky;
  top: 78px;
  padding: 28px 0;
  max-height: calc(100vh - 78px);
  overflow-y: auto;
}
.sidebar h3 {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 22px 0 8px;
}
.sidebar ol { list-style: none; margin: 0; padding: 0; counter-reset: lesson; }
.sidebar li { counter-increment: lesson; }
.sidebar li a {
  display: block;
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--ink-soft);
  font-size: .93rem;
}
.sidebar li a::before {
  content: counter(lesson) ". ";
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.sidebar li a:hover { background: var(--bg-soft); text-decoration: none; }
.sidebar li a.active {
  background: var(--brand);
  color: var(--ink);
  font-weight: 600;
}
.sidebar li a.active::before { color: var(--ink-soft); }

.content { padding: 30px 0 60px; min-width: 0; }

/* ---------- Nested sidebar (parts → chapters → lessons) ---------- */
/* Qidiruv maydoni */
.side-search { position: sticky; top: 0; background: var(--bg); padding: 4px 4px 10px; z-index: 2; }
.side-search input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: .9rem;
  font-family: inherit;
  background: var(--bg-soft);
  color: var(--ink);
}
.side-search input:focus { outline: 2px solid var(--brand); outline-offset: -1px; background: #fff; }
.side-noresult { color: var(--muted); font-size: .85rem; padding: 8px 10px; }
/* Dars ICHIDAN (matndan) topilgan natijaga belgi */
.sidebar li.content-hit > a::after {
  content: " · matn ichida";
  color: var(--muted);
  font-size: .72em;
  font-style: italic;
}

/* Qism (part) — birinchi daraja yig'iladigan */
.sidebar .part-group { margin: 2px 0; }
.sidebar summary.part-summary {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--brand-dark);
  font-weight: 800;
  padding: 8px 8px;
  border-radius: 8px;
}
.sidebar summary.part-summary:hover { background: #fffbe6; }

.sidebar details { margin: 0 0 1px; }
.sidebar summary {
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  font-weight: 600;
  font-size: .9rem;
  color: var(--ink);
  list-style: none;
  user-select: none;
}
.sidebar summary::-webkit-details-marker { display: none; }
.sidebar summary::before {
  content: "▸";
  display: inline-block;
  margin-inline-end: 6px;
  color: var(--muted);
  transition: transform .15s ease;
  font-size: .8em;
}
.sidebar details[open] > summary::before { transform: rotate(90deg); }
.sidebar summary:hover { background: var(--bg-soft); }
.sidebar .chapter-group { margin-inline-start: 6px; }
.sidebar details ol {
  list-style: none;
  margin: 2px 0 8px;
  padding: 0 0 0 18px;
  counter-reset: none;
}
.sidebar details li { counter-increment: none; }
.sidebar details li a { font-size: .88rem; padding: 5px 10px; }
.sidebar details li a::before { content: none; }
/* Qidiruvda yashirilgan elementlar */
.sidebar li.hidden, .sidebar .chapter-group.hidden, .sidebar .part-group.hidden { display: none; }

/* Footer muallif havolalari */
.site-footer .author a { color: var(--accent); font-weight: 600; }

/* Breadcrumb (chapter name above lesson title) */
.crumbs {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 6px;
}

/* Home page part / chapter headings */
.part-head {
  font-size: 1.7rem;
  margin: 44px 0 4px;
  padding-bottom: 8px;
  border-bottom: 3px solid var(--brand);
}
.chapter-head {
  font-size: 1.2rem;
  margin: 26px 0 12px;
  color: var(--ink-soft);
}

/* ---------- Hero (home) ---------- */
.hero {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: #fff;
  border-radius: 16px;
  padding: 56px 44px;
  margin-bottom: 40px;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "{ }";
  position: absolute;
  right: 30px;
  bottom: -20px;
  font-family: var(--mono);
  font-size: 12rem;
  color: rgba(240, 219, 79, .08);
  font-weight: 900;
}
.hero h1 { font-size: 2.6rem; margin: 0 0 12px; line-height: 1.15; }
.hero p { font-size: 1.15rem; color: #cbd5e1; max-width: 620px; margin: 0 0 26px; }
.hero .btn { position: relative; z-index: 1; }

.btn {
  display: inline-block;
  background: var(--brand);
  color: var(--ink);
  font-weight: 700;
  padding: 12px 26px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 1rem;
  transition: transform .12s ease, background .12s ease;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; transform: translateY(-1px); }
.btn.secondary { background: transparent; color: var(--accent); border: 2px solid var(--accent); }
.btn.secondary:hover { background: var(--accent); color: #fff; }

/* ---------- Lesson cards (home) ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  background: var(--bg);
  transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
  display: block;
  color: inherit;
}
.card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-3px);
  border-color: var(--brand);
  text-decoration: none;
}
.card .num {
  font-family: var(--mono);
  font-weight: 800;
  color: var(--brand-dark);
  font-size: 1.4rem;
}
.card h3 { margin: 6px 0 8px; font-size: 1.12rem; color: var(--ink); }
.card p { margin: 0; color: var(--muted); font-size: .92rem; }

/* ---------- Article / lesson content ---------- */
.article h1 { font-size: 2.1rem; margin: 0 0 8px; line-height: 1.2; }
.article .lead { font-size: 1.12rem; color: var(--ink-soft); margin: 0 0 28px; }
.article h2 {
  font-size: 1.5rem;
  margin: 40px 0 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.article h3 { font-size: 1.2rem; margin: 26px 0 10px; }
.article p { margin: 14px 0; }
.article ul, .article ol { padding-inline-start: 24px; }
.article li { margin: 6px 0; }
.article code {
  font-family: var(--mono);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 6px;
  font-size: .88em;
  color: #be185d;
}

/* Callout / note boxes */
.note, .warn, .tip {
  border-radius: var(--radius);
  padding: 14px 18px 14px 44px;
  margin: 22px 0;
  position: relative;
  font-size: .96rem;
}
.note::before, .warn::before, .tip::before {
  position: absolute;
  left: 16px;
  top: 14px;
  font-size: 1.1rem;
}
.note { background: #eff6ff; border-left: 4px solid var(--accent); }
.note::before { content: "ℹ️"; }
.warn { background: #fef2f2; border-left: 4px solid var(--danger); }
.warn::before { content: "⚠️"; }
.tip { background: #f0fdf4; border-left: 4px solid var(--success); }
.tip::before { content: "💡"; }

/* ---------- Interactive code playground ---------- */
.playground {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 24px 0;
  box-shadow: var(--shadow);
}
.playground .pg-bar {
  background: var(--bg-code);
  color: #cbd5e1;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .82rem;
  font-family: var(--mono);
}
.playground .pg-bar .dots { display: flex; gap: 6px; }
.playground .pg-bar .dots span {
  width: 11px; height: 11px; border-radius: 50%; display: inline-block;
}
.dots .r { background: #ff5f56; }
.dots .y { background: #ffbd2e; }
.dots .g { background: #27c93f; }
.playground textarea {
  width: 100%;
  min-height: 130px;
  background: var(--bg-code);
  color: #e4e4e7;
  border: none;
  padding: 16px;
  font-family: var(--mono);
  font-size: .9rem;
  line-height: 1.6;
  resize: vertical;
  tab-size: 2;
}
.playground textarea:focus { outline: 2px solid var(--brand); outline-offset: -2px; }
.playground .pg-actions {
  background: #15151f;
  padding: 10px 14px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.pg-run {
  background: var(--brand);
  color: var(--ink);
  border: none;
  border-radius: 7px;
  padding: 7px 18px;
  font-weight: 700;
  cursor: pointer;
  font-size: .9rem;
}
.pg-run:hover { background: var(--brand-dark); }
.pg-clear {
  background: transparent;
  color: #9ca3af;
  border: 1px solid #374151;
  border-radius: 7px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: .9rem;
}
.pg-clear:hover { color: #fff; border-color: #6b7280; }
.pg-output {
  background: #0d0d15;
  color: #e4e4e7;
  font-family: var(--mono);
  font-size: .86rem;
  padding: 14px 16px;
  min-height: 24px;
  white-space: pre-wrap;
  word-break: break-word;
  border-top: 1px solid #262636;
}
.pg-output .err { color: #f87171; }
.pg-output .muted { color: #6b7280; }

/* Static (non-editable) code block */
pre.code {
  background: var(--bg-code);
  color: #e4e4e7;
  padding: 16px 18px;
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: .88rem;
  line-height: 1.6;
  margin: 20px 0;
}
pre.code code {
  background: none; border: none; padding: 0; color: inherit; font-size: inherit;
}

/* ---------- Lesson footer nav ---------- */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 50px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.lesson-nav a {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  transition: border-color .15s ease, background .15s ease;
}
.lesson-nav a:hover { border-color: var(--brand); background: var(--bg-soft); text-decoration: none; }
.lesson-nav a.next { text-align: end; }
.lesson-nav .dir { display: block; font-size: .8rem; color: var(--muted); }
.lesson-nav .ttl { font-weight: 600; color: var(--ink); }

/* ---------- Footer ---------- */
.site-footer {
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
  margin-top: 60px;
}
.site-footer .inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 30px 20px;
  color: var(--muted);
  font-size: .9rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

/* ---------- Mobile ---------- */
.menu-toggle {
  display: none;
  background: none;
  border: 1px solid #374151;
  color: #fff;
  border-radius: 7px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 1.2rem;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }

  /* Yon menyu — kontent USTIDA ochiladigan chap "drawer" (overlay) */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 86%;
    max-width: 340px;
    max-height: 100vh;
    margin: 0;
    padding: 16px 16px 40px;
    background: var(--bg);
    box-shadow: 4px 0 24px rgba(0, 0, 0, .25);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 300;
    transform: translateX(-100%);
    transition: transform .25s ease;
    border: none;
    display: block;          /* ko'rinish transform bilan boshqariladi */
  }
  .sidebar.open { transform: translateX(0); }

  /* Orqa fon (backdrop) — bosilganda menyu yopiladi */
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 250;
    opacity: 0;
    visibility: hidden;
    transition: opacity .25s ease, visibility .25s ease;
  }
  .sidebar-backdrop.show { opacity: 1; visibility: visible; }

  /* Menyu ochiq bo'lganda sahifa aylanmasin */
  body.nav-open { overflow: hidden; }

  /* Drawer ichidagi yopish tugmasi */
  .side-close {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 6px;
    font-weight: 800;
    color: var(--ink);
  }
  .side-close button {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1.2rem;
    line-height: 1;
    padding: 4px 10px;
    cursor: pointer;
    color: var(--ink);
  }

  .menu-toggle { display: inline-block; }
  .site-nav { display: none; }
  .hero { padding: 40px 26px; }
  .hero h1 { font-size: 2rem; }
  .hero::after { display: none; }
}

/* Yopish paneli faqat mobil drawerda ko'rinadi */
.side-close { display: none; }
