* { box-sizing: border-box; font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial; }
body {
  margin: 0;
  align-items: center;
  min-height: 100vh;
  background-color: #333;
  color: #fff;
}

#canvasWrapper {
  position: relative;
  width: 100vw; /* was 900px */
  height: 100vh; /* was 500px */
  border: 2px solid #000;
  box-shadow: 0 0 20px rgba(0,0,0,0.5);
  overflow: hidden; /* Varmistaa, että overlayt pysyvät sisällä */
}

#gameContainer, #canvasOverlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

#gameContainer canvas {
  display: block; /* Varmistaa, ettei canvas-elementillä ole ylimääräistä tilaa */
}

#canvasOverlay {
  position:absolute;
  left:0;
  top:0;
  width:100%;
  height:100%;
  pointer-events:none;
  overflow:hidden;
  border-radius:4px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 50%, rgba(0,0,0,0.7) 100%);
  pointer-events: none; /* Sallii klikkaukset läpi overlayn */
}

/* Clouds: moving subtle gradient layers */
#clouds {
  position:absolute; left:-10%; top:0; width:120%; height:60%;
  background-image: radial-gradient(rgba(255,255,255,0.22) 10%, rgba(255,255,255,0) 60%),
                    radial-gradient(rgba(255,255,255,0.18) 8%, rgba(255,255,255,0) 60%);
  background-size: 600px 200px, 900px 300px;
  background-position: 0 20px, 0 80px;
  filter: blur(8px) saturate(90%);
  animation: cloud-pan 60s linear infinite;
  opacity: 0.9;
}
@keyframes cloud-pan {
  from { background-position: 0 20px, 0 80px; }
  to { background-position: -1200px 20px, -1800px 80px; }
}

/* Vignette for cinematic look */
#vignette {
  position:absolute; left:0; top:0; width:100%; height:100%;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 45%, rgba(0,0,0,0.25) 100%);
  pointer-events:none;
}

/* Game title overlay */
#gameTitle { position: absolute; left: 14px; top: 8px; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,0.6); font-weight:700; font-size:18px; pointer-events:none; }

/* Basic styles for UI elements, adapted for Phaser */
#ui {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  pointer-events: none; /* UI-elementit eivät estä pelin klikkauksia */
}

#ui > * {
  pointer-events: all; /* Mutta niiden lapset voivat vastaanottaa klikkauksia */
  background: rgba(0,0,0,0.5);
  padding: 8px 12px;
  border-radius: 5px;
  font-size: 16px;
}

#health { background: rgba(0,0,0,0.45); color: #fff; padding:6px 10px; border-radius:8px; backdrop-filter: blur(4px); }
#coins { background: rgba(0,0,0,0.45); color: #fff; padding:6px 10px; border-radius:8px; backdrop-filter: blur(4px); }
#settingsBtn {
  background: rgba(0,0,0,0.45);
  color: #fff;
  border-radius:8px;
  padding:6px 10px;
  cursor: pointer;
}

#backpackBtn {
  background: rgba(0,0,0,0.45);
  color: #fff;
  border-radius:8px;
  padding:6px 10px;
  cursor: pointer;
}

#settingsMenu {
  position: absolute;
  top: 50px;
  right: 10px;
  background: rgba(0,0,0,0.8);
  padding: 15px;
  border-radius: 5px;
  border: 1px solid #555;
  z-index: 100;
}

.merchant-inline button {
  background: #5c6bc0;
  color: white;
  border: none;
  padding: 6px 10px;
  border-radius: 5px;
  cursor: pointer;
  margin: 4px 0 8px;
}

.merchant-inline button:hover { background: #7986cb; }

/* Inventory styles */
#inventory {
  position: absolute;
  left: 50%;
  bottom: 10px; /* pin inventory to bottom */
  transform: translateX(-50%);
  display: flex;
  gap: 5px;
  background: rgba(0,0,0,0.5);
  padding: 8px;
  border-radius: 8px;
}

.slot {
  width: 40px;
  height: 40px;
  border: 2px solid #888;
  border-radius: 5px;
  background: #444;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 12px; /* slightly smaller to fit text and tool name */
  color: #fff;
}

