/* fpga4fun.com site stylesheet */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1d2530;
  --muted: #5d6a79;
  --border: #e2e6eb;
  --accent: #0b7a70;
  --accent-strong: #075e57;
  --accent-weak: #e3f3f1;
  --code-bg: #f2f4f7;
  --code-text: #1d2530;
  --keyword: #7a3cc9;
  --topbar-h: 58px;
  --sidebar-w: 268px;
  --content-w: 960px;
  /* sidebar + content column + main's side padding */
  --site-w: calc(var(--sidebar-w) + var(--content-w) + 96px);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1a2028;
    --text: #e3e8ee;
    --muted: #9aa6b4;
    --border: #2b333e;
    --accent: #4fc3b5;
    --accent-strong: #7dd8cc;
    --accent-weak: #173a37;
    --code-bg: #0f1318;
    --code-text: #dfe6ee;
    --keyword: #c4a2ff;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 var(--font);
}

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-strong); }

.skip {
  position: absolute; left: -999px; top: 8px;
  background: var(--surface); padding: 8px 12px; border-radius: 6px; z-index: 100;
}
.skip:focus { left: 8px; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
  /* the bar spans the window, its contents line up with the centered layout */
  padding: 0 max(20px, calc((100% - var(--site-w)) / 2 + 20px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex; align-items: center; gap: 9px;
  color: var(--text); text-decoration: none;
  font-weight: 700; font-size: 1.3rem; letter-spacing: -0.01em;
}
.brand:hover { color: var(--text); }
.brand-chip { color: var(--accent); flex: none; }

.tagline {
  color: var(--muted); font-size: 0.9rem;
  padding-left: 14px; border-left: 1px solid var(--border);
}

.top-links { margin-left: auto; display: flex; gap: 4px; }
.top-links a {
  color: var(--muted); text-decoration: none; font-size: 0.92rem;
  padding: 6px 12px; border-radius: 8px;
}
.top-links a:hover { color: var(--text); background: var(--code-bg); }

.menu-btn {
  display: none;
  border: 1px solid var(--border); background: transparent; color: var(--text);
  width: 40px; height: 40px; border-radius: 8px;
  align-items: center; justify-content: center; cursor: pointer;
}

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  max-width: var(--site-w);
  margin: 0 auto;
}

/* once the window is wider than the site, close the sidebar on its left side too */
@media (min-width: 1325px) {
  .sidenav { border-left: 1px solid var(--border); }
}

.sidenav {
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 18px 12px 40px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  scrollbar-width: thin;
}

.nav-group { margin-bottom: 16px; }

.nav-title {
  font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted);
  padding: 0 10px 4px;
}

.sidenav a {
  display: block;
  padding: 4px 10px;
  border-radius: 7px;
  color: var(--text); text-decoration: none;
  font-size: 0.92rem; line-height: 1.45;
}
.sidenav a:hover { background: var(--code-bg); color: var(--text); }

/* htmlmake marks the current page with class "w3-lime" */
.sidenav a.w3-lime {
  background: var(--accent-weak);
  color: var(--accent-strong);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}

.scrim { display: none; }

.main {
  min-width: 0;
  padding: 36px 48px 0;
}

.page-head, .main > .w3-container, .site-footer {
  max-width: var(--content-w);
}

.page-head h2 {
  margin: 0 0 24px;
  font-size: 2rem; line-height: 1.2; letter-spacing: -0.02em;
  font-weight: 750;
}

/* ---------- page content ---------- */

.w3-container { overflow-wrap: break-word; }

.w3-container h4 {
  font-size: 1.35rem; line-height: 1.3;
  margin: 2.2rem 0 0.6rem;
}
.w3-container h5 {
  font-size: 1.12rem; line-height: 1.35;
  margin: 1.8rem 0 0.5rem;
}
.w3-container h6 {
  font-size: 1rem;
  margin: 1.4rem 0 0.4rem;
}
.w3-container h1 { font-size: 2rem; }

.w3-container p { margin: 0 0 1rem; }
.w3-container ul, .w3-container ol { padding-left: 1.5rem; margin: 0 0 1rem; }
.w3-container li { margin: 0.2rem 0; }

.w3-container img {
  max-width: 100%; height: auto;
  border-radius: 6px;
  vertical-align: middle;
}
.w3-container iframe { max-width: 100%; border: 0; border-radius: var(--radius); }

.w3-container hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

