html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  touch-action: none;
  background: #8fc9ef;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#worldCanvas {
  display: block;
  width: 100vw;
  height: 100vh;
}

.hud {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  top: max(14px, env(safe-area-inset-top));
  z-index: 3;
  box-sizing: border-box;
  width: min(380px, calc(100vw - 28px));
  padding: 15px;
  border: 1px solid rgba(255, 255, 255, 0.30);
  border-radius: 20px;
  color: #f7fbff;
  background: linear-gradient(145deg, rgba(7, 25, 41, 0.72), rgba(7, 25, 41, 0.48));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(18px);
}

.hud-toggle {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.hud-toggle > span {
  display: block;
  color: #cfefff;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.hud strong {
  display: block;
  margin: 3px 0 12px;
  font-size: clamp(2.1rem, 9vw, 4.1rem);
  line-height: 0.9;
  letter-spacing: -0.06em;
}

.hud-toggle b {
  display: none;
}

.hud-details {
  display: block;
}

.hud dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.hud div {
  min-width: 0;
}

.hud dl div {
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.08);
}

.hud dt {
  color: #c4d9e8;
  font-size: 0.68rem;
  font-weight: 850;
  text-transform: uppercase;
}

.hud dd {
  margin: 3px 0 0;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.hud dl .pose-card {
  grid-column: 1 / -1;
}

#poseValue {
  font-size: 0.76rem;
  line-height: 1.25;
}

.hud p {
  margin: 10px 0 0;
  color: #e0f0f8;
  font-size: 0.82rem;
  line-height: 1.4;
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.render-log-panel {
  margin-top: 10px;
  padding: 9px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
}

.render-log-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 6px;
  align-items: center;
}

.render-log-actions span {
  color: #dceef8;
  font-size: 0.74rem;
  font-weight: 900;
  white-space: nowrap;
}

.render-log-actions button {
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  color: #f8fcff;
  background: rgba(255, 255, 255, 0.13);
  font-size: 0.72rem;
  font-weight: 850;
}

#renderLogPreview {
  max-height: 148px;
  margin: 8px 0 0;
  padding: 8px;
  overflow: auto;
  border-radius: 10px;
  color: rgba(244, 251, 255, 0.88);
  background: rgba(4, 18, 31, 0.26);
  white-space: pre-wrap;
  font: 700 0.68rem/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.range-control {
  display: grid;
  grid-template-columns: auto minmax(90px, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 9px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
}

.pose-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.pose-control input {
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  color: #f8fcff;
  background: rgba(4, 18, 31, 0.28);
  font: 700 0.72rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.pose-control button {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  color: #f8fcff;
  background: rgba(255, 255, 255, 0.13);
  font-weight: 850;
}

.range-control span,
.range-control b {
  color: #dceef8;
  font-size: 0.74rem;
  font-weight: 900;
  white-space: nowrap;
}

.range-control input {
  width: 100%;
  accent-color: #a7e5ff;
}

.flight-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  margin-top: 10px;
}

.flight-control button {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  color: #f8fcff;
  background: rgba(255, 255, 255, 0.13);
  font-weight: 850;
}

.flight-control button[aria-pressed="true"] {
  border-color: rgba(176, 236, 255, 0.62);
  color: #052338;
  background: rgba(183, 238, 255, 0.86);
}

.actions button {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  color: #f8fcff;
  background: rgba(255, 255, 255, 0.13);
  font-weight: 850;
}

.controls {
  opacity: 0.78;
}

.joystick {
  position: fixed;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 4;
  display: none;
  width: 126px;
  height: 126px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  background: rgba(4, 18, 31, 0.34);
  backdrop-filter: blur(12px);
}

.joystick i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.58);
  transform: translate(-50%, -50%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

@media (pointer: coarse), (max-width: 760px) {
  .hud {
    width: min(128px, calc(100vw - 24px));
    padding: 10px 12px;
    border-radius: 17px;
  }
  .hud.is-expanded {
    width: min(
      330px,
      calc(
        100vw - max(14px, env(safe-area-inset-left)) - max(14px, env(safe-area-inset-right))
      )
    );
    max-height: calc(
      100dvh - max(14px, env(safe-area-inset-top)) - max(14px, env(safe-area-inset-bottom))
    );
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  .hud strong {
    margin: 2px 0 0;
    font-size: clamp(1.65rem, 9vw, 2.35rem);
    text-align: center;
  }
  .hud.is-expanded strong {
    margin-bottom: 10px;
    text-align: left;
  }
  .hud:not(.is-expanded) .hud-toggle > span,
  .hud:not(.is-expanded) .hud-toggle b {
    display: none;
  }
  .hud-toggle b {
    position: absolute;
    right: 11px;
    top: 10px;
    display: block;
    color: rgba(255, 255, 255, 0.68);
    font-size: 0.68rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
  .hud.is-expanded .hud-toggle b {
    color: rgba(255, 255, 255, 0.86);
  }
  .hud:not(.is-expanded) .hud-details {
    display: none;
  }
  .hud.is-expanded .hud-details {
    min-height: 0;
    padding-right: 2px;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }
  .hud dl {
    gap: 6px;
  }
  .hud dl div {
    padding: 7px;
  }
  .hud p {
    font-size: 0.78rem;
  }
  .pose-control input,
  .pose-control button,
  .flight-control button,
  .render-log-actions button,
  .actions button {
    min-width: 44px;
    min-height: 44px;
  }
  .pose-control input {
    height: 44px;
  }
  .range-control input {
    height: 44px;
    touch-action: pan-x;
  }
  .hud.is-expanded ~ .joystick {
    display: none;
  }
  .joystick {
    display: block;
  }
}