.slot:hover {
  border-color: #fff;
}

/* Merchant window styles */
#merchant {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0,0,0,0.7);
  z-index: 200;
}

/* Ensure hidden overrides #merchant display */
#merchant.hidden { display: none; }

.merchant-box {
  background: rgba(255,255,255,0.95);
  padding: 12px;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  text-align: center;
  border: 2px solid #888;
  border-radius: 10px;
  max-width: 320px;
}

.merchant-box h3 {
  margin: 0;
  color: #ffc107;
}

.merchant-box button {
  background: #5c6bc0;
  color: white;
  border: none;
  padding: 8px 12px;
  border-radius: 5px;
  cursor: pointer;
  margin: 5px;
}

.merchant-box button:hover {
  background: #7986cb;
}

.hidden {
  display: none;
}

/* Start/pause overlays */
.overlay {
  position: fixed;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 300;
}
.overlay .panel {
  background: rgba(255,255,255,0.96);
  color: #222;
  border: 2px solid #666;
  border-radius: 12px;
  padding: 16px 18px;
  width: min(720px, 92vw);
  box-shadow: 0 10px 24px rgba(0,0,0,0.35);
  text-align: center;
}
.overlay h1 { margin: 6px 0 8px; color:#3f51b5; font-size: 28px; }
.overlay h3 { margin: 6px 0 8px; color:#3f51b5; }
.overlay p { margin: 8px 0 14px; color:#333; }
.overlay .actions { display:flex; gap:10px; justify-content:center; flex-wrap:wrap; }
.overlay button { background:#5c6bc0; color:#fff; border:none; padding:10px 14px; border-radius:8px; cursor:pointer; }
.overlay button:hover { background:#7986cb; }

/* Ensure hidden wins over overlay's display */
.overlay.hidden { display: none !important; }

/* Backpack panel */
#backpackPanel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0,0,0,0.7);
  z-index: 210;
}

#backpackPanel.hidden { display:none; }

.bp-box {
  background: rgba(255,255,255,0.95);
  padding: 12px;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  text-align: center;
  border: 2px solid #888;
  border-radius: 10px;
  width: 320px;
}

.bp-box h3 { margin: 0 0 8px; color:#ffc107; }
.bp-slots { display:grid; grid-template-columns: 1fr; gap:8px; margin: 8px 0; }
.bp-slot { display:flex; justify-content:space-between; align-items:center; background:#f1f1f1; padding:8px 10px; border-radius:8px; color:#333; }
.bp-actions { display:flex; justify-content:space-between; gap:10px; margin-top:10px; }
.bp-actions button { background:#5c6bc0; color:#fff; border:none; border-radius:6px; padding:8px 12px; cursor:pointer; }
.bp-actions button:hover { background:#7986cb; }

/* --- Mobiiliohjaimet --- */
#touchControls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 12px 14px;
  display: none; /* oletuksena piilossa; näytetään mobiilissa */
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none; /* estä koko kerroksen blokkaus */
  z-index: 120; /* nouse canvasin ja inventaarion yläpuolelle */
}

#touchControls .tc-left,
#touchControls .tc-right {
  display: flex;
  gap: 12px;
  pointer-events: auto; /* mutta napit ovat klikattavia */
}

.tc-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.5);
  background: rgba(0,0,0,0.35);
  color: #fff;
  font-size: 22px;
  box-shadow: 0 6px 14px rgba(0,0,0,0.35);
  backdrop-filter: blur(4px);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.tc-btn.primary {
  background: rgba(0,120,255,0.5);
  border-color: rgba(120,190,255,0.8);
}

.tc-hint {
  position: absolute;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.45);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  pointer-events: none;
}

.tc-mode {
  position: absolute;
  right: 14px;
  bottom: 90px;
  background: rgba(255,193,7,0.9);
  color: #000;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
  display: none; /* näkyy kun asetus-tila päällä */
}

/* Näytä ohjaimet pienillä ruuduilla tai kun on kosketuslaite */
@media (pointer: coarse), (max-width: 900px) {
  #touchControls { display: flex; }
  /* tee inventoriosta hieman kompaktimpi mobiilissa */
  #inventory { bottom: 90px; }
}
