/* Picnic Panic -- checkered-blanket presentation layer. */

:root {
  --red: #e5484d;
  --red-dark: #c43338;
  --cream: #fff6e6;
  --brown: #5d3517;
  --wood: #9c6b30;
  --wood-dark: #7a4a21;
  --gold: #ffd95e;
  --ink: #3d2410;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  touch-action: none;
  font-family: 'Fredoka One', 'Comic Sans MS', cursive;
  /* The picnic blanket: gingham via stacked translucent stripes. */
  background:
    repeating-linear-gradient(0deg, rgba(229, 72, 77, 0.5) 0 26px, transparent 26px 52px),
    repeating-linear-gradient(90deg, rgba(229, 72, 77, 0.5) 0 26px, transparent 26px 52px),
    var(--cream);
}

#wrap {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
}

#stage {
  position: relative;
  width: 960px; height: 600px;
  flex: none;
  transform-origin: center center;
  border: 5px solid var(--brown);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(61, 36, 16, 0.45);
  background: #79b450;
}

canvas#game {
  position: absolute;
  left: 0; top: 60px;
  width: 960px; height: 540px;
  display: block;
}

/* ---- HUD ---- */

#hud {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 60px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px;
  background: linear-gradient(#a87437, #8a5a26);
  border-bottom: 4px solid var(--brown);
  color: var(--cream);
  z-index: 5;
  user-select: none;
}

.stat {
  display: flex; align-items: center; gap: 6px;
  background: rgba(61, 36, 16, 0.4);
  border-radius: 9px;
  padding: 5px 11px;
  font-size: 19px;
  letter-spacing: 0.5px;
  min-width: 78px;
  justify-content: center;
}

.stat svg { flex: none; }

#lives-stat.hurt { animation: hurtflash 0.45s; }
@keyframes hurtflash {
  0%, 100% { background: rgba(61, 36, 16, 0.4); }
  30% { background: var(--red); }
}

#hud .spacer { flex: 1; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

.hud-btn {
  height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  background: var(--cream);
  color: var(--ink);
  font-size: 17px;
  border-bottom: 3px solid #cdb795;
  transition: transform 0.08s, filter 0.12s;
}
.hud-btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.hud-btn:active { transform: translateY(1px); }

#wave-btn {
  background: var(--red);
  color: #fff;
  border-bottom-color: var(--red-dark);
  min-width: 200px;
}
#wave-btn:disabled { filter: saturate(0.25) brightness(0.85); cursor: default; transform: none; }

.icon-btn { width: 40px; padding: 0; display: flex; align-items: center; justify-content: center; }
.icon-btn.on { outline: 3px solid var(--gold); }

/* ---- floating popups ---- */

.popup {
  position: absolute;
  z-index: 8;
  background: var(--cream);
  border: 3px solid var(--brown);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 8px 22px rgba(61, 36, 16, 0.4);
  display: none;
}
.popup.show { display: block; }

.popup-close {
  position: absolute;
  top: -12px; right: -12px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  border: 2px solid var(--red-dark);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  z-index: 9;
}
.popup-close:hover { filter: brightness(1.1); }

#build-popup { display: none; grid-template-columns: repeat(2, 1fr); gap: 6px; width: 232px; }
#build-popup.show { display: grid; }

.tower-card {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: #fff;
  border: 2px solid #e3d5bb;
  border-radius: 9px;
  padding: 6px 4px 5px;
  font-family: inherit;
  color: var(--ink);
  transition: transform 0.08s, border-color 0.08s;
}
.tower-card:hover { border-color: var(--red); transform: translateY(-2px); }
.tower-card:disabled { opacity: 0.45; cursor: default; transform: none; }
.tower-card canvas { width: 40px; height: 40px; }
.tower-card .t-name { font-size: 12.5px; }
.tower-card .t-cost { font-size: 12px; color: var(--red-dark); }

