@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2");
}

:root {
  --bg: #062033;
  --ink: #e7f4ff;
  --muted: #8fb4d4;
  --line: rgba(150, 198, 235, 0.45);
  --plate: rgba(8, 32, 54, 0.92);
  --blue: #7ec8ff;
  --sans: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(4, 18, 32, 0.2), rgba(3, 14, 26, 0.55)),
    repeating-linear-gradient(0deg, transparent 0 47px, rgba(126, 186, 230, 0.09) 48px),
    repeating-linear-gradient(90deg, transparent 0 47px, rgba(126, 186, 230, 0.09) 48px),
    radial-gradient(900px 620px at 50% 42%, #0e4c78 0%, #041525 68%);
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid #d7f1ff; outline-offset: 2px; }
[hidden] { display: none !important; }
.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}

#graph { position: fixed; inset: 0; z-index: 0; }
#graph canvas { display: block; }

#loader, #error, .noscript {
  position: fixed; inset: 0; z-index: 8;
  display: grid; place-items: center; gap: 0.8rem;
  background: rgba(4, 18, 32, 0.78);
  text-align: center; padding: 1.5rem;
}
body.ready #loader { display: none; }
.noscript { position: fixed; }

.mast, #legend, #hint, #tools, #caption { z-index: 3; }
#searchwrap, #panel { z-index: 5; }
.overlay { z-index: 6; }

.mast {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: auto 1fr auto minmax(220px, 320px);
  gap: 0.8rem 1.2rem;
  align-items: end;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(180deg, rgba(5, 22, 38, 0.94), rgba(5, 22, 38, 0.78));
  border-bottom: 1px solid var(--line);
}
.mast::before, .mast::after {
  content: "";
  position: absolute;
  width: 12px; height: 12px;
  border: 1px solid #9fd4ff;
  pointer-events: none;
}
.mast::before { top: 6px; left: 6px; border-right: 0; border-bottom: 0; }
.mast::after { top: 6px; right: 6px; border-left: 0; border-bottom: 0; }
.home {
  align-self: center;
  color: var(--blue);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  border-bottom: 1px solid transparent;
}
.home:hover { border-bottom-color: var(--blue); }
.mast-title { min-width: 0; }
.kicker {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #9fd4ff;
}
h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2vw, 1.7rem);
  font-weight: 500;
  letter-spacing: -0.03em;
}
.gauges {
  display: flex;
  gap: 0;
  margin: 0;
  border: 1px solid var(--line);
}
.gauges p {
  margin: 0;
  min-width: 4.6rem;
  padding: 0.25rem 0.55rem 0.3rem;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}
.gauges p:last-child { border-right: 0; }
.gauges b {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 500;
}
.gauges span {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

#searchwrap { position: relative; align-self: center; }
#q {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 0.4rem 0.1rem;
  font-size: 16px;
  border-radius: 0;
}
#q::placeholder { color: #7fa6c6; }
#results {
  list-style: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  margin: 0;
  padding: 0.25rem;
  background: var(--plate);
  border: 1px solid var(--line);
  max-height: min(46vh, 280px);
  overflow: auto;
}
#results button, #lbody button, #plinks button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0.55rem 0.45rem;
  min-height: 44px;
  display: flex;
  justify-content: flex-start;
  gap: 0.45rem;
  align-items: baseline;
  flex-wrap: wrap;
}
#results button:hover, #results button[aria-selected="true"],
#lbody button:hover, #plinks button:hover { background: rgba(126, 200, 255, 0.14); }
#results .kind, #lbody .kind { margin-left: auto; color: var(--muted); font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
#results .empty, #plinks .empty { padding: 0.7rem; color: var(--muted); }

#legend {
  position: fixed;
  left: 16px;
  top: 92px;
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--line);
  background: rgba(6, 28, 46, 0.82);
  max-width: 190px;
}
#legend button {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 40px;
  padding: 0.3rem 0.6rem;
  border: 0;
  border-bottom: 1px solid rgba(150, 198, 235, 0.25);
  background: transparent;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
