/* Pantheon Biography Matrix — "observatory atlas" theme.
   Dark indigo field, warm gold accent, editorial serif display. */

:root {
  --bg:        #0b0c12;
  --bg-2:      #111219;
  --bg-3:      #171927;
  --bg-well:   #0e0f17;
  --line:      #262835;
  --line-lit:  #383b4d;
  --ink:       #ece9e0;
  --ink-dim:   #9a9aab;
  --ink-faint: #5f606d;
  --gold:      #e6b64c;
  --gold-dim:  #9c7e3c;
  --grid-bg:   #0f0f1a;

  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-ui: 'Archivo', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Faint grain + a low glow behind the header. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.4'/></svg>");
  opacity: 0.025;
  mix-blend-mode: screen;
}

/* ---- Header ---------------------------------------------------------- */

.app-header {
  flex: none;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 22px 34px 20px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(620px 150px at 18% -40%, rgba(230, 182, 76, 0.10), transparent 70%),
    var(--bg-2);
  animation: drop-in 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.app-header-mark {
  font-size: 26px;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(230, 182, 76, 0.5);
}

.app-header-text { flex: 1; }

.app-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(26px, 3vw, 38px);
  letter-spacing: -0.015em;
  line-height: 1;
}

.app-header h1 em {
  font-style: italic;
  font-weight: 500;
  color: var(--gold);
}

.app-header-sub {
  margin: 7px 0 0;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.app-header-source {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.5;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: right;
  color: var(--ink-faint);
  border-left: 1px solid var(--line);
  padding-left: 22px;
}

/* ---- Layout ---------------------------------------------------------- */

.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ---- Controls panel -------------------------------------------------- */

.controls {
  flex: none;
  width: 320px;
  overflow-y: auto;
  padding: 8px 26px 30px;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  animation: slide-right 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) 0.08s both;
}

.control-group {
  padding: 22px 0;
  border-bottom: 1px solid var(--line);
}

.control-label {
  margin: 0 0 4px;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.control-label span {
  color: var(--gold);
  font-size: 11px;
}

.control-hint {
  margin: 0 0 13px;
  font-size: 12px;
  color: var(--ink-faint);
}

/* Segmented control */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line-lit);
  border-radius: 3px;
  overflow: hidden;
}

.seg input { position: absolute; opacity: 0; pointer-events: none; }

.seg label {
  text-align: center;
  padding: 9px 0;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.seg label:first-of-type { border-right: 1px solid var(--line-lit); }
.seg label:hover { color: var(--ink); }

.seg input:checked + label {
  background: var(--gold);
  color: #1a160b;
  font-weight: 500;
}

.seg input:focus-visible + label { outline: 2px solid var(--gold); outline-offset: -2px; }

/* Fields */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

.field-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.field > label,
.field-head label {
  font-size: 12px;
  color: var(--ink-dim);
  letter-spacing: 0.02em;
}

.readout {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--gold-dim);
  letter-spacing: 0.04em;
}

.field-pair {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-dash { color: var(--ink-faint); }

input[type="number"] {
  width: 100%;
  min-width: 0;
  padding: 8px 9px;
  background: var(--bg-well);
  border: 1px solid var(--line-lit);
  border-radius: 3px;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13px;
  text-align: center;
}

input[type="number"]::-webkit-inner-spin-button { opacity: 0.35; }

select {
  width: 100%;
  margin-top: 6px;
  padding: 8px 9px;
  background: var(--bg-well);
  border: 1px solid var(--line-lit);
  border-radius: 3px;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 12.5px;
  cursor: pointer;
}

input[type="number"]:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(230, 182, 76, 0.16);
}

/* Custom checkbox */
.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 15px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--ink-dim);
  line-height: 1.4;
}

.check input { position: absolute; opacity: 0; pointer-events: none; }

.check-box {
  flex: none;
  width: 17px;
  height: 17px;
  margin-top: 1px;
  border: 1px solid var(--line-lit);
  border-radius: 3px;
  background: var(--bg-well);
  position: relative;
  transition: background 0.15s, border-color 0.15s;
}

