/* ==========================================================================
   v3 — NES.css, unmodified + a thin RTL/font layer + page chrome
   --------------------------------------------------------------------------
   This file is NOT a theme. It does three things and nothing else:

     1. font layer    — NES.css declares  font-family:"Press Start 2P"  with no
                        fallback and ships no @font-face. The font is hosted here
                        (12 KB) so nothing is fetched from a CDN.
     2. RTL layer     — scoped to [dir="rtl"]. NES.css is LTR-only; the rules
                        below are the complete list of what actually breaks.
     3. page chrome   — the lab shell (rail, topbar, section grid). Plain CSS,
                        no component styling: every component on the page is
                        NES.css itself, unmodified.
   ========================================================================== */

@font-face {
  font-family: "Press Start 2P";
  src: url("../fonts/press-start-2p.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn.woff2") format("woff2-variations"),
       url("../fonts/Vazirmatn.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --ink: #212529;
  --paper: #ffffff;
  --paper-2: #f4f4f1;
  --rule: #212529;
  --muted: #6c757d;
  --muted-2: #adafbc;
  --primary: #209cee;
  --success: #92cc41;
  --warning: #f7d51d;
  --error: #e76e55;
  --ui: "Vazirmatn", "Segoe UI", system-ui, Tahoma, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --rail: 264px;
}

/* ==========================================================================
   1. font layer
   NES.css: html, body, pre, code, kbd, samp { font-family:"Press Start 2P" }
   Class-scoped selectors below outrank it (0,1,2 > 0,0,1) and load after it.
   ========================================================================== */

html.f-pixel,
html.f-pixel body,
html.f-pixel pre,
html.f-pixel code,
html.f-pixel kbd,
html.f-pixel samp { font-family: "Press Start 2P"; }

/* hybrid = NES.css's own stack with a Persian fallback appended. Press Start 2P
   has no Arabic glyphs, so the browser resolves per glyph: Latin and digits in
   pixels, Persian in Vazirmatn. No JS, no font splitting. */
html.f-hybrid,
html.f-hybrid body,
html.f-hybrid pre,
html.f-hybrid code,
html.f-hybrid kbd,
html.f-hybrid samp { font-family: "Press Start 2P", "Vazirmatn", monospace; }

html.f-vazir,
html.f-vazir body,
html.f-vazir pre,
html.f-vazir code,
html.f-vazir kbd,
html.f-vazir samp { font-family: "Vazirmatn", system-ui, sans-serif; }

/* Persian needs more leading than NES.css's 1.5 — its line box was built for a
   Latin pixel face. Only the two Persian-capable modes are touched. */
html.f-hybrid body,
html.f-vazir body { line-height: 1.9; }

html.f-pixel body { line-height: 2.1; }

/* ==========================================================================
   2. RTL layer — complete list, scoped to [dir="rtl"]
   Everything NES.css positions with physical left/right that carries meaning
   for reading order. Pixel sprites are deliberately NOT mirrored: the art is
   the art. Balloon tails are NOT mirrored either — from-left / from-right are
   named sides, not reading-order sides.
   ========================================================================== */

/* reboot puts text-align:left on <html>; dir="rtl" does not override an
   explicit alignment, so every line in the document stays left-aligned. */
[dir="rtl"] { text-align: right; }

/* checkbox: the 16px art is drawn at left:-28px inside a 28px gap that the
   input's own margin-left opens. Mirror the gap and mirror the shadow. */
[dir="rtl"] .nes-checkbox {
  margin-left: 0;
  margin-right: 28px;
}

[dir="rtl"] .nes-checkbox + span::before,
[dir="rtl"] .nes-checkbox:checked + span::before,
[dir="rtl"] .nes-checkbox:focus + span::before,
[dir="rtl"] .nes-checkbox:checked:focus + span::before {
  left: auto;
  right: -28px;
  -webkit-transform: scaleX(-1);
  transform: scaleX(-1);
}

/* radio: same construction, 20px gap */
[dir="rtl"] .nes-radio {
  margin-left: 0;
  margin-right: 20px;
}

[dir="rtl"] .nes-radio + span::before,
[dir="rtl"] .nes-radio:checked + span::before,
[dir="rtl"] .nes-radio:focus + span::before,
[dir="rtl"] .nes-radio:checked:focus + span::before {
  left: auto;
  right: -20px;
  -webkit-transform: scaleX(-1);
  transform: scaleX(-1);
}

/* select: extra padding and the arrow live on the right. Swap both. The arrow
   art is symmetric on its vertical axis, so it is moved, not mirrored. */
[dir="rtl"] .nes-select select {
  padding: 0.5rem 1rem 0.5rem 2.5rem;
}

[dir="rtl"] .nes-select::after {
  right: auto;
  left: 9px;
}

/* lists: bullets are drawn 22px to the left of the item. The list's own
   padding flips with dir, so only the art has to follow. */
[dir="rtl"] .nes-list.is-disc li::before,
[dir="rtl"] .nes-list.is-circle li::before {
  left: auto;
  right: -22px;
  -webkit-transform: scaleX(-1);
  transform: scaleX(-1);
}

/* inline field label: NES.css reserves its 1.5rem on the right and right-aligns
   it, which in RTL piles the gap onto the wrong side. */
[dir="rtl"] .nes-field.is-inline > label {
  margin-right: 0;
  margin-left: 1.5rem;
  text-align: right;
}

/* ==========================================================================
   3. page chrome — lab shell only
   ========================================================================== */

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background-color: var(--paper-2);
  /* 8px dot grid: two hard 2px squares, no anti-aliasing — the "8-bit" grid */
  background-image:
    linear-gradient(90deg, rgba(33, 37, 41, 0.07) 2px, transparent 2px),
    linear-gradient(rgba(33, 37, 41, 0.07) 2px, transparent 2px);
  background-size: 8px 8px;
  background-position: 0 0;
}

