* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #0e1014;
  color: #e8e8ec;
}

#canvas-wrap {
  position: absolute;
  inset: 0;
  z-index: 0;
}

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

.panel {
  position: absolute;
  top: 12px;
  bottom: 12px;
  width: 300px;
  padding: 16px;
  background: rgba(22, 24, 30, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  backdrop-filter: blur(8px);
  overflow-y: auto;
  z-index: 10;
}

.panel-right {
  right: 12px;
  width: 272px;
  padding: 8px 10px 10px;
  pointer-events: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.panel-left {
  left: 12px;
  width: 240px;
  pointer-events: none;
}

body.play-mode .panel-right {
  opacity: 0.55;
  pointer-events: none;
}

body.settings-mode .panel-right {
  opacity: 1;
  pointer-events: auto;
}

body.settings-mode {
  cursor: default;
}

body.play-mode {
  cursor: none;
}

body.play-mode .panel-left {
  opacity: 0.92;
}

body.play-mode .debug-hud,
body.play-mode .debug-hud-title {
  display: none;
}

body.play-mode .panel-left h2:first-of-type,
body.play-mode .game-status,
body.play-mode .score-row,
body.play-mode .level-diff-label,
body.play-mode .level-stats,
body.play-mode .distance-meter {
  display: block;
}

.crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  z-index: 50;
  pointer-events: none;
  opacity: 0.85;
}

.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
}

.crosshair::before {
  left: 10px;
  top: 4px;
  width: 2px;
  height: 14px;
}

.crosshair::after {
  left: 4px;
  top: 10px;
  width: 14px;
  height: 2px;
}

body.shoot-mode .crosshair {
  opacity: 1;
}

body.shoot-mode .crosshair::before,
body.shoot-mode .crosshair::after {
  background: #ffcc66;
}

body.edm-dome-lighting .panel-right,
body.edm-dome-lighting .hud.panel-left {
  box-shadow: 0 0 24px rgba(255, 0, 180, 0.12);
}

body.edm-dome-lighting.play-mode .crosshair::before,
body.edm-dome-lighting.play-mode .crosshair::after {
  background: #00e5ff;
  box-shadow: 0 0 8px rgba(0, 229, 255, 0.75);
}

.treasure-compass {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 45;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  transition: opacity 0.25s;
}

.treasure-compass .compass-arrow {
  display: block;
  width: 42px;
  height: 24px;
  fill: #ffcc00;
  filter: drop-shadow(0 0 6px rgba(255, 200, 0, 0.9));
  transform-origin: 50% 50%;
  overflow: visible;
}

/* Distance sits directly under the arrow — the two are read together. */
.treasure-compass .compass-distance {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.1;
  margin-top: 2px;
  color: #ffe680;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.85);
  font-variant-numeric: tabular-nums;
}

.treasure-compass.near .compass-distance {
  color: #8dffb4;
}

.treasure-compass .compass-label {
  font-size: 10px;
  color: #ffe680;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.treasure-compass.near .compass-arrow {
  fill: #66ff99;
  filter: drop-shadow(0 0 8px rgba(80, 255, 140, 0.95));
  animation: pulse 0.6s ease-in-out infinite alternate;
}

.tutorial-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  max-width: 420px;
  padding: 12px 20px;
  border-radius: 10px;
  background: rgba(16, 20, 32, 0.92);
  border: 1px solid rgba(91, 156, 255, 0.45);
  color: #c8d4ec;
  font-size: 14px;
  text-align: center;
  z-index: 180;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s, transform 0.35s;
}

.tutorial-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.pause-menu,
.game-complete {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 8, 14, 0.72);
  backdrop-filter: blur(4px);
}

.pause-inline {
  margin: 12px 0 14px;
  padding: 12px;
  border-radius: 10px;
  background: rgba(91, 156, 255, 0.12);
  border: 1px solid rgba(91, 156, 255, 0.35);
  pointer-events: auto;
}

.pause-inline-hint {
  font-size: 12px;
  color: #9ec5ff;
  margin-bottom: 10px;
  line-height: 1.4;
}

.pause-inline-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pause-inline-actions .btn-primary,
.pause-inline-actions .btn-secondary {
  padding: 10px 12px;
  font-size: 13px;
}

body.game-paused .panel-right {
  opacity: 1;
  pointer-events: auto;
  z-index: 20;
}

body.game-paused .panel-left {
  pointer-events: none;
}

body.game-paused .pause-inline {
  pointer-events: auto;
}

