:root {
  color-scheme: light;
  --ink: #202938;
  --muted: #667085;
  --line: #d5dbe7;
  --paper: #f7f8fb;
  --panel: #ffffff;
  --accent: #d45a3a;
  --green: #2e766f;
  --blue: #2f5fa8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  background: #eceff4;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(520px, 1.5fr) minmax(380px, 1fr);
  gap: 12px;
  height: 100vh;
  padding: 12px;
  overflow: hidden;
}

.panel {
  min-width: 0;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 82px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
}

.primary-button {
  min-width: 104px;
  border: 0;
  border-radius: 6px;
  padding: 11px 15px;
  background: var(--ink);
  color: white;
  cursor: pointer;
}

.form-grid {
  display: grid;
  gap: 14px;
  padding: 18px;
}

fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

fieldset:disabled {
  opacity: 0.55;
}

fieldset:disabled input,
fieldset:disabled select,
fieldset:disabled textarea {
  cursor: not-allowed;
}

input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
}

fieldset:not(:disabled) label:has(input:disabled),
fieldset:not(:disabled) label:has(select:disabled),
fieldset:not(:disabled) label:has(textarea:disabled) {
  opacity: 0.55;
}

legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fbfcff;
  color: var(--ink);
}

input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

.orientation-control {
  grid-column: 1 / -1;
}

.slider-input-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 10px;
  align-items: center;
}

.slider-input-pair input[type="number"] {
  padding-inline: 8px;
}

textarea {
  grid-column: 1 / -1;
  min-height: 160px;
  resize: vertical;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.field-note {
  grid-column: 1 / -1;
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.calculation-summary {
  grid-column: 1 / -1;
}

.calculation-summary output {
  white-space: normal;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

.plot-stage {
  position: relative;
  min-height: 420px;
}

.simulate-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  gap: 14px;
  align-content: center;
  padding: 24px;
  background: rgba(247, 248, 251, 0.96);
  text-align: center;
}

.simulate-overlay[hidden] {
  display: none;
}

.simulate-overlay p {
  max-width: 34ch;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 650;
  line-height: 1.4;
}

.plot-stage.is-pending canvas,
.plot-stage.is-pending + .table-wrap {
  display: none;
}

.cell-viewer {
  position: relative;
  width: 100%;
  height: 340px;
  min-height: 280px;
  background: #f6f4ef;
  cursor: grab;
  touch-action: none;
}

.cell-view-note {
  position: absolute;
  left: 14px;
  bottom: 12px;
  z-index: 3;
  border-radius: 6px;
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.cell-legend {
  position: absolute;
  left: 14px;
  top: 12px;
  z-index: 3;
  display: flex;
  max-width: calc(100% - 132px);
  flex-wrap: wrap;
  gap: 8px 12px;
  border-radius: 6px;
  padding: 7px 9px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.atom-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.atom-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1px solid rgba(32, 41, 56, 0.12);
  border-radius: 999px;
  flex: 0 0 auto;
}

.inline-toggle,
.checkbox-row {
  display: inline-flex;
  align-items: center;
  grid-auto-flow: column;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.inline-toggle input,
.checkbox-row input {
  width: auto;
  accent-color: var(--accent);
}

.inline-toggle:has(input:disabled) {
  opacity: 0.55;
  cursor: not-allowed;
}

.geometry-viewer {
  position: relative;
  width: 100%;
  height: 360px;
  min-height: 300px;
  background: #f7f8fb;
  cursor: grab;
  touch-action: none;
}

.geometry-viewer:active {
  cursor: grabbing;
}

.geometry-viewer canvas {
  width: 100%;
  height: 100%;
}

.compact-viewer {
  height: 340px;
  min-height: 280px;
}

.locked-viewer {
  cursor: default;
}

.cell-viewer:active {
  cursor: grabbing;
}

.cell-viewer canvas {
  width: 100%;
  height: 100%;
}

.lab-axis-triad {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 2;
  width: 96px;
  height: 96px;
  pointer-events: none;
}

.axis-line {
  position: absolute;
  left: 28px;
  bottom: 28px;
  display: block;
  width: 48px;
  height: 3px;
  border-radius: 999px;
  transform-origin: 0 50%;
}

.axis-line::after {
  position: absolute;
  right: -2px;
  top: 50%;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  content: "";
  transform: translateY(-50%);
}

.axis-x {
  background: #c84a31;
}

.axis-x::after {
  border-left: 10px solid #c84a31;
}

.axis-z {
  background: #2f5fa8;
  transform: rotate(-90deg);
}

.axis-z::after {
  border-left: 10px solid #2f5fa8;
}

.axis-y {
  position: absolute;
  left: 19px;
  bottom: 19px;
  display: block;
  width: 18px;
  height: 18px;
  border: 3px solid #2e766f;
  border-radius: 50%;
}

.axis-y::after {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2e766f;
  content: "";
  transform: translate(-50%, -50%);
}

.axis-label {
  position: absolute;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.label-x {
  right: 0;
  bottom: 22px;
}

.label-y {
  left: 42px;
  bottom: 6px;
}

.label-z {
  left: 22px;
  top: 0;
}

.locked-viewer,
.locked-viewer:active,
.locked-viewer canvas,
.locked-viewer:active canvas {
  cursor: default;
}

.visual-stack {
  display: grid;
}

.cell-viewer-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.cell-viewer-pair .visual-section {
  border-bottom: 0;
}

.cell-viewer-pair .visual-section:first-child {
  border-right: 1px solid var(--line);
}

.visual-section {
  border-bottom: 1px solid var(--line);
}

.visual-section:last-child {
  border-bottom: 0;
}

.visual-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: #fbfcff;
  border-bottom: 1px solid #edf0f5;
}

.visual-title-row h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.visual-title-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-align: right;
}

.table-wrap {
  max-height: 280px;
  overflow: auto;
  border-top: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 14px;
  border-bottom: 1px solid #edf0f5;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  background: #f7f8fb;
  color: var(--muted);
  font-weight: 800;
}

output {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

body:not([data-mode="single-crystal"]) .single-crystal-only {
  display: none;
}

body[data-plot-view="reciprocal-space-map"] .table-wrap {
  display: none;
}

@media (max-width: 1250px) {
  .app-shell {
    grid-template-columns: minmax(320px, 420px) minmax(520px, 1fr);
  }

  .visual-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 1040px) {
  .cell-viewer-pair {
    grid-template-columns: 1fr;
  }

  .cell-viewer-pair .visual-section:first-child {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .panel {
    max-height: none;
  }

  .visual-panel,
  .data-panel {
    grid-column: auto;
  }

  fieldset {
    grid-template-columns: 1fr;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }
}
