/*! SocketForge — Real-time JavaScript & WebSocket resource
 *  Main stylesheet. Hand-written, no build step required.
 *  Theme: CSS custom properties, light/dark, responsive grid. */

/* ----------------------------------------------------------------
   Design tokens
----------------------------------------------------------------- */
:root {
  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  --bg: #f7f8fb;
  --bg-elev: #ffffff;
  --bg-code: #0f172a;
  --text: #1b2333;
  --text-soft: #54607a;
  --border: #e3e8f0;
  --brand: #2f6df6;
  --brand-2: #19c1a5;
  --brand-ink: #ffffff;
  --warn-bg: #fff7e6;
  --warn-border: #f3c969;
  --warn-text: #7a5a06;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 1120px;
}

html[data-theme="dark"] {
  --bg: #0b1020;
  --bg-elev: #121a31;
  --bg-code: #060a16;
  --text: #e7ecf6;
  --text-soft: #97a3bd;
  --border: #233052;
  --brand: #5d8bff;
  --brand-2: #2bd6b6;
  --warn-bg: #2a2210;
  --warn-border: #6b5613;
  --warn-text: #ffd874;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

img { max-width: 100%; display: block; }

.container {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: 20px;
}

.muted { color: var(--text-soft); }
.center { text-align: center; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }

/* ----------------------------------------------------------------
   Header / navigation
----------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.nav {
  display: flex;
  align-items: center;
  gap: 18px;
  height: 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -.02em;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center;
  color: #fff; font-weight: 900; font-size: .95rem;
  box-shadow: var(--shadow);
}
.brand small { color: var(--text-soft); font-weight: 500; font-size: .72rem; display:block; margin-top:-4px;}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  list-style: none;
  padding: 0; margin-block: 0;
}
.nav-links a {
  display: inline-block;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-weight: 600;
  font-size: .94rem;
}
.nav-links a:hover { background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--text); text-decoration: none; }
.nav-links a.active { color: var(--brand); }

.nav-tools { display: flex; align-items: center; gap: 8px; margin-left: 8px; }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  height: 38px; min-width: 38px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 700;
  font-size: .85rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .08s ease, border-color .15s ease;
}
.icon-btn:hover { border-color: var(--brand); }
.icon-btn:active { transform: translateY(1px); }

.nav-toggle { display: none; }

/* ----------------------------------------------------------------
   Maintenance banner
----------------------------------------------------------------- */
.maintenance {
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-border);
  color: var(--warn-text);
}
.maintenance .container {
  display: flex; align-items: center; gap: 12px;
  padding-block: 10px;
  font-size: .92rem;
}
.maintenance .ico { font-size: 1.1rem; line-height: 1; }
.maintenance strong { font-weight: 800; }

/* ----------------------------------------------------------------
   Buttons
----------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: .95rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: var(--brand-ink); box-shadow: var(--shadow); }
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 88%, #000); }
.btn-ghost { background: var(--bg-elev); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--brand); }

/* ----------------------------------------------------------------
   Hero
----------------------------------------------------------------- */
.hero {
  padding: 64px 0 40px;
  background:
    radial-gradient(1200px 400px at 80% -10%, color-mix(in srgb, var(--brand) 16%, transparent), transparent),
    radial-gradient(900px 360px at 0% 0%, color-mix(in srgb, var(--brand-2) 12%, transparent), transparent);
}
.hero h1 {
  font-size: clamp(2rem, 4.5vw, 3.2rem);
  line-height: 1.08;
  letter-spacing: -.03em;
  margin: 0 0 16px;
  max-width: 18ch;
}
.hero p.lead {
  font-size: 1.15rem;
  color: var(--text-soft);
  max-width: 62ch;
  margin: 0 0 26px;
}
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.eyebrow {
  display: inline-block;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-size: .72rem;
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  padding: 5px 10px;
  border-radius: 999px;
  margin-bottom: 18px;
}

/* ----------------------------------------------------------------
   Sections / cards
----------------------------------------------------------------- */
section { padding: 44px 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.section-head h2 { font-size: 1.6rem; letter-spacing: -.02em; margin: 0; }
.section-head a { font-weight: 700; font-size: .92rem; }

.grid { display: grid; gap: 20px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .15s ease;
  display: flex; flex-direction: column;
}
.card:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--brand) 45%, var(--border)); }
.card .tag {
  align-self: flex-start;
  font-size: .72rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
  color: var(--brand-2);
  background: color-mix(in srgb, var(--brand-2) 14%, transparent);
  padding: 4px 9px; border-radius: 999px; margin-bottom: 12px;
}
.card h3 { margin: 0 0 8px; font-size: 1.18rem; letter-spacing: -.01em; }
.card h3 a { color: var(--text); }
.card p { margin: 0 0 16px; color: var(--text-soft); font-size: .96rem; }
.card .meta { margin-top: auto; font-size: .82rem; color: var(--text-soft); display: flex; gap: 10px; align-items: center; }
.card .meta .dot { width: 4px; height: 4px; border-radius: 50%; background: var(--text-soft); opacity: .6; }