.pause-card,
.complete-card {
  width: min(380px, 92vw);
  padding: 24px;
  border-radius: 14px;
  background: rgba(22, 26, 36, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
}

.pause-card h2,
.complete-card h2 {
  font-size: 22px;
  margin-bottom: 8px;
  color: #ffe680;
}

.pause-hint,
.complete-summary {
  font-size: 13px;
  color: #9aa3b8;
  margin-bottom: 18px;
}

.pause-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-primary,
.btn-secondary {
  padding: 12px 16px;
  border-radius: 8px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: #5b9cff;
  color: #fff;
}

.btn-primary:hover {
  background: #4a8ae8;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #e8e8ec;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn-link {
  color: #7eb4ff;
  font-size: 14px;
  text-decoration: none;
  padding: 8px;
}

.complete-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.complete-stats div {
  padding: 10px 6px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
}

.complete-stats span {
  display: block;
  font-size: 10px;
  color: #8a93a8;
  text-transform: uppercase;
}

.complete-stats strong {
  display: block;
  font-size: 18px;
  color: #ffcc66;
  margin-top: 4px;
}

.level-stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  margin-bottom: 10px;
  font-size: 12px;
}

.level-stats .label {
  color: #7a8498;
}

.level-stats .value {
  color: #e8e8ec;
  font-variant-numeric: tabular-nums;
}

.start-mission-name {
  font-size: 15px;
  color: #7eb4ff;
  margin-bottom: 6px;
}

.how-to-play {
  max-width: 420px;
  margin: 0 auto 16px;
  padding: 12px 16px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  text-align: left;
}

.how-to-play h3 {
  font-size: 13px;
  color: #ffcc66;
  margin-bottom: 8px;
}

.how-to-play ul {
  list-style: none;
  font-size: 13px;
  color: #b8c0d0;
  line-height: 1.6;
}

.how-to-play li {
  margin-bottom: 4px;
}

/*
 * The shortcut list.
 *
 * Sized to fit its contents rather than scroll: a scrollbar on a reference
 * panel hides exactly the keys you opened it to find. It is now wider and
 * tall enough for the full list, and only falls back to scrolling on a screen
 * too short to hold it at all.
 */
.shortcuts-panel {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 40;
  width: min(620px, calc(100vw - 24px));
  max-height: min(88vh, 720px);
  overflow-y: auto;
  padding: 12px 14px 14px;
  border-radius: 10px;
  background: rgba(18, 22, 32, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  pointer-events: none;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  /* Fades out on its own after the opening moment; see updateShortcutsPanel. */
  transition: opacity 0.6s ease;
}

.shortcuts-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  color: #c8d4ec;
}

.shortcuts-panel-hint {
  font-size: 10px;
  color: #7a8498;
  font-weight: 400;
}

/*
 * Two columns in the floating panel.
 *
 * The list has grown past twenty entries, and one column of those needs more
 * vertical space than most screens have — which is where the scrollbar came
 * from. Laid out in two columns it is wider and roughly half as tall, so the
 * whole set is readable at once.
 */
/* Two class names deep, because the shared `.shortcut-list` rule below sets
   display:flex and would otherwise win on source order. */
.shortcuts-panel .shortcuts-panel-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 16px;
  align-content: start;
}

.shortcuts-panel .shortcuts-panel-list > div {
  grid-template-columns: 84px 1fr;
}

body.play-mode .shortcuts-panel {
  opacity: 0.94;
}

.music-track-hint {
  font-size: 10px;
  color: #8a93a8;
  margin-top: 3px;
  line-height: 1.25;
}

.mode-banner {
  font-size: 10px;
  padding: 4px 8px;
  border-radius: 5px;
  margin-bottom: 6px;
  background: rgba(91, 156, 255, 0.15);
  border: 1px solid rgba(91, 156, 255, 0.35);
  color: #9ec5ff;
  line-height: 1.3;
}

.game-status {
  font-size: 14px;
  font-weight: 600;
  color: #ffcc66;
  margin-bottom: 10px;
}

body.victory .game-status {
  color: #66ff99;
  animation: pulse 1s ease-in-out infinite alternate;
}

.score-row {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}

.score-box {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 204, 102, 0.25);
}

.score-caption {
  display: block;
  font-size: 10px;
  color: #8a93a8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.score-value {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: #ffcc66;
  font-variant-numeric: tabular-nums;
}

.level-diff-label {
  font-size: 11px;
  color: #7a8498;
  margin-bottom: 10px;
}

.level-up-banner {
  position: fixed;
  top: 18%;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  padding: 14px 28px;
  border-radius: 12px;
  background: rgba(20, 28, 20, 0.92);
  border: 2px solid #ffcc00;
  color: #ffe680;
  font-size: 18px;
  font-weight: 700;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s, transform 0.35s;
  text-align: center;
  box-shadow: 0 8px 32px rgba(255, 200, 0, 0.25);
}

