* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0b3b52;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ---------- Mynt och meny ---------- */

#hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }

#coins {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px 6px 8px;
  background: rgba(30, 18, 8, 0.6);
  border: 2px solid rgba(255, 210, 110, 0.55);
  border-radius: 999px;
  font-size: 22px;
  font-weight: 800;
  text-shadow: 0 2px 2px rgba(0, 0, 0, 0.5);
  min-width: 96px;
}
#coins.bump { animation: bump 0.25s ease-out; }
@keyframes bump { 50% { transform: scale(1.15); } }

.coin {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3b0, #f5c13c 45%, #b8811a 100%);
  box-shadow: inset 0 0 0 2px #a8700f;
}

#settings-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(20, 30, 40, 0.55);
  font-size: 24px;
}

#settings {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(320px, calc(100% - 32px));
  padding: 18px;
  background: rgba(25, 18, 12, 0.92);
  border: 2px solid rgba(255, 210, 110, 0.5);
  border-radius: 16px;
  text-align: center;
}
#settings h2 { margin: 0 0 6px; }
#settings p { margin: 0 0 12px; opacity: 0.85; }
#quality-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
#settings button {
  padding: 10px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
}
#settings button.active { border-color: #f5c13c; background: rgba(245, 193, 60, 0.25); }
#settings-close { width: 100%; }

/* ---------- Joystick och knapp ---------- */

#joystick {
  position: fixed;
  left: max(24px, env(safe-area-inset-left));
  bottom: max(28px, env(safe-area-inset-bottom));
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  border: 2px solid rgba(255, 255, 255, 0.35);
  touch-action: none;
}
#joystick[hidden] { display: none; }
#stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

#action-btn {
  position: fixed;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(48px, env(safe-area-inset-bottom));
  padding: 18px 22px;
  border-radius: 999px;
  border: 3px solid #fff3b0;
  background: linear-gradient(#f5c13c, #c98a14);
  color: #3b2104;
  font-size: 18px;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  touch-action: none;
  animation: pulse 1.2s ease-in-out infinite;
}
#action-btn[hidden] { display: none; }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* ---------- Texter ---------- */

#hint {
  position: fixed;
  left: 50%;
  top: 72px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.45);
  font-size: 14px;
  text-align: center;
  pointer-events: none;
  transition: opacity 1s;
}
#hint.fade { opacity: 0; }

.popup {
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translateX(-50%);
  font-size: 30px;
  font-weight: 900;
  color: #ffd75e;
  text-shadow: 0 3px 0 #7a4a06, 0 4px 10px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  animation: rise 1.6s ease-out forwards;
}
@keyframes rise {
  0% { opacity: 0; transform: translate(-50%, 20px) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -60px) scale(1); }
}

#loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: linear-gradient(#5795d8, #f2dcbc);
  font-size: 20px;
  font-weight: 700;
  transition: opacity 0.6s;
}
#loading.done { opacity: 0; pointer-events: none; }
.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#errors {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 8px;
  max-height: 40%;
  overflow: auto;
  padding: 10px;
  background: rgba(150, 0, 0, 0.9);
  border-radius: 8px;
  font: 13px/1.4 monospace;
  white-space: pre-wrap;
  user-select: text;
  -webkit-user-select: text;
}
