*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b0c15;
  color: #e8eaf0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#world {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0b0c15;
  z-index: 50;
  transition: opacity 0.4s ease;
}

.screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(100, 180, 255, 0.2);
  border-top-color: #64b4ff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 10;
}

.hud.hidden {
  display: none;
}

.hud > * {
  pointer-events: auto;
}

.hud-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(11,12,21,0.85) 0%, rgba(11,12,21,0) 100%);
}

.title-block h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  font-weight: 700;
  color: #9ecbff;
}

.phase-title {
  margin-top: 4px;
  font-size: 14px;
  color: #cbd5e8;
  min-height: 18px;
}

.help-block {
  display: flex;
  gap: 8px;
}

.help-block button, .jump-panel button, #touch-controls button {
  appearance: none;
  border: 1px solid rgba(100, 180, 255, 0.35);
  background: rgba(18, 24, 44, 0.75);
  color: #d6e4ff;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.15s, transform 0.05s;
}

.help-block button:active, .jump-panel button:active, #touch-controls button:active {
  transform: scale(0.96);
  background: rgba(35, 55, 95, 0.85);
}

.phase-card {
  position: absolute;
  top: 72px;
  left: 16px;
  max-width: min(420px, calc(100% - 32px));
  background: rgba(12, 16, 30, 0.82);
  border: 1px solid rgba(120, 160, 255, 0.2);
  border-radius: 14px;
  padding: 14px 16px;
  backdrop-filter: blur(5px);
  transition: opacity 0.25s ease;
}

.phase-card.hidden {
  opacity: 0;
  pointer-events: none;
}

.child-line {
  font-size: 16px;
  line-height: 1.4;
  color: #ffffff;
  font-weight: 500;
}

.tech-detail {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.45;
  color: #a9c0f0;
  border-top: 1px solid rgba(120, 160, 255, 0.15);
  padding-top: 10px;
}

.tech-detail.hidden {
  display: none;
}

.phase-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.phase-actions button {
  appearance: none;
  border: 1px solid rgba(100, 180, 255, 0.35);
  background: rgba(18, 24, 44, 0.75);
  color: #d6e4ff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}

.jump-panel {
  position: absolute;
  top: 72px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(12, 16, 30, 0.88);
  border: 1px solid rgba(120, 160, 255, 0.2);
  border-radius: 12px;
  padding: 10px;
  max-height: 70vh;
  overflow-y: auto;
}

.jump-panel.hidden {
  display: none;
}

.jump-panel button {
  text-align: left;
  padding: 9px 12px;
}

.hud-bottom {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 12px 16px 18px;
  background: linear-gradient(0deg, rgba(11,12,21,0.85) 0%, rgba(11,12,21,0) 100%);
  gap: 12px;
}

.desktop-hint {
  font-size: 12px;
  color: #9aa8c8;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  max-width: 55%;
}

.key {
  display: inline-block;
  min-width: 22px;
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(100, 180, 255, 0.15);
  border: 1px solid rgba(100, 180, 255, 0.3);
  text-align: center;
  font-weight: 600;
  color: #c6ddff;
}

#touch-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

#touch-controls .dpad-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

#touch-controls button {
  width: 52px;
  height: 44px;
  font-size: 18px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 640px) {
  .title-block h1 {
    font-size: 15px;
  }
  .phase-title {
    font-size: 12px;
  }
  .desktop-hint {
    display: none;
  }
  .hud-top {
    padding: 10px 12px;
  }
  .phase-card {
    top: 64px;
    left: 10px;
    right: 10px;
    max-width: none;
    padding: 11px 13px;
  }
  .child-line {
    font-size: 14px;
  }
  .tech-detail {
    font-size: 12px;
  }
  #touch-controls button {
    width: 46px;
    height: 40px;
  }
}
