/* ---------------------------------------------------------------- tokens */
:root {
  color-scheme: light;
  --surface-0: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #eceae5;
  --surface-sunken: #e6e4de;
  --border: #d9d6cf;
  --border-strong: #bcb8ae;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #86847d;
  --accent: #2a78d6;
  --accent-soft: #e3edfb;
  --ink: #33322f;           /* phase-boundary ink */
  --tieline: #b9b6ad;
  --invariant: #c8322f;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --grid: #e4e2dc;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.05);
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --surface-sunken: #0d0d0c;
    --border: #34342f;
    --border-strong: #4a4a44;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8d8c83;
    --accent: #3987e5;
    --accent-soft: #16283f;
    --ink: #d6d5cc;
    --tieline: #4e4d47;
    --invariant: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --grid: #2b2b28;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211; --surface-1: #1a1a19; --surface-2: #232322;
  --surface-sunken: #0d0d0c; --border: #34342f; --border-strong: #4a4a44;
  --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #8d8c83;
  --accent: #3987e5; --accent-soft: #16283f; --ink: #d6d5cc; --tieline: #4e4d47;
  --invariant: #e66767; --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --grid: #2b2b28; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
/* the host page's reset declares [hidden] at the same specificity as our
   component classes, so display rules like .toggle would otherwise win */
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--surface-0); color: var(--text-primary);
  font-family: var(--sans); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
button { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- header */
header {
  display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap;
  padding: 14px 20px; background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
header h1 { font-size: 16px; letter-spacing: -.01em; }
header .tag {
  font-size: 11px; font-family: var(--mono); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 99px; padding: 1px 8px;
}
header .spacer { flex: 1; }
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 5px 10px; cursor: pointer;
  font-size: 12px; color: var(--text-secondary);
}
.icon-btn:hover { border-color: var(--border-strong); color: var(--text-primary); }

main { padding: 16px 20px 48px; max-width: 1560px; margin: 0 auto; }

.panel {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.panel-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.panel-head h2 { font-size: 13px; letter-spacing: .02em; text-transform: uppercase;
  color: var(--text-secondary); font-weight: 600; }
.panel-body { padding: 14px; }

/* ------------------------------------------------------- periodic table */
.ptable-wrap { overflow-x: auto; padding-bottom: 4px; }
.ptable {
  display: grid;
  grid-template-columns: repeat(18, minmax(30px, 1fr));
  gap: 3px; min-width: 620px;
}
.pt-cell {
  grid-row: var(--r); grid-column: var(--c);
  aspect-ratio: 1 / 1; border-radius: 5px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0; line-height: 1.05; transition: transform .08s ease, background .12s ease;
}
.pt-cell .sym { font-size: clamp(10px, 1.05vw, 14px); font-weight: 600; }
.pt-cell .z { position: absolute; top: 2px; left: 3px; font-size: 8px; color: var(--text-muted); }
.pt-cell .cnt { font-size: 8px; color: var(--text-muted); font-family: var(--mono); }
.pt-cell:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--border-strong); }
.pt-cell[data-state="off"] { opacity: .28; cursor: not-allowed; }
.pt-cell[data-state="on"] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.pt-cell[data-state="on"] .z, .pt-cell[data-state="on"] .cnt { color: rgba(255,255,255,.8); }
.pt-cell[data-state="dim"] { opacity: .35; }
.pt-gap { grid-row: 8; height: 6px; }
.pt-label {
  grid-row: var(--r); grid-column: 1 / 3;
  font-size: 9px; color: var(--text-muted);
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 8px; white-space: nowrap;
}
/* visual break between the main table and the detached f-block */
.ptable { row-gap: 3px; }
.pt-cell[style*="--r:9"], .pt-label[style*="--r:9"] { margin-top: 10px; }

/* --------------------------------------------------------- selection bar */
.selbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 14px 0; padding: 10px 14px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 99px; padding: 3px 6px 3px 11px; font-weight: 600; font-size: 13px;
}
.chip button {
  border: 0; background: none; cursor: pointer; padding: 0 3px;
  color: inherit; opacity: .65; font-size: 14px; line-height: 1;
}
.chip button:hover { opacity: 1; }
.selbar .order { font-family: var(--mono); font-size: 12px; color: var(--text-muted); }
.selbar .hint { color: var(--text-muted); font-size: 13px; }
input[type="search"], select {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 9px; color: var(--text-primary); font: inherit;
  font-size: 13px; min-width: 150px;
}
input[type="search"]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.plot-toolbar select { min-width: 0; padding: 3px 6px; font-size: 12px; }