.level-up-banner.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@keyframes pulse {
  from { opacity: 0.85; }
  to { opacity: 1; }
}

.distance-meter {
  margin-bottom: 14px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.distance-header {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #9aa0b4;
  margin-bottom: 6px;
}

.distance-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #4488ff;
}

.distance-track {
  height: 10px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.distance-bar {
  height: 100%;
  width: 50%;
  border-radius: 5px;
  background: #4488ff;
  transition: width 0.15s ease, background 0.15s ease;
}

.distance-legend {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: #6b728a;
  margin-top: 4px;
}

body.play-mode .mode-banner {
  background: rgba(120, 200, 120, 0.12);
  border-color: rgba(120, 200, 120, 0.35);
  color: #a8d8a8;
}

.shortcut-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
}

.shortcut-list > div {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  align-items: center;
}

.shortcut-list dt {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

.shortcut-list dd {
  color: #9aa0b4;
  margin: 0;
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  font-family: inherit;
  font-size: 10px;
  text-align: center;
  color: #e8e8ec;
}

.panel-left h2 {
  margin-top: 14px;
}

.class-legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
}

.class-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #9aa0b4;
}

.class-row .swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.15);
}

.missions-link {
  display: inline-block;
  margin-bottom: 4px;
  font-size: 11px;
  color: #5b9cff;
  text-decoration: none;
}

.missions-link:hover { text-decoration: underline; }

.panel h1 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}

.panel h2 {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #9aa0b4;
  margin: 8px 0 3px;
}

.panel-right h2:first-of-type {
  margin-top: 4px;
}

.subtitle {
  font-size: 10px;
  color: #7a8198;
  margin-bottom: 5px;
  line-height: 1.3;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  font-size: 11px;
}

.stat-grid .label {
  color: #9aa0b4;
}

.stat-grid .value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.control {
  margin-bottom: 6px;
}

.control label {
  display: block;
  font-size: 11px;
  color: #b8bdd0;
  margin-bottom: 2px;
  line-height: 1.25;
}

.control input[type="range"] {
  width: 100%;
  height: 14px;
  accent-color: #5b9cff;
}

.control select,
.control input[type="color"] {
  width: 100%;
  padding: 4px 6px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #252830;
  color: #e8e8ec;
  font-size: 11px;
}

.control input[type="color"] {
  height: 26px;
  padding: 2px;
  cursor: pointer;
}

.slider-value {
  font-size: 11px;
  font-weight: 600;
  color: #5b9cff;
  margin-top: 1px;
  line-height: 1.2;
}

.slider-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 10px;
  color: #8a90a8;
}

.slider-meta input[type="number"] {
  width: 72px;
  padding: 2px 4px;
  font-size: 10px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.25);
  color: #d8dce8;
}

.control-hint {
  font-size: 9px;
  color: #6d738a;
  margin-top: 3px;
  line-height: 1.25;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #b8bdd0;
  margin: 3px 0;
  cursor: pointer;
  line-height: 1.25;
}

.checkbox-row input[type="checkbox"] {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.legend-bar {
  height: 8px;
  border-radius: 3px;
  margin-top: 4px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: #7a8198;
  margin-top: 2px;
}

.panel-right .mode-panel h2 {
  margin-top: 4px;
}

.panel-right .class-legend {
  gap: 2px;
  font-size: 10px;
}

.panel-right .class-row .swatch {
  width: 11px;
  height: 11px;
}

.panel-right .stat-grid {
  margin-top: 6px !important;
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.panel-right .control:has(input[type="range"]) {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 6px;
  align-items: center;
}

.panel-right .control:has(input[type="range"]) label {
  grid-column: 1;
  grid-row: 1;
  margin-bottom: 0;
}

.panel-right .control:has(input[type="range"]) input[type="range"] {
  grid-column: 1 / -1;
  grid-row: 2;
}

.panel-right .control:has(input[type="range"]) .slider-value {
  grid-column: 2;
  grid-row: 1;
  margin-top: 0;
  text-align: right;
  font-size: 10px;
  white-space: nowrap;
}

.panel-right .control:has(select) + .checkbox-row,
.panel-right .mode-panel .checkbox-row {
  margin-top: 2px;
}

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

#loading a {
  color: #7ec8ff;
  margin-top: 12px;
}

#loading,
#click-to-play {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 14, 0.92);
  z-index: 100;
  text-align: center;
  pointer-events: auto;
  cursor: default;
}