/* code */
.w3-container pre, .w3-container code,
.w3-container td[bgcolor="#d0d0f0"], .w3-container td[bgcolor="#d0f0d0"] {
  font-family: var(--mono);
  /* keep "<=" and "!=" as typed: programming fonts would turn them into symbols */
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
}
.w3-container pre {
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 0 0 1.2rem;
  font-size: 0.86rem; line-height: 1.55;
  overflow-x: auto;
}
.w3-container pre b { color: var(--keyword); font-weight: 600; }

/* older pages put code in a table cell with a colored background */
.w3-container table {
  max-width: 100%;
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 0 0 1.2rem;
}
.w3-container td[bgcolor="#d0d0f0"],
.w3-container td[bgcolor="#d0f0d0"] {
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.86rem; line-height: 1.6;
  padding: 14px 18px;
  white-space: nowrap;
}
.w3-container td[bgcolor="#d0d0f0"] b,
.w3-container td[bgcolor="#d0f0d0"] b { color: var(--keyword); font-weight: 600; }
.w3-container th[bgcolor="#d0d0f0"] {
  background: transparent;
  text-align: left; padding: 4px 18px; color: var(--muted); font-size: 0.85rem;
}
.w3-container td[bgcolor="#ffd0d0"] {
  background: var(--accent-weak);
  border-radius: var(--radius);
  padding: 16px 20px;
}

/* data tables */
.w3-container table[border] th,
.w3-container table[border] td {
  border: 1px solid var(--border);
  padding: 7px 12px;
  text-align: left;
  vertical-align: top;
}
.w3-container table[border] th { background: var(--code-bg); font-weight: 600; }

/* the "next page" button htmlmake adds at the bottom of each page */
.w3-pagination {
  list-style: none;
  padding: 0 !important;
  margin: 2.5rem 0 1rem !important;
}
.w3-pagination li { margin: 0; }
.w3-pagination a {
  display: block;
  padding: 14px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-decoration: none;
  font-weight: 600; font-size: 1.05rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.w3-pagination a::before {
  content: "Next";
  display: block;
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
}
.w3-pagination a:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

/* home page */
.w3-container .lead {
  font-size: 1.15rem; color: var(--muted);
  margin: -8px 0 1.5rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  margin: 0 0 1rem;
}
.card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text); text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.card:hover {
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.07);
  transform: translateY(-1px);
}
.card-title { font-weight: 650; color: var(--accent-strong); }
.card-text { font-size: 0.9rem; line-height: 1.5; color: var(--muted); }

.news {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin: 0 0 1rem;
}
.news-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.news-item p { margin: 0; padding: 12px 16px 14px; }
.news-item .date {
  display: block;
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
}
.video { position: relative; aspect-ratio: 16 / 9; background: #000; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 0; }

@media (prefers-color-scheme: dark) {
  .card:hover { box-shadow: none; }
}

/* small helpers still used by a few pages (SD card terminal window) */
.w3-card-8 { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18); border-radius: 8px; overflow: hidden; }
.w3-white { background: #fff !important; color: #000 !important; }
.w3-black { background: #111 !important; color: #eee !important; padding: 8px 12px; }
.w3-right { float: right; }

.site-footer {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px;
  margin-top: 48px;
  padding: 20px 0 32px;
  border-top: 1px solid var(--border);
  color: var(--muted); font-size: 0.88rem;
}
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--text); }

/* ---------- dark mode tweaks ---------- */

@media (prefers-color-scheme: dark) {
  /* most diagrams are GIFs drawn for a white page */
  .w3-container img { background: #fff; padding: 4px; }
  .w3-pagination a:hover { box-shadow: none; }
  .w3-container font[color="red"] { color: #ff7b72; }
}

/* ---------- small screens ---------- */

@media (max-width: 960px) {
  .menu-btn { display: inline-flex; }
  .tagline { display: none; }
  .layout { display: block; }

  .sidenav {
    position: fixed; z-index: 25;
    top: var(--topbar-h); left: 0; bottom: 0;
    width: min(300px, 85vw); height: auto;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: none;
  }
  .nav-open .sidenav { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, 0.25); }

  .nav-open .scrim {
    display: block;
    position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 20;
    background: rgba(0, 0, 0, 0.35);
  }

  .main { padding: 24px 16px 0; }
  .page-head h2 { font-size: 1.6rem; }
}

@media (max-width: 520px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .top-links a { padding: 6px 8px; }
}

@media print {
  .topbar, .sidenav, .scrim, .w3-pagination, .site-footer { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
}