.shell {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  align-items: start;
  min-height: 100vh;
}

/* ---- rail (first column: right edge in RTL) ---- */

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 16px 14px 18px;
  background: var(--paper);
  border-inline-end: 4px solid var(--rule);
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--rule);
}

.brand__mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: #fff;
  font-family: var(--mono);
  font-size: 15px;
  flex: 0 0 auto;
  /* stepped 4px corner, the NES.css border trick in one line */
  box-shadow: 2px 0 #fff, -2px 0 #fff, 0 2px #fff, 0 -2px #fff;
}

.brand__name { font-family: var(--ui); font-size: 13px; font-weight: 700; line-height: 1.4; }
.brand__sub { font-family: var(--ui); font-size: 11px; color: var(--muted); line-height: 1.6; }

.brand__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 14px;
  font-family: var(--mono);
  font-size: 10px;
}

.tag {
  display: inline-block;
  padding: 3px 6px;
  border: 2px solid var(--rule);
  background: #fff;
  color: var(--ink);
  white-space: nowrap;
}

.tag--ink { background: var(--ink); color: #fff; }
.tag--primary { background: var(--primary); color: #fff; border-color: var(--primary); }

.rail__label {
  font-family: var(--ui);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 6px 0 6px;
}

.toc { list-style: none; margin: 0; padding: 0; }
.toc a {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 6px;
  align-items: baseline;
  padding: 7px 6px;
  font-family: var(--ui);
  font-size: 12px;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid #e7e7e7;
}
.toc a:hover { background: var(--paper-2); }
.toc a.is-on { background: var(--ink); color: #fff; }
.toc a.is-on .toc__n,
.toc a.is-on .toc__c { color: #fff; }
.toc__n { font-family: var(--mono); font-size: 10px; color: var(--muted); }
.toc__c { font-family: var(--mono); font-size: 10px; color: var(--muted-2); }

.rail__foot {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 2px solid var(--rule);
  font-family: var(--ui);
  font-size: 11px;
  line-height: 1.9;
  color: var(--muted);
}
.rail__foot b { color: var(--ink); font-family: var(--mono); font-size: 12px; }

/* ---- content column ---- */

.content { min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  padding: 10px 18px;
  background: var(--paper);
  border-bottom: 4px solid var(--rule);
}

.ctl { display: flex; align-items: center; gap: 8px; }
.ctl__label {
  font-family: var(--ui);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

/* the three controls are real .nes-select components; they are narrower than
   the component's default because the topbar is a chrome area, not a demo */
.ctl .nes-select { width: 168px; margin: 0; }
.ctl .nes-select select { font-size: 11px; }
.ctl--ver .nes-select { width: 150px; }

.topbar__spacer { flex: 1 1 auto; }

.topbar__count {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
}

main { padding: 0 18px 56px; }

/* ---- hero ---- */

.hero {
  margin: 18px 0 26px;
  padding: 18px 18px 16px;
  background: var(--paper);
  border: 4px solid var(--rule);
  box-shadow: 6px 6px 0 0 var(--rule);
}

.hero__eyebrow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 12px;
}

.hero h1 {
  font-family: var(--ui);
  font-size: 26px;
  line-height: 1.35;
  margin: 0 0 10px;
  font-weight: 700;
}
.hero h1 span { font-family: var(--mono); font-size: 15px; color: var(--muted); }

.hero p {
  font-family: var(--ui);
  font-size: 13px;
  line-height: 2;
  margin: 0;
  max-width: 74ch;
  color: #33383d;
}

.hero__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin-top: 16px;
  border: 2px solid var(--rule);
  width: fit-content;
}

.hero__stat {
  padding: 8px 14px;
  border-inline-start: 2px solid var(--rule);
  font-family: var(--ui);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.6;
}
.hero__stat:first-child { border-inline-start: 0; }
.hero__stat b {
  display: block;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 3px;
}

/* ---- sections ---- */

.sec { margin: 0 0 30px; scroll-margin-top: 74px; }

.sec__head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: baseline;
  padding: 0 0 8px;
  margin-bottom: 14px;
  border-bottom: 4px solid var(--rule);
}

.sec__n {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--ink);
  color: #fff;
  padding: 3px 7px;
}

.sec__t { font-family: var(--ui); font-size: 17px; font-weight: 700; margin: 0; }

.sec__c {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  margin-inline-start: auto;
}

.sec__note {
  flex-basis: 100%;
  font-family: var(--ui);
  font-size: 12px;
  line-height: 1.95;
  color: var(--muted);
  margin: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
}

.cell {
  grid-column: span 12;
  min-width: 0;
  background: var(--paper);
  border: 2px solid var(--rule);
  padding: 0 0 14px;
  overflow: hidden;
}

.cell--3 { grid-column: span 3; }
.cell--4 { grid-column: span 4; }
.cell--6 { grid-column: span 6; }
.cell--8 { grid-column: span 8; }
.cell--9 { grid-column: span 9; }

.cell__bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  align-items: center;
  padding: 6px 10px;
  margin-bottom: 14px;
  border-bottom: 2px dashed #d6d6d0;
  background: #fbfbf9;
}