#loading.hidden,
#click-to-play.hidden,
.crosshair.hidden,
.treasure-compass.hidden,
.pause-inline.hidden,
.shortcuts-panel.hidden,
.game-complete.hidden {
  display: none;
}

#click-to-play h1 {
  font-size: 28px;
  margin-bottom: 16px;
  letter-spacing: 0.04em;
}

#play-btn {
  padding: 14px 32px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: #5b9cff;
  color: #fff;
  cursor: pointer;
}

#play-btn:hover {
  background: #4a8ae8;
}

.start-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.start-secondary-btn {
  display: inline-block;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #e8e8ec;
  border: 1px solid rgba(255, 255, 255, 0.15);
  text-decoration: none;
}

.start-secondary-btn:hover {
  background: rgba(91, 156, 255, 0.18);
  border-color: rgba(91, 156, 255, 0.35);
  color: #fff;
}

.lock-error {
  color: #ff6b6b;
  font-size: 12px;
  min-height: 18px;
  margin-bottom: 8px;
}

.lock-retry {
  display: inline-block;
  margin-bottom: 10px;
  padding: 6px 14px;
  font-size: 13px;
  border-radius: 6px;
  border: 1px solid rgba(255, 107, 107, 0.45);
  background: rgba(255, 107, 107, 0.12);
  color: #ffd9d9;
  cursor: pointer;
}

.lock-retry:hover {
  background: rgba(255, 107, 107, 0.22);
}

.lock-retry.hidden {
  display: none;
}

.controls-hint {
  font-size: 13px;
  margin-top: 16px;
  color: #6b728a;
  max-width: 420px;
  line-height: 1.5;
}

.start-subtitle {
  font-size: 14px;
  color: #9aa3b8;
  margin-bottom: 16px;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 10px;
  max-width: 520px;
  max-height: 420px;
  overflow-y: auto;
  margin-bottom: 12px;
  padding: 0 12px;
}

.character-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px 10px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(30, 34, 44, 0.9);
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}

.character-card:hover {
  border-color: rgba(91, 156, 255, 0.55);
  transform: translateY(-2px);
}

.character-card.selected {
  border-color: #5b9cff;
  background: rgba(40, 70, 120, 0.45);
  box-shadow: 0 0 0 1px rgba(91, 156, 255, 0.35);
}

.character-preview {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.25);
}

.character-name {
  font-size: 12px;
  font-weight: 600;
}

.character-tag {
  font-size: 10px;
  color: #7a8498;
}

.sprite-creator-panel {
  max-width: 520px;
  margin: 0 auto 18px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  text-align: left;
}

.sprite-creator-panel h3 {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9aa3ad;
}

.sprite-creator-intro {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.45;
  color: #c8ced8;
}

.sprite-creator-intro a {
  color: #7eb4ff;
}

.character-status {
  margin: 10px 0 0;
  min-height: 18px;
  font-size: 12px;
  color: #9aa3ad;
  text-align: center;
}

.character-grid--empty {
  display: none;
}

.character-upload-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
  margin: 8px 0 4px;
}

.character-upload-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid #5b9cff;
  background: rgba(91, 156, 255, 0.18);
  color: #dbe7ff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.character-upload-btn:hover {
  background: rgba(91, 156, 255, 0.32);
}

.settings-upload-btn {
  width: 100%;
  margin-bottom: 8px;
}

.character-upload-clear {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: transparent;
  color: #c8ced8;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.character-upload-hint {
  font-size: 12px;
  color: #9aa3b8;
  max-width: 440px;
  margin: 0 auto 8px;
  line-height: 1.45;
}

.character-upload-status {
  font-size: 12px;
  color: #8ec7ff;
  min-height: 16px;
  margin-bottom: 8px;
}

.character-upload-clear.hidden {
  display: none;
}

#click-to-play {
  overflow-y: auto;
  padding: 24px 16px 32px;
}

.osm-paths-status {
  font-size: 11px;
  color: #8a90a8;
  margin: 4px 0 10px 24px;
  min-height: 1.2em;
}

.osm-paths-status.ok { color: #9d7dff; }
.osm-paths-status.warn { color: #c9a040; }

.bgt-template-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 6px;
}

.bgt-swatch-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 9px;
  color: #8a90a8;
}

.bgt-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  flex-shrink: 0;
}

.bgt-colors-status {
  font-size: 10px;
  margin: 4px 0 8px;
  line-height: 1.3;
  color: #8a90a8;
}

