:root {
  color-scheme: light;
  --surface: #f5f7fb; --viewport: #eef2f7; --text: #0f172a; --muted: #526277;
  --kicker: #71839b; --border: rgba(15,23,42,.08); --chip: #fff; --focus: #2f6db5;
  --o0: #2f6db5; --o1: #d9542b; --o2: #e0a526; --o3: #1f9e89; --o4: #b8407a;
  --lattice: #7a8699; --edited: #d9542b;
  font-family: Roboto, system-ui, sans-serif; color: var(--text);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #121828; --viewport: #0a0f1c; --text: #eef3ff; --muted: rgba(236,242,255,.72);
  --kicker: rgba(236,242,255,.54); --border: rgba(238,243,255,.12); --chip: #1a2135; --focus: #5b9be6;
  --o0: #5b9be6; --o1: #f07a52; --o2: #f2bf4a; --o3: #3fc4ad; --o4: #e06aa6;
  --lattice: #8a96aa; --edited: #f07a52;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--surface); font-size: 13px; }
.embed-mode body { background: transparent; }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
button { border: 0; background: none; }
a { color: inherit; }
button, a, input, [tabindex] { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.ov { text-decoration: overline; }
sub { font-size: .73em; line-height: 0; }
i { font-weight: 400; }
.standalone-header { max-width: 1120px; margin: 0 auto; padding: 32px 16px 12px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
h1 { margin: 0; font: 600 28px 'Google Sans', system-ui, sans-serif; }
.standalone-header p { color: var(--muted); margin: 8px 0 0; }
.standalone-header a { font-size: 13px; }
.embed-mode .standalone-header { display: none; }
#explorer { width: 100%; max-width: 1120px; margin: 0 auto; padding: 16px; display: grid; gap: 12px; }
/* Grid items must be allowed to shrink below their scrollable content (chip rows), or the whole figure widens. */
#explorer > *, .token-row { min-width: 0; }
.kicker { font-size: 11px; font-weight: 500; letter-spacing: .16em; text-transform: uppercase; color: var(--kicker); line-height: 1.5; }
.kicker .sym { text-transform: none; letter-spacing: .04em; font-size: 12px; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 6px; }
.toolbar > .crystal-picker > .kicker { margin-right: 6px; }
.crystal-picker, #crystals { display: contents; }
.crystal-chip { flex-shrink: 0; white-space: nowrap; height: 32px; padding: 0 11px; border-radius: 999px; border: 1px solid var(--border); background: var(--chip); font: 500 13.5px 'Google Sans', system-ui, sans-serif; scroll-snap-align: center; }
.crystal-chip.system-start { margin-left: 8px; }
.crystal-chip[aria-pressed="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }
.view-controls { display: flex; align-items: center; gap: 16px; margin-left: auto; height: 32px; padding-left: 14px; }
.switch-control { min-height: 36px; display: flex; align-items: center; gap: 8px; padding: 0 2px; }
.switch-control[aria-disabled="true"] { opacity: .4; cursor: default; }
.switch { width: 22px; height: 12px; background: var(--lattice); border-radius: 8px; position: relative; opacity: .6; }
.switch::after { content: ''; position: absolute; width: 8px; height: 8px; top: 2px; left: 2px; background: var(--surface); border-radius: 50%; transition: transform 180ms ease-out; }
[aria-checked="true"] .switch { background: var(--text); opacity: 1; }
[aria-checked="true"] .switch::after { transform: translateX(10px); }
.segments { display: flex; padding: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; height: 28px; }
.segments button { border-radius: 5px; padding: 0 10px; font-size: 12px; }
.segments [aria-pressed="true"] { background: var(--text); color: var(--surface); }
.main-row { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 12px; }
#viewport { height: 560px; min-width: 0; border: 1px solid var(--border); background: var(--viewport); border-radius: 20px; overflow: hidden; position: relative; }
#viewport canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.axis-labels { position: absolute; inset: 0; pointer-events: none; }
.axis-label { font-size: 12.5px; font-style: italic; color: var(--muted); text-shadow: 0 0 3px var(--viewport), 0 0 3px var(--viewport), 0 0 2px var(--viewport); }
.viewport-badge { position: absolute; top: 16px; left: 16px; right: 12px; z-index: 2; display: flex; align-items: center; gap: 8px; pointer-events: none; color: var(--muted); font-size: 12px; }
#structure-badge.edited { background: var(--chip); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; }
#structure-badge.edited::before, .slider-row.changed output::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--edited); }
#reset { pointer-events: auto; min-height: 24px; text-decoration: underline; text-underline-offset: 3px; padding: 0 4px; }
.cell-caption { position: absolute; z-index: 2; left: 16px; bottom: 18px; color: var(--muted); font-size: 12px; pointer-events: none; }
.drag-hint { position: absolute; z-index: 2; right: 16px; bottom: 38px; font-size: 11px; color: var(--kicker); pointer-events: none; }
.webgl-message { position: absolute; inset: 60px 24px; display: grid; place-content: center; color: var(--muted); text-align: center; line-height: 1.6; }
.atom-tooltip { position: absolute; z-index: 4; max-width: calc(100% - 24px); padding: 7px 9px; border-radius: 6px; border: 1px solid var(--border); background: var(--chip); color: var(--text); font-size: 12px; pointer-events: none; animation: tooltip-in 80ms ease-out; }
@keyframes tooltip-in { from { opacity: 0; } to { opacity: 1; } }
#panel { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px 16px; height: 560px; overflow-y: auto; scrollbar-width: thin; scrollbar-gutter: stable; scrollbar-color: color-mix(in srgb, var(--text) 22%, transparent) transparent; min-width: 0; }
.panel-title { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.panel-title h2 { font: 600 22px 'Google Sans', system-ui, sans-serif; margin: 0; }
.panel-title span { color: var(--muted); font-size: 13px; }
.space-symbol { font: 500 20px 'Google Sans', system-ui, sans-serif; margin-top: 3px; }
.space-meta { font-size: 12.5px; color: var(--muted); margin: 4px 0 14px; }
.skeleton { margin-top: 6px; }
.orbit-row, .lattice-row { width: 100%; min-height: 32px; text-align: left; display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-left: 2px solid transparent; border-radius: 3px; }
.orbit-row { font-size: 14px; }
.orbit-row strong { font-weight: 500; }
.chart { font-size: 13px; }
.multiplicity { color: var(--muted); margin-left: auto; font-size: 12px; }
.dot, .lattice-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--orbit-color); flex-shrink: 0; }
.lattice-swatch { background: var(--lattice); border-radius: 3px; }
.lattice-row { flex-wrap: wrap; column-gap: 9px; --orbit-color: var(--lattice); }
.lattice-ties { color: var(--muted); font-size: 12px; margin-left: 19px; width: calc(100% - 19px); }
.orbit-row[aria-pressed="true"], .lattice-row[aria-pressed="true"] { border-left-color: var(--orbit-color); background: color-mix(in srgb, var(--orbit-color) 8%, transparent); }
.is-hovered { outline: 1px solid var(--orbit-color); outline-offset: -1px; }
.detail { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 12px; }
.detail-copy { color: var(--muted); margin: 12px 0; line-height: 1.5; }
.slider-row { display: grid; grid-template-columns: 18px minmax(60px, 1fr) 80px; gap: 8px; align-items: center; min-height: 32px; }
.slider-row > i { font-size: 14px; }
.slider-row output { font-variant-numeric: tabular-nums; text-align: right; font-size: 12px; white-space: nowrap; }
input[type="range"] { width: 100%; height: 24px; margin: 0; appearance: none; background: transparent; cursor: pointer; accent-color: var(--orbit-color); }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: color-mix(in srgb, var(--orbit-color) 30%, var(--surface)); }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 16px; height: 16px; margin-top: -6px; border: 0; border-radius: 50%; background: var(--orbit-color); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: color-mix(in srgb, var(--orbit-color) 30%, var(--surface)); }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: var(--orbit-color); }
.members-heading { margin-top: 12px; }
.member-list { margin-top: 4px; max-height: 120px; overflow-y: auto; scrollbar-width: thin; }
.member-row { width: 100%; height: 20px; display: flex; align-items: center; gap: 8px; text-align: left; padding: 0 5px; color: var(--muted); font-size: 12px; border-radius: 3px; }
.member-ring { width: 10px; height: 10px; border: 1.5px solid var(--orbit-color); border-radius: 50%; }
.member-spacer { width: 10px; }
.member-label { min-width: 27px; }
.crystal-note { color: var(--muted); font-size: 13.5px; line-height: 1.5; margin: 0; }
.token-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; display: grid; gap: 12px; min-width: 0; }
.token-heading { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; margin-bottom: 7px; }
.token-count { font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.token-scroll { display: flex; gap: 5px; overflow-x: auto; padding: 2px; scrollbar-width: thin; scroll-snap-type: x proximity; }
.token { height: 30px; display: inline-flex; gap: 6px; align-items: center; flex-shrink: 0; white-space: nowrap; border-radius: 8px; background: var(--chip); border: 1px solid var(--border); padding: 0 8px; font-size: 13px; font-variant-numeric: tabular-nums; scroll-snap-align: start; }
.atom-token { padding: 0 5px; gap: 4px; }
.token .dot { width: 8px; height: 8px; }
.token[aria-pressed="true"] { border-color: var(--orbit-color); background: color-mix(in srgb, var(--orbit-color) 8%, var(--chip)); }
.token-values { display: inline-flex; gap: 8px; font-size: 12px; }
.token-lattice { --orbit-color: var(--lattice); }
.wyckoff-drawer { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
#drawer-toggle { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 0 12px; width: 100%; min-height: 36px; text-align: left; }
#drawer-toggle > span:last-child { white-space: nowrap; font-size: 12px; }
.chevron { display: inline-block; font-size: 18px; margin-left: 4px; transition: transform 220ms ease-out; }
[aria-expanded="true"] .chevron { transform: rotate(90deg); }
.drawer-content { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 220ms ease-out; }
.drawer-content.open { grid-template-rows: 1fr; }
.table-scroll { min-height: 0; overflow: hidden; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { color: var(--muted); font-weight: 400; text-align: left; }
th, td { height: 30px; padding: 4px 12px; border-top: 1px solid var(--border); }
tr.occupied { background: color-mix(in srgb, var(--orbit-color) 8%, transparent); cursor: pointer; }
.occupants { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.occupants .dot { width: 8px; height: 8px; }
@media (max-width: 719px) {
  .standalone-header { align-items: flex-start; flex-direction: column; }
  .crystal-picker { display: flex; align-items: center; gap: 10px; min-width: 0; flex-basis: 100%; }
  #crystals { display: flex; align-items: center; gap: 6px; min-width: 0; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; padding: 3px; }
  .view-controls { margin-left: 0; padding-left: 0; }
  .main-row { grid-template-columns: minmax(0, 1fr); }
  #viewport { height: 340px; }
  #panel { height: auto; overflow: visible; }
  .token-heading { flex-wrap: wrap; row-gap: 3px; }
  .token-count { font-size: 12px; margin-left: auto; max-width: 100%; text-align: right; white-space: normal; }
  th:nth-child(2), td:nth-child(2), th:nth-child(3), td:nth-child(3) { display: none; }
  th, td { padding: 4px 8px; }
  #drawer-title { letter-spacing: .08em; font-size: 10px; }
  .viewport-badge { font-size: 11px; left: 12px; gap: 4px; }
}
@media (pointer: coarse) {
  .crystal-chip, .token, .segments, .segments button, .member-row, #reset { min-height: 36px; }
  .view-controls { height: 40px; }
  .member-list { max-height: 216px; }
  input[type="range"] { height: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; scroll-behavior: auto !important; }
}