#tower-panel { width: 196px; text-align: center; }
#tower-panel .tp-title { font-size: 16px; color: var(--ink); margin-bottom: 2px; }
#tower-panel .tp-stats { font-size: 11.5px; color: #8a6d4a; margin-bottom: 7px; }
.tp-row { display: flex; gap: 6px; }
.tp-row button {
  flex: 1;
  border-radius: 8px;
  padding: 8px 4px;
  font-size: 14px;
  font-family: inherit;
}
#tp-upgrade { background: var(--gold); color: var(--ink); border-bottom: 3px solid #d9ab2e; }
#tp-upgrade:disabled { filter: saturate(0.3) brightness(0.9); cursor: default; }
#tp-sell { background: #e3d5bb; color: var(--ink); border-bottom: 3px solid #c4b08a; }

/* ---- shop + inventory ---- */

#shop-items {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0 4px;
}

.gear-card {
  display: flex; align-items: center; gap: 10px;
  background: #fff;
  border: 2px solid #e3d5bb;
  border-radius: 10px;
  padding: 8px 10px;
  text-align: left;
}
.gear-card canvas { width: 44px; height: 44px; flex: none; }
.gear-info { flex: 1; min-width: 0; }
.gear-info .g-name { font-size: 14px; color: var(--ink); }
.gear-info .g-desc { font-size: 11px; line-height: 1.25; color: #8a6d4a; font-family: 'Trebuchet MS', sans-serif; }
.gear-info .g-state { font-size: 11px; color: #4d9633; }
.gear-buy {
  flex: none;
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 8px;
  background: #f5a623;
  color: var(--ink);
  border-bottom: 3px solid #c97f12;
}
.gear-buy:disabled { filter: saturate(0.25) brightness(0.9); cursor: default; }

#inv-strip {
  position: absolute;
  left: 8px; bottom: 8px;
  display: flex; gap: 8px;
  z-index: 6;
}
.inv-item {
  position: relative;
  width: 46px; height: 46px;
  border-radius: 10px;
  background: rgba(255, 246, 230, 0.92);
  border: 3px solid var(--brown);
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  transition: transform 0.08s;
}
.inv-item:hover { transform: translateY(-2px); }
.inv-item.armed { outline: 3px solid var(--gold); }
.inv-item canvas { width: 34px; height: 34px; }
.inv-count {
  position: absolute;
  top: -8px; right: -8px;
  min-width: 19px; height: 19px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--red-dark);
}

/* ---- cutscenes ---- */

#cutscene-overlay { background: rgba(22, 13, 4, 0.78); cursor: pointer; }

#cutscene-box {
  position: relative;
  width: 860px;
  max-width: 94%;
}

#cutscene-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 920 / 300;
  border: 4px solid var(--brown);
  border-radius: 14px 14px 0 0;
  background: #87ceeb;
}

#cs-dialogue {
  background: var(--cream);
  border: 4px solid var(--brown);
  border-top: 0;
  border-radius: 0 0 14px 14px;
  padding: 14px 18px 16px;
  min-height: 64px;
  color: var(--ink);
}
#cs-name { font-size: 15px; letter-spacing: 1px; margin-right: 10px; }
#cs-text { font-size: 17px; font-family: 'Trebuchet MS', sans-serif; line-height: 1.35; }
#cs-hint {
  float: right;
  margin-top: 6px;
  font-size: 12px;
  color: #b59d77;
  animation: bounce 1.4s ease-in-out infinite;
}

#cs-skip {
  position: absolute;
  top: -14px; right: -10px;
  font-family: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 9px;
  background: var(--wood);
  color: var(--cream);
  border-bottom: 3px solid var(--wood-dark);
  cursor: pointer;
}
#cs-skip:hover { filter: brightness(1.1); }

/* ---- banner ---- */

#banner {
  position: absolute;
  top: 100px; left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  font-size: 40px;
  color: #fff;
  text-shadow: 0 3px 0 var(--red-dark), 0 0 18px rgba(0, 0, 0, 0.35);
  -webkit-text-stroke: 1.5px var(--red-dark);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
#banner.show { animation: bannerpop 2.2s ease-out forwards; }
@keyframes bannerpop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.4); }
  12% { opacity: 1; transform: translateX(-50%) scale(1.12); }
  20% { transform: translateX(-50%) scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-22px) scale(0.96); }
}

/* ---- overlays ---- */

.overlay {
  position: absolute; inset: 0;
  z-index: 10;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(40, 25, 8, 0.45);
}
.overlay.show { display: flex; }

