:root {
  --bg: radial-gradient(circle at 20% 20%, #1c2340, #0b1024 60%, #060915 100%);
  --hud-bg: rgba(8, 12, 26, 0.75);
  --accent: #00e0ff;
  --text: #e6e9ff;
  --danger: #ff6b6b;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: var(--bg);
  color: var(--text);
  padding: 0;
}

.desktop-header {
  width: min(1100px, 98vw);
  display: flex;
  justify-content: center;
  padding: 18px 12px 6px 12px;
}

.desktop-header.touch-hidden {
  display: none;
}

.desktop-title {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 2px 18px rgba(0, 224, 255, 0.15), 0 2px 24px rgba(0, 0, 0, 0.45);
}

.layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100vw;
  max-width: none;
  gap: 10px;
}

.hud {
  width: 100%;
  padding: 16px;
  background: var(--hud-bg);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  min-width: 260px;
}

.title {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.3px;
  margin-bottom: 10px;
}

.hud-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  line-height: 1.4;
}

.label {
  font-weight: 600;
  color: #9fb3ff;
}

.value {
  font-weight: 700;
}

.value.large {
  font-size: 18px;
}

.value.good {
  color: #67f4c1;
}

.value.warn {
  color: #ffde59;
}

.instructions {
  margin-top: 6px;
  color: #b8c4ff;
}

.status {
  margin-top: 6px;
  min-height: 18px;
  color: var(--danger);
  font-weight: 600;
}

#gameCanvas {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  box-shadow: var(--shadow);
  background: linear-gradient(180deg, #0e1535 0%, #0a0f28 100%);
  display: block;
}

.hud-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 6px;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 10px;
}

.hud-icon {
  width: 28px;
  height: 24px;
  flex-shrink: 0;
}

.hud-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hud-text.subline {
  gap: 6px;
}

.hud-text .value {
  font-size: 16px;
}

.hud-text .label {
  font-size: 13px;
  color: #9fb3ff;
}

.summary-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 18, 0.82);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.summary-overlay.visible {
  display: flex;
}

.summary-card {
  display: flex;
  flex-direction: column;
  width: min(520px, 92vw);
  max-height: 82vh;
  overflow: hidden;
  background: #0f1735;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px 20px;
  color: var(--text);
}

.summary-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: block;
  padding-bottom: 12px;
}

.summary-scroll > * + * {
  margin-top: 12px;
}

.summary-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.summary-inline {
  display: flex;
  align-items: center;
  gap: 10px;
}

.summary-inline-label {
  font-weight: 700;
  color: #fcd34d;
}

.summary-inline .summary-input {
  flex: 1;
  min-width: 0;
}

.summary-inline .summary-button.small {
  width: auto;
  white-space: nowrap;
}

.summary-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
}

.summary-title.small {
  font-size: 16px;
  margin-top: 8px;
}

.summary-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.summary-section {
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
  margin: 0;
}

.summary-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: transparent;
  border: none;
  color: inherit;
  font-weight: 700;
  cursor: pointer;
}

.summary-toggle .chevron {
  transition: transform 0.2s ease;
}

.summary-section.collapsed .summary-toggle .chevron {
  transform: rotate(-90deg);
}

.summary-details {
  max-height: 500px;
  transition: max-height 0.25s ease, opacity 0.25s ease;
  opacity: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.summary-section.collapsed .summary-details {
  max-height: 0;
  opacity: 0;
  padding: 0 12px;
  margin-top: 0;
}

.summary-row {
  margin: 0;
}

.summary-section .summary-details {
  padding: 0 12px 12px 12px;
  margin-top: 6px;
}

.summary-value {
  font-size: 18px;
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  font-size: 14px;
  margin: 0;
}

.summary-row span:last-child {
  font-weight: 700;
}

.summary-row.summary-accent {
  border-color: rgba(103, 244, 193, 0.4);
  background: rgba(103, 244, 193, 0.06);
}

.summary-row.summary-sub {
  margin-left: 12px;
  font-size: 13px;
}

.summary-card .summary-row + .summary-row {
  margin-top: 0;
}

.summary-button {
  width: 100%;
  margin-top: 12px;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(90deg, #38bdf8, #60a5fa);
  color: #0b1024;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.summary-button:hover {
  filter: brightness(1.05);
}

.summary-button.small {
  width: auto;
  padding: 8px 12px;
  margin: 0;
}

.summary-input {
  width: 140px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.summary-icon {
  width: 16px;
  height: 16px;
  margin-right: 6px;
  vertical-align: middle;
}

.summary-highscores {
  margin-top: 10px;
}

.summary-list {
  list-style: none;
  padding: 0;
  margin: 6px 0 0 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-list li {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 6px;
}

.summary-row .summary-icon {
  width: 16px;
  height: 16px;
}

.info-row {
  display: flex;
  gap: 12px;
  margin-top: 10px;
  justify-content: flex-end;
}

.info-row.touch-hidden {
  display: none;
}

.info-button {
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
}

.info-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}

.info-button:disabled:hover {
  filter: none;
}

.info-button:hover {
  filter: brightness(1.08);
}

.info-button.test-enabled {
  border-color: rgba(244, 211, 94, 0.8);
  background: linear-gradient(90deg, rgba(248, 196, 80, 0.25), rgba(255, 221, 118, 0.2));
  box-shadow: 0 0 12px rgba(248, 196, 80, 0.4);
  color: #fcd34d;
}

.info-button.ghost {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.08);
}

.info-button.ghost.test-enabled {
  border-color: rgba(244, 211, 94, 0.8);
  background: linear-gradient(90deg, rgba(248, 196, 80, 0.25), rgba(255, 221, 118, 0.2));
}

.run-setup-deactivate-button {
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  white-space: nowrap;
}

.start-actions .summary-button,
.start-actions .info-button {
  width: 100%;
  min-height: 44px;
}

.start-actions .run-setup-testmode-row {
  display: flex;
  width: 100%;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.start-actions .run-setup-testmode-row .info-button {
  width: auto;
}

.start-actions .run-setup-testmode-row #runSetupTestModeButton {
  flex: 1 1 220px;
}

.start-actions .run-setup-testmode-row #runSetupDeactivateTestModeButton {
  flex: 0 0 auto;
}

.start-actions .run-setup-testmode-row #startTestModeButton {
  flex: 1 1 220px;
}

