:root {
  --bg-color: #f0f7f7; /* Very pale turquoise background */
  --header-bg: #5abeb0; /* Turquoise header */
  --text-color: #2c5a53; /* Darker teal text */
  --accent-color: #49a699; /* slightly darker turquoise for accents */
  --accent-hover: #3d8c81;
  --border-radius: 16px;
  --footer-bg: #5abeb0; /* Turquoise footer */
}

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

body, html {
  height: 100%;
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

/* Header */
#header {
  background-color: var(--header-bg);
  color: white; /* White text on turquoise */
  padding: env(safe-area-inset-top, 10px) 15px 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  z-index: 10;
}

h1 {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
}

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

.upload-btn {
  background-color: white; /* White button on turquoise */
  color: var(--header-bg);
  padding: 8px 14px;
  border-radius: var(--border-radius);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.2s;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.upload-btn:active {
  background-color: #f0f0f0;
}

#image-upload {
  display: none;
}

#difficulty-select {
  padding: 8px 10px;
  border-radius: var(--border-radius);
  border: 1px solid rgba(0,0,0,0.1);
  background-color: white;
  color: var(--text-color);
  font-size: 0.9rem;
  font-weight: 500;
  outline: none;
}

/* Game Area */
#game-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #e5ded0; /* Slightly darker than bg to make canvas pop */
}

#canvas-container {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

/* The canvas itself */
#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  touch-action: none; /* VERY IMPORTANT: Let us handle all gestures */
  image-rendering: pixelated; /* Keep pixels sharp */
}

/* Loading Overlay */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(240, 247, 247, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 20;
}

#loading-overlay.hidden {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--bg-color);
  border-top-color: var(--header-bg);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 15px;
}

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

/* Zoom Controls */
#zoom-controls {
  position: absolute;
  right: 15px;
  bottom: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 5;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-color: white;
  color: var(--header-bg);
  border: none;
  font-size: 1.5rem;
  font-weight: 300;
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: transform 0.1s, background-color 0.2s;
  outline: none;
}

.icon-btn:active {
  background-color: #f0f0f0;
  transform: scale(0.95);
}

/* Footer / Palette */
#palette-footer {
  background-color: var(--footer-bg);
  padding: 15px 15px calc(15px + env(safe-area-inset-bottom, 10px));
  box-shadow: 0 -2px 15px rgba(0,0,0,0.1);
  z-index: 10;
}

#palette-container {
  display: flex;
  overflow-x: auto;
  gap: 12px;
  padding-bottom: 5px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
}

#palette-container::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.swatch-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.color-swatch {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3); /* lighter border on turquoise */
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
  transition: transform 0.2s, border-color 0.2s;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.color-swatch.selected {
  transform: scale(1.15);
  border-color: white; /* white border when selected */
  border-width: 3px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.swatch-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: white; /* white text on turquoise footer */
}
