/* PHILIP K. DICK x SILICON VALLEY — Retro-Futurist Editorial Theme */

:root,
[data-theme='light'] {
  --hero-bg: url('hero-bg-light.png');

  --hero-filter: none;
  --color-bg: #f5f3ef;
  --color-surface: #faf9f6;
  --color-surface-2: #f0ede8;
  --color-surface-offset: #e8e5df;
  --color-border: #d6d2cb;
  --color-divider: #e0dcd5;
  --color-text: #1a1510;
  --color-text-muted: #5e5546;
  --color-text-faint: #9b9285;
  --color-primary: #b45309;
  --color-primary-2: #d97706;
  --color-accent: #7c3aed;
  --color-success: #15803d;
  --color-error: #b91c1c;
  --color-warning: #b45309;
  --shadow-sm: 0 1px 3px rgba(15,10,0,0.06);
  --shadow-md: 0 4px 12px rgba(15,10,0,0.08);
}

[data-theme='dark'] {
  --hero-bg: url('hero-bg-dark.png');
  --hero-filter: none;
  --color-bg: #111110;
  --color-surface: #1a1916;
  --color-surface-2: #22211e;
  --color-surface-offset: #2a2925;
  --color-border: #33312d;
  --color-divider: #2a2824;
  --color-text: #e8e4db;
  --color-text-muted: #9b9585;
  --color-text-faint: #6b6558;
  --color-primary: #f59e0b;
  --color-primary-2: #fbbf24;
  --color-accent: #a78bfa;
  --color-success: #4ade80;
  --color-error: #f87171;
  --color-warning: #fbbf24;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
} 0; padding: 0; }

html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  transition: background 0.25s ease, color 0.25s ease;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: var(--hero-bg);
  background-size: cover;
  background-position: top center;
  background-repeat: no-repeat;
  background-attachment: scroll;
  filter: var(--hero-filter, none);
  opacity: 0.35;
  transition: filter 0.25s ease, opacity 0.25s ease;
}

h1, h2, h3 { line-height: 1.2; text-wrap: balance; }
a { color: var(--color-primary); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--color-primary-2); }
button { cursor: pointer; font: inherit; color: inherit; background: none; border: none; }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 3px; border-radius: 3px; }

code { font-family: 'JetBrains Mono', monospace; font-size: 0.9em; background: var(--color-surface-2); padding: 0.1em 0.3em; border-radius: 3px; }

/* --- Topbar --- */
.topbar { background: var(--color-surface); border-bottom: 1px solid var(--color-border); position: static; }
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { width: 36px; height: 36px; color: var(--color-primary); flex-shrink: 0; }
.brand h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { font-size: 0.8rem; color: var(--color-text-muted); }
.last-updated { font-size: 0.72rem; color: var(--color-text-faint); font-family: 'JetBrains Mono', monospace; white-space: nowrap; }

/* --- Navbar --- */
.navbar { background: var(--color-surface-2); border-bottom: 1px solid var(--color-border); position: sticky; top: 0; z-index: 60; }
.navbar-inner { max-width: 1100px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; justify-content: space-between; min-height: 46px; }
.nav-menu { display: flex; align-items: center; flex: 1; justify-content: space-between; }
.nav-links { display: flex; list-style: none; gap: 4px; flex-shrink: 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.topbar-actions .refresh-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 6px; border: 1px solid var(--color-border);
  background: var(--color-surface); color: var(--color-text);
  font-size: 0.78rem; cursor: pointer; transition: background 0.15s;
}
.topbar-actions .refresh-btn:hover { background: var(--color-primary); color: #fff; }
.topbar-actions [data-theme-toggle] { background: none; border: none; color: var(--color-text-muted); cursor: pointer; padding: 4px; }
.topbar-actions [data-theme-toggle]:hover { color: var(--color-primary); }
.nav-links a {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 12px; border-radius: 6px;
  font-size: 0.82rem; font-weight: 500; color: var(--color-text-muted);
  text-decoration: none; transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}
.nav-links a:hover, .nav-links a.active { color: var(--color-primary); background: var(--color-surface); }

.hamburger { display: none; flex-direction: column; justify-content: center; gap: 4px; width: 38px; height: 38px; padding: 8px; }
.hamburger span { display: block; height: 2px; width: 100%; background: var(--color-text); border-radius: 2px; transition: transform 0.2s, opacity 0.2s; }
.hamburger.open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

section[id] { scroll-margin-top: 70px; }

@media (max-width: 900px) {
  .hamburger { display: flex; }
  .nav-menu {
    position: absolute; top: 46px; left: 0; right: 0;
    flex-direction: column; background: var(--color-surface);
    border-bottom: 1px solid var(--color-border); padding: 8px 12px;
    transform: translateY(-200%); transition: transform 300ms ease; z-index: 99;
  }
  .nav-menu.open { transform: translateY(0); }
  .nav-links { flex-direction: column; gap: 2px; }
  .nav-links a { padding: 10px 12px; }
  
}

/* --- Container --- */
.container { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; display: flex; flex-direction: column; gap: 28px; }

/* --- Section Head --- */
.section-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.q-num {
  width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0;
  background: color-mix(in srgb, var(--color-primary) 50%, #0b0f14); color: #fff; font-weight: 700; font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
  font-family: 'JetBrains Mono', monospace;
}
.section-head h2 { font-size: 1.15rem; font-weight: 700; }
.card-note { font-size: 0.78rem; color: var(--color-text-faint); }

/* --- Lead Card --- */
.lead-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary); border-radius: 10px; padding: 28px;
  box-shadow: var(--shadow-sm);
}
.lead-badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; background: rgba(245, 158, 11, 0.12); color: var(--color-primary); margin-bottom: 12px; }
.lead-card h2 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 8px; }
.lead-subhead { color: var(--color-text-muted); font-size: 1.02rem; margin-bottom: 16px; line-height: 1.55; }
.pullquote {
  border-left: 3px solid var(--color-primary); padding: 10px 16px;
  font-size: 0.9rem; color: var(--color-text-muted); font-style: italic; line-height: 1.55;
}

