@font-face {
  font-family: "Schibsted Grotesk";
  src: url("../fonts/schibsted-grotesk-latin-wght-normal.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #1c2228;
  --surface: #232a32;
  --raised: #2a323b;
  --chassis: #181e29;
  --line: rgba(226, 232, 240, 0.11);
  --line-strong: rgba(226, 232, 240, 0.22);
  --text: #e8ecf0;
  --muted: #9aa7b3;
  --accent: #e5a93c;
  --accent-ink: #1a2026;
  --alpha: #e05252;
  --lcd: #c8d6cd;
  --lcd-inset: #bdcebe;
  --lcd-ink: #1a2530;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --sans: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --gutter: clamp(18px, 4.5vw, 48px);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; scrollbar-color: #3b4652 var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
}
::selection { background: rgba(229, 169, 60, 0.35); color: #fff; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
html[lang="en"] [lang="es"], html[lang="es"] [lang="en"] { display: none; }

.shell { width: 100%; max-width: 1120px; margin: 0 auto; padding-inline: var(--gutter); }

/* Header */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding-block: 18px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  font-weight: 650;
  font-size: 1rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.brand img { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line-strong); display: block; }
.top-end { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.top nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

.link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 11px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 8px;
  border: 0;
  background: transparent;
  font-family: inherit;
  cursor: pointer;
  transition: color 150ms var(--ease), background-color 150ms var(--ease);
}
.btn-app {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 700;
  transition: background-color 150ms var(--ease), transform 140ms var(--ease);
}
.btn-app:active { transform: scale(0.97); }

.switcher {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}
.switcher button {
  min-width: 40px;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}
html[lang="en"] .switcher [data-lang="en"],
html[lang="es"] .switcher [data-lang="es"] { background: var(--accent); color: var(--accent-ink); }

/* Booklet layout */
.booklet { display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px 48px; padding-block: 32px 64px; }
.toc-wrap { border-bottom: 1px solid var(--line); padding-bottom: 18px; }
.toc-label {
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}
.toc { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.toc a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: 7px;
  text-decoration: none;
  font-size: 0.88rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  transition: color 140ms var(--ease), border-color 140ms var(--ease), background-color 140ms var(--ease);
}
.toc-num { font-family: var(--mono); font-size: 0.76rem; font-weight: 800; color: var(--accent); }
.toc a[aria-current="true"] { color: var(--text); background: var(--raised); border-color: var(--accent); }

@media (min-width: 900px) {
  .booklet { grid-template-columns: 230px minmax(0, 1fr); align-items: start; padding-block: 40px 80px; }
  .toc-wrap { position: sticky; top: 24px; border-bottom: 0; border-right: 1px solid var(--line); padding: 0 22px 0 0; }
  .toc { flex-direction: column; gap: 4px; }
  .toc a { width: 100%; background: transparent; border-color: transparent; padding: 8px 10px; }
  .toc a[aria-current="true"] { background: var(--surface); border-color: var(--line-strong); }
}

/* Intro & Chapters */
.doc-head { padding-bottom: 28px; border-bottom: 1px solid var(--line); }
.doc-head h1 { margin: 0; font-size: clamp(1.85rem, 3.6vw, 2.55rem); font-weight: 700; line-height: 1.1; letter-spacing: -0.025em; }
.doc-lede { margin: 12px 0 0; max-width: 60ch; color: var(--muted); font-size: 1.02rem; }

.chapter { padding-block: 34px; border-bottom: 1px solid var(--line); scroll-margin-top: 24px; }
.chapter:last-child { border-bottom: 0; }
.ch-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.ch-num { font-family: var(--mono); font-size: 0.92rem; font-weight: 800; color: var(--accent); }
.ch-head h2 { margin: 0; font-size: clamp(1.25rem, 2.2vw, 1.5rem); font-weight: 680; letter-spacing: -0.015em; }
.ch-intro { margin: 0 0 20px; max-width: 62ch; color: var(--muted); font-size: 0.96rem; }

/* Keycaps & Reference Rows */
.ref-list { border-top: 1px solid var(--line); }
.ref-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px 20px;
  padding: 13px 10px;
  border-bottom: 1px solid var(--line);
  align-items: center;
  transition: background-color 140ms var(--ease);
}
.ref-row[data-preview] { cursor: pointer; }
.ref-row[data-preview].is-active { background: rgba(229, 169, 60, 0.08); }
@media (min-width: 640px) { .ref-row { grid-template-columns: 245px minmax(0, 1fr); } }

