@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600;700&display=swap');

:root {
  --wood-dark:  #4e3319;
  --wood:       #7a4e28;
  --wood-light: #9a6a3a;
  --cream:      #f4e4c1;
  --gold:       #ffcf3f;
  --gold-dark:  #c8951a;
  --green:      #66c14a;
  --green-dark: #3f8c2b;
  --red:        #e8503a;
  --red-dark:   #a83322;
  --panel:      #2f2216;
  --blue:       #29b6d8;
}

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

html, body {
  height: 100%;
  font-family: 'Fredoka', system-ui, 'Segoe UI', sans-serif;
  color: var(--cream);
  overflow: hidden;
}

body {
  background:
    radial-gradient(1200px 700px at 50% -10%, #4fb7e6 0%, #2e86c1 40%, #1f5d94 100%),
    #1f5d94;
}

/* faint sky clouds */
body::before {
  content: '';
  position: fixed; inset: 0;
  background:
    radial-gradient(140px 60px at 15% 18%, rgba(255,255,255,0.18), transparent 70%),
    radial-gradient(200px 80px at 78% 12%, rgba(255,255,255,0.14), transparent 70%),
    radial-gradient(160px 70px at 55% 30%, rgba(255,255,255,0.10), transparent 70%);
  pointer-events: none;
}

#game-wrap {
  position: fixed;
  top: 0;
  left: 0;
  width: 960px;
  transform-origin: 0 0;
  /* translate + scale are set by JS auto-fit (Game.fit) */
}

/* ============================================================ TOP BAR === */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  margin-bottom: 8px;
  background: linear-gradient(#8a5a30, #6b4322);
  border: 3px solid var(--wood-dark);
  border-radius: 16px;
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.25), inset 0 -4px 8px rgba(0,0,0,0.35), 0 6px 14px rgba(0,0,0,0.35);
}

.hud-chip {
  display: flex; align-items: center; gap: 7px;
  background: linear-gradient(#241a10, #3a2c1a);
  border: 2px solid #12100c;
  border-radius: 12px;
  padding: 6px 14px;
  font-weight: 700;
  font-size: 20px;
  box-shadow: inset 0 2px 3px rgba(255,255,255,0.12), 0 2px 4px rgba(0,0,0,0.3);
  min-width: 84px;
  justify-content: center;
}
.gold-chip { color: var(--gold); text-shadow: 0 1px 0 #7a5600; }
.wave-chip { color: #cfe8ff; font-size: 16px; gap: 6px; }
.wave-chip .chip-label { font-size: 11px; opacity: 0.7; letter-spacing: 1px; }
.lives-chip { color: #ffd7d0; }
.hud-right { display: flex; gap: 10px; }

.title-plate {
  font-weight: 700; letter-spacing: 1px;
  display: flex; gap: 8px; align-items: baseline;
  text-shadow: 0 2px 0 var(--wood-dark), 0 3px 6px rgba(0,0,0,0.4);
}
.title-main { color: var(--gold); font-size: 26px; }
.title-sub  { color: #fff; font-size: 20px; -webkit-text-stroke: 0.5px var(--wood-dark); }

/* coin + heart icons */
.coin {
  width: 18px; height: 18px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe89a, #ffcf3f 55%, #d79a12 100%);
  border: 2px solid #a9750d;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.25);
  display: inline-block; flex: none;
}
.coin.big { width: 24px; height: 24px; }
.heart {
  width: 20px; height: 20px; flex: none;
  background: radial-gradient(circle at 35% 30%, #ff7a6a, #e8503a 60%, #b3271a 100%);
  clip-path: path('M10 18 L2.5 10.5 C-1 7 1.5 1.5 6 3 C8 3.7 9.2 5 10 6.3 C10.8 5 12 3.7 14 3 C18.5 1.5 21 7 17.5 10.5 Z');
}

/* ============================================================== STAGE === */
#stage {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  border: 5px solid var(--wood-dark);
  box-shadow: 0 10px 30px rgba(0,0,0,0.45), inset 0 0 0 3px rgba(0,0,0,0.25);
  line-height: 0;
}
#game { display: block; width: 100%; height: auto; touch-action: none; }

/* wave banner */
#banner {
  position: absolute; top: 34%; left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  font-size: 56px; font-weight: 700; color: var(--gold);
  text-shadow: 0 3px 0 var(--wood-dark), 0 6px 16px rgba(0,0,0,0.6);
  opacity: 0; pointer-events: none;
  -webkit-text-stroke: 1.5px var(--wood-dark);
}
#banner.show { animation: bannerPop 1.6s ease-out forwards; }
@keyframes bannerPop {
  0%   { opacity: 0; transform: translate(-50%,-50%) scale(0.4); }
  18%  { opacity: 1; transform: translate(-50%,-50%) scale(1.05); }
  75%  { opacity: 1; transform: translate(-50%,-50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%,-60%) scale(1); }
}

/* ========================================================= INSPECT ====== */
#inspect {
  position: absolute;
  width: 180px;
  background: linear-gradient(#8a5a30, #6b4322);
  border: 3px solid var(--wood-dark);
  border-radius: 14px;
  padding: 10px;
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.22), 0 8px 18px rgba(0,0,0,0.5);
  z-index: 20; line-height: 1.2;
}
#inspect.hidden, #overlay.hidden { display: none; }
#insp-title { font-weight: 700; font-size: 15px; text-align: center; margin-bottom: 6px; color: var(--gold); }
#insp-stats { display: flex; flex-wrap: wrap; gap: 4px 10px; justify-content: center; font-size: 13px; margin-bottom: 9px; color: #fff; }
#insp-stats span { background: rgba(0,0,0,0.28); padding: 2px 7px; border-radius: 7px; }
.insp-target-btn { width: 100%; font-size: 12px; padding: 6px; margin-bottom: 7px; }
.insp-actions { display: flex; gap: 6px; }
.insp-actions .btn { flex: 1; font-size: 13px; padding: 7px 4px; }

/* ========================================================== OVERLAY ===== */
#overlay {
  position: absolute; inset: 0;
  background: rgba(15,25,40,0.78);
  display: flex; align-items: center; justify-content: center;
  z-index: 30; backdrop-filter: blur(3px);
}
#overlay-card {
  width: 500px; max-width: 92%;
  text-align: center;
  background: linear-gradient(#8a5a30, #64401f);
  border: 5px solid var(--wood-dark);
  border-radius: 22px;
  padding: 30px 28px;
  box-shadow: inset 0 3px 0 rgba(255,255,255,0.22), 0 16px 40px rgba(0,0,0,0.6);
}
#overlay-card h1 {
  font-size: 42px; font-weight: 700; color: var(--gold);
  text-shadow: 0 3px 0 var(--wood-dark), 0 6px 12px rgba(0,0,0,0.5);
  -webkit-text-stroke: 1px var(--wood-dark);
  margin-bottom: 12px;
}
#overlay-card p { font-size: 16px; line-height: 1.5; color: var(--cream); margin-bottom: 22px; }
#overlay-card.win  h1 { color: #ffe066; }
#overlay-card.lose h1 { color: #ff7a68; }

/* =============================================================== SHOP === */
#shop {
  display: flex; gap: 12px;
  margin-top: 8px;
  padding: 10px 12px;
  background: linear-gradient(#8a5a30, #6b4322);
  border: 3px solid var(--wood-dark);
  border-radius: 16px;
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.22), 0 6px 14px rgba(0,0,0,0.35);
}
#shop-cards { display: flex; gap: 9px; flex: 1; }