.bgt-colors-status.ok { color: #7cb87a; }
.bgt-colors-status.warn { color: #c9a040; }


/* Grenade blast banner — big, brief, and shaken. */
.kaboom-banner {
  position: fixed;
  top: 32%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(38px, 9vw, 104px);
  font-weight: 900;
  letter-spacing: 3px;
  color: #ffd34d;
  text-shadow:
    0 0 18px rgba(255, 120, 0, 0.9),
    0 6px 0 #8a2b00,
    0 0 60px rgba(255, 60, 0, 0.6);
  pointer-events: none;
  opacity: 0;
  z-index: 60;
  white-space: nowrap;
}

.kaboom-banner.visible {
  animation: kaboom-pop 1.55s ease-out forwards;
}

@keyframes kaboom-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.25) rotate(-10deg); }
  8% { opacity: 1; transform: translate(-50%, -50%) scale(1.45) rotate(4deg); }
  16% { transform: translate(-54%, -46%) scale(1.12) rotate(-5deg); }
  26% { transform: translate(-46%, -54%) scale(1.22) rotate(3deg); }
  38% { transform: translate(-52%, -48%) scale(1.05) rotate(-2deg); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -58%) scale(0.92); }
}

/* After a close blast: white-out, then tunnel vision + ringing world. */
.shellshock {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 55;
  opacity: 0;
  --shock: 1;
  background:
    radial-gradient(ellipse at center, rgba(255, 246, 210, calc(var(--shock) * 0.55)) 0%, rgba(255, 140, 40, calc(var(--shock) * 0.18)) 28%, rgba(6, 4, 2, calc(var(--shock) * 0.78)) 100%);
  mix-blend-mode: overlay;
}

.shellshock.active {
  animation: shellshock-hit 4.6s ease-out forwards;
}

@keyframes shellshock-hit {
  0% {
    opacity: 1;
    filter: contrast(1.8) saturate(0.05) brightness(2.6);
    mix-blend-mode: screen;
  }
  6% {
    opacity: 0.95;
    filter: contrast(1.5) saturate(0.1) brightness(1.6);
  }
  14% {
    opacity: 0.85;
    filter: contrast(1.35) saturate(0.12) brightness(0.7);
    mix-blend-mode: overlay;
  }
  40% {
    opacity: 0.55;
    filter: contrast(1.15) saturate(0.25) brightness(0.85);
  }
  100% {
    opacity: 0;
    filter: none;
  }
}


/* Density scanner readout — same idea as KABOOM, calmer palette. */
.density-readout {
  position: fixed;
  top: 26%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: baseline;
  gap: 10px;
  pointer-events: none;
  opacity: 0;
  z-index: 58;
  white-space: nowrap;
}

.density-readout-value {
  font-size: clamp(34px, 7.5vw, 86px);
  font-weight: 900;
  letter-spacing: 1px;
  color: #7dffd6;
  text-shadow:
    0 0 16px rgba(40, 255, 200, 0.75),
    0 4px 0 #06503f,
    0 0 48px rgba(0, 220, 170, 0.45);
}

.density-readout-unit {
  font-size: clamp(14px, 2.2vw, 26px);
  font-weight: 700;
  letter-spacing: 2px;
  color: #b8fff0;
  text-shadow: 0 0 10px rgba(40, 255, 200, 0.6);
}

.density-readout.visible {
  animation: density-pop 1.6s ease-out forwards;
}

@keyframes density-pop {
  0% { opacity: 0; transform: translate(-50%, -46%) scale(0.7); }
  10% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  20% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -54%) scale(0.98); }
}


/* ---------------------------------------------------------------- gun rack */
/*
 * The weapon strip along the bottom. It has to be readable over a bright sky
 * and over dark ballast, so every slot carries its own dark plate rather than
 * relying on the scene behind it.
 */
.gun-hud {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 7px 9px;
  border-radius: 12px;
  background: rgba(10, 14, 20, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.09);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 40;
}

.gun-hud.visible {
  pointer-events: auto;
}

.gun-slot {
  position: relative;
  width: 74px;
  padding: 6px 4px 5px;
  border-radius: 8px;
  text-align: center;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.gun-slot:hover {
  background: rgba(255, 255, 255, 0.1);
}

.gun-slot-key {
  position: absolute;
  top: 2px;
  left: 5px;
  font-size: 10px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.4);
}

.gun-slot-icon {
  display: block;
  width: 52px;
  height: 21px;
  margin: 3px auto 2px;
}

/* Inactive weapons read as unlit metal; the active one lights up. */
.gun-slot-icon path {
  fill: rgba(215, 226, 238, 0.5);
}

