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

html, body {
  height: 100%;
  background: #1c2a1a;
  font-family: "Comic Sans MS", "Chalkboard SE", "Marker Felt", system-ui, sans-serif;
  color: #2b2b2b;
  overflow: hidden;
}

#game-wrap {
  position: relative;
  width: 960px;
  height: 600px;
  margin: 20px auto;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  background: #8fd07a;
}

canvas#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  background: linear-gradient(180deg, #ffe6a8 0%, #ffb8c5 100%);
  padding: 40px;
}

.overlay h1 {
  font-size: 72px;
  color: #5b3b88;
  text-shadow: 4px 4px 0 #fff, 8px 8px 0 rgba(91,59,136,0.25);
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.overlay .subtitle {
  font-size: 20px;
  color: #7a4a99;
  margin-bottom: 32px;
}

.overlay button {
  font-family: inherit;
  font-size: 24px;
  padding: 14px 40px;
  border: none;
  border-radius: 999px;
  background: #ff8fb1;
  color: white;
  cursor: pointer;
  box-shadow: 0 6px 0 #c75d80, 0 10px 20px rgba(0,0,0,0.2);
  transition: transform 0.1s, box-shadow 0.1s;
}

.overlay button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 0 #c75d80, 0 14px 24px rgba(0,0,0,0.25);
}

.overlay button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #c75d80;
}

.overlay button.secondary {
  background: #5b3b88;
  font-size: 14px;
  padding: 8px 22px;
  margin-top: 8px;
  box-shadow: 0 4px 0 #3b2462, 0 8px 16px rgba(0,0,0,0.2);
}

/* Add visual gap between the big New Game button and the small secondary ones */
#title-screen #start-btn { margin-bottom: 22px; }

.name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 18px 0;
}
.name-row label {
  font-size: 16px;
  color: #5b3b88;
  font-weight: bold;
}
.name-row input {
  font-family: inherit;
  font-size: 18px;
  padding: 8px 16px;
  border: 3px solid #5b3b88;
  border-radius: 999px;
  background: white;
  color: #2b2b2b;
  width: 160px;
  text-align: center;
  outline: none;
}
.name-row input:focus {
  box-shadow: 0 0 0 4px rgba(91, 59, 136, 0.25);
}
.overlay button.secondary:active {
  box-shadow: 0 1px 0 #3b2462;
}

#level-select h2 {
  font-size: 36px;
  color: #5b3b88;
  margin-bottom: 4px;
  text-shadow: 2px 2px 0 #fff;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 800px;
  margin-top: 16px;
}

.level-section {
  background: rgba(255,255,255,0.5);
  border-radius: 14px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.level-section h3 {
  font-size: 14px;
  color: #5b3b88;
  text-align: center;
  margin-bottom: 4px;
}

.level-section button {
  font-family: inherit;
  font-size: 12px !important;
  padding: 6px 10px !important;
  border: none;
  border-radius: 8px;
  background: #ff8fb1;
  color: white;
  cursor: pointer;
  text-align: left;
  box-shadow: 0 2px 0 #c75d80 !important;
}
.level-section button:hover {
  background: #ff7fa4;
}
.level-section button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #c75d80 !important;
}

#save-files h2 {
  font-size: 36px;
  color: #5b3b88;
  margin-bottom: 4px;
  text-shadow: 2px 2px 0 #fff;
}

.save-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 820px;
  margin-top: 20px;
}

.save-slot {
  background: rgba(255,255,255,0.7);
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
}

.save-slot .slot-title {
  font-weight: bold;
  font-size: 14px;
  color: #5b3b88;
}

