:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2430;
  --muted: #657184;
  --line: #d8dee8;
  --accent: #1267a8;
  --accent-dark: #0d4f82;
  --error: #8f1d1d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.header {
  margin-bottom: 20px;
}

.header h1 {
  margin: 0 0 8px;
  font-size: 32px;
  line-height: 1.15;
}

.header p {
  margin: 0;
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

h2 {
  margin: 0 0 16px;
  font-size: 20px;
}

.panel-header h2 {
  margin: 0;
}

h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
}

.grid {
  display: grid;
  gap: 12px;
}

.lattice-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.plane-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.range-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 20px;
}

.plane-pair {
  display: grid;
  gap: 16px;
}

.range-block + .range-block {
  margin-top: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--text);
  font: inherit;
  font-weight: 500;
}

input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(18, 103, 168, 0.14);
}

.unit-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.unit-toggle label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
}

.unit-toggle input {
  width: auto;
  height: auto;
}

button {
  width: 100%;
  min-height: 42px;
  margin-top: 16px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.secondary {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--accent);
}

.secondary:hover {
  background: #eef6fc;
}

.result {
  min-height: 110px;
  margin: 16px 0 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fafc;
  padding: 12px;
  overflow-x: auto;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.table-wrap {
  max-height: 380px;
  margin-top: 16px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: right;
  white-space: nowrap;
}

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

.empty-state {
  margin: 0;
  padding: 14px;
  color: var(--muted);
}

th:has(.sort-button) {
  padding: 0;
}

.sort-button {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  width: 100%;
  min-height: 38px;
  margin: 0;
  padding: 9px 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: inherit;
  font: inherit;
  text-align: right;
  white-space: nowrap;
}

.sort-button:hover {
  background: #eaf0f5;
  color: var(--accent);
}

.sort-button:focus:not(:focus-visible) {
  outline: none;
}

.sort-indicator {
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
  flex-shrink: 0;
}

.sort-up,
.sort-down {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}

.sort-up {
  border-bottom: 5px solid #b1bdca;
}

.sort-down {
  border-top: 5px solid #b1bdca;
}

th[aria-sort="ascending"] .sort-up {
  border-bottom-color: var(--accent);
}

th[aria-sort="descending"] .sort-down {
  border-top-color: var(--accent);
}

.sort-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

th[aria-sort="ascending"],
th[aria-sort="descending"] {
  color: var(--accent);
}

@media (max-width: 860px) {
  .lattice-grid,
  .tools {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 520px) {
  .shell {
    width: min(100% - 20px, 1120px);
    padding: 20px 0;
  }

  .plane-grid {
    grid-template-columns: 1fr;
  }

  .button-row {
    grid-template-columns: 1fr;
  }
}