#legend button:last-child { border-bottom: 0; }
#legend button[aria-pressed="true"] { background: rgba(126, 200, 255, 0.16); }
#legend b { margin-left: auto; color: var(--muted); font-weight: 500; }
.swatch { width: 0.7rem; height: 0.7rem; display: inline-block; background: var(--swatch, var(--blue)); }
.swatch-sphere { border-radius: 50%; }
.swatch-cube { border-radius: 1px; }
.swatch-ring { border-radius: 50%; background: transparent !important; box-shadow: inset 0 0 0 2px var(--swatch, var(--blue)); }
.swatch-octahedron { transform: rotate(45deg); border-radius: 1px; }
.swatch-crystal { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.swatch-tetra { clip-path: polygon(50% 0, 100% 100%, 0 100%); }

#hint {
  position: fixed;
  left: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  margin: 0;
  max-width: 16rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

#tools {
  position: fixed;
  right: 16px;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--line);
  background: rgba(6, 28, 46, 0.9);
}
#tools button, .text-btn, .x {
  min-width: 44px;
  min-height: 40px;
  border: 0;
  border-bottom: 1px solid rgba(150, 198, 235, 0.28);
  background: transparent;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.95rem;
}
#tools button:last-child, .cnav .text-btn:last-child { border-bottom: 0; }
#tools button[aria-pressed="true"] { background: #145a92; color: white; }
.text-btn { padding: 0 0.75rem; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.text-btn.ghost { background: transparent; }

#panel {
  position: fixed;
  top: 108px;
  right: 112px;
  width: min(340px, calc(100vw - 120px));
  max-height: min(68vh, 560px);
  overflow: auto;
  padding: 0.9rem 1rem 1.1rem;
  background: var(--plate);
  border: 1px solid var(--line);
  box-shadow: 8px 12px 0 rgba(4, 16, 28, 0.35);
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 0 100%);
}
.handle { display: none; }
.ptype {
  margin: 0 0 0.35rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--c, var(--blue));
}
#ptitle { margin: 0 2rem 0.45rem 0; font-size: 1.35rem; font-weight: 500; letter-spacing: -0.03em; }
#psummary { margin: 0; color: #d5eaf8; }
.degree { color: var(--muted); font-family: var(--mono); font-size: 0.78rem; }
#panel h3 {
  margin: 1rem 0 0.25rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}
#plinks { list-style: none; margin: 0; padding: 0; border-top: 1px solid rgba(150, 198, 235, 0.28); }
#plinks .rel { color: #b7ddff; font-family: var(--mono); font-size: 0.82rem; }
#panel .x { position: absolute; top: 8px; right: 8px; border: 1px solid var(--line); background: transparent; }

#caption {
  position: fixed;
  left: 16px;
  bottom: 78px;
  width: min(420px, calc(100% - 120px));
  padding: 0.8rem 0.9rem 0.9rem;
  background: var(--plate);
  border: 1px solid var(--line);
}
#progress { display: flex; gap: 4px; margin-bottom: 0.45rem; }
#progress i { height: 3px; flex: 1; background: rgba(150, 198, 235, 0.28); }
#progress i.on, #progress i.done { background: #9fd4ff; }
.eyebrow { margin: 0; font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.16em; text-transform: uppercase; color: #9fd4ff; }
#ctitle { margin: 0.15rem 0; font-size: 1.25rem; font-weight: 500; }
#cbody { margin: 0 0 0.7rem; color: #d5eaf8; }
.cnav { display: flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--line); }
.cnav .text-btn { border-right: 1px solid var(--line); border-bottom: 0; }

.overlay {
  position: fixed; inset: 0;
  background: rgba(3, 12, 22, 0.66);
  display: grid; place-items: center;
  padding: 16px;
}
.sheet {
  position: relative;
  width: min(480px, 100%);
  max-height: min(80vh, 640px);
  overflow: auto;
  background: #071e33;
  border: 1px solid var(--line);
  padding: 1rem 1rem 1.15rem;
}
.sheet h2 { margin: 0 0 0.7rem; font-weight: 500; }
.sheet .x { position: absolute; top: 8px; right: 8px; border: 1px solid var(--line); background: #071e33; }
dl { display: grid; grid-template-columns: 5rem 1fr; gap: 0.4rem 0.8rem; margin: 0; font-family: var(--mono); font-size: 0.86rem; }
dt { color: #d7f1ff; }
dd { margin: 0; color: #c5dfef; }
.note { color: var(--muted); }
.toggle { display: flex; gap: 0.55rem; align-items: center; min-height: 44px; }
#lbody h3 { margin: 0.85rem 0 0.15rem; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; }
#lbody ul { list-style: none; margin: 0; padding: 0; }
#lbody .sum { display: block; color: var(--muted); font-size: 0.82rem; }

@media (max-width: 800px) {
  .mast {
    grid-template-columns: 1fr auto;
    align-items: start;
  }
  .gauges { grid-column: 1 / -1; }
  #searchwrap { grid-column: 1 / -1; }
  #legend {
    top: auto;
    bottom: calc(58px + env(safe-area-inset-bottom));
    left: 8px; right: 8px;
    max-width: none;
    flex-direction: row;
    flex-wrap: wrap;
  }
  #legend button { flex: 1 1 auto; border-bottom: 0; border-right: 1px solid rgba(150, 198, 235, 0.25); font-size: 0.66rem; }
  #hint { display: none; }
  #tools { flex-direction: row; left: 8px; right: 8px; width: auto; }
  #tools button { flex: 1 1 0; border-bottom: 0; border-right: 1px solid rgba(150, 198, 235, 0.28); padding: 0 0.15rem; min-width: 0; font-size: 0.68rem; }
  #panel {
    top: auto;
    left: 8px; right: 8px;
    bottom: calc(148px + env(safe-area-inset-bottom));
    width: auto;
    max-height: min(46vh, 380px);
    clip-path: none;
    box-shadow: none;
  }
  .handle {
    display: block;
    width: 36px; height: 3px;
    margin: 0 auto 0.6rem;
    background: rgba(159, 212, 255, 0.7);
  }
  #caption {
    left: 8px; right: 8px; width: auto;
    bottom: calc(148px + env(safe-area-inset-bottom));
  }
}

@media (min-width: 801px) {
  .mast { padding-right: 18px; }
}