.gun-slot-name {
  display: block;
  font-size: 9.5px;
  line-height: 1.15;
  color: rgba(255, 255, 255, 0.45);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gun-slot.active {
  background: rgba(255, 190, 60, 0.16);
  border-color: rgba(255, 190, 60, 0.65);
}

.gun-slot.active .gun-slot-icon path {
  fill: #ffce5c;
}

.gun-slot.active .gun-slot-name,
.gun-slot.active .gun-slot-key {
  color: #ffe6a8;
}

@media (max-width: 900px) {
  .gun-slot { width: 54px; }
  .gun-slot-icon { width: 40px; height: 16px; }
  .gun-slot-name { font-size: 8px; }
}


/* Admin-only block in the settings panel: pin this look to the mission. */
.mission-default-box {
  margin-top: 10px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 190, 60, 0.08);
  border: 1px solid rgba(255, 190, 60, 0.32);
}


/* ============================================================================
   Touch: the on-screen controls, and the HUD at phone size.
   See touch-controls.js. Everything here is inert until the OSD switches
   `body.touch-mode` on, so a desktop session is untouched by it.
   ========================================================================== */

/*
 * A game, not a document.
 *
 * Every gesture belongs to the controls: without `touch-action: none` a drag
 * to look around scrolls the page instead, and a double tap to fire twice
 * zooms in. `overscroll-behavior` kills the pull-to-refresh that a downward
 * drag near the top edge would otherwise trigger mid-firefight.
 */
body.touch-mode {
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* There is no cursor to hide, and hiding it looks odd on a hybrid device
   where a mouse is still plugged in. */
body.touch-mode.play-mode {
  cursor: default;
}

.touch-osd {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  /* No padding here: the drag layers must cover the whole pane of glass. The
     buttons dodge the notch themselves with env() insets. */
}

.touch-osd.visible {
  display: block;
}

.touch-look,
.touch-move {
  position: absolute;
  touch-action: none;
}

/* Look is the whole screen; the stick zone below sits on top of its corner. */
.touch-look {
  inset: 0;
}

/*
 * The stick zone.
 *
 * Deliberately much bigger than the stick it draws: you should be able to put
 * a thumb down anywhere in the bottom-left of the screen and start walking,
 * without aiming for a circle. Capped in px so a tablet does not hand over
 * half its screen to it.
 */
.touch-move {
  left: 0;
  bottom: 0;
  width: 46%;
  max-width: 420px;
  height: 62%;
}

.touch-stick {
  position: absolute;
  width: 136px;
  height: 136px;
  margin: -68px 0 0 -68px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: radial-gradient(circle, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.03) 70%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.touch-stick.visible {
  opacity: 1;
}

/* The rim is sprint, so it has to look like it. */
.touch-stick.sprint {
  border-color: rgba(140, 255, 180, 0.9);
  box-shadow: 0 0 20px rgba(120, 255, 170, 0.4);
}

.touch-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
}

.touch-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  background: rgba(14, 18, 26, 0.46);
  color: #eaf0ff;
  font-family: inherit;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: auto;
  touch-action: none;
  transition: transform 0.08s ease, background 0.12s ease;
}

.touch-btn-glyph {
  font-size: 20px;
  line-height: 1;
}

.touch-btn-label {
  font-size: 9px;
  line-height: 1;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  opacity: 0.85;
}

.touch-btn.pressed {
  transform: scale(0.93);
  background: rgba(91, 156, 255, 0.5);
}

/* Latched: rapid fire, crouch, and the sheet button while it is open. */
.touch-btn.on {
  background: rgba(255, 190, 60, 0.34);
  border-color: rgba(255, 190, 60, 0.85);
  color: #fff3d6;
}

.touch-btn-fire {
  width: 96px;
  height: 96px;
  background: rgba(214, 58, 58, 0.36);
  border-color: rgba(255, 130, 130, 0.6);
}

.touch-btn-fire .touch-btn-glyph {
  font-size: 30px;
}

.touch-btn-fire .touch-btn-label {
  font-size: 10px;
}

.touch-btn-mid {
  width: 72px;
  height: 72px;
}

.touch-btn-small {
  width: 60px;
  height: 60px;
}

.touch-btn-small .touch-btn-glyph {
  font-size: 17px;
}

/* Utility row: square-ish, label hidden, aria-label carries the meaning. */
.touch-btn-util {
  width: 44px;
  height: 44px;
  border-radius: 12px;
}

.touch-btn-util .touch-btn-glyph {
  font-size: 17px;
}

.touch-btn-util .touch-btn-label {
  display: none;
}

/*
 * The action cluster: two columns, the trigger bottom-right where the thumb
 * already rests, jump beside it, the two modifiers a row up. A grid rather
 * than four absolute positions, so it survives a change of button size or an
 * extra button.
 */
