:root {
  color-scheme: dark;
  font-family:
    system-ui,
    -apple-system,
    sans-serif;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0a0a12;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* The corner link back to the tutorial hub. */
.back-link {
  position: fixed;
  top: 0.8rem;
  left: 0.9rem;
  color: #7982a9;
  font-size: 0.8rem;
  text-decoration: none;
  z-index: 3;
}

.back-link:hover {
  color: #59d4ff;
}

#notice {
  position: fixed;
  top: 1rem;
  left: 50%;
  translate: -50% 0;
  margin: 0;
  padding: 0.4rem 0.9rem;
  border-radius: 0.5rem;
  background: rgb(10 10 18 / 0.75);
  color: #cfd2e0;
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

#notice[data-visible] {
  opacity: 1;
}

#fallback {
  position: fixed;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  color: #cfd2e0;
  text-align: center;
}

#fallback[hidden] {
  display: none;
}

#fallback img {
  max-width: min(90vw, 900px);
  max-height: 75vh;
}

#fallback figcaption {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  translate: -50% 0;
  max-width: 30rem;
  font-size: 0.9rem;
}

#panel {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: 17rem;
  max-height: calc(100% - 2rem);
  border-radius: 0.5rem;
  background: rgb(10 10 18 / 0.82);
  color: #cfd2e0;
  font-size: 0.8rem;
}

#panel[hidden] {
  display: none;
}

#panel summary {
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
}

#panel .panel-body {
  display: grid;
  gap: 0.6rem;
  padding: 0 0.9rem 0.9rem;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
}

#panel fieldset {
  margin: 0;
  padding: 0.5rem 0.6rem 0.7rem;
  border: 1px solid rgb(207 210 224 / 0.18);
  border-radius: 0.4rem;
  display: grid;
  gap: 0.45rem;
}

#panel legend {
  padding: 0 0.3rem;
  font-weight: 600;
}

#panel .preset-row {
  display: flex;
  gap: 0.4rem;
}

#panel select {
  flex: 1;
  min-width: 0;
  background: #14141f;
  color: inherit;
  border: 1px solid rgb(207 210 224 / 0.25);
  border-radius: 0.3rem;
  padding: 0.2rem 0.3rem;
}

#panel button {
  background: #14141f;
  color: inherit;
  border: 1px solid rgb(207 210 224 / 0.25);
  border-radius: 0.3rem;
  padding: 0.2rem 0.55rem;
  cursor: pointer;
}

#panel button:hover {
  border-color: rgb(207 210 224 / 0.5);
}

#panel .gate-status {
  margin: 0;
  min-height: 0;
  color: #e0a0a0;
}

#panel .gate-status:empty {
  display: none;
}

#panel .params[data-rejected] {
  border-color: #a05555;
}

#panel .slider-row {
  display: grid;
  grid-template-columns: 5.2rem 1fr 3.4rem;
  align-items: center;
  gap: 0.5rem;
}

#panel .slider-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#panel input[type='range'] {
  width: 100%;
  margin: 0;
}

#panel output {
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}

#panel input[type='color'] {
  width: 100%;
  height: 1.4rem;
  padding: 0;
  border: 1px solid rgb(207 210 224 / 0.25);
  border-radius: 0.3rem;
  background: #14141f;
}

#panel input[type='text'],
#panel input[type='number'] {
  width: 100%;
  min-width: 0;
  background: #14141f;
  color: inherit;
  border: 1px solid rgb(207 210 224 / 0.25);
  border-radius: 0.3rem;
  padding: 0.15rem 0.3rem;
  font: inherit;
}

#panel .check-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

#panel .status-line {
  margin: 0;
  color: #8f97b8;
  font-size: 0.75rem;
  min-height: 0;
}

#panel .status-line:empty {
  display: none;
}

#panel .stats {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.5;
  color: #8f97b8;
  white-space: pre-wrap;
  font-variant-numeric: tabular-nums;
}

#panel .sim-settings summary {
  cursor: pointer;
  color: #8f97b8;
  font-size: 0.75rem;
}

#panel .seg-list {
  display: grid;
  gap: 0.55rem;
}

#panel .seg-row {
  display: grid;
  gap: 0.3rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid rgb(207 210 224 / 0.1);
}

#panel .seg-tools {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

#panel .seg-tools .slider-row {
  flex: 1;
  min-width: 0;
  grid-template-columns: 2rem 1fr;
}

#panel .seg-tools button {
  padding: 0.15rem 0.4rem;
}

/* Tour player + export overlay — full-viewport layer above the scene. */
.player {
  position: fixed;
  inset: 0;
  z-index: 5;
  background: #070a12;
  display: flex;
  flex-direction: column;
}

.player[hidden] {
  display: none;
}

.player-canvas {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: block;
}

.export .player-canvas {
  /* The export canvas renders at fixed output size; it is previewed
     scaled, never interactive. */
  object-fit: contain;
  pointer-events: none;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem 1rem;
  background: rgb(10 10 18 / 0.9);
  color: #cfd2e0;
  font-size: 0.8rem;
}

.player-bar button {
  background: #14141f;
  color: inherit;
  border: 1px solid rgb(207 210 224 / 0.25);
  border-radius: 0.3rem;
  padding: 0.25rem 0.7rem;
  cursor: pointer;
}

.player-bar button:hover {
  border-color: rgb(207 210 224 / 0.5);
}

.player-progress {
  flex: 1;
  height: 0.3rem;
  border-radius: 0.15rem;
  background: rgb(207 210 224 / 0.12);
  overflow: hidden;
}

.player-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #59d4ff, #c77dff);
  transition: width 0.2s linear;
}

.player-status {
  color: #8f97b8;
  min-width: 8rem;
  font-variant-numeric: tabular-nums;
}