.start-actions .run-setup-testmode-row #startDeactivateTestModeButton {
  flex: 0 0 auto;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.info-tile,
.power-tile {
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.info-key {
  font-weight: 800;
  color: #fcd34d;
}

.info-desc {
  color: #cdd4ff;
}

.power-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.power-tile img {
  width: 20px;
  height: 20px;
}

.power-tile div {
  font-weight: 700;
}

.power-tile span {
  color: #cdd4ff;
  font-size: 12px;
}

.modern-text {
  margin-bottom: 12px;
  color: #dfe4ff;
}

.modal-card.start-card {
  text-align: center;
  padding: 26px 24px;
}

.start-title {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 6px;
}

.start-subtitle {
  color: #cdd4ff;
  margin-bottom: 10px;
}

.start-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
}

.start-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.start-spaceman {
  width: clamp(56px, 18vw, 96px);
  height: auto;
  max-height: 22vh;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.35));
}

.start-message {
  color: #dfe4ff;
  font-size: 14px;
}

@media (max-width: 640px), (max-height: 760px) {
  .modal-card.start-card {
    padding: 20px 18px;
    max-height: 72vh;
  }
  .start-spaceman {
    width: clamp(48px, 18vw, 84px);
    max-height: 18vh;
  }
  .start-title {
    font-size: 19px;
  }
  .start-subtitle {
    margin-bottom: 8px;
  }
  .start-message {
    font-size: 12px;
    line-height: 1.35;
  }
  .start-hero {
    gap: 7px;
    margin-bottom: 8px;
  }
}

@media (max-width: 480px), (max-height: 680px) {
  .modal-card.start-card {
    padding: 16px 14px;
    max-height: 68vh;
  }
  .start-spaceman {
    width: clamp(44px, 16vw, 72px);
    max-height: 16vh;
  }
  .start-title {
    font-size: 18px;
  }
  .start-subtitle {
    font-size: 13px;
    margin-bottom: 6px;
  }
  .start-message {
    font-size: 11.5px;
  }
  .start-actions {
    gap: 8px;
  }
  .start-hero {
    gap: 6px;
    margin-bottom: 8px;
  }
}

.rotate-overlay .modal-card {
  max-width: 360px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 18, 0.82);
  backdrop-filter: blur(8px);
  z-index: 20;
}

.run-setup-overlay {
  background: rgba(5, 8, 18, 0.68);
  backdrop-filter: blur(6px);
}

.run-setup-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  margin-bottom: 14px;
}

.run-setup-actions .summary-button {
  width: auto;
  white-space: nowrap;
}

.run-setup-hint {
  margin: 0;
}

.modal-overlay.hidden {
  display: none;
}

.modal-overlay.visible {
  display: flex;
}

.modal-card {
  width: min(640px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
  background: #0f1735;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  color: var(--text);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.modal-header .summary-title.small {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.4px;
  margin: 0;
}

.modal-body .summary-title.small {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.35px;
  margin-top: 18px;
  margin-bottom: 6px;
  color: #b8c4ff;
}

.modal-body .summary-title.small.modal-section-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.45px;
  margin-top: 22px;
  margin-bottom: 8px;
  color: #dfe4ff;
}

.modal-card .modern-text {
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 14px;
}

.modal-card .modern-text.subtext {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.55;
  color: #cdd4ff;
  margin-top: 0;
  margin-bottom: 12px;
}

.modal-close {
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.modal-body .info-list {
  padding-left: 18px;
  margin: 6px 0 12px 0;
  line-height: 1.5;
}

.modal-body .info-powerups {
  list-style: none;
  padding: 0;
  margin: 6px 0 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-body .info-powerups li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.testmode-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
  margin-top: 8px;
  padding: 12px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: filter 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.testmode-row:hover {
  filter: brightness(1.06);
  border-color: rgba(255, 255, 255, 0.14);
}

.testmode-row input[type="checkbox"] {
  accent-color: #fcd34d;
}

.testmode-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  opacity: 0.95;
}

.testmode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.testmode-grid .testmode-row {
  margin-top: 0;
}

.testmode-desc {
  font-size: 12px;
  color: #9fb3ff;
  flex-basis: 100%;
  margin-left: 44px;
  margin-top: 2px;
}

.testmode-section {
  margin-top: 18px;
}

.testmode-sliders {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.testmode-slider-row {
  padding: 12px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.testmode-slider-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.testmode-slider-label {
  font-weight: 700;
  color: rgba(255, 255, 255, 0.92);
}

.testmode-slider-value {
  font-size: 12px;
  font-weight: 600;
  color: #cdd4ff;
  font-variant-numeric: tabular-nums;
}

.testmode-range {
  width: 100%;
  accent-color: #fcd34d;
}

.testmode-controls-grid {
  margin-top: 8px;
}

.testmode-controls-grid .testmode-row {
  margin-top: 0;
}

.testmode-help {
  font-size: 12px;
  color: #b8c4ff;
  margin-top: 6px;
}

.testmode-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
  gap: 10px;
}

.testmode-reset-button {
  padding: 8px 10px;
  font-size: 12px;
  min-height: 36px;
  white-space: nowrap;
}

