*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: #ffffff;
  color: #1a1a1a;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

#app {
  display: grid;
  grid-template-columns: 348px 1fr 348px;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ── Shared panel styles ────────────────────────────────────── */

#left-panel,
#control-panel {
  background: #ffffff;
  padding: 32px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
}

#left-panel {
  border-right: 1px solid #efefef;
}

#control-panel {
  border-left: 1px solid #e0e0e0;
}

/* ── Panel header ───────────────────────────────────────────── */

.panel-header {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.panel-title {
  font-size: 19px;
  font-weight: 700;
  color: #111111;
  letter-spacing: 0.01em;
}

.panel-subtitle {
  font-size: 13px;
  color: #777777;
  letter-spacing: 0.01em;
}

.divider {
  height: 1px;
  background: #e8e8e8;
  flex-shrink: 0;
}

/* ── Control groups ─────────────────────────────────────────── */

.control-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ctrl-label {
  font-size: 11px;
  font-weight: 700;
  color: #888888;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

/* ── Projection dropdown ────────────────────────────────────── */

.select-wrapper {
  position: relative;
}

.select-wrapper::after {
  content: '';
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #666;
  pointer-events: none;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background: #f8f8f8;
  color: #1a1a1a;
  border: 1.5px solid #d8d8d8;
  border-radius: 7px;
  padding: 10px 40px 10px 14px;
  font-size: 15px;
  cursor: pointer;
  width: 100%;
  transition: border-color 0.15s;
  font-family: inherit;
}

select:focus {
  outline: none;
  border-color: #4a90d9;
}

select option,
select optgroup {
  background: #ffffff;
  color: #1a1a1a;
}

/* ── Buttons ────────────────────────────────────────────────── */

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

button {
  background: #f4f4f4;
  color: #333333;
  border: 1.5px solid #d8d8d8;
  border-radius: 7px;
  padding: 11px 16px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  width: 100%;
  text-align: center;
  letter-spacing: 0.02em;
}

button:hover:not(:disabled) {
  background: #e8e8e8;
  color: #111111;
  border-color: #bbb;
}

button:active:not(:disabled) {
  background: #e0e0e0;
}

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

#reset-btn {
  color: #111;
  border-color: #c0c0c0;
  font-weight: 600;
}

/* ── Segmented graticule toggle ─────────────────────────────── */

.seg-control {
  display: flex;
  border: 1.5px solid #d8d8d8;
  border-radius: 7px;
  overflow: hidden;
  background: #f4f4f4;
}

.seg-btn {
  flex: 1;
  background: transparent;
  color: #666666;
  border: none;
  border-radius: 0;
  padding: 10px 8px;
  font-size: 14px;
  font-family: inherit;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.seg-btn:first-child {
  border-right: 1.5px solid #d8d8d8;
}

.seg-btn:hover:not(.active) {
  background: #ececec;
  color: #333;
}

.seg-btn.active {
  background: #1a6cc0;
  color: #ffffff;
  font-weight: 600;
  cursor: default;
}

/* ── Status line ────────────────────────────────────────────── */

#status-line {
  font-size: 13px;
  color: #888;
  min-height: 20px;
  letter-spacing: 0.02em;
  line-height: 1.5;
}

#status-line.error {
  color: #d9534f;
}

/* ── Pole readout (left panel) ──────────────────────────────── */

.pole-block {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.pole-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.pole-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pole-name.north {
  color: #c0392b;
}

.pole-name.south {
  color: #2471a3;
}

.pole-value {
  font-size: 16px;
  color: #333333;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  line-height: 1.5;
}

.pole-redef-note {
  font-size: 12px;
  color: #999999;
  letter-spacing: 0.01em;
}

/* ── Projection diagram (left panel) ────────────────────────── */

#projection-diagram {
  display: flex;
  flex-direction: column;
  align-items: center;
}


/* ── Visualization area ─────────────────────────────────────── */

#visualization {
  position: relative;
  overflow: hidden;
  background: #e8e8e8;
}

#map-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

#seam-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: block;
}

#map-canvas.state-projected {
  cursor: crosshair;
}

#map-canvas.state-projected:active {
  cursor: crosshair;
}

#map-canvas.state-animating {
  cursor: default;
  pointer-events: none;
}

/* ── Overlays ───────────────────────────────────────────────── */

#instruction {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.92);
  color: #444;
  padding: 9px 20px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  pointer-events: none;
  white-space: nowrap;
  border: 1px solid #ddd;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
  transition: opacity 0.4s ease;
}

#instruction.hidden {
  opacity: 0;
}

/* ── Loading overlay ────────────────────────────────────────── */

#loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e8e8e8;
  z-index: 10;
  transition: opacity 0.5s ease;
}

#loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-text {
  font-size: 14px;
  color: #777;
  letter-spacing: 0.06em;
}

/* ── Seam display ───────────────────────────────────────────── */

.seam-display {
  font-size: 13px;
  color: #666;
  letter-spacing: 0.02em;
}

/* ── Distortion compare ─────────────────────────────────────── */

.distortion-hidden {
  display: none;
}

.active-toggle {
  background: #1a6cc0;
  color: #ffffff;
  border-color: #1a6cc0;
  font-weight: 600;
}

.active-toggle:hover:not(:disabled) {
  background: #1558a0;
  border-color: #1558a0;
  color: #fff;
}

/* Color picker rows */
#distortion-color-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-label {
  font-size: 11px;
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  width: 36px;
  flex-shrink: 0;
}

.color-desc {
  font-size: 12px;
  color: #777;
}

input[type="color"] {
  width: 36px;
  height: 28px;
  border: 1.5px solid #d8d8d8;
  border-radius: 5px;
  padding: 2px;
  cursor: pointer;
  background: #f8f8f8;
  flex-shrink: 0;
}

/* Preset buttons */
.preset-btn {
  font-size: 13px;
  padding: 9px 12px;
}

/* ── Bivariate legend ───────────────────────────────────────── */

#legend-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.legend-center-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-axis-label {
  font-size: 10px;
  color: #888;
  text-align: center;
  line-height: 1.3;
}

.legend-top,
.legend-bottom {
  display: block;
}

.legend-side {
  width: 28px;
  text-align: center;
}

#legend-canvas {
  border: 1px solid #ccc;
  border-radius: 2px;
  display: block;
}

.legend-axis-note {
  font-size: 10px;
  color: #888;
  text-align: center;
  margin-top: 3px;
  letter-spacing: 0.01em;
}

.legend-swatch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid #ccc;
  flex-shrink: 0;
}

.legend-swatch-label {
  font-size: 11px;
  color: #666;
}
