/* ==========================================================================
   halvorhansen.no – shared layout, navigation, dark mode and image placeholders
   Loaded after Tailwind on every page except economicOutlook.html.
   ========================================================================== */

:root {
  --nav-w: 232px;
  --nav-bg: #000;
  --nav-fg: #d4d4d8;
  --nav-fg-muted: #8b8b93;
  --nav-hover: #18181b;
  --nav-active: #27272a;

  --page-bg: #f9fafb;
  --surface: #ffffff;
  --text: #1f2937;
  --text-strong: #111827;
  --accent: #1d5fd1;
  --accent-hover: #123f91;
  --ph: #e5e7eb; /* image placeholder */
  --ph-2: #f1f2f4;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page-bg: #111214;
    --surface: #1a1b1e;
    --text: #d6d6da;
    --text-strong: #f1f1f3;
    --accent: #7ab4ff;
    --accent-hover: #a9cdff;
    --ph: #24262a;
    --ph-2: #2c2e33;
  }
}

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

body {
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-bg) !important;
  color: var(--text) !important;
}

/* ---------- Skip link ---------- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: #fff;
  color: #000;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
}
.skip-link:focus {
  left: 0.75rem;
  top: 0.75rem;
}

/* ==========================================================================
   Navigation
   ========================================================================== */
.site-nav {
  background: var(--nav-bg);
  color: var(--nav-fg);
  z-index: 60;
}
.site-nav a {
  color: inherit;
  text-decoration: none;
}
.site-nav__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.site-nav__logo {
  display: block;
  line-height: 0;
  border-radius: 0.75rem;
}
.site-nav__logo img {
  display: block;
  width: auto;
  height: 72px;
  max-width: 100%;
  object-fit: contain;
}
.site-nav__links {
  list-style: none;
  margin: 0;
  padding: 0;
}
.site-nav__links a {
  display: block;
  padding: 0.6rem 0.85rem;
  border-radius: 0.5rem;
  font-weight: 500;
  font-size: 0.975rem;
  line-height: 1.3;
  /* Long labels wrap instead of overflowing the column */
  white-space: normal;
  overflow-wrap: anywhere;
  hyphens: auto;
  transition: background-color 0.15s, color 0.15s;
}
.site-nav__links a:hover {
  background: var(--nav-hover);
  color: #fff;
}
.site-nav__links a[aria-current="page"] {
  background: var(--nav-active);
  color: #fff;
}
/* The discreet blog link */
.site-nav__minor {
  display: inline-block;
  margin: 0.9rem 0 0 0.85rem;
  padding: 0.15rem 0;
  font-size: 0.825rem;
  color: var(--nav-fg-muted) !important;
  border-bottom: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.site-nav__minor:hover,
.site-nav__minor[aria-current="page"] {
  color: #fff !important;
  border-bottom-color: #52525b;
}
.site-nav__social {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}
.site-nav__social a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.5rem;
  color: var(--nav-fg-muted);
  transition: color 0.15s, background-color 0.15s;
}
.site-nav__social a:hover {
  color: #fff;
  background: var(--nav-hover);
}
.site-nav__social svg {
  width: 1.3rem;
  height: 1.3rem;
}
.site-nav a:focus-visible,
.site-nav button:focus-visible {
  outline: 2px solid #7ab4ff;
  outline-offset: 2px;
}

/* Menu button: the three lines */
.site-nav__toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  margin-right: -0.4rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: #fff;
  cursor: pointer;
}
.site-nav__toggle:hover {
  background: var(--nav-hover);
}
.burger {
  position: relative;
  display: block;
  width: 22px;
  height: 16px;
}
.burger span {
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform 0.2s ease, opacity 0.15s ease, top 0.2s ease;
}
.burger span:nth-child(1) { top: 0; }
.burger span:nth-child(2) { top: 7px; }
.burger span:nth-child(3) { top: 14px; }
.site-nav.is-open .burger span:nth-child(1) { top: 7px; transform: rotate(45deg); }
.site-nav.is-open .burger span:nth-child(2) { opacity: 0; }
.site-nav.is-open .burger span:nth-child(3) { top: 7px; transform: rotate(-45deg); }

/* ---------- Desktop: fixed sidebar on the left ---------- */
@media (min-width: 768px) {
  .site-nav {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--nav-w);
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 1.75rem 1.1rem 1.25rem;
  }
  .site-nav__bar {
    justify-content: center;
    margin-bottom: 1.75rem;
  }
  .site-nav__menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .site-nav__links {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
  }
  .site-nav__social {
    margin-top: auto;
    padding: 1.5rem 0.4rem 0;
  }
  .site-main {
    padding-left: var(--nav-w);
  }
}

/* Narrow laptops / tablets: a slightly slimmer column */
@media (min-width: 768px) and (max-width: 1023px) {
  :root { --nav-w: 200px; }
  .site-nav { padding-left: 0.75rem; padding-right: 0.75rem; }
  .site-nav__logo img { height: 60px; }
  .site-nav__social { gap: 0.1rem; padding-left: 0; padding-right: 0; }
  .site-nav__social a { width: 2.2rem; height: 2.2rem; }
}

