/* Styles for apps.primbs.ca — follows primbs.ca's palette, typography, and
   privacy-first philosophy (self-hosted fonts, zero third-party requests). */

@font-face {
  font-family: 'Plus Jakarta Sans';
  font-weight: 400;
  font-display: swap;
  src: url(/fonts/plus-jakarta-sans-400-normal-latin.woff2) format('woff2');
}
@font-face {
  font-family: 'Plus Jakarta Sans';
  font-weight: 700;
  font-display: swap;
  src: url(/fonts/plus-jakarta-sans-700-normal-latin.woff2) format('woff2');
}

:root {
  color-scheme: light;
  --text-main: #242424;
  --text-muted: #666666;
  --text-faint: #8A8A8A;
  --accent: #0C7C74;
  --accent-hover: #09665F;
  --accent-soft: rgba(12, 124, 116, 0.10);
  --accent-fg: #FFFFFF;
  --bg: #FFFFFF;
  --header-bg: rgba(255, 255, 255, 0.92);
  --surface: #FAFAFA;
  --surface-strong: #F2F2F2;
  --surface-hover: #EAEAEA;
  --border: #E9E9E9;
  --border-strong: #D6D6D6;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.07);
  --radius: 14px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --text-main: #E8E8E8;
  --text-muted: #A0A0A0;
  --text-faint: #787878;
  --accent: #44A49C;
  --accent-hover: #58B8B0;
  --accent-soft: rgba(68, 164, 156, 0.14);
  --accent-fg: #141414;
  --bg: #181818;
  --header-bg: rgba(24, 24, 24, 0.92);
  --surface: #212121;
  --surface-strong: #2A2A2A;
  --surface-hover: #333333;
  --border: #2F2F2F;
  --border-strong: #424242;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.42);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-main);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Top Navigation --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--header-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-main);
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.brand:hover { color: var(--accent); text-decoration: none; }
.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  margin: 0;
  padding: 0;
  flex-wrap: wrap;
}

.nav-links a {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-muted);
  transition: background 140ms ease, color 140ms ease;
}
.nav-links a:hover {
  color: var(--text-main);
  background: var(--surface-strong);
  text-decoration: none;
}
.nav-links a[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}

/* Shared menu (../network.json): one entry opens a submenu. It appears on
   hover and on keyboard focus, with no JavaScript - same as primbs.ca. */
.nav-links li { position: relative; }
.nav-links .submenu-parent {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: default;
  transition: background 140ms ease, color 140ms ease;
}
.nav-links .submenu-parent::after {
  content: "";
  display: inline-block;
  margin-left: 6px;
  vertical-align: 2px;
  border: 4px solid transparent;
  border-top-color: currentColor;
  border-bottom: 0;
}
.nav-links li:hover > .submenu-parent,
.nav-links li:focus-within > .submenu-parent {
  color: var(--text-main);
  background: var(--surface-strong);
}
/* The outer box is transparent padding, so the pointer can cross from the
   label to the panel without leaving the hover target. */
.nav-links .submenu {
  position: absolute;
  top: 100%;
  left: 0;
  padding-top: 8px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 140ms ease, visibility 140ms ease;
  z-index: 60;
}
.nav-links li:hover > .submenu,
.nav-links li:focus-within > .submenu {
  opacity: 1;
  visibility: visible;
}
.nav-links .submenu ul {
  list-style: none;
  margin: 0;
  padding: 6px;
  min-width: 230px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
}
.nav-links .submenu a {
  display: block;
  white-space: nowrap;
}

/* Theme toggle (same 3-state convention as primbs.ca) */
.theme-toggle {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-left: 6px;
  flex-shrink: 0;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease;
}
.theme-toggle:hover {
  color: var(--text-main);
  border-color: var(--border-strong);
  background: var(--surface-strong);
}
.theme-toggle svg { display: none; }
:root[data-theme-mode="auto"] .theme-toggle .icon-auto,
:root[data-theme-mode="light"] .theme-toggle .icon-sun,
:root[data-theme-mode="dark"] .theme-toggle .icon-moon {
  display: block;
}

/* --- Masthead --- */
.masthead {
  background:
    radial-gradient(900px 260px at 12% -10%, var(--accent-soft), transparent 70%),
    var(--surface);
  border-bottom: 1px solid var(--border);
}

.masthead-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 44px 24px 36px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.masthead-copy { max-width: 660px; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 10px;
}

.masthead h1 {
  font-size: clamp(30px, 4.5vw, 42px);
  line-height: 1.12;
  letter-spacing: -0.025em;
  margin: 0 0 12px;
}

.lead {
  color: var(--text-muted);
  font-size: 17px;
  line-height: 1.55;
  margin: 0;
}

.masthead-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-weight: 700;
  color: var(--text-main);
}

/* --- Main Content & Grid --- */
main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 36px 24px 56px;
}

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

.app-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}
.app-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

/* Visual Preview */
.card-media {
  position: relative;
  display: block;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: var(--surface-strong);
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}
.card-media:hover { text-decoration: none; }

.card-media img.preview-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 320ms ease;
}
.app-card:hover .card-media img.preview-img {
  transform: scale(1.03);
}