/* --------------------------------------------------------------- layout */
.split { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

/* -------------------------------------------------------------- results */
.results { max-height: 68vh; overflow-y: auto; }
.result {
  display: grid; grid-template-columns: auto 1fr; gap: 10px;
  padding: 9px 12px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.result:last-child { border-bottom: 0; }
.result:hover { background: var(--surface-2); }
.result[aria-selected="true"] { background: var(--accent-soft); }
.result .swatch {
  width: 3px; border-radius: 2px; background: transparent; align-self: stretch;
}
.result .name { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.result .meta { font-size: 11.5px; color: var(--text-muted); }
.result .badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.badge {
  font-size: 10px; font-family: var(--mono); padding: 0 5px; border-radius: 3px;
  border: 1px solid var(--border); color: var(--text-muted); background: var(--surface-2);
}
.badge.warn { color: var(--invariant); border-color: color-mix(in srgb, var(--invariant) 40%, transparent); }
/* how the data was produced - distinct from the neutral descriptive badges */
.badge.method {
  color: var(--accent); background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  font-weight: 600; letter-spacing: .02em;
}
.empty { padding: 28px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ----------------------------------------------------------------- plot */
.plot-panel { min-height: 420px; }
#plot { width: 100%; display: block; touch-action: none; }
#plot text { font-family: var(--sans); fill: var(--text-secondary); }
#plot .axis-line { stroke: var(--border-strong); stroke-width: 1; }
#plot .grid-line { stroke: var(--grid); stroke-width: 1; }
#plot .tick { font-size: 11px; }
#plot .axis-title { font-size: 12.5px; fill: var(--text-primary); font-weight: 500; }
#plot .boundary { fill: none; stroke-width: 1.6;
  stroke-linejoin: round; stroke-linecap: round; }
/* every assessment other than the highlighted one, and every assessment while
   none is highlighted - one style throughout, so selecting a database only
   adds a bold curve instead of restyling everything under it */
#plot .ghost { fill: none; stroke-width: .9; stroke-linejoin: round;
  stroke-linecap: round; stroke-opacity: .3; stroke-dasharray: 3 2.5; }
#plot .tieline { stroke-width: .6; }
#plot .invariant { stroke-width: 1.5; }
#plot .plabel { font-size: 11px; fill: var(--text-primary); font-family: var(--mono); }
#plot .plabel-bg { fill: var(--surface-1); fill-opacity: .82; }
#plot .crosshair { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
#plot .zoombox { fill: var(--accent); fill-opacity: .12; stroke: var(--accent); stroke-width: 1; }
.plot-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toggle {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
  color: var(--text-secondary); cursor: pointer; user-select: none;
}
.readout {
  font-family: var(--mono); font-size: 12px; color: var(--text-secondary);
  min-height: 18px; padding: 0 14px 10px;
}
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 10px 14px 0; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  color: var(--text-secondary); font-family: var(--mono); }
.legend-line { width: 18px; height: 0; border-top-width: 2px; border-top-style: solid; }

/* ---------------------------------------------------------------- meta */
.meta-grid { display: grid; grid-template-columns: 128px 1fr; gap: 4px 12px; font-size: 13px; }
.meta-grid dt { color: var(--text-muted); }
.meta-grid dd { margin: 0; }
.phase-list { display: flex; flex-wrap: wrap; gap: 4px; }
.notes {
  margin-top: 10px; padding: 9px 11px; background: var(--surface-sunken);
  border-radius: 6px; font-family: var(--mono); font-size: 11.5px;
  color: var(--text-secondary); white-space: pre-wrap; max-height: 190px; overflow: auto;
}
.tablebox { max-height: 260px; overflow: auto; margin-top: 10px; }
table.data { border-collapse: collapse; width: 100%; font-size: 12px; font-family: var(--mono); }
table.data th, table.data td { text-align: left; padding: 3px 8px; border-bottom: 1px solid var(--border); }
table.data th { color: var(--text-muted); font-weight: 600; position: sticky; top: 0; background: var(--surface-1); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.spinner { color: var(--text-muted); font-size: 13px; padding: 30px; text-align: center; }

/* ---------------------------------------------------------------- about */
footer#about {
  margin-top: 28px; padding: 16px 18px; border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 12.5px; max-width: 78ch;
}
footer#about p { margin: 0 0 8px; }
footer#about a { color: var(--accent); }
footer#about code { font-family: var(--mono); font-size: 11.5px; }

/* --------------------------------------------------------------- cite */
.cite {
  margin-top: 12px; padding: 10px 12px; border-radius: 6px;
  background: var(--surface-sunken); border: 1px solid var(--border);
  font-size: 12.5px; line-height: 1.55;
}
.cite h4 {
  margin: 0 0 6px; font-size: 11px; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-muted); font-weight: 600;
}
.cite p { margin: 0 0 6px; }
.cite p:last-child { margin-bottom: 0; }
.cite a { color: var(--accent); }
.cite .who { color: var(--text-muted); }