.touch-cluster {
  position: absolute;
  right: calc(10px + env(safe-area-inset-right));
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: auto auto;
  gap: 10px;
  align-items: end;
  justify-items: center;
  pointer-events: none;
}

.touch-utility {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  display: flex;
  gap: 6px;
  pointer-events: none;
}

/* Left thumb, above the stick zone: the only thing that hand has to reach. */
.touch-crouch {
  position: absolute;
  left: calc(12px + env(safe-area-inset-left));
  bottom: calc(160px + env(safe-area-inset-bottom));
}

.touch-rotate-hint {
  position: absolute;
  left: 50%;
  bottom: calc(190px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: none;
  max-width: 70vw;
  padding: 5px 12px;
  border-radius: 12px;
  font-size: 11px;
  text-align: center;
  color: #d6e0f5;
  background: rgba(10, 14, 20, 0.66);
  pointer-events: none;
}

@media (orientation: portrait) {
  .touch-osd.visible .touch-rotate-hint {
    display: block;
  }
}

/*
 * The menu sheet: the keyboard shortcuts, as rows.
 *
 * Anchored under the utility row it was opened from, and no wider than it
 * needs to be — the point of a phone menu is that it does not take the game
 * away from you while it is open.
 */
.touch-sheet {
  position: absolute;
  top: calc(58px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  width: min(330px, calc(100vw - 24px));
  max-height: calc(100vh - 76px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  display: none;
  flex-direction: column;
  overflow: hidden;
  border-radius: 14px;
  background: rgba(16, 20, 30, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
}

.touch-osd.sheet-open .touch-sheet {
  display: flex;
}

/*
 * While the sheet is open the world controls step back, so a tap that lands
 * beside a row cannot also swing the camera or squeeze the trigger.
 */
.touch-osd.sheet-open .touch-look,
.touch-osd.sheet-open .touch-move,
.touch-osd.sheet-open .touch-crouch,
.touch-osd.sheet-open .touch-cluster {
  pointer-events: none;
  opacity: 0.2;
}

.touch-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px 9px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 13px;
  font-weight: 600;
  color: #cfe0ff;
}

.touch-sheet-close {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.06);
  color: #e8ecf6;
  font-family: inherit;
  font-size: 14px;
  touch-action: none;
}

/* The one scrollable thing on the page, so it opts back into panning. */
.touch-sheet-rows {
  padding: 4px 12px 10px;
  overflow-y: auto;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.touch-sheet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.touch-sheet-label {
  font-size: 12.5px;
  color: #dfe6f5;
}

.touch-sheet-btns {
  display: flex;
  flex: none;
  gap: 6px;
}

/* 44 px is the smallest target a thumb hits reliably; nothing here is under it. */
.touch-sheet-btn {
  min-width: 46px;
  height: 42px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.07);
  color: #eaf0ff;
  font-family: inherit;
  font-size: 15px;
  touch-action: none;
}

.touch-sheet-btn.wide {
  min-width: 104px;
  font-size: 12.5px;
}

.touch-sheet-btn.pressed {
  background: rgba(91, 156, 255, 0.45);
}

/* ---- the rest of the interface, once the OSD is on ---------------------- */

/*
 * Keyboard help without a keyboard is noise, and the reverse is just as true.
 * Both lists live in the markup; the input path picks one.
 */
.how-to-play-touch,
.shortcuts-panel .touch-help-list {
  display: none;
}

body.touch-mode .how-to-play-keys,
body.touch-mode .shortcuts-panel .shortcuts-keys-list,
body.touch-mode .shortcuts-panel-hint {
  display: none;
}

body.touch-mode .how-to-play-touch {
  display: block;
}

body.touch-mode .shortcuts-panel .touch-help-list {
  display: grid;
  grid-template-columns: 1fr;
}

body.touch-mode .shortcuts-panel .touch-help-list > div {
  grid-template-columns: 116px 1fr;
}

.shortcuts-close {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.06);
  color: #e8ecf6;
  font-family: inherit;
  font-size: 14px;
}

/*
 * On touch the shortcuts panel is a card you open and close deliberately:
 * there is no K to toggle it, and no corner of the screen it can hide in
 * without sitting under a thumb.
 */
body.touch-mode .shortcuts-panel {
  left: 50%;
  right: auto;
  top: 50%;
  bottom: auto;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100vw - 28px));
  max-height: min(82vh, 560px);
  z-index: 70;
  pointer-events: auto;
  touch-action: pan-y;
}

body.touch-mode .shortcuts-close {
  display: block;
}

/*
 * Left HUD: a strip, not a column.
 *
 * On a 390 px tall landscape phone the desktop block covers a third of the
 * view with numbers you glance at twice a level. Score, level and the distance
 * bar stay; the debug grid and the legends go.
 */