.feature-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.feature-list li { display: flex; gap: 12px; }
.feature-list .ic {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px;
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  color: var(--brand); display: grid; place-items: center; font-weight: 800;
}
.feature-list h4 { margin: 0 0 2px; font-size: 1rem; }
.feature-list p { margin: 0; color: var(--text-soft); font-size: .92rem; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.stat { text-align: center; }
.stat .num { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; color: var(--brand); }
.stat .lbl { color: var(--text-soft); font-size: .86rem; }

/* ----------------------------------------------------------------
   Code blocks
----------------------------------------------------------------- */
pre, code { font-family: var(--font-mono); }
code.inline {
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  color: var(--text);
  padding: 1px 6px; border-radius: 6px; font-size: .9em;
}
.codeblock {
  position: relative;
  background: var(--bg-code);
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, #fff 8%, var(--bg-code));
  margin: 18px 0;
  overflow: hidden;
}
.codeblock .codebar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  color: #94a3b8; font-size: .78rem; font-family: var(--font-mono);
}
.codeblock .codebar .dots { display: flex; gap: 6px; margin-right: 6px; }
.codeblock .codebar .dots i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.codeblock .codebar .dots i:nth-child(1){ background:#ff5f57;}
.codeblock .codebar .dots i:nth-child(2){ background:#febc2e;}
.codeblock .codebar .dots i:nth-child(3){ background:#28c840;}
.codeblock .codebar .copy {
  margin-left: auto; cursor: pointer; color: #94a3b8;
  background: transparent; border: 0; font-size: .78rem; font-family: var(--font-mono);
}
.codeblock .codebar .copy:hover { color: #fff; }
.codeblock pre {
  margin: 0; padding: 16px 18px; overflow-x: auto;
  color: #e2e8f0; font-size: .88rem; line-height: 1.6;
}
.codeblock .tok-kw { color: #c792ea; }
.codeblock .tok-str { color: #c3e88d; }
.codeblock .tok-com { color: #6b7a99; font-style: italic; }
.codeblock .tok-fn { color: #82aaff; }
.codeblock .tok-num { color: #f78c6c; }

/* ----------------------------------------------------------------
   Article
----------------------------------------------------------------- */
.article { padding: 40px 0 60px; }
.article-wrap { display: grid; grid-template-columns: minmax(0,1fr) 260px; gap: 40px; }
.prose { max-width: 72ch; }
.prose h1 { font-size: clamp(1.8rem, 3.5vw, 2.5rem); line-height: 1.15; letter-spacing: -.025em; margin: 0 0 10px; }
.prose h2 { font-size: 1.5rem; margin: 38px 0 12px; letter-spacing: -.01em; }
.prose h3 { font-size: 1.18rem; margin: 26px 0 8px; }
.prose p { margin: 0 0 16px; }
.prose ul, .prose ol { margin: 0 0 16px; padding-left: 22px; }
.prose li { margin: 6px 0; }
.prose blockquote {
  margin: 20px 0; padding: 12px 18px;
  border-left: 4px solid var(--brand);
  background: color-mix(in srgb, var(--brand) 7%, transparent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-soft);
}
.article-meta { color: var(--text-soft); font-size: .9rem; margin-bottom: 26px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, var(--brand), var(--brand-2)); display: inline-grid; place-items: center; color: #fff; font-weight: 800; font-size: .8rem; }
.crumbs { font-size: .85rem; color: var(--text-soft); margin-bottom: 14px; }
.crumbs a { color: var(--text-soft); }

.toc {
  position: sticky; top: 90px;
  align-self: start;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: var(--radius);
  padding: 18px;
  font-size: .9rem;
}
.toc h4 { margin: 0 0 10px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-soft); }
.toc ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.toc a { color: var(--text-soft); }
.toc a:hover { color: var(--brand); }

/* Tables inside prose (comparison / reference) */
.table-wrap { overflow-x: auto; margin: 20px 0; border: 1px solid var(--border); border-radius: var(--radius); }
table.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.tbl th, table.tbl td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.tbl thead th { background: color-mix(in srgb, var(--brand) 9%, var(--bg-elev)); font-weight: 700; color: var(--text); white-space: nowrap; }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover { background: color-mix(in srgb, var(--brand) 5%, transparent); }
table.tbl code { font-family: var(--font-mono); font-size: .86em; background: color-mix(in srgb, var(--brand) 12%, transparent); padding: 1px 5px; border-radius: 5px; }
table.tbl .yes { color: var(--brand-2); font-weight: 700; }
table.tbl .no { color: #e2557b; font-weight: 700; }

/* Definition list for FAQ / glossary */
.qa { display: grid; gap: 8px; margin: 22px 0; }
.qa details {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-elev); padding: 4px 18px;
}
.qa details[open] { border-color: color-mix(in srgb, var(--brand) 40%, var(--border)); }
.qa summary {
  cursor: pointer; font-weight: 700; padding: 12px 0; list-style: none;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.qa summary::-webkit-details-marker { display: none; }
.qa summary::after { content: "+"; color: var(--brand); font-weight: 800; font-size: 1.3rem; }
.qa details[open] summary::after { content: "−"; }
.qa details > p { margin: 0 0 14px; color: var(--text-soft); }

.tags { display: flex; gap: 8px; flex-wrap: wrap; margin: 26px 0; }
.tags a {
  font-size: .82rem; font-weight: 600;
  background: var(--bg-elev); border: 1px solid var(--border);
  padding: 5px 11px; border-radius: 999px; color: var(--text-soft);
}

/* ----------------------------------------------------------------
   Demo widget
----------------------------------------------------------------- */
.demo {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin: 24px 0;
}
.demo .demo-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: .92rem;
}
.demo .status-dot { width: 10px; height: 10px; border-radius: 50%; background: #cbd5e1; }
.demo[data-state="open"] .status-dot { background: #28c840; box-shadow: 0 0 0 4px rgba(40,200,64,.18); }
.demo[data-state="connecting"] .status-dot { background: #febc2e; animation: pulse 1s infinite; }
.demo[data-state="closed"] .status-dot { background: #ff5f57; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }
.demo .demo-body { padding: 16px; }
.demo .log {
  height: 180px; overflow-y: auto;
  background: var(--bg-code); color: #cbd5e1;
  border-radius: var(--radius-sm); padding: 12px;
  font-family: var(--font-mono); font-size: .82rem; line-height: 1.5;
  margin-bottom: 12px;
}
.demo .log .l-in { color: #82aaff; }
.demo .log .l-out { color: #c3e88d; }
.demo .log .l-sys { color: #6b7a99; }
.demo .controls { display: flex; gap: 8px; flex-wrap: wrap; }
.demo input[type=text] {
  flex: 1; min-width: 180px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-family: var(--font-mono); font-size: .9rem;
}
.demo input[type=text]:focus { outline: 2px solid color-mix(in srgb, var(--brand) 60%, transparent); border-color: var(--brand); }

/* ----------------------------------------------------------------
   Forms
----------------------------------------------------------------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 11px 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-elev); color: var(--text); font: inherit;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: 2px solid color-mix(in srgb, var(--brand) 55%, transparent); border-color: var(--brand);
}
.form-note { font-size: .85rem; color: var(--text-soft); }
.alert {
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--brand-2) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand-2) 40%, transparent);
  color: var(--text); font-size: .92rem; margin-top: 14px;
}

/* Newsletter */
.newsletter {
  background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 14%, var(--bg-elev)), color-mix(in srgb, var(--brand-2) 12%, var(--bg-elev)));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}
.newsletter form { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.newsletter input { flex: 1; min-width: 220px; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); }

/* ----------------------------------------------------------------
   Footer
----------------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  margin-top: 30px;
  padding: 40px 0 28px;
}
.footer-grid { display: grid; grid-template-columns: 1.6fr repeat(3, 1fr); gap: 28px; }
.footer-grid h5 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-soft); margin: 0 0 12px; }
.footer-grid ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.footer-grid a { color: var(--text-soft); font-size: .92rem; }
.footer-grid a:hover { color: var(--brand); }
.footer-bottom {
  margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  color: var(--text-soft); font-size: .85rem;
}

/* Lang visibility — controlled by i18n.js */
.lang { display: none; }
html[data-lang="en"] .lang-en { display: block; }
html[data-lang="ru"] .lang-ru { display: block; }
span.lang { display: none; }
html[data-lang="en"] span.lang-en { display: inline; }
html[data-lang="ru"] span.lang-ru { display: inline; }

/* ----------------------------------------------------------------
   Responsive
----------------------------------------------------------------- */
@media (max-width: 920px) {
  .article-wrap { grid-template-columns: 1fr; }
  .toc { display: none; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .nav-links {
    position: absolute; top: 64px; left: 0; right: 0;
    flex-direction: column; align-items: stretch;
    background: var(--bg-elev); border-bottom: 1px solid var(--border);
    padding: 10px; gap: 2px;
    display: none;
  }
  .nav-links.open { display: flex; }
  .nav-toggle { display: inline-flex; }
  .footer-grid { grid-template-columns: 1fr; }
}
