/* ============================================================
   SAVE THE DOG — Drawing Puzzle Game
   Cartoon cute style, light beige background
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #f5e6c8;
  font-family: 'Comic Sans MS', 'Marker Felt', 'Segoe UI', sans-serif;
  color: #5a3a1a;
  touch-action: none;
  overscroll-behavior: none;
}

.screen {
  position: fixed; inset: 0;
  display: none;
  flex-direction: column;
  background: #f5e6c8;
  z-index: 1;
}
.screen.active { display: flex; }

/* ============ START SCREEN ============ */
#screenStart { justify-content: center; align-items: center; }
.start-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 20% 30%, rgba(255,200,150,0.4) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(150,220,150,0.3) 0%, transparent 50%);
  animation: bgFloat 6s ease-in-out infinite alternate;
}
@keyframes bgFloat {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-10px) scale(1.05); }
}
.start-content {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center;
  padding: 20px; width: 100%; max-width: 440px;
}
.game-title {
  display: flex; align-items: center; gap: 12px;
  font-size: clamp(36px, 11vw, 64px);
  font-weight: 900;
  margin-bottom: 10px;
  color: #5a3a1a;
  text-shadow: 3px 3px 0 #fff, 5px 5px 0 rgba(0,0,0,0.1);
}
.title-emoji { font-size: 1.3em; animation: wag 1s ease-in-out infinite; }
@keyframes wag {
  0%,100% { transform: rotate(-10deg); }
  50% { transform: rotate(10deg); }
}
.title-text {
  background: linear-gradient(135deg, #ff8844, #ffcc44);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.tagline {
  text-align: center; font-size: 14px; color: #8a6a3a;
  margin-bottom: 30px; font-weight: 700;
}
.start-buttons {
  width: 100%; display: flex; flex-direction: column; gap: 12px;
  align-items: center; margin-bottom: 20px;
}
.home-ranking {
  font-size: 14px; font-weight: 800; color: #aa7733;
}

/* ============ BUTTONS ============ */
.btn-primary {
  padding: 14px 48px;
  background: linear-gradient(135deg, #ff8844, #ff6622);
  border: 3px solid #fff;
  border-radius: 28px;
  color: #fff; font-family: inherit; font-weight: 900; font-size: 18px;
  cursor: pointer;
  box-shadow: 0 5px 0 #cc5511, 0 8px 15px rgba(0,0,0,0.15);
  transition: transform 0.1s, box-shadow 0.1s;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 7px 0 #cc5511, 0 10px 18px rgba(0,0,0,0.2); }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 2px 0 #cc5511; }

.btn-secondary {
  padding: 12px 36px;
  background: #fff;
  border: 3px solid #ff8844;
  border-radius: 24px;
  color: #ff6622; font-family: inherit; font-weight: 800; font-size: 15px;
  cursor: pointer;
  box-shadow: 0 4px 0 #cc6633;
  transition: transform 0.1s, box-shadow 0.1s;
}
.btn-secondary:hover { transform: translateY(-1px); }
.btn-secondary:active { transform: translateY(2px); box-shadow: 0 2px 0 #cc6633; }

.copy-btn {
  padding: 8px 16px;
  background: rgba(255,255,255,0.7);
  border: 2px dashed #aa7733;
  border-radius: 20px;
  color: #8a5a1a; font-family: inherit; font-size: 13px; font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(5px);
}
#screenStart .copy-btn { position: absolute; bottom: 20px; }

/* ============ TOP BAR ============ */
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: rgba(255,255,255,0.6);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
  z-index: 10;
}
.back-btn {
  width: 40px; height: 40px;
  background: #fff;
  border: 2px solid #ff8844;
  border-radius: 50%;
  color: #ff6622; font-family: inherit; font-weight: 900; font-size: 16px;
  cursor: pointer;
  box-shadow: 0 3px 0 #cc6633;
}
.back-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #cc6633; }
.bar-title {
  flex: 1; text-align: center;
  font-size: 20px; font-weight: 900; color: #5a3a1a;
}
.bar-spacer { width: 40px; }
.coin-display {
  display: flex; align-items: center; gap: 4px;
  background: #fff;
  border: 2px solid #ffcc44;
  border-radius: 16px;
  padding: 4px 12px;
  font-weight: 900; color: #aa7700;
}
.level-num {
  flex: 1; text-align: center;
  font-size: 20px; font-weight: 900; color: #5a3a1a;
}
.icon-btn {
  width: 40px; height: 40px;
  background: #fff;
  border: 2px solid #ff8844;
  border-radius: 50%;
  font-size: 18px; cursor: pointer;
  box-shadow: 0 3px 0 #cc6633;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #cc6633; }

/* ============ CANVAS ============ */
.canvas-wrap {
  flex: 1; position: relative;
  background: #f5e6c8;
  overflow: hidden;
}
#gameCanvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}
.ripple-layer {
  position: absolute; inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.ripple {
  position: absolute;
  border: 3px solid rgba(255, 136, 68, 0.5);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: rippleAnim 0.6s ease-out forwards;
  pointer-events: none;
}
@keyframes rippleAnim {
  0% { width: 10px; height: 10px; opacity: 1; }
  100% { width: 60px; height: 60px; opacity: 0; }
}

/* ============ POWERUP BAR ============ */
.powerup-bar {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px;
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(10px);
  border-radius: 30px;
  padding: 8px 12px;
  border: 2px solid rgba(0,0,0,0.1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 5;
}
.powerup-item {
  position: relative;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: #fff;
  border: 2px solid #ddd;
  border-radius: 12px;
  cursor: pointer;
  font-size: 22px;
  transition: all 0.15s;
}
.powerup-item:hover { transform: translateY(-2px); border-color: #ff8844; }
.powerup-item.active {
  background: linear-gradient(135deg, #ff8844, #ff6622);
  border-color: #cc5511;
  box-shadow: 0 0 12px rgba(255,102,34,0.5);
}
.powerup-item.disabled { opacity: 0.4; pointer-events: none; }
.pu-count {
  position: absolute; top: -4px; right: -4px;
  background: #ff3344;
  color: #fff;
  font-size: 10px; font-weight: 900;
  border-radius: 10px;
  padding: 1px 5px;
  border: 1px solid #fff;
}
.game-copy {
  position: absolute; bottom: 16px; right: 16px;
  width: 40px; height: 40px;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  border-radius: 50%;
  z-index: 5;
}

/* ============ LEVEL SELECT ============ */
.level-grid {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 12px;
  align-content: start;
}
.level-card {
  aspect-ratio: 1;
  background: linear-gradient(135deg, #fff, #f0e0c0);
  border: 3px solid #ff8844;
  border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 0 #cc6633;
  transition: transform 0.1s;
  position: relative;
}
.level-card.locked {
  background: #ddd; border-color: #aaa; box-shadow: 0 4px 0 #888;
  cursor: not-allowed;
}
.level-card:active:not(.locked) { transform: translateY(3px); box-shadow: 0 1px 0 #cc6633; }
.level-card-num { font-size: 26px; font-weight: 900; color: #5a3a1a; }
.level-card.stars { position: absolute; bottom: 4px; font-size: 12px; }
.level-card.locked .level-card-num { color: #999; }

/* ============ SHOP ============ */
.shop-grid {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  align-content: start;
}
.shop-item {
  background: #fff;
  border: 3px solid #ff8844;
  border-radius: 18px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 4px 0 #cc6633;
}
.shop-icon { font-size: 40px; margin-bottom: 6px; }
.shop-name { font-size: 14px; font-weight: 900; color: #5a3a1a; margin-bottom: 4px; }
.shop-desc { font-size: 11px; color: #8a6a3a; margin-bottom: 10px; min-height: 32px; }
.shop-buy {
  padding: 6px 16px;
  background: linear-gradient(135deg, #ffcc44, #ffaa22);
  border: 2px solid #fff; border-radius: 16px;
  color: #fff; font-family: inherit; font-weight: 900; font-size: 13px;
  cursor: pointer;
  box-shadow: 0 2px 0 #cc8811;
}
.shop-buy:active { transform: translateY(1px); box-shadow: 0 1px 0 #cc8811; }

/* ============ MODAL ============ */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.2s;
}
.modal.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: linear-gradient(135deg, #fff8e8, #fff);
  border: 4px solid #ff8844;
  border-radius: 28px;
  padding: 28px 24px;
  text-align: center;
  max-width: 360px; width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  animation: popIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes popIn { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.lose-card { border-color: #ff4444; background: linear-gradient(135deg, #fff0f0, #fff); }
.win-card { border-color: #44cc66; }
.modal-dog { font-size: 64px; margin-bottom: 8px; animation: dogBounce 0.5s ease; }
@keyframes dogBounce {
  0% { transform: translateY(-30px) scale(0.5); opacity: 0; }
  60% { transform: translateY(10px) scale(1.1); }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
.modal-title { font-size: 24px; font-weight: 900; color: #5a3a1a; margin-bottom: 8px; }
.modal-hint { font-size: 13px; color: #8a6a3a; margin-bottom: 20px; }
.modal-stars { font-size: 32px; margin-bottom: 12px; letter-spacing: 4px; }
.modal-score { margin-bottom: 20px; font-size: 16px; font-weight: 800; color: #aa7733; }
.score-lbl { margin-right: 8px; }
.score-val { color: #ff8844; font-size: 20px; }
.modal-buttons { display: flex; gap: 10px; justify-content: center; }

/* ============ RANKING ============ */
.rank-list {
  text-align: left;
  max-height: 250px; overflow-y: auto;
  margin-bottom: 16px;
}
.rank-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: #fff8e8;
  border-radius: 10px;
  margin-bottom: 6px;
  font-weight: 700;
}
.rank-1 { color: #ffaa00; }
.rank-2 { color: #aaa; }
.rank-3 { color: #cc7722; }

/* ============ TOAST ============ */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: #44cc66; color: #fff;
  padding: 10px 24px; border-radius: 20px;
  font-weight: 900; font-size: 14px;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  animation: toastIn 0.3s;
}
.toast.hidden { display: none; }
@keyframes toastIn { from { transform: translateX(-50%) translateY(20px); opacity: 0; } to { transform: translateX(-50%) translateY(0); opacity: 1; } }

/* ============ SCROLLBAR ============ */
.level-grid::-webkit-scrollbar,
.shop-grid::-webkit-scrollbar,
.rank-list::-webkit-scrollbar { width: 6px; }
.level-grid::-webkit-scrollbar-track,
.shop-grid::-webkit-scrollbar-track,
.rank-list::-webkit-scrollbar-track { background: transparent; }
.level-grid::-webkit-scrollbar-thumb,
.shop-grid::-webkit-scrollbar-thumb,
.rank-list::-webkit-scrollbar-thumb { background: rgba(255,136,68,0.3); border-radius: 3px; }

.hidden { display: none !important; }