.tower-card {
  position: relative;
  flex: 1;
  background: linear-gradient(#f2e2bf, #d9c096);
  border: 3px solid #7a4e28;
  border-radius: 13px;
  padding: 8px 4px 6px;
  cursor: pointer;
  font-family: inherit;
  color: #3a2a16;
  transition: transform 0.08s ease, box-shadow 0.1s ease;
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.5), 0 3px 0 #7a4e28, 0 5px 8px rgba(0,0,0,0.25);
}
.tower-card:hover { transform: translateY(-2px); box-shadow: inset 0 2px 0 rgba(255,255,255,0.5), 0 5px 0 #7a4e28, 0 8px 12px rgba(0,0,0,0.3); }
.tower-card:active { transform: translateY(1px); box-shadow: inset 0 2px 0 rgba(255,255,255,0.4), 0 1px 0 #7a4e28; }
.tower-card.selected {
  border-color: var(--gold);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.5), 0 0 0 3px var(--gold), 0 4px 10px rgba(0,0,0,0.35);
}
.tower-card.cant-afford { filter: grayscale(0.5) brightness(0.9); }
.tower-card.cant-afford .tc-cost { color: var(--red-dark); }

.tc-icon { font-size: 30px; line-height: 1; margin-bottom: 2px; filter: drop-shadow(0 2px 1px rgba(0,0,0,0.3)); }
.tc-name { font-size: 12px; font-weight: 600; line-height: 1.1; margin-bottom: 3px; }
.tc-cost { font-size: 15px; font-weight: 700; color: #8a5a10; display: flex; align-items: center; justify-content: center; gap: 4px; }
.tc-cost .coin { width: 14px; height: 14px; }
.tc-key {
  position: absolute; top: 3px; right: 4px;
  font-size: 10px; font-weight: 700; color: #fff;
  background: rgba(0,0,0,0.45); border-radius: 5px; padding: 0 4px;
}

#shop-controls { display: flex; flex-direction: column; gap: 7px; width: 200px; flex: none; }
.ctrl-row { display: flex; gap: 7px; }
.ctrl-row .btn { flex: 1; }

/* =============================================================== BUTTONS = */
.btn {
  font-family: inherit; font-weight: 700; font-size: 16px;
  color: #fff; cursor: pointer;
  border: none; border-radius: 12px;
  padding: 11px 16px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
  transition: transform 0.07s ease, filter 0.1s ease;
  user-select: none;
}
.btn:active { transform: translateY(2px); }
.btn:disabled { cursor: default; filter: grayscale(0.55) brightness(0.82); }
.btn-green  { background: linear-gradient(#7ad35a, var(--green-dark)); box-shadow: inset 0 2px 0 rgba(255,255,255,0.4), 0 4px 0 #2e6b1e, 0 6px 10px rgba(0,0,0,0.3); }
.btn-green:not(:disabled):hover  { filter: brightness(1.06); }
.btn-gold   { background: linear-gradient(#ffe066, var(--gold-dark)); color: #5a3d00; text-shadow: 0 1px 0 rgba(255,255,255,0.4); box-shadow: inset 0 2px 0 rgba(255,255,255,0.5), 0 4px 0 #9a7412, 0 6px 12px rgba(0,0,0,0.35); }
.btn-red    { background: linear-gradient(#f2705a, var(--red-dark)); box-shadow: inset 0 2px 0 rgba(255,255,255,0.3), 0 4px 0 #7e2417, 0 5px 8px rgba(0,0,0,0.3); }
.btn-wood   { background: linear-gradient(#a06a38, #6b4322); box-shadow: inset 0 2px 0 rgba(255,255,255,0.25), 0 4px 0 #3f2914, 0 5px 8px rgba(0,0,0,0.3); font-size: 15px; }
.btn.busy   { background: linear-gradient(#c98a3a, #8a5a20); }
.wide-btn { width: 100%; font-size: 18px; padding: 13px; }
.big-btn  { font-size: 22px; padding: 14px 40px; }
.btn-wood.off { color: #b89; }

/* ===================================================== SCORE + MENU ==== */
.hidden { display: none !important; }

.score-chip { color: #ffe9a8; font-size: 16px; gap: 6px; }
.score-chip .chip-label,
.wave-chip .chip-label { font-size: 11px; opacity: 0.7; letter-spacing: 1px; }

#overlay-card p { margin-bottom: 14px; }
#menu-extra { margin: 2px 0 16px; display: flex; flex-direction: column; gap: 11px; }

.sel-group { display: flex; align-items: center; gap: 10px; justify-content: center; flex-wrap: wrap; }
.sel-label { font-size: 12px; letter-spacing: 1px; color: #f0dcae; min-width: 84px; text-align: right; opacity: 0.85; }

.seg { display: inline-flex; gap: 5px; background: rgba(0,0,0,0.22); padding: 4px; border-radius: 12px; }
.seg-btn {
  font-family: inherit; font-weight: 600; font-size: 14px; color: #f4e4c1;
  background: transparent; border: none; border-radius: 8px; padding: 7px 14px; cursor: pointer;
  transition: background 0.1s, color 0.1s, transform 0.06s;
}
.seg-btn:hover { background: rgba(255,255,255,0.12); }
.seg-btn:active { transform: translateY(1px); }
.seg-btn.on { background: linear-gradient(#ffe066, var(--gold-dark)); color: #5a3d00; box-shadow: inset 0 1px 0 rgba(255,255,255,0.5); }

.maps { display: inline-flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.map-card {
  padding: 4px; background: rgba(0,0,0,0.22); border: 2px solid transparent; border-radius: 10px;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px;
  transition: transform 0.06s;
}
.map-card:hover { background: rgba(255,255,255,0.12); }
.map-card:active { transform: translateY(1px); }
.map-card.on { border-color: var(--gold); background: rgba(255,207,63,0.18); }
.map-prev { display: block; border-radius: 6px; width: 100px; height: 66px; }
.map-name { font-size: 11px; font-weight: 600; color: #f4e4c1; }

#best-score { font-size: 14px; color: #ffe9a8; margin-top: 2px; }
#best-score b { color: #fff; }
.hint { font-size: 13px; color: #cfe8ff; opacity: 0.9; }
.ov-buttons { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; }

/* ======================================================= PORTRAIT ====== */
body.portrait .title-plate { display: none; }
body.portrait #top-bar { padding: 7px 10px; gap: 8px; }
body.portrait .hud-chip { min-width: 64px; font-size: 17px; padding: 6px 10px; }
body.portrait #shop { flex-direction: column; }
body.portrait #shop-cards { gap: 6px; }
body.portrait .tower-card { min-width: 58px; padding: 7px 2px 5px; }
body.portrait .tc-icon { font-size: 26px; }
body.portrait .tc-name { font-size: 10px; }
body.portrait #shop-controls { width: 100%; flex-direction: row; align-items: stretch; }
body.portrait #start-wave { flex: 1; font-size: 16px; }
body.portrait .ctrl-row { flex: 0 0 auto; }

/* boss-round start button */
.btn-green.boss {
  background: linear-gradient(#f2705a, #a2301f);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.3), 0 4px 0 #7a1f13, 0 5px 10px rgba(0,0,0,0.4);
  animation: bossPulse 0.85s ease-in-out infinite;
}
@keyframes bossPulse { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.2); } }
