* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #07111d;
  color: #eff6ff;
}

.layout {
  --panel-width: clamp(360px, 30vw, 520px);
  display: grid;
  grid-template-columns: var(--panel-width) minmax(0, 1fr);
  min-height: 100vh;
  position: relative;
}

.layout.panel-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem;
  background: rgba(8, 15, 24, 0.96);
  border-right: 1px solid rgba(148, 163, 184, 0.22);
  overflow-y: auto;
}

[hidden] {
  display: none !important;
}

.layout.panel-collapsed .panel {
  display: none;
}

.panel-toggle {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  width: auto;
  min-width: 2.2rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 0.55rem;
  background: rgba(8, 15, 24, 0.94);
  color: #eff6ff;
  cursor: pointer;
  z-index: 5;
}

.layout:not(.panel-collapsed) .panel-toggle {
  left: calc(var(--panel-width) - 1.5rem);
}

.panel h1,
.panel h2 {
  margin: 0;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.9rem;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 0.75rem;
  background: rgba(15, 23, 42, 0.35);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-weight: 700;
}

.panel label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.95rem;
}

.time-mode {
  flex-direction: row !important;
  align-items: center;
}

.panel input,
.panel select,
.panel button {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 0.5rem;
  background: #0f172a;
  color: inherit;
}

.panel button {
  cursor: pointer;
}

.panel button#time-parts-toggle,
.panel button#rate-parts-toggle {
  width: auto;
  padding-inline: 0.8rem;
  white-space: nowrap;
}

.panel button#transfer-open {
  width: auto;
}

.transfer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.transfer-actions button {
  width: auto;
}

.time-group {
  display: grid;
  gap: 0.45rem;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
}

.time-group label {
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
}

.time-group span {
  font-size: 0.85rem;
  color: #cbd5e1;
}

.speed-group {
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
}

.playback {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.playback p {
  margin: 0;
  font-size: 0.85rem;
  color: #cbd5e1;
}

.toggles {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.toggles label {
  flex-direction: row;
  align-items: center;
}

.range-control > span {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

.range-control input[type="range"] {
  padding: 0;
}

.transfer-dialog {
  width: min(760px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 0.85rem;
  background: #08101d;
  color: #eff6ff;
}

.transfer-dialog::backdrop {
  background: rgba(2, 6, 23, 0.78);
}

.transfer-dialog form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.2rem;
  overflow: auto;
}

.dialog-header,
.dialog-section-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.dialog-header h2,
.dialog-section-header h3 {
  margin: 0;
}

.dialog-close {
  width: auto !important;
  padding: 0.2rem 0.65rem !important;
  font-size: 1.4rem;
}

.transfer-endpoints,
.maneuver-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.transfer-time-mode {
  flex-direction: row !important;
  align-items: center;
}

.transfer-time-control {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.transfer-angle-hint,
#transfer-auto-result {
  grid-column: 1 / -1;
  margin: 0;
}

.transfer-auto-toggle,
.transfer-target-fields {
  grid-column: 1 / -1;
}

.transfer-auto-toggle {
  flex-direction: row !important;
  align-items: center;
}

.transfer-target-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.transfer-time-parts {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.35rem;
}

.transfer-time-parts label {
  gap: 0.2rem;
  font-size: 0.78rem;
}

.transfer-time-parts input {
  min-width: 0;
  padding-inline: 0.45rem;
}

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

.dialog-section {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.9rem;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 0.7rem;
  background: rgba(15, 23, 42, 0.42);
}

.maneuver-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.maneuver-row {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.75rem;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 0.6rem;
}

.maneuver-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-weight: 700;
}

.maneuver-remove {
  width: auto !important;
  padding: 0.3rem 0.55rem !important;
}

.dialog-actions {
  justify-content: flex-end;
}

.dialog-actions button {
  width: auto;
}

.form-error {
  min-height: 1.2em;
  margin: 0;
  color: #fda4af;
}

.viewport-wrap,
#viewport {
  position: relative;
  min-width: 0;
  min-height: 100vh;
}

#viewport canvas {
  display: block;
}

#labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scene-label {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background: rgba(8, 15, 24, 0.75);
  color: #f8fafc;
  font-size: 0.75rem;
  white-space: nowrap;
}

#transfer-summary,
.hint {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.4;
  color: #cbd5e1;
}

.transfer-search {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.7rem;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 0.6rem;
  background: rgba(15, 23, 42, 0.5);
}

.transfer-search h3 {
  margin: 0;
  font-size: 0.9rem;
}

.transfer-window-results {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 10rem;
  overflow: auto;
}

.transfer-window-results button {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  text-align: left;
  font-size: 0.8rem;
  line-height: 1.35;
  padding: 0.45rem 0.55rem;
}

.transfer-window-title {
  font-weight: 700;
}

.transfer-window-meta {
  color: #cbd5e1;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .layout:not(.panel-collapsed) .panel-toggle {
    left: 0.75rem;
  }

  .panel {
    border-right: 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.22);
  }

  .viewport-wrap,
  #viewport {
    min-height: 70vh;
  }

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

  .transfer-endpoints,
  .maneuver-fields {
    grid-template-columns: 1fr;
  }

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