/* Custom Poster Fallbacks (used until a screenshot is supplied) */
.poster {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  position: relative;
  overflow: hidden;
  transition: transform 320ms ease;
}
.app-card:hover .poster { transform: scale(1.02); }

.poster-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.78;
  z-index: 1;
}

.poster--dormice {
  background:
    radial-gradient(circle at 20% 25%, rgba(196, 154, 108, 0.22), transparent 55%),
    repeating-linear-gradient(0deg, rgba(92, 68, 44, 0.045) 0 1px, transparent 1px 28px),
    repeating-linear-gradient(90deg, rgba(92, 68, 44, 0.045) 0 1px, transparent 1px 28px),
    #F3ECDF;
  color: #4A3828;
}
.poster--dormice img {
  width: 82px;
  height: 82px;
  border-radius: 20px;
  box-shadow: 0 10px 24px rgba(74, 56, 40, 0.18);
}

.poster--tankbrain {
  background:
    radial-gradient(circle at 30% 35%, rgba(0, 229, 255, 0.20), transparent 55%),
    radial-gradient(circle at 74% 68%, rgba(255, 79, 216, 0.18), transparent 55%),
    #10151D;
  color: #CFE9F0;
}
.poster-orbit {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 2px solid rgba(0, 229, 255, 0.55);
  display: grid;
  place-items: center;
  position: relative;
  box-shadow: 0 0 28px rgba(0, 229, 255, 0.22), inset 0 0 22px rgba(255, 79, 216, 0.16);
}
.poster-orbit::before {
  content: "";
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1.5px dashed rgba(255, 79, 216, 0.65);
}
.poster-orbit::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #FF4FD8;
  box-shadow: 0 0 14px #FF4FD8;
}

.poster--default {
  background:
    radial-gradient(circle at 25% 25%, var(--accent-soft), transparent 60%),
    var(--surface-strong);
  color: var(--text-muted);
}

/* Category Badge */
.card-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(20, 20, 20, 0.72);
  color: #FFFFFF;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  letter-spacing: 0.01em;
}

/* Card Body */
.card-body {
  padding: 20px 22px 16px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-title {
  font-size: 21px;
  line-height: 1.25;
  letter-spacing: -0.015em;
  margin: 0 0 8px;
}
.card-title a {
  color: var(--text-main);
  text-decoration: none;
}
.card-title a:hover { color: var(--accent); text-decoration: none; }

.card-desc {
  margin: 0;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.55;
}

.card-note {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--text-faint);
}

/* Card Footer Action Bar */
.card-actions {
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  transition: background 140ms ease, transform 120ms ease;
}
.btn-primary:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

.secondary-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.action-chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease;
}
.action-chip:hover {
  color: var(--text-main);
  border-color: var(--border-strong);
  background: var(--surface-strong);
  text-decoration: none;
}
.action-chip svg { flex-shrink: 0; }

/* --- Footer --- */
.site-footer {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 24px 48px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 14px;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

/* --- Share / QR Dialog --- */
dialog.qr-dialog {
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text-main);
  max-width: 390px;
  width: calc(100% - 32px);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.32);
}
dialog.qr-dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(4px);
}

.qr-dialog-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.qr-dialog-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
}
.qr-close {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.qr-close:hover { color: var(--text-main); border-color: var(--border-strong); }

.qr-dialog-body {
  padding: 22px 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* Always white with generous quiet zone so QR scans cleanly in dark mode */
.qr-frame {
  background: #FFFFFF;
  padding: 18px;
  border-radius: 12px;
  border: 1px solid #E5E5E5;
  display: grid;
  place-items: center;
}
.qr-frame svg {
  display: block;
  width: 220px;
  height: 220px;
  shape-rendering: crispEdges;
}

.qr-url-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 6px 6px 12px;
}
.qr-url-text {
  flex: 1;
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: 13px;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qr-copy-btn {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: var(--accent-fg);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.qr-copy-btn:hover { background: var(--accent-hover); }

.qr-dialog-foot {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Fullscreen presentation mode for the QR code */
dialog.qr-dialog.is-fullscreen {
  max-width: none;
  width: min(560px, calc(100vw - 32px));
}
dialog.qr-dialog.is-fullscreen .qr-frame { padding: 26px; }
dialog.qr-dialog.is-fullscreen .qr-frame svg {
  width: min(380px, 72vw);
  height: min(380px, 72vw);
}

@media (max-width: 780px) {
  .apps-grid { grid-template-columns: 1fr; }
  .masthead-inner { padding: 32px 20px 28px; }
  main { padding: 24px 20px 44px; }
  .topbar-inner { padding: 10px 16px; }
  .nav-links a,
  .nav-links .submenu-parent { padding: 5px 8px; font-size: 13px; }
  /* The menu wraps here, so a panel hung under its own label could run off
     either edge. Hang it under the whole bar instead. */
  .nav-links li.has-submenu { position: static; }
  .nav-links .submenu { left: 16px; right: 16px; padding-top: 0; }
  .nav-links .submenu a { white-space: normal; }
}