.card {
  position: relative; /* anchors .popup-close to the card, not the overlay */
  background: var(--cream);
  border: 4px solid var(--brown);
  border-radius: 18px;
  padding: 26px 34px;
  text-align: center;
  color: var(--ink);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  max-width: 560px;
}

#menu .card { background: rgba(255, 246, 230, 0.94); }

.title {
  font-size: 58px;
  line-height: 1;
  color: var(--red);
  text-shadow: 0 4px 0 var(--red-dark), 0 7px 0 rgba(61, 36, 16, 0.25);
  margin-bottom: 4px;
}
.title .bounce { display: inline-block; animation: bounce 1.6s ease-in-out infinite; }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

.subtitle { font-size: 16px; color: #8a6d4a; margin-bottom: 18px; }

.big-btn {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 13px;
  font-size: 22px;
  font-family: inherit;
  border-radius: 12px;
  background: var(--red);
  color: #fff;
  border-bottom: 4px solid var(--red-dark);
  transition: transform 0.08s, filter 0.12s;
}
.big-btn:hover { filter: brightness(1.07); transform: translateY(-2px); }
.big-btn:active { transform: translateY(1px); }
.big-btn.alt { background: var(--wood); border-bottom-color: var(--wood-dark); font-size: 17px; padding: 10px; }
.big-btn.gold { background: #f5a623; border-bottom-color: #c97f12; }
.big-btn.continue { background: #4d9633; border-bottom-color: #36701f; }

.scores { margin-top: 14px; font-size: 14px; color: #8a6d4a; }
.scores h3 { font-size: 15px; color: var(--ink); margin-bottom: 5px; letter-spacing: 1px; }
.scores ol { list-style: none; }
.scores li { display: flex; justify-content: space-between; gap: 18px; padding: 1.5px 8px; }
.scores li.you { background: var(--gold); border-radius: 6px; color: var(--ink); }

/* tutorial */
.tut-step {
  display: flex; align-items: center; gap: 14px;
  text-align: left;
  background: #fff;
  border: 2px solid #e3d5bb;
  border-radius: 12px;
  padding: 10px 14px;
  margin: 8px 0;
  font-size: 14.5px;
  line-height: 1.35;
  font-family: 'Trebuchet MS', sans-serif;
}
.tut-step b { color: var(--red-dark); font-family: 'Fredoka One', cursive; }
.tut-step .glyph { font-size: 30px; flex: none; }

/* end screen */
#end-title { font-size: 44px; margin-bottom: 6px; }
#end-title.win { color: #4d9633; text-shadow: 0 3px 0 #36701f; }
#end-title.lose { color: var(--red); text-shadow: 0 3px 0 var(--red-dark); }
#end-sub { font-size: 17px; color: #8a6d4a; margin-bottom: 12px; }
#end-score { font-size: 30px; color: var(--ink); margin-bottom: 14px; }

#initials-form { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }
#initials {
  width: 96px;
  font-family: inherit;
  font-size: 24px;
  text-align: center;
  text-transform: uppercase;
  border: 3px solid var(--brown);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  padding: 5px;
}
#initials-form button {
  padding: 5px 18px;
  font-family: inherit;
  font-size: 17px;
  border-radius: 9px;
  background: var(--gold);
  color: var(--ink);
  border-bottom: 3px solid #d9ab2e;
}

/* ---- fullscreen + rotate hint ---- */

#sg-fs-btn, #mute-btn {
  position: fixed; top: 8px; right: 8px;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  padding: 0; border: 0; border-radius: 6px;
  background: rgba(0, 0, 0, 0.45); color: #fff; cursor: pointer; z-index: 9999;
}
#sg-fs-btn:hover, #mute-btn:hover { background: rgba(0, 0, 0, 0.7); }
#mute-btn { right: 42px; }

#rotate-hint {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 12px;
  text-align: center;
  color: var(--brown);
  font-size: 13px;
  z-index: 50;
  pointer-events: none;
  text-shadow: 0 1px 0 var(--cream);
}
@media (orientation: portrait) and (max-width: 700px) {
  #rotate-hint { display: block; }
}