.check input:checked + .check-box {
  background: var(--gold);
  border-color: var(--gold);
}

.check input:checked + .check-box::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid #1a160b;
  border-width: 0 2px 2px 0;
  transform: rotate(43deg);
}

.check input:focus-visible + .check-box {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.check-text em { font-style: italic; color: var(--ink-faint); }

.reset-btn {
  margin-top: 22px;
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px solid var(--line-lit);
  border-radius: 3px;
  color: var(--ink-dim);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.reset-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ---- View ------------------------------------------------------------ */

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  animation: fade-in 0.7s ease 0.16s both;
}

.view-top {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 30px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.summary {
  margin: 0;
  font-size: 13px;
  color: var(--ink-dim);
}

.summary strong {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--gold);
}

/* Legend */
.legend {
  display: flex;
  align-items: center;
  gap: 10px;
}

.legend-cap {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.legend-bar {
  width: 168px;
  height: 11px;
  border-radius: 2px;
  border: 1px solid var(--line-lit);
  background: linear-gradient(
    90deg,
    #440154 0%, #3b528b 25%, #21918c 50%, #5ec962 75%, #fde725 100%
  );
}

.legend-scale {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
}

.legend-scale strong { color: var(--gold); font-weight: 500; }

.empty {
  margin: 0;
  padding: 60px 30px;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 19px;
  color: var(--ink-faint);
}

/* ---- Matrix ---------------------------------------------------------- */

.matrix-container {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--grid-bg);
}

.matrix-grid {
  display: grid;
  width: max-content;
}

.matrix-corner,
.matrix-col-headers,
.matrix-row-headers {
  background: var(--bg-2);
}

.matrix-corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 3;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-end;
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.matrix-col-headers {
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 1px solid var(--line);
}

.matrix-row-headers {
  position: sticky;
  left: 0;
  z-index: 2;
  border-right: 1px solid var(--line);
}

.matrix-col-head {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 9px;
}

.matrix-col-head span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  max-height: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: lowercase;
  font-variant: small-caps;
  color: var(--ink-dim);
  transition: color 0.12s;
}

.matrix-row-head {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  padding: 0 11px;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink-dim);
  transition: color 0.12s;
}

.matrix-col-head.is-hover span,
.matrix-row-head.is-hover {
  color: var(--gold);
  font-weight: 600;
}

.matrix-canvas-wrap { position: relative; }

.matrix-canvas {
  display: block;
  cursor: crosshair;
}

.matrix-highlight {
  position: absolute;
  pointer-events: none;
  border: 2px solid var(--gold);
  box-shadow: 0 0 14px rgba(230, 182, 76, 0.55);
  z-index: 1;
}

.matrix-tooltip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  padding: 9px 12px;
  background: var(--bg-3);
  border: 1px solid var(--line-lit);
  border-radius: 4px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.6);
  max-width: 280px;
}

.matrix-tooltip-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 3px;
}

.matrix-tooltip-count {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--gold);
}

/* ---- Status / loading ----------------------------------------------- */

.status {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  transition: opacity 0.4s ease;
}

.status.is-hidden { opacity: 0; pointer-events: none; }

.status.is-error {
  color: #e6736b;
  text-transform: none;
  letter-spacing: 0;
  font-family: var(--font-ui);
  font-size: 14px;
}

.status-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line-lit);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.status.is-error .status-spinner { display: none; }

/* ---- Scrollbars ------------------------------------------------------ */

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: var(--line-lit);
  border: 3px solid var(--bg);
  border-radius: 6px;
}
::-webkit-scrollbar-thumb:hover { background: var(--gold-dim); }
::-webkit-scrollbar-corner { background: var(--bg); }

/* ---- Animations ------------------------------------------------------ */

@keyframes drop-in {
  from { opacity: 0; transform: translateY(-14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slide-right {
  from { opacity: 0; transform: translateX(-18px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

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