.combo { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.op { color: var(--muted); font-family: var(--mono); font-size: 0.85rem; font-weight: 700; padding-inline: 1px; }
.op.arrow { color: var(--accent); }

.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 26px;
  padding: 0 9px;
  border-radius: 5px;
  background: #2b303a;
  color: #f1f5f9;
  border: 1px solid #494e5b;
  box-shadow: 0 2px 0 #111419;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  user-select: none;
  transition: transform 90ms ease, box-shadow 90ms ease;
}
.key.is-shift { background: var(--accent); color: #14181f; border-color: #a6761f; box-shadow: 0 2px 0 #704f11; }
.key.is-alpha { background: var(--alpha); color: #ffffff; border-color: #9e3131; box-shadow: 0 2px 0 #661c1c; }
.key.is-pressed, .ref-row[data-preview]:active .key { transform: translateY(2px); box-shadow: 0 0 0 #111419; }

.lcd-pill {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 9px;
  border-radius: 4px;
  background: var(--lcd);
  color: var(--lcd-ink);
  border: 1px solid var(--lcd-inset);
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1;
}
.ref-desc { margin: 0; color: var(--text); font-size: 0.94rem; }

/* Hardware / LCD Diagrams */
.diagram-box {
  margin-top: 20px;
  background: var(--chassis);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 14px;
}
.diagram-box svg { display: block; width: 100%; height: auto; }
.diagram-cap { margin: 10px 2px 0; color: var(--muted); font-size: 0.84rem; }

.live-lcd {
  margin-top: 16px;
  background: var(--lcd);
  color: var(--lcd-ink);
  border-radius: 8px;
  padding: 11px 14px;
  border: 1px solid var(--lcd-inset);
  box-shadow: inset 0 2px 5px rgba(26, 37, 48, 0.22);
  font-family: var(--mono);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 16px;
}
.live-lcd-label { font-size: 0.74rem; font-weight: 700; opacity: 0.72; }
.live-lcd-val { font-size: 0.98rem; font-weight: 800; }

/* PWA Steps */
.pwa-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.pwa-item { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.pwa-item h3 { margin: 0 0 6px; font-size: 0.95rem; font-weight: 700; color: var(--accent); }
.pwa-item p { margin: 0; color: var(--muted); font-size: 0.9rem; }

/* Footer */
footer { margin-top: auto; border-top: 1px solid var(--line); }
.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 20px;
  padding-block: 16px;
  font-size: 0.88rem;
  color: var(--muted);
}
.foot nav { display: flex; flex-wrap: wrap; gap: 4px; }

@media (hover: hover) and (pointer: fine) {
  .link:hover { color: var(--text); background: var(--surface); }
  .btn-app:hover { background: #edb74f; }
  .toc a:hover { color: var(--text); border-color: var(--line-strong); }
  .ref-row[data-preview]:hover { background: rgba(255, 255, 255, 0.03); }
}

@media (max-width: 639px) {
  .top { padding-block: 12px; }
  .btn-app { order: -1; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition-duration: 0.01ms !important; }
}

@media print {
  :root {
    color-scheme: light;
    --bg: #ffffff;
    --surface: #f5f7f9;
    --raised: #edf1f5;
    --chassis: #e8ecf1;
    --line: #cbd5e1;
    --line-strong: #94a3b8;
    --text: #0f172a;
    --muted: #475569;
    --accent: #b45309;
    --lcd: #dce7e0;
    --lcd-ink: #0f172a;
  }
  body { background: #fff; color: #0f172a; font-size: 10.5pt; }
  .top nav, .switcher, .btn-app, .toc-wrap, .live-lcd, footer { display: none !important; }
  .booklet { display: block; padding-block: 8pt; }
  .chapter { break-inside: avoid; page-break-inside: avoid; padding-block: 14pt; }
  .key { background: #e2e8f0; color: #0f172a; border-color: #64748b; box-shadow: none; }
  .key.is-shift { background: #fde68a; color: #0f172a; box-shadow: none; }
  .key.is-alpha { background: #fecaca; color: #7f1d1d; box-shadow: none; }
  .diagram-box { background: #f8fafc; border-color: #94a3b8; }
}