body.touch-mode .panel-left {
  position: fixed;
  top: calc(4px + env(safe-area-inset-top));
  left: calc(4px + env(safe-area-inset-left));
  width: auto;
  max-width: 58vw;
  max-height: 44vh;
  padding: 6px 9px;
  border-radius: 9px;
  background: rgba(16, 20, 28, 0.62);
  font-size: 11px;
  overflow: hidden;
}

body.touch-mode #level-title {
  font-size: 12px;
  font-weight: 600;
  margin: 0;
}

body.touch-mode .score-row {
  gap: 6px;
  margin-bottom: 4px;
}

body.touch-mode .score-box {
  padding: 3px 7px;
}

body.touch-mode .score-value {
  font-size: 15px;
}

body.touch-mode .distance-meter {
  margin-bottom: 0;
  padding: 5px 7px;
}

body.touch-mode.play-mode .game-status,
body.touch-mode.play-mode .level-diff-label,
body.touch-mode.play-mode .level-stats,
body.touch-mode.play-mode .distance-legend,
body.touch-mode.play-mode .mode-banner {
  display: none;
}

/* Paused, the left strip shares the screen with the settings sheet. */
body.touch-mode.game-paused .panel-left {
  max-height: 32vh;
  overflow-y: auto;
  touch-action: pan-y;
}

/*
 * Settings: a bottom sheet, full width, and only while paused.
 *
 * A 272 px column down the side of a phone leaves every label wrapping to
 * three lines. `display: none` while playing rather than the desktop fade — it
 * is a scrolling form, and it must not be under the trigger.
 */
body.touch-mode .panel-right {
  top: auto;
  left: calc(6px + env(safe-area-inset-left));
  right: calc(6px + env(safe-area-inset-right));
  bottom: calc(6px + env(safe-area-inset-bottom));
  width: auto;
  max-height: 60vh;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

body.touch-mode.play-mode .panel-right {
  display: none;
}

/* Thumb-sized form controls, not mouse-sized ones. */
body.touch-mode .panel-right select,
body.touch-mode .panel-right input[type="number"] {
  min-height: 40px;
  font-size: 14px;
}

body.touch-mode .panel-right input[type="range"] {
  height: 30px;
}

body.touch-mode .checkbox-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
}

/*
 * The weapon rack doubles as the picker on touch.
 *
 * It normally sits below the OSD, which would eat the taps, so opening the
 * tray lifts it over the top and takes the look layer out of the way.
 */
body.touch-mode .gun-hud {
  bottom: calc(8px + env(safe-area-inset-bottom));
  pointer-events: none;
}

body.touch-mode.weapon-tray-open .gun-hud {
  z-index: 80;
  pointer-events: auto;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100vw - 24px);
}

body.touch-mode.weapon-tray-open .gun-slot {
  padding: 8px 6px 7px;
}

body.touch-mode.weapon-tray-open .touch-look,
body.touch-mode.weapon-tray-open .touch-move,
body.touch-mode.weapon-tray-open .touch-cluster {
  pointer-events: none;
}

/* The compass is the whole navigation game; give it room to be read. */
body.touch-mode .treasure-compass {
  top: calc(6px + env(safe-area-inset-top));
}

/* The start card is a scrolling page on a phone, not a centred dialog. */
body.touch-mode #click-to-play {
  justify-content: flex-start;
  padding: 16px 12px 28px;
}

body.touch-mode #play-btn {
  padding: 16px 34px;
  font-size: 17px;
}

body.touch-mode .pause-inline-actions .btn-primary,
body.touch-mode .pause-inline-actions .btn-secondary,
body.touch-mode .btn-primary,
body.touch-mode .btn-secondary {
  min-height: 46px;
}

/*
 * Landscape phones are short, not narrow: the vertical budget runs out first,
 * so the start card loses its decoration before it loses its buttons, and the
 * buttons themselves come in a size.
 */
@media (orientation: landscape) and (max-height: 460px) {
  body.touch-mode #click-to-play h1 {
    font-size: 20px;
    margin-bottom: 8px;
  }

  body.touch-mode .sprite-creator-panel,
  body.touch-mode .start-subtitle {
    display: none;
  }

  body.touch-mode .touch-btn-fire {
    width: 84px;
    height: 84px;
  }

  body.touch-mode .touch-btn-mid {
    width: 64px;
    height: 64px;
  }

  body.touch-mode .touch-btn-small {
    width: 54px;
    height: 54px;
  }

  body.touch-mode .touch-crouch {
    bottom: calc(140px + env(safe-area-inset-bottom));
  }
}
