/* =========================================================
   MT3 — Takrorlash operatori turlari
   mamun.club / dasturlash.mamun.club uslubidagi tungi dizayn
   ========================================================= */

:root {
  --bg: #141413;
  --text: #ecebe6;
  --muted: #9e9c95;
  --border: #2e2d2a;
  --code-bg: #1c1b19;
  --term-bg: #0d0d0c;
  --term-text: #f2f2f2;
  --accent: #d9d6cc;
  --ok: #8fbd8a;
  --err: #e08c7f;
  --radius: 4px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 24px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Umumiy elementlar ---------- */

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
}

a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 3px;
}

a:hover,
a:focus-visible {
  text-decoration-color: var(--muted);
}

code,
pre,
var {
  font-family: var(--mono);
  font-size: 0.92em;
}

:not(pre) > code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.05em 0.35em;
  color: var(--text);
}

var {
  font-style: italic;
  color: var(--text);
}

h1,
h2,
h3 {
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 {
  font-size: clamp(1.6rem, 3.4vw, 2.2rem);
  margin: 0 0 12px;
}

h2 {
  font-size: clamp(1.2rem, 2.2vw, 1.45rem);
  margin: 0 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

h3 {
  font-size: 1.02rem;
  margin: 0 0 10px;
}

p {
  margin: 0 0 12px;
}

.muted {
  color: var(--muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Navigatsiya ---------- */

.site-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(20, 20, 19, 0.94);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
}

.nav-inner + .nav-inner {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  padding-bottom: 8px;
}

.nav-inner a {
  font-family: var(--mono);
  font-size: 0.82rem;
  text-decoration: none;
  color: var(--muted);
}

.nav-inner a:hover,
.nav-inner a:focus-visible {
  color: var(--text);
}

.nav-back {
  color: var(--text) !important;
}

.nav-brand {
  margin-left: auto;
}

.nav-links {
  gap: 8px 18px;
  overflow-x: auto;
  flex-wrap: nowrap;
  scrollbar-width: none;
}

.nav-links::-webkit-scrollbar {
  display: none;
}

.nav-links a {
  flex: 0 0 auto;
}

/* ---------- Sarlavha (hero) ---------- */

.hero {
  border-bottom: 1px solid var(--border);
  padding: 44px 0 36px;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 10px;
}

.hero-sub {
  color: var(--muted);
  max-width: 70ch;
  margin: 0 0 24px;
}

/* ---------- K paneli ---------- */

.k-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  max-width: 560px;
}

.k-panel label {
  font-size: 0.9rem;
  font-weight: 500;
}

.k-panel input {
  width: 76px;
  padding: 6px 10px;
  font-family: var(--mono);
  font-size: 1rem;
  text-align: center;
  color: var(--text);
  background: var(--term-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
}

.k-panel input:focus-visible {
  outline: 1px solid var(--muted);
  outline-offset: 1px;
}

.k-help {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.k-help strong {
  color: var(--text);
  font-family: var(--mono);
  font-weight: 500;
}

/* ---------- Bo'limlar ---------- */

main > section {
  padding: 40px 0;
  border-bottom: 1px solid var(--border);
}

.lead {
  font-size: 1.02rem;
  max-width: 78ch;
}

.topic-list {
  margin: 0 0 20px;
  padding-left: 20px;
  color: var(--muted);
  max-width: 80ch;
}

.topic-list li {
  margin-bottom: 6px;
}

.topic-list li::marker {
  color: var(--border);
}

.topic-list code {
  color: var(--text);
}

.task-box {
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius);
  background: var(--code-bg);
  padding: 16px 18px;
  margin: 0 0 22px;
}

.task-box p {
  margin-bottom: 12px;
  color: var(--text);
}

.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--bg);
  background: var(--accent);
  border-radius: 3px;
  padding: 1px 7px;
  margin-right: 6px;
  vertical-align: 2px;
}

.formula {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--muted);
}

