:root {
  --bg: #fef6e4;
  --primary: #ff8a5b;
  --primary-dark: #e8734a;
  --secondary: #4ecdc4;
  --secondary-dark: #3bb8b0;
  --accent: #7b6cf6;
  --text: #33334d;
  --card-bg: #ffffff;
  --border-radius: 22px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Nunito', sans-serif;
  color: var(--text);
}

.app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Barra superior ---------- */
.top-bar {
  height: 90px;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: var(--card-bg);
  box-shadow: 0 3px 10px rgba(0,0,0,0.08);
  z-index: 5;
}

.top-bar h1 {
  font-family: 'Baloo 2', sans-serif;
  font-size: 34px;
  margin: 0;
  color: var(--primary-dark);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.top-actions { display: flex; gap: 14px; }

/* ---------- Botones ---------- */
.btn {
  font-family: 'Baloo 2', sans-serif;
  font-size: 18px;
  font-weight: 700;
  text-transform: uppercase;
  border: none;
  border-radius: 16px;
  padding: 14px 22px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 4px 0 rgba(0,0,0,0.15);
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.15); }

.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: var(--secondary); color: white; }
.btn-ghost { background: #eef0ff; color: var(--accent); }

/* ---------- Pantallas ---------- */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.screen.active { display: flex; }

/* ---------- Galería (selector) ---------- */
.gallery {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 26px;
  padding: 30px 40px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: 0 6px 16px rgba(0,0,0,0.10);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  border: 4px solid transparent;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.card:hover { transform: translateY(-4px); border-color: var(--secondary); }

.card-thumb {
  height: 150px;
  background: #f4f4fb;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.card-thumb img { max-height: 100%; max-width: 100%; object-fit: contain; }

.card-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: 22px;
  text-align: center;
  padding: 12px 8px;
  color: var(--text);
  text-transform: uppercase;
}

.card-add {
  border: 4px dashed var(--secondary);
  align-items: center;
  justify-content: center;
  min-height: 214px;
}
.card-add .card-thumb { font-size: 56px; color: var(--secondary); background: transparent; }
.card-add .card-title { color: var(--secondary-dark); }

.card-delete {
  position: relative;
}
.card-delete .remove-x {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #ff5c5c;
  color: white;
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  z-index: 2;
}

/* ---------- Pantalla de juego ---------- */
.game-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  padding: 20px 30px;
  gap: 24px;
}

.canvas-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f4f4fb;
  border-radius: var(--border-radius);
  box-shadow: inset 0 0 0 2px #e4e4f5;
}

#canvas {
  height: 560px;
  max-width: 100%;
  cursor: crosshair;
  border-radius: 8px;
  background: white;
}

.palette {
  width: 190px;
  min-width: 190px;
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.color-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 3px solid transparent;
  background: #f7f7fb;
  cursor: pointer;
  font-family: 'Baloo 2', sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
.color-btn.selected {
  border-color: var(--accent);
  background: #eeeaff;
  transform: scale(1.04);
}
.color-swatch {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 2px solid rgba(0,0,0,0.15);
  flex-shrink: 0;
}
.label-text {
  white-space: normal;
  line-height: 1.15;
}
.long-label {
  font-size: 15px;
}

/* ---------- Pantalla de subida ---------- */
.upload-body {
  flex: 1;
  overflow-y: auto;
  padding: 30px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
}

.upload-hint {
  font-family: 'Baloo 2', sans-serif;
  font-size: 20px;
  color: var(--text);
  text-align: center;
}

.text-input, input[type="file"] {
  font-family: 'Nunito', sans-serif;
  font-size: 18px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 2px solid #ddd;
  width: 100%;
  max-width: 420px;
}

.upload-preview img {
  max-height: 220px;
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.1);
  margin-top: 10px;
}

.legend-rows {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f7f7fb;
  padding: 8px 12px;
  border-radius: 12px;
}
.legend-row input[type="text"] {
  width: 60px;
  text-align: center;
  font-family: 'Baloo 2', sans-serif;
  font-size: 18px;
  border-radius: 10px;
  border: 2px solid #ddd;
  padding: 8px;
  text-transform: uppercase;
}
.legend-row input[type="color"] {
  width: 50px;
  height: 40px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.legend-row .remove-row {
  margin-left: auto;
  background: #ff5c5c;
  color: white;
  border: none;
  border-radius: 8px;
  width: 30px;
  height: 30px;
  font-weight: 800;
  cursor: pointer;
}
