/* R47 Docs AI — mobile-first stylesheet.
   ──────────────────────────────────────
   Two font-stacks. Prose uses the system stack (fast, native, full
   Greek + math symbol coverage on every modern OS — no @font-face
   download required). The calculator's own bitmap fonts are used ONLY
   inside .lcd / .key-label / .calc-text contexts where matching the
   physical R47 look is the point.

   The C47 fonts are ~80 KB each as WOFF2; loaded lazily and only when
   one of those contexts appears on the page. Subset to the BMP range
   the engine actually uses if we ever need to trim further.
*/

@font-face {
  font-family: "C47Standard";
  src: url("/static/fonts/C47__StandardFont.woff2") format("woff2"),
       url("/static/fonts/C47__StandardFont.ttf")   format("truetype");
  font-display: swap;          /* render with system font until C47 arrives */
}
@font-face {
  font-family: "C47Numeric";
  src: url("/static/fonts/C47__NumericFont.woff2") format("woff2"),
       url("/static/fonts/C47__NumericFont.ttf")   format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "C47Tiny";
  src: url("/static/fonts/C47__TinyFont.woff2") format("woff2"),
       url("/static/fonts/C47__TinyFont.ttf")   format("truetype");
  font-display: swap;
}

:root {
  /* Prose: system font stack — fast, no download, full Unicode coverage. */
  --font-prose:
      -apple-system, BlinkMacSystemFont,
      "Segoe UI", Roboto,
      "Helvetica Neue", Arial,
      "Noto Sans", "Noto Sans Symbols", "Noto Sans Math",
      "Apple Color Emoji", "Segoe UI Emoji",
      sans-serif;
  /* Mono: system mono stack for examples / stack diagrams. */
  --font-mono:
      ui-monospace, "SF Mono", Menlo, Consolas, Monaco,
      "Liberation Mono", monospace;
  /* Calc: bitmap font matching what the calculator's LCD shows. */
  --font-calc: "C47Standard", var(--font-mono);

  --bg:           #1a1a1c;
  --bg-elev:     #25252a;
  --fg:           #ececef;
  --fg-muted:    #9a9ba1;
  --fg-dim:      #64656d;
  --accent:       #d6a15a;        /* matches calculator's f-gold */
  --accent-2:     #7eb6ba;        /* g-cyan */
  --line:        #34343a;
  --hit:         #2c2c33;
  --lcd-bg:       #d5dac8;        /* default LCD theme */
  --lcd-fg:       #1a1f12;
  --tap:          44px;            /* minimum touch-target */
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:        #ffffff;
    --bg-elev:   #f4f4f6;
    --fg:        #18181b;
    --fg-muted:  #5a5a62;
    --fg-dim:    #a0a0a8;
    --line:      #e4e4e8;
    --hit:       #ececf0;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-prose);
  font-size: clamp(15px, 4.1vw, 17px);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover, a:focus { text-decoration: underline; }

/* ─── Top bar ─────────────────────────────────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  min-height: var(--tap);
}
.top .logo { font-weight: 600; flex: 0 0 auto; }
.top .search-wrap { flex: 1; min-width: 0; }
.top input.search {
  width: 100%; min-height: var(--tap);
  padding: 0 12px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 16px;            /* iOS won't zoom inputs at ≥16px */
  font-family: inherit;
}
.top button.icon-btn {
  min-width: var(--tap); min-height: var(--tap);
  background: transparent; border: 0;
  color: var(--fg-muted);
  font-size: 20px; cursor: pointer;
}

/* ─── Page wrapper ────────────────────────────────────────────────── */
main { padding: 12px; max-width: 1080px; margin: 0 auto; }
.breadcrumb {
  font-size: 13px; color: var(--fg-muted);
  margin: 4px 0 12px;
}
h1, h2, h3 { line-height: 1.2; margin: 1.2em 0 0.4em; }
h1 { font-size: clamp(22px, 5.6vw, 28px); }
h2 { font-size: clamp(18px, 4.8vw, 22px); }
h3 { font-size: clamp(16px, 4.2vw, 19px); color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* ─── Chip filter rows (Browse + Search) ──────────────────────────── */
.chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 6px 0;
}
.chip {
  display: inline-flex; align-items: center; min-height: 32px;
  padding: 0 12px;
  background: var(--bg-elev);
  color: var(--fg-muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  font: 13px/1 var(--font-prose);
  cursor: pointer; user-select: none;
}
.chip[aria-pressed="true"] {
  background: var(--accent);
  color: #1a140a;
  border-color: var(--accent);
}

/* ─── Universal Browse list rows ──────────────────────────────────── */
.browse-list { list-style: none; padding: 0; margin: 16px 0; }
.browse-row {
  display: block;
  padding: 12px 8px;
  border-bottom: 1px solid var(--line);
  color: inherit;
  min-height: var(--tap);
}
.browse-row:hover { background: var(--hit); }
.browse-row .name {
  font-weight: 600;
  font-size: 16px;
  margin-right: 8px;
}
.browse-row .name.calc { font-family: var(--font-calc); }
.browse-row .badge {
  display: inline-block;
  padding: 1px 6px;
  font-size: 11px;
  background: var(--bg-elev);
  color: var(--fg-muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  vertical-align: middle;
}
.browse-row .summary {
  display: block;
  font-size: 14px;
  color: var(--fg-muted);
  margin-top: 2px;
}

/* ─── Calculator-look elements (use the C47 font) ─────────────────── */
.calc-text, .key-label, .softkey-label {
  font-family: var(--font-calc);
}
.lcd {
  background: var(--lcd-bg);
  color: var(--lcd-fg);
  font-family: var(--font-calc);
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 18px;
}

/* Stylised key tile (used on key-detail and the keyboard atlas). */
.key-tile {
  display: inline-block;
  background: #212121;
  color: #fff;
  border: 1px solid #444;
  border-radius: 4px;
  padding: 14px 12px 12px;
  min-width: 56px;
  min-height: 44px;
  text-align: center;
  font-family: var(--font-calc);
}
.key-tile .label-f, .key-tile .label-g {
  display: block; font-size: 11px; line-height: 1;
}
.key-tile .label-f { color: var(--accent); }
.key-tile .label-g { color: var(--accent-2); }
.key-tile .label-primary { display: block; font-size: 18px; margin-top: 4px; }

/* ─── Tablet / desktop progressive enhancement ────────────────────── */
@media (min-width: 640px) {
  .top { padding: 10px 16px; }
  main { padding: 16px 24px; }
}
@media (min-width: 1024px) {
  body { font-size: 16px; }
  main { padding: 24px 32px; max-width: 1120px; }
  /* Persistent left rail for the topical doors on desktop. */
  .layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 32px;
    align-items: start;
  }
  .doors {
    position: sticky; top: 60px;
  }
}