.formula span {
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 4px 10px;
  background: var(--term-bg);
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin: 0;
}

.meta-grid > div {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.meta-grid dt {
  font-family: var(--mono);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 2px;
}

.meta-grid dd {
  margin: 0;
  font-size: 0.92rem;
}

/* ---------- Jadval ---------- */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  text-align: left;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--code-bg);
  border-bottom: 1px solid var(--border);
  padding: 9px 14px;
  white-space: nowrap;
}

tbody th,
tbody td {
  text-align: left;
  vertical-align: top;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

tbody tr:last-child th,
tbody tr:last-child td {
  border-bottom: 0;
}

tbody th {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  width: 1%;
}

tbody td {
  color: var(--muted);
}

tbody td code {
  color: var(--text);
}

.k-row td,
.k-row th {
  background: rgba(255, 255, 255, 0.025);
}

.test-table td {
  white-space: nowrap;
}

.test-table td:first-child {
  white-space: normal;
  min-width: 220px;
}

.test-table td[data-test-sum],
.test-table td[data-test-fact],
.test-table td[data-test-n] {
  font-family: var(--mono);
  color: var(--text);
  word-break: break-all;
  white-space: normal;
}

.ok {
  color: var(--ok) !important;
}

.fail {
  color: var(--err) !important;
}

/* ---------- Kod bloki ---------- */

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--code-bg);
  padding: 8px 12px;
}

.file-name {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}

.btn {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 0.85rem;
  line-height: 1.2;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  border-color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
}

.btn:focus-visible {
  outline: 1px solid var(--muted);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 500;
}

.btn-primary:hover {
  background: #fff;
  border-color: #fff;
}

.copy-status {
  min-height: 1.4em;
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--ok);
}

.code-block {
  margin: 0;
  padding: 16px 18px;
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: 0.85rem;
  line-height: 1.6;
  tab-size: 4;
}

.code-block code {
  font-size: inherit;
}