.save-slot .slot-info {
  font-size: 11px;
  color: #4a3a55;
  background: rgba(255,255,255,0.7);
  border-radius: 8px;
  padding: 6px 6px;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.save-slot .slot-actions {
  display: flex;
  gap: 4px;
}

.save-slot button {
  flex: 1;
  font-family: inherit;
  font-size: 11px !important;
  padding: 5px 6px !important;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: white;
  box-shadow: 0 2px 0 rgba(0,0,0,0.2) !important;
}
.save-slot button:hover { transform: translateY(-1px); }
.save-slot button:active { transform: translateY(1px); box-shadow: 0 0 0 rgba(0,0,0,0.2) !important; }

.save-slot .save-btn { background: #ff8fb1; }
.save-slot .load-btn { background: #5cd35a; }
.save-slot .del-btn  { background: #c75d80; max-width: 30px; }

.save-slot button:disabled {
  background: #b9b3c2 !important;
  cursor: not-allowed;
  opacity: 0.55;
}

.save-slot .slot-name {
  font-size: 13px;
  font-weight: bold;
  color: #5b3b88;
  background: rgba(91,59,136,0.1);
  border-radius: 8px;
  padding: 4px 8px;
}

.save-slot .new-player-btn {
  background: #5cd35a !important;
  color: white;
  font-size: 13px !important;
  padding: 8px 10px !important;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-weight: bold;
  margin-top: 4px;
  box-shadow: 0 2px 0 #2f8a36 !important;
}
.save-slot .new-player-btn:hover { transform: translateY(-1px); }
.save-slot .new-player-btn:active { transform: translateY(1px); box-shadow: 0 0 0 #2f8a36 !important; }

.save-slot.clickable { cursor: pointer; transition: transform 0.1s, box-shadow 0.1s; }
.save-slot.clickable:hover { background: rgba(255,255,255,0.95); transform: translateY(-2px); box-shadow: 0 4px 0 rgba(91,59,136,0.25); }
.save-slot.clickable:active { transform: translateY(0); box-shadow: 0 1px 0 rgba(91,59,136,0.25); }

.save-slot .slot-name-input {
  font-family: inherit;
  font-size: 12px;
  padding: 5px 8px;
  border: 2px solid #5b3b88;
  border-radius: 8px;
  text-align: center;
  outline: none;
  width: 100%;
  background: white;
  color: #2b2b2b;
}
.save-slot .slot-name-input:focus { box-shadow: 0 0 0 3px rgba(91,59,136,0.2); }

.overlay .controls {
  margin-top: 30px;
  font-size: 16px;
  color: #5b3b88;
  background: rgba(255,255,255,0.5);
  padding: 14px 20px;
  border-radius: 14px;
}

.dialogue {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  width: 80%;
  background: #fff;
  border: 4px solid #5b3b88;
  border-radius: 18px;
  padding: 18px 24px 14px 24px;
  box-shadow: 0 8px 0 rgba(0,0,0,0.2);
}

.dialogue .speaker {
  position: absolute;
  top: -16px;
  left: 20px;
  background: #5b3b88;
  color: white;
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: bold;
}

.dialogue .text {
  font-size: 20px;
  line-height: 1.4;
  color: #2b2b2b;
  min-height: 56px;
}

.dialogue .hint {
  text-align: right;
  font-size: 12px;
  color: #888;
  margin-top: 4px;
}

.cutscene {
  background: linear-gradient(180deg, #1a1530 0%, #2a1f48 100%);
  color: white;
}

.cutscene .phone {
  width: 220px;
  height: 380px;
  background: #f6c1d4;
  border-radius: 36px;
  padding: 14px;
  box-shadow: 0 12px 0 #b97894, 0 20px 40px rgba(0,0,0,0.4);
  animation: phone-shake 0.5s ease-in-out infinite;
  margin-bottom: 24px;
}

.cutscene .phone-screen {
  width: 100%;
  height: 100%;
  background: #0e1a2b;
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: white;
  padding: 20px;
}

.cutscene .caller { font-size: 18px; opacity: 0.7; margin-bottom: 12px; }
.cutscene .caller-name { font-size: 32px; font-weight: bold; }

.cutscene-text {
  font-size: 22px;
  max-width: 600px;
  text-align: center;
  line-height: 1.4;
  background: rgba(255,255,255,0.1);
  padding: 16px 24px;
  border-radius: 14px;
  min-height: 80px;
}

.cutscene .hint {
  margin-top: 16px;
  font-size: 14px;
  opacity: 0.7;
}

@keyframes phone-shake {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}

.hud {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  gap: 16px;
  align-items: center;
}

.stone-slot {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: rgba(0,0,0,0.3);
  border: 3px dashed rgba(255,255,255,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
}

.stone-slot.has-stone {
  background: radial-gradient(circle at 35% 30%, #c8ffae, #4caf50 60%, #1f6b2c);
  border: 3px solid #fff;
  box-shadow: 0 0 16px #7eff7e, inset 0 0 8px rgba(255,255,255,0.6);
  animation: stone-glow 1.6s ease-in-out infinite;
}

#slot-red.has-stone {
  background: radial-gradient(circle at 35% 30%, #ffe0a0, #ff5533 50%, #6b1810);
  box-shadow: 0 0 16px #ff8844, inset 0 0 8px rgba(255,255,200,0.6);
}

#fire-fill {
  background: linear-gradient(90deg, #ff5533, #ffd166);
}

.stone-slot.active {
  transform: scale(1.18);
  outline: 4px solid #fff;
  outline-offset: 2px;
}

.lives {
  display: flex;
  gap: 2px;
  background: rgba(0,0,0,0.4);
  padding: 6px 10px;
  border-radius: 999px;
  align-items: center;
}
.lives .heart {
  font-size: 16px;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.4));
  transition: opacity 0.2s, transform 0.2s;
}
.lives .heart.lost {
  opacity: 0.25;
  filter: grayscale(1);
  transform: scale(0.85);
}

@keyframes stone-glow {
  0%, 100% { box-shadow: 0 0 12px #7eff7e, inset 0 0 8px rgba(255,255,255,0.6); }
  50% { box-shadow: 0 0 28px #b6ffb6, inset 0 0 12px rgba(255,255,255,0.8); }
}

.stamina {
  background: rgba(0,0,0,0.35);
  padding: 8px 12px;
  border-radius: 12px;
  color: white;
}

.stamina-label { font-size: 12px; margin-bottom: 4px; }

.stamina-bar {
  width: 140px;
  height: 12px;
  background: rgba(255,255,255,0.2);
  border-radius: 999px;
  overflow: hidden;
}

.stamina-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff8fb1, #ffd1dc);
  transition: width 0.2s;
}

.toast {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: white;
  padding: 12px 24px;
  border-radius: 999px;
  font-size: 18px;
  pointer-events: none;
  transition: opacity 0.3s;
}

.hidden { display: none !important; }