/* ---------- Phone: top bar, menu drops down under it ---------- */
@media (max-width: 767px) {
  .site-nav {
    position: sticky;
    top: 0;
    width: 100%;
  }
  .site-nav__bar {
    height: 56px;
    padding: 0 1rem;
  }
  .site-nav__logo img {
    height: 36px;
  }
  .js .site-nav__toggle {
    display: inline-flex;
  }
  .site-nav__menu {
    padding: 0.25rem 0.75rem 1rem;
    border-top: 1px solid #1f1f23;
  }
  .js .site-nav__menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--nav-bg);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
    max-height: calc(100dvh - 56px);
    overflow-y: auto;
    visibility: hidden;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0.18s;
  }
  .js .site-nav.is-open .site-nav__menu {
    visibility: visible;
    opacity: 1;
    transform: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
  }
  .site-nav__links a {
    padding: 0.8rem 0.75rem;
    font-size: 1.05rem;
  }
  .site-nav__minor {
    margin-left: 0.75rem;
  }
  .site-nav__social {
    margin-top: 0.75rem;
    padding: 0.75rem 0.4rem 0;
    border-top: 1px solid #1f1f23;
  }
  /* LambdaSim's floating GitHub button: keep it out of the thumb zone */
  #github-button {
    bottom: 1rem !important;
    right: 1rem !important;
    font-size: 0.85rem;
    padding: 0.6rem 0.9rem !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .site-nav *,
  .site-nav__menu {
    transition: none !important;
  }
}

/* ==========================================================================
   Content tweaks shared by all pages
   ========================================================================== */
.site-main {
  min-height: 100vh;
}

/* Long words and URLs never push the page sideways on phones */
.site-main p,
.site-main h1,
.site-main h2,
.site-main h3,
.site-main li {
  overflow-wrap: break-word;
}

/* No gradients: accent links are a single solid colour */
.gradient-text {
  background: none !important;
  -webkit-background-clip: border-box !important;
  background-clip: border-box !important;
  -webkit-text-fill-color: currentColor !important;
  color: var(--accent) !important;
}
.gradient-text:hover {
  color: var(--accent-hover) !important;
}
.timeline::before {
  background: #38acfc !important;
}

/* ==========================================================================
   Image placeholders – a quiet pulse in the space the image will fill.
   Every <img> carries width/height so the space is reserved up front.
   ========================================================================== */
@keyframes hh-pulse {
  0%, 100% { background-color: var(--ph); }
  50% { background-color: var(--ph-2); }
}
.js img.hh-ph:not(.is-loaded) {
  background-color: var(--ph);
  animation: hh-pulse 1.4s ease-in-out infinite;
}
.js img.hh-ph {
  transition: opacity 0.3s ease;
}
.js img.hh-ph:not(.is-loaded) {
  /* the pulse shows through; the image fades in on top once decoded */
  color: transparent;
}
@media (prefers-reduced-motion: reduce) {
  .js img.hh-ph:not(.is-loaded) { animation: none; }
}

/* ==========================================================================
   Dark mode – follows the device setting.
   Maps the Tailwind utility classes the pages use onto dark equivalents.
   The sidebar is black in both modes and is not affected.
   ========================================================================== */
@media (prefers-color-scheme: dark) {
  .site-main .bg-white { background-color: var(--surface) !important; }
  .site-main .bg-gray-50 { background-color: #16171a !important; }
  .site-main .bg-gray-100 { background-color: #25262a !important; }
  .site-main .bg-blue-50 { background-color: #17243a !important; }

  .site-main .text-gray-900 { color: var(--text-strong) !important; }
  .site-main .text-gray-800 { color: #e4e4e7 !important; }
  .site-main .text-gray-700 { color: #cfcfd4 !important; }
  .site-main .text-gray-600 { color: #b4b4bb !important; }
  .site-main .text-gray-500 { color: #9b9ba3 !important; }
  .site-main .text-gray-400 { color: #7c7c84 !important; }
  .site-main .text-blue-600,
  .site-main .text-blue-500 { color: var(--accent) !important; }
  .site-main .hover\:text-blue-800:hover { color: var(--accent-hover) !important; }
  .site-main .hover\:text-gray-900:hover { color: #fff !important; }
  .site-main .hover\:bg-gray-50:hover { background-color: #222327 !important; }
  .site-main .hover\:bg-gray-200:hover { background-color: #303136 !important; }

  .site-main .border-gray-100,
  .site-main .border-gray-200,
  .site-main [class*="border-gray-200"] { border-color: #2c2d32 !important; }
  .site-main .border-white { border-color: #2c2d32 !important; }

  .site-main [class*="shadow"] { --tw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4) !important; }

  .site-main input,
  .site-main textarea {
    color: var(--text-strong);
  }
  .site-main input::placeholder,
  .site-main textarea::placeholder { color: #7c7c84; }

  .site-main .bg-black { background-color: #f1f1f3 !important; color: #111 !important; }
  .site-main .bg-black:hover { background-color: #ffffff !important; }

  /* LambdaSim timeline details */
  .site-main details > div { background-color: #16171a !important; }
  .timeline-item::before { border-color: var(--page-bg) !important; }

  /* Transparent logos/graphics that are dark-on-light */
  .site-main img.invert-in-dark { filter: invert(1) hue-rotate(180deg); }
}
