:root {
  color-scheme: dark;
  --bg: #071117;
  --panel: #0c1c24;
  --panel-strong: #102731;
  --line: rgba(179, 224, 230, 0.18);
  --text: #e3f0f0;
  --muted: #8faeb2;
  --cyan: #7dd4da;
  --left: #51bfd1;
  --right: #e89a87;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--text);
  background:
    radial-gradient(circle at 50% 2%, rgba(39, 103, 124, 0.22), transparent 34rem),
    var(--bg);
  font-family: Calibri, Arial, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
select {
  font: inherit;
}

button,
select,
input {
  accent-color: var(--cyan);
}

.surface-shell {
  width: min(100% - 36px, 1400px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0 34px;
  display: grid;
  grid-template-rows: auto minmax(430px, 1fr) auto auto;
  gap: 14px;
}

.surface-header,
.surface-controls,
.surface-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.surface-header {
  min-height: 70px;
}

.back-link {
  color: var(--cyan);
  font-size: 13px;
  letter-spacing: 0.02em;
  text-decoration: none;
}

.back-link:hover {
  color: var(--text);
}

h1 {
  margin: 8px 0 1px;
  color: var(--text);
  font-size: clamp(25px, 4vw, 38px);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.05;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

code {
  color: var(--cyan);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

.load-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 0 4px rgba(125, 212, 218, 0.11);
}

.state-dot.ready {
  background: #8bd6aa;
  box-shadow: 0 0 0 4px rgba(139, 214, 170, 0.1);
}

.state-dot.error {
  background: #eb927f;
  box-shadow: 0 0 0 4px rgba(235, 146, 127, 0.1);
}

.surface-stage {
  position: relative;
  min-height: 430px;
  overflow: hidden;
  border: 1px solid var(--line);
  background:
    linear-gradient(rgba(126, 184, 194, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(126, 184, 194, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 50% 45%, rgba(25, 78, 95, 0.5), rgba(6, 17, 23, 0.98) 72%);
  background-size: 46px 46px, 46px 46px, auto;
}

.viewer,
.viewer canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.viewer {
  position: absolute;
  inset: 0;
  min-height: 430px;
}

.viewer-hint {
  position: absolute;
  right: 16px;
  bottom: 14px;
  color: rgba(205, 231, 232, 0.7);
  font-size: 12px;
  pointer-events: none;
}

.viewer-error {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(440px, calc(100% - 40px));
  transform: translate(-50%, -50%);
  padding: 18px 20px;
  border: 1px solid rgba(235, 146, 127, 0.35);
  background: rgba(56, 24, 25, 0.8);
  color: #f5c5bb;
  line-height: 1.45;
  text-align: center;
}

.viewer-error strong,
.viewer-error span {
  display: block;
}

.viewer-error span {
  margin-top: 4px;
  color: #dba59c;
  font-size: 13px;
}

.surface-controls {
  flex-wrap: wrap;
  padding: 10px 0 2px;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hemisphere-controls {
  gap: 6px;
}

.control-label {
  margin-right: 4px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.toggle,
.select-wrap,
.reset-button {
  min-height: 34px;
  border: 1px solid var(--line);
  background: rgba(16, 39, 49, 0.72);
  color: var(--text);
  font-size: 13px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  cursor: pointer;
}

.toggle-left {
  border-color: rgba(81, 191, 209, 0.42);
}

.toggle-right {
  border-color: rgba(232, 154, 135, 0.42);
}

.toggle input {
  margin: 0;
}

.select-wrap {
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
}

select {
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

option {
  color: #102027;
  background: #e3f0f0;
}

.reset-button {
  margin-left: auto;
  padding: 7px 12px;
  cursor: pointer;
}

.reset-button:hover,
.reset-button:focus-visible,
.toggle:hover,
.select-wrap:hover {
  border-color: var(--cyan);
  background: rgba(35, 85, 97, 0.72);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.surface-footer {
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

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

.legend-swatch {
  width: 9px;
  height: 9px;
  margin-left: 10px;
  border-radius: 50%;
}

.legend-swatch:first-child {
  margin-left: 0;
}

.left-swatch {
  background: var(--left);
}

.right-swatch {
  background: var(--right);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 620px) {
  .surface-shell {
    width: min(100% - 24px, 1400px);
    padding-top: 18px;
    grid-template-rows: auto minmax(420px, 1fr) auto auto;
  }

  .surface-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .load-state {
    align-self: flex-end;
  }

  .surface-stage,
  .viewer {
    min-height: 420px;
  }

  .viewer-hint {
    right: 10px;
    bottom: 9px;
    font-size: 11px;
  }

  .surface-footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }
}