/* --- Figures Grid --- */
.figures-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px;
}
.figure-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 10px; padding: 20px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 10px;
}
.figure-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.figure-card h3 { font-size: 1.05rem; font-weight: 700; }
.figure-role { font-size: 0.76rem; color: var(--color-primary-2); font-weight: 600; }
.sf-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.sf-tag {
  font-size: 0.7rem; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: rgba(124, 58, 237, 0.1); color: var(--color-accent);
}
.figure-manifest { font-size: 0.82rem; color: var(--color-text); line-height: 1.5; }
.figure-misreading { font-size: 0.8rem; color: var(--color-text-muted); font-style: italic; line-height: 1.5; padding: 8px 12px; background: var(--color-surface-2); border-radius: 6px; }
.dick-traits { display: flex; flex-wrap: wrap; gap: 4px; margin-top: auto; padding-top: 8px; border-top: 1px solid var(--color-divider); }
.dick-trait {
  font-size: 0.66rem; font-weight: 600; padding: 2px 6px; border-radius: 4px;
  background: rgba(245, 158, 11, 0.08); color: var(--color-warning);
  text-transform: uppercase; letter-spacing: 0.03em;
}
.figure-sources { display: flex; flex-wrap: wrap; gap: 6px; }
.figure-sources a { font-size: 0.72rem; }

/* --- Works Table --- */
.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--color-border); margin-top: 4px; }
.works-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.works-table th {
  text-align: left; padding: 10px 14px; font-weight: 600; font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-muted);
  background: var(--color-surface-offset); border-bottom: 2px solid var(--color-border);
}
.works-table td { padding: 12px 14px; border-bottom: 1px solid var(--color-divider); vertical-align: top; line-height: 1.5; }
.works-table td:first-child { font-weight: 700; color: var(--color-primary); white-space: nowrap; }
.works-table td:nth-child(2) { font-size: 0.78rem; color: var(--color-text-muted); white-space: nowrap; }
.works-table td:nth-child(3), .works-table td:nth-child(4) { font-size: 0.82rem; }
.works-table td:last-child { font-size: 0.78rem; color: var(--color-primary-2); font-weight: 500; }
.works-table tr:last-child td { border-bottom: none; }

/* --- Dick Lens Grid --- */
.dick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.dick-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 10px; padding: 20px; box-shadow: var(--shadow-sm);
}
.dick-card h3 { font-size: 0.95rem; font-weight: 700; color: var(--color-primary); margin-bottom: 6px; }
.dick-work { font-size: 0.72rem; color: var(--color-text-faint); font-weight: 500; margin-bottom: 8px; }
.dick-quote { font-size: 0.82rem; color: var(--color-text-muted); font-style: italic; line-height: 1.5; padding: 8px 12px; background: var(--color-surface-2); border-radius: 6px; margin-bottom: 10px; border-left: 3px solid var(--color-accent); }
.dick-manifest { font-size: 0.82rem; color: var(--color-text); line-height: 1.5; }