/* Sintaksis ranglari */
.cm { color: #75736c; font-style: italic; }
.kw { color: #cfc7b0; }
.str { color: #a9c4a1; }
.num { color: #c9b48f; }
.fn { color: #e4e0d4; }

.mini-code {
  margin: 10px 0 0;
  padding: 12px 14px;
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.84rem;
  line-height: 1.6;
}

.mini-code code {
  font-size: inherit;
}

/* ---------- Test bloki ---------- */

.test-block {
  margin-top: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  background: transparent;
}

.test-block h3 {
  font-family: var(--mono);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 500;
}

.test-block .table-scroll {
  border: 0;
}

.test-block thead th {
  background: transparent;
  padding-left: 0;
  border-bottom: 1px solid var(--border);
}

.test-block tbody th,
.test-block tbody td {
  padding-left: 0;
}

/* ---------- Demo ---------- */

.demo-form {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 0 0 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 260px;
  margin-bottom: 12px;
}

.field label {
  font-size: 0.85rem;
  color: var(--muted);
}

.field input {
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--text);
  background: var(--term-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
}

.field input:focus-visible {
  outline: 1px solid var(--muted);
  outline-offset: 1px;
}

.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.error-msg {
  margin: 12px 0 0;
  font-size: 0.88rem;
  color: var(--err);
  min-height: 0;
}

.error-msg:empty {
  display: none;
}

.terminal-output {
  margin: 0;
  padding: 16px 18px;
  overflow-x: auto;
  background: var(--term-bg);
  color: var(--term-text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.65;
  white-space: pre;
  tab-size: 4;
}

/* ---------- Savollar ---------- */

details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  padding: 0 16px;
  background: transparent;
}

details[open] {
  background: var(--code-bg);
}

summary {
  cursor: pointer;
  padding: 12px 0;
  font-weight: 500;
  list-style-position: outside;
  color: var(--text);
}

summary::marker {
  color: var(--muted);
}

summary:focus-visible {
  outline: 1px solid var(--muted);
  outline-offset: 2px;
}

details > p,
details > pre {
  color: var(--muted);
  margin-bottom: 14px;
  max-width: 82ch;
}

details > p code {
  color: var(--text);
}

/* ---------- Xulosa ---------- */

#xulosa p {
  max-width: 84ch;
  color: var(--muted);
}

#xulosa code {
  color: var(--text);
}

/* ---------- Footer ---------- */

.site-footer {
  padding: 24px 0 40px;
  font-size: 0.82rem;
  color: var(--muted);
}

.site-footer p {
  margin: 0;
  font-family: var(--mono);
}

.site-footer a {
  color: var(--muted);
}

.site-footer a:hover {
  color: var(--text);
}

/* ---------- Print / PDF ---------- */

@media print {
  @page {
    margin: 16mm;
  }

  html {
    scroll-behavior: auto;
  }

  body {
    background: #fff !important;
    color: #000 !important;
    font-size: 11pt;
    line-height: 1.45;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .site-nav,
  .site-footer,
  .k-panel,
  .code-toolbar,
  .btn,
  #demo {
    display: none !important;
  }

  main > section {
    padding: 12pt 0;
  }

  /* Chop etishda ranglar — faqat oq fon va qora matn */
  .copy-status {
    display: none !important;
  }

  .task-box p,
  .task-box h3,
  .lead,
  .meta-grid dd,
  .meta-grid dt,
  summary,
  summary code,
  tbody th,
  .meta-grid dd,
  .meta-grid dt,
  .file-name,
  .formula,
  details > p code,
  #xulosa code,
  .terminal-output {
    color: #000 !important;
  }

  .terminal-output {
    background: #fff !important;
  }

  .badge {
    background: #e5e5e5 !important;
    color: #000 !important;
  }

  .wrap,
  .nav-inner {
    max-width: none;
    padding: 0;
  }

  main > section {
    border-bottom: 0;
    padding: 12pt 0;
  }

  .hero {
    border-bottom: 1px solid #000;
    padding: 0 0 12pt;
  }

  h2 {
    border-bottom: 1px solid #000;
    page-break-after: avoid;
  }

  a {
    color: #000 !important;
    text-decoration: none;
  }

  .muted,
  .eyebrow,
  .hero-sub,
  .topic-list,
  tbody td,
  summary::marker,
  #xulosa p,
  details > p {
    color: #333 !important;
  }

  :not(pre) > code,
  .task-box,
  .meta-grid > div,
  .table-scroll,
  .code-block,
  .mini-code,
  .test-block,
  details {
    background: #fff !important;
    border-color: #999 !important;
    color: #000 !important;
  }

  .formula span {
    background: #f4f4f4 !important;
    border-color: #999 !important;
    color: #000 !important;
  }

  thead th {
    background: #fff !important;
    border-color: #999 !important;
    color: #000 !important;
  }

  var {
    color: #000 !important;
  }

  .cm { color: #555 !important; }
  .kw { color: #000 !important; font-weight: 600; }
  .str { color: #333 !important; }
  .num { color: #000 !important; }
  .fn { color: #000 !important; font-weight: 600; }
  .ok { color: #000 !important; }

  .terminal-output {
    white-space: pre-wrap;
    word-break: break-all;
  }

  .code-block code {
    white-space: pre-wrap;
  }

  details {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .code-block {
    page-break-inside: auto;
    break-inside: auto;
  }

  summary {
    list-style: none;
  }

  details > *:not(summary) {
    display: block !important;
  }
}

/* ---------- Harakatni kamaytirish ---------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .btn {
    transition: none;
  }
}

/* ---------- Kichik ekranlar ---------- */

@media (max-width: 640px) {
  .wrap,
  .nav-inner {
    padding-left: 16px;
    padding-right: 16px;
  }

  .hero {
    padding: 28px 0 24px;
  }

  .nav-links {
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .nav-links a {
    flex: 0 0 auto;
  }

  .demo-actions .btn {
    flex: 1 1 auto;
  }
}
