:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  --ui-scale: 0.9;
  background: #f4f1ea;
  color: #172026;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-size: 1rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(255, 255, 255, 0)),
    #f4f1ea;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 300px);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "viewport status"
    "viewport controls";
  gap: 12px;
  min-height: 100vh;
  padding: 12px;
}

.topbar,
.file-grid,
.hdv-panel,
.external-panel,
.transport {
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  gap: 10px;
  padding: 10px;
  border: 1px solid #d8d1c4;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.controls {
  grid-area: controls;
  display: flex;
  flex-direction: column;
  gap: 12px;
  zoom: var(--ui-scale);
}

.topbar {
  grid-area: status;
  flex-direction: column;
  align-self: start;
  zoom: var(--ui-scale);
}

p {
  margin: 0;
  color: #617079;
  line-height: 1.35;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stats span {
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid #cfd8dc;
  border-radius: 6px;
  background: #eef6f7;
  color: #21343a;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.viewport {
  grid-area: viewport;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: calc(100vh - 24px);
  border: 1px solid #cbd5d8;
  border-radius: 8px;
  overflow: hidden;
  background: #eaf0ef;
}

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

.transport {
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 8px;
}

.transport,
.file-grid {
  display: grid;
}

.transport .slider-label,
.transport input[type="range"] {
  grid-column: 1 / -1;
}

.transport .speed-label {
  justify-self: start;
}

button,
select {
  min-height: 32px;
  border: 1px solid #98a8ae;
  border-radius: 6px;
  background: #ffffff;
  color: #172026;
}

button {
  padding: 0 10px;
  cursor: pointer;
}

button:hover {
  background: #f0f6f7;
}

select {
  padding: 0 8px;
}

input[type="range"] {
  width: 100%;
  accent-color: #2f7f86;
}

.slider-label,
.speed-label,
.file-grid label {
  color: #46565e;
  white-space: nowrap;
}

.file-grid {
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: end;
}

.file-grid label {
  display: grid;
  gap: 5px;
}

.required-file > span > span {
  color: #c82127;
  font-weight: 700;
}

input[type="file"] {
  max-width: 100%;
  min-height: 32px;
  padding: 5px;
  border: 1px solid #c3ccd0;
  border-radius: 6px;
  background: #ffffff;
  color: #172026;
}

.hdv-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
}

.hdv-panel h2,
.external-panel h2 {
  grid-column: 1 / -1;
  margin: 0;
  color: #21343a;
  font-size: inherit;
  font-weight: 400;
  line-height: 1.35;
}

#placeHdvButton.is-placing,
#playButton.is-playing {
  border-color: #216fb8;
  background: #e6f2ff;
  color: #124f86;
}

.hdv-instructions {
  grid-column: 1 / -1;
  min-height: 18px;
}

.steering-label,
#hdvSteeringSlider {
  grid-column: 1 / -1;
}

canvas.is-placing-hdv {
  cursor: crosshair;
}

.external-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
}

.external-panel input[type="url"] {
  min-width: 0;
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid #c3ccd0;
  border-radius: 6px;
  background: #ffffff;
  color: #172026;
}

.external-checkbox {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 7px;
  color: #44525a;
  font-size: 0.82rem;
  line-height: 1.2;
  cursor: pointer;
}

.external-checkbox input {
  width: 15px;
  height: 15px;
  min-width: 15px;
  min-height: 15px;
  margin: 0;
  padding: 0;
  cursor: pointer;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 38, 0.38);
  z-index: 20;
}

.modal[hidden] {
  display: none;
}

.modal-panel {
  width: min(420px, 100%);
  padding: 18px;
  border: 1px solid #d6c8c6;
  border-radius: 8px;
  background: #fffdf9;
  box-shadow: 0 18px 45px rgba(23, 32, 38, 0.22);
}

.modal-panel h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.modal-panel p {
  margin: 0 0 16px;
  color: #46565e;
  line-height: 1.45;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "status"
      "controls"
      "viewport";
  }

  .topbar,
  .controls {
    align-items: stretch;
  }

  .viewport {
    height: clamp(340px, 62vh, 620px);
  }

  .file-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
  }

  .viewport {
    height: clamp(300px, 56vh, 460px);
  }

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

  .transport input[type="range"],
  .slider-label {
    grid-column: 1 / -1;
  }

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

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