/* --- Methodology & Sources --- */
.methodology-content { margin-bottom: 20px; }
.methodology-content ol { margin: 0 0 12px 18px; font-size: 0.86rem; color: var(--color-text-muted); display: flex; flex-direction: column; gap: 6px; }
.methodology-content li { line-height: 1.5; }
.sources-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 8px; }
.sources-row { display: flex; flex-wrap: wrap; gap: 8px; }
.sources-grid a, .sources-row a {
  font-size: 0.78rem; color: var(--color-primary-2); text-decoration: none;
  border: 1px solid var(--color-border); padding: 5px 12px; border-radius: 999px;
  transition: background 0.15s, color 0.15s; white-space: nowrap;
}
.sources-grid a:hover, .sources-row a:hover { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* --- Footer --- */
.footer { text-align: center; padding: 20px; font-size: 0.74rem; color: var(--color-text-faint); border-top: 1px solid var(--color-border); }

/* --- Toast --- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--color-surface); color: var(--color-text);
  border: 1px solid var(--color-border); border-left: 4px solid var(--color-success);
  padding: 12px 20px; border-radius: 8px; font-size: 0.86rem;
  box-shadow: var(--shadow-md); opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-left-color: var(--color-error); }
.toast.info { border-left-color: var(--color-primary); }

@media (max-width: 640px) {
  .container { padding: 16px 12px 40px; gap: 20px; }
  .lead-card { padding: 20px; }
  .lead-card h2 { font-size: 1.25rem; }
  .works-table th, .works-table td { padding: 8px 6px; }
}

/* --- Hero Background Transparency Overrides (20% transparent = 80% opaque) --- */
body {
  background-color: color-mix(in srgb, var(--color-bg) 85%, transparent);
}

.topbar {
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  backdrop-filter: blur(8px);
}

.navbar {
  background: color-mix(in srgb, var(--color-surface-2) 80%, transparent);
  backdrop-filter: blur(24px);
}

.lead-card {
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  backdrop-filter: blur(4px);
}

.figure-card {
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  backdrop-filter: blur(4px);
}

.dick-card {
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  backdrop-filter: blur(4px);
}

.works-table th {
  background: color-mix(in srgb, var(--color-surface-offset) 80%, transparent);
  backdrop-filter: blur(4px);
}

.table-wrap {
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  backdrop-filter: blur(4px);
}

.methodology-content {
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  backdrop-filter: blur(4px);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 16px;
}

.sources-grid a, .sources-row a {
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
}

.nav-menu {
  background: color-mix(in srgb, var(--color-surface) 85%, transparent);
  backdrop-filter: blur(32px);
}

.toast {
  background: color-mix(in srgb, var(--color-surface) 85%, transparent);
  backdrop-filter: blur(16px);
}

.footer {
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  backdrop-filter: blur(4px);
}

/* --- Subnav dropdown (subsection sub-items) --- */
.nav-item { position: relative; }
.subnav {
  position: absolute; top: 100%; left: 0; min-width: 240px; max-height: 70vh; overflow-y: auto;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 8px; box-shadow: var(--shadow-md);
  display: none; flex-direction: column; padding: 6px; z-index: 300;
}
.nav-item:hover .subnav,
.nav-item:focus-within .subnav,
.nav-item.subnav-open .subnav { display: flex; }
.subnav a {
  padding: 7px 12px; font-size: 0.76rem; border-radius: 6px;
  color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.subnav a:hover { background: var(--color-surface-offset); color: var(--color-primary); }
@media (max-width: 900px) {
  .subnav { position: static; min-width: 0; max-height: none; box-shadow: none; border: none; border-left: 1px solid var(--color-divider); margin: 0 0 4px 14px; padding: 2px 0 2px 8px; display: none; }
  .nav-item.subnav-open .subnav { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Nav / subnav horizontal overflow guard --- */
.nav-links { flex-wrap: nowrap; flex-shrink: 0; }
.nav-menu { min-width: 0; }
.navbar-inner { height: auto; }
#refresh-btn { display: none; }
.nav-item.subnav-right > .subnav { left: auto !important; right: 0 !important; }
.nav-item.subnav-right > .subnav.subnav-nested { left: auto !important; right: 100% !important; }
html.nav-collapsed .hamburger { display: flex; }
html.nav-collapsed .nav-menu { position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; background: var(--color-surface); border-bottom: 1px solid var(--color-border); padding: 8px 12px; transform: translateY(-200%); transition: transform 300ms ease; z-index: 99; }
html.nav-collapsed .nav-menu.open { transform: translateY(0); }
html.nav-collapsed .nav-links { flex-direction: column; gap: 2px; }
html.nav-collapsed .nav-links a { padding: 10px 12px; }


/* research corpus (md2wiki researchFiles) */
.research-list { display: flex; flex-wrap: wrap; gap: 8px; }
.research-link { font-size: 0.82rem; color: var(--color-primary); text-decoration: none; background: var(--color-surface-2, rgba(0,0,0,0.04)); border: 1px solid var(--color-border); padding: 5px 10px; border-radius: 999px; }
.research-link:hover { text-decoration: underline; }