.cell__t {
  font-family: var(--ui);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
}

.cell__cls {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--muted);
  background: #f1f1ee;
  padding: 2px 5px;
  margin-inline-start: auto;
  direction: ltr;
  unicode-bidi: isolate;
  /* longest label is 60 characters; at 390px a nowrap label pushed the cell
     past its own padding box and got clipped by overflow:hidden */
  white-space: normal;
  overflow-wrap: anywhere;
  max-width: 100%;
  min-width: 0;
}

.cell__body { padding: 0 14px; }

/* Chrome's UA sheet gives every [open] <dialog> position:absolute + margin:auto,
   which floats it over the whole page. A specimen belongs inside its card, so
   this pins it. It is the only rule here that touches a NES.css component's box
   model, and it exists because of a UA default — not because of NES.css. */
.cell .nes-dialog[open] { position: static; margin: 0; max-width: none; }

/* demo helpers — layout only, never component styling */
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row--end { align-items: flex-end; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.swatch { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 9.5px; }
.swatch i { width: 26px; height: 26px; display: block; border: 2px solid var(--rule); }
.note { font-family: var(--ui); font-size: 11px; line-height: 1.9; color: var(--muted); margin: 10px 0 0; }
.ltr { direction: ltr; unicode-bidi: isolate; }

/* gap table: chrome table, deliberately NOT .nes-table, so the missing pieces
   are shown as missing */
.gap { width: 100%; border-collapse: collapse; font-family: var(--ui); font-size: 11.5px; }
.gap th, .gap td { border: 2px solid var(--rule); padding: 7px 9px; text-align: right; vertical-align: top; }
.gap th { background: var(--ink); color: #fff; font-weight: 600; font-size: 11px; }
.gap td.y { color: #2b7a0b; font-family: var(--mono); font-size: 10px; white-space: nowrap; }
.gap td.n { color: #a33; font-family: var(--mono); font-size: 10px; white-space: nowrap; }
.gap code, .gap .m { font-family: var(--mono); font-size: 10px; direction: ltr; unicode-bidi: isolate; }

/* mini panel built only from NES.css primitives */
.panel { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; }
.panel__main { grid-column: span 12; }
@media (min-width: 1000px) {
  .panel__nav { grid-column: span 3; }
  .panel__main { grid-column: span 9; }
}
.panel__nav { grid-column: span 12; }
.panel .nes-container { margin: 0; }

.foot {
  margin-top: 26px;
  padding-top: 12px;
  border-top: 4px solid var(--rule);
  font-family: var(--ui);
  font-size: 11px;
  line-height: 2;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}

/* ---- responsive ---- */

@media (max-width: 1100px) {
  .cell--3 { grid-column: span 6; }
  .cell--4 { grid-column: span 6; }
  .cell--9 { grid-column: span 12; }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: static;
    height: auto;
    border-inline-end: 0;
    border-bottom: 4px solid var(--rule);
  }
  .toc {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 6px;
  }
  .toc li { flex: 0 0 auto; }
  .toc a {
    grid-template-columns: auto auto;
    border: 2px solid var(--rule);
    white-space: nowrap;
    padding: 5px 8px;
  }
  .rail__foot { display: none; }
  .topbar { position: static; }
  .sec { scroll-margin-top: 10px; }
  .hero { box-shadow: 4px 4px 0 0 var(--rule); }
}

@media (max-width: 700px) {
  main { padding: 0 12px 40px; }
  .cell--3, .cell--4, .cell--6, .cell--8, .cell--9 { grid-column: span 12; }
  .ctl, .ctl .nes-select { width: 100%; }
  .ctl { flex-direction: column; align-items: stretch; }
  .ctl .nes-select { width: 100%; }
  .hero h1 { font-size: 21px; }
  .hero__stats { width: 100%; }
  .hero__stat { flex: 1 1 50%; }
}
