/* ── Reset ── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ── Theme Variables ── */
:root {
  --hub-bg: #f0f2f5;
  --hub-card-bg: #fff;
  --hub-card-border: #e0e0e0;
  --hub-text: #1a1a2e;
  --hub-text-desc: #666;
  --hub-overlay-bg: rgba(240, 242, 245, 0.85);
  --hub-spinner: #4a6cf7;
  --hub-shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --hub-shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
}

/* ── Domains ──
   Copied from the OKN registry at https://okn.us, which sets these two colours
   inline on its own graph cards. It is the authority on which domain a graph
   belongs to, so the palette is taken from it rather than chosen here; a card
   picks up both by carrying `data-cat`.

   All fourteen of okn.us's domains are here, not only the nine the nineteen
   documented graphs use, so adding a graph is one line in js/app.js. */
[data-cat="bio"]         { --cat-fg: #6A1B9A; --cat-bg: #F3E5F5; }
[data-cat="climate"]     { --cat-fg: #0277BD; --cat-bg: #E1F5FE; }
[data-cat="environment"] { --cat-fg: #2E7D32; --cat-bg: #E8F5E9; }
[data-cat="health"]      { --cat-fg: #C62828; --cat-bg: #FFEBEE; }
[data-cat="industry"]    { --cat-fg: #EF6C00; --cat-bg: #FFF3E0; }
[data-cat="justice"]     { --cat-fg: #333333; --cat-bg: #F5F5F5; }
[data-cat="reference"]   { --cat-fg: #455A64; --cat-bg: #ECEFF1; }
[data-cat="science"]     { --cat-fg: #283593; --cat-bg: #E8EAF6; }
[data-cat="security"]    { --cat-fg: #5D4037; --cat-bg: #EFEBE9; }
[data-cat="social"]      { --cat-fg: #AD1457; --cat-bg: #FCE4EC; }
[data-cat="soil"]        { --cat-fg: #827717; --cat-bg: #F9FBE7; }
[data-cat="space"]       { --cat-fg: #1565C0; --cat-bg: #E3F2FD; }
[data-cat="water"]       { --cat-fg: #00838F; --cat-bg: #E0F7FA; }
[data-cat="wildlife"]    { --cat-fg: #558B2F; --cat-bg: #F1F8E9; }

/* ── Base ── */
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--hub-bg);
  color: var(--hub-text);
  -webkit-font-smoothing: antialiased;
}

/* ── Landing ── */
#landing {
  padding: 40px 32px 48px;
  max-width: 1200px;
  margin: 0 auto;
  transition: opacity 0.25s ease;
}

#landing.visible {
  opacity: 1;
}

#landing.hidden {
  opacity: 0;
  pointer-events: none;
  position: absolute;
}

/* ── Card Grid ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* A button, not a div: it does what a click does, and the keyboard should
   reach it. `text-align: left` is what a button costs. */
.card {
  display: block;
  width: 100%;
  padding: 20px 20px 18px;
  font: inherit;
  text-align: left;
  background: var(--hub-card-bg);
  border: 1px solid var(--hub-card-border);
  border-left: 4px solid var(--cat-fg, var(--hub-card-border));
  border-radius: 10px;
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.15s, border-color 0.2s;
  box-shadow: var(--hub-shadow-sm);
}

.card:hover,
.card:focus-visible {
  box-shadow: var(--hub-shadow-lg);
  transform: translateY(-2px);
  border-color: var(--cat-fg, var(--hub-card-border));
}

/* The same pill okn.us puts on its own cards: the domain's ink on the domain's
   wash, so the colour is legible as a label and not only as an edge. */
.card-cat {
  display: inline-block;
  margin-bottom: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--cat-bg);
  color: var(--cat-fg);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.card-title {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 1rem;
  color: var(--hub-text);
}

.card-desc {
  display: block;
  font-size: 0.85rem;
  color: var(--hub-text-desc);
  line-height: 1.4;
}

/* ── Back to the grid ──
   Over the documentation rather than in a bar above it: the app's header is
   already the chrome here, and a graph's own page wants the whole frame.

   Top left, where a back control is looked for -- which is also where WIDOCO
   puts its table of contents, so this is opaque and dark rather than a
   translucent chip. Sitting *on* the page instead of tinting it is what keeps
   it legible over whatever it lands on, and what stops it reading as part of
   the documentation. */
.back-btn {
  display: none;
  position: fixed;
  left: 16px;
  top: 16px;
  z-index: 600;
  align-items: center;
  gap: 7px;
  padding: 11px 18px 11px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--hub-text);
  color: #fff;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
}

.back-btn:hover,
.back-btn:focus-visible {
  background: #2c2c4a;
  transform: translateY(-1px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.34);
}

.back-btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: -6px;
}

.back-btn.visible {
  display: flex;
}

/* ── Loading Overlay ── */
#loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--hub-overlay-bg);
  z-index: 500;
  align-items: center;
  justify-content: center;
}

#loading-overlay.visible {
  display: flex;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--hub-card-border);
  border-top-color: var(--hub-spinner);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Iframe ── */
#child-frame {
  display: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  #landing {
    padding: 24px 16px 32px;
  }
}

@media (max-width: 600px) {
  .card-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .back-btn {
    transition: none;
  }
  .card:hover,
  .card:focus-visible,
  .back-btn:hover,
  .back-btn:focus-visible {
    transform: none;
  }
  .spinner {
    animation-duration: 2s;
  }
}
