@font-face{font-family:'Alfa Slab One';font-style:normal;font-weight:400;src:url(../fonts/alfa-slab-one.woff2) format('woff2');font-display:swap}
@font-face{font-family:'Courier Prime';font-style:normal;font-weight:400;src:url(../fonts/courier-prime.woff2) format('woff2');font-display:swap}
@font-face{font-family:'Courier Prime';font-style:normal;font-weight:700;src:url(../fonts/courier-prime-bold.woff2) format('woff2');font-display:swap}

:root{
  --cream:#F1E6CC;
  --parquet-a:#C89A5B;
  --parquet-b:#A87A42;
  --orange:#C8551F;
  --mustard:#D9A321;
  --avocado:#6E7A2E;
  --ink:#3A2416;
  --tomato:#D8402B;
  --brass:#E2B33C;
  --kraft:#D2B48C;
  --water:#9FC3C9;
  --mouse:#8A7B6A;
  --outline:2px solid var(--ink);
}

*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
[hidden]{display:none !important}
html,body{margin:0;height:100%;overflow:hidden}
body{
  font-family:'Courier Prime',monospace;
  color:var(--ink);
  background:var(--cream);
  letter-spacing:.04em;
}
h1,h2,h3,.slab,.hud-num,.stamp-btn{font-family:'Alfa Slab One',serif;letter-spacing:.02em}

#grain{
  position:fixed;inset:0;z-index:9999;pointer-events:none;
  background-image:url(../img/grain.png);
  background-size:160px 160px;
  opacity:.06;mix-blend-mode:multiply;
}

#app{display:flex;flex-direction:column;height:100dvh;height:100vh;width:100vw;background:var(--cream)}

/* ---------- top bar ---------- */
#topbar{
  flex:0 0 auto;display:flex;align-items:center;gap:16px;
  padding:10px 16px;background:var(--cream);
  border-bottom:3px solid var(--ink);
  min-height:66px;
}
.hud{display:flex;align-items:center;gap:9px}
.hud-label{font-size:12px;text-transform:lowercase;letter-spacing:.14em;opacity:.75}
.hud-num{font-size:30px;line-height:1;color:var(--ink)}
.hud-of{font-family:'Courier Prime';font-size:17px;opacity:.6;margin-left:1px}
.hud-wave{background:var(--mustard);border:var(--outline);border-radius:10px;padding:5px 14px}
.hud-lives{background:var(--cream);border:var(--outline);border-radius:10px;padding:4px 14px}
.hud-lives.low{background:var(--tomato)}
.hud-lives.low .hud-label{color:var(--cream);opacity:.9}
.hud-lives.low .hud-num{color:var(--cream)}
.hud-coins{
  background:var(--kraft);border:var(--outline);border-radius:10px;
  padding:5px 16px;box-shadow:inset 0 -3px 0 rgba(58,36,22,.15)
}
.coin-icon{
  width:30px;height:30px;border-radius:50%;background:var(--brass);
  border:2px solid var(--ink);position:relative;flex:0 0 auto
}
.coin-icon::after{content:"";position:absolute;inset:7px;border-radius:50%;border:2px dashed rgba(58,36,22,.55)}
.hud-coins .hud-num{font-size:34px}
.topbar-right{margin-left:auto;display:flex;align-items:center;gap:12px}

.lives-bowl{width:88px;height:44px;display:block;flex:0 0 auto}
.hud-lives .hud-num{font-size:34px}

/* ---------- stamp buttons ---------- */
.stamp-btn{
  font-family:'Alfa Slab One',serif;font-size:17px;letter-spacing:.06em;
  color:var(--cream);background:var(--orange);
  border:2px solid var(--ink);border-radius:999px;
  padding:10px 20px;cursor:pointer;
  box-shadow:0 3px 0 rgba(58,36,22,.35), inset 0 0 0 3px rgba(241,230,204,.28);
  transition:transform .12s ease, box-shadow .12s ease, filter .12s ease;
  white-space:nowrap;
}
.stamp-btn:active{transform:translateY(3px) scale(.97);box-shadow:0 0 0 rgba(58,36,22,.35), inset 0 0 0 3px rgba(241,230,204,.28)}
.stamp-btn.small{font-size:18px;padding:8px 12px}
.stamp-btn.big{font-size:26px;padding:16px 44px}
.stamp-btn:disabled{filter:grayscale(.5) brightness(1.05);opacity:.55;cursor:default}
.stamp-btn.ghost{background:var(--cream);color:var(--ink);box-shadow:0 3px 0 rgba(58,36,22,.25)}

/* the Start Wave rubber stamp stays bold and orange, running or not */
#startWave{
  font-size:19px;padding:13px 30px;
  box-shadow:0 4px 0 rgba(58,36,22,.35), inset 0 0 0 4px rgba(241,230,204,.34), inset 0 0 0 8px rgba(58,36,22,.16);
}
#startWave:disabled{
  filter:none;opacity:1;background:var(--orange);color:var(--cream);cursor:default;
  box-shadow:0 4px 0 rgba(58,36,22,.35), inset 0 0 0 4px rgba(241,230,204,.34), inset 0 0 0 8px rgba(58,36,22,.16);
}

/* ---------- stage ---------- */
#stage{flex:1 1 auto;display:flex;min-height:0;min-width:0;background:var(--parquet-b)}
#boardWrap{position:relative;flex:1 1 auto;min-width:0;min-height:0;overflow:hidden}
#board{position:absolute;inset:0}
#board canvas{display:block}

/* ---------- shop shelf ---------- */
#shop{
  flex:0 0 auto;width:262px;background:var(--kraft);
  border-left:3px solid var(--ink);
  display:flex;flex-direction:column;min-height:0;
  box-shadow:inset 6px 0 0 rgba(58,36,22,.08);
}
.shop-shelf-label{
  font-family:'Alfa Slab One';font-size:16px;text-transform:lowercase;
  letter-spacing:.16em;color:var(--ink);
  padding:10px 14px 8px;border-bottom:2px dashed rgba(58,36,22,.4)
}
#shopCards{
  flex:1 1 auto;overflow-y:auto;overflow-x:hidden;
  display:flex;flex-direction:column;gap:12px;padding:14px;
  scrollbar-width:thin;
}

/* ---------- price tag cards ---------- */
.tag{
  position:relative;background:var(--cream);
  border:2px solid var(--ink);
  padding:34px 14px 16px;cursor:pointer;
  clip-path:polygon(0 16px,16px 0,100% 0,100% 100%,0 100%);
  box-shadow:2px 3px 0 rgba(58,36,22,.22);
  transition:transform .16s cubic-bezier(.2,1.5,.4,1), box-shadow .16s ease, opacity .16s ease;
  display:flex;gap:14px;align-items:center;
  flex:1 1 auto;min-height:120px;
}
.tag::before{ /* punched hole */
  content:"";position:absolute;top:9px;left:12px;width:13px;height:13px;border-radius:50%;
  background:var(--kraft);border:2px solid var(--ink)
}
.tag::after{ /* string */
  content:"";position:absolute;top:-11px;left:16px;width:3px;height:18px;
  background:var(--ink);transform:rotate(-18deg);transform-origin:bottom
}
.tag:hover{transform:translateY(-2px)}
.tag.selected{transform:translateY(-5px);border-color:var(--mustard);box-shadow:0 0 0 3px var(--mustard),3px 6px 0 rgba(58,36,22,.28)}
.tag.cant{opacity:.4;transform:rotate(2deg);cursor:pointer}
.tag.cant:hover{transform:rotate(2deg)}
.tag-portrait{width:70px;height:70px;flex:0 0 auto;background:var(--cream);border-radius:10px}
.tag-info{display:flex;flex-direction:column;gap:3px;min-width:0}
.tag-name{font-family:'Alfa Slab One';font-size:19px;line-height:1.05}
.tag-role{font-size:12.5px;opacity:.75;letter-spacing:.02em;text-transform:lowercase}
.tag-cost{
  margin-top:6px;font-family:'Alfa Slab One';font-size:24px;line-height:1;
  display:flex;align-items:center;gap:7px
}
.tag-cost .coin-icon{width:22px;height:22px;border-width:2px}
.tag-cost .coin-icon::after{inset:4px;border-width:1px}
.tag.cant .tag-cost{color:var(--tomato)}

/* ---------- popover ---------- */
.popover{
  position:absolute;z-index:40;display:flex;flex-direction:column;gap:6px;
  background:var(--cream);border:2px solid var(--ink);
  padding:16px 10px 10px;min-width:150px;
  clip-path:polygon(0 10px,10px 0,100% 0,100% 100%,0 100%);
  box-shadow:3px 4px 0 rgba(58,36,22,.3);
  transform:translate(-50%,-100%);
}
.popover-tab{position:absolute;top:7px;left:9px;width:8px;height:8px;border-radius:50%;background:var(--kraft);border:2px solid var(--ink)}
.popover button{
  font-family:'Alfa Slab One';font-size:13px;letter-spacing:.04em;
  border:2px solid var(--ink);border-radius:8px;padding:8px 10px;cursor:pointer;
  background:var(--mustard);color:var(--ink)
}
.popover #popSell{background:var(--cream)}
.popover button:disabled{opacity:.45;cursor:default}
.popover #popUpgrade:disabled{background:var(--cream)}

.toast{
  position:absolute;left:50%;bottom:16px;transform:translateX(-50%);
  background:var(--ink);color:var(--cream);padding:8px 14px;border-radius:8px;
  font-size:13px;z-index:50;pointer-events:none
}

/* ---------- help ---------- */
#helpPanel{
  position:fixed;inset:0;z-index:300;background:transparent
}
.help-inner{
  position:absolute;top:66px;right:14px;
  background:var(--cream);border:2px solid var(--ink);border-radius:14px;
  padding:20px 22px;max-width:min(390px,90vw);max-height:72vh;overflow:auto;
  box-shadow:4px 6px 0 rgba(58,36,22,.4)
}
.help-inner h2{font-family:'Alfa Slab One';font-size:24px;margin:0 0 10px}
.help-inner ul{margin:0;padding-left:18px}
.help-inner li{font-size:14px;line-height:1.45;margin-bottom:7px}
.help-inner b{background:var(--mustard);border-radius:4px;padding:0 4px}
.help-tip{font-size:12.5px;opacity:.8;margin:12px 0 0}
.help-close{
  position:absolute;top:8px;right:10px;width:32px;height:32px;border-radius:50%;
  border:2px solid var(--ink);background:var(--orange);color:var(--cream);
  font-size:20px;line-height:1;cursor:pointer
}

/* ---------- end overlay ---------- */
#overlay{
  position:fixed;inset:0;z-index:200;display:flex;align-items:center;justify-content:center;
  background:rgba(58,36,22,.45);padding:18px
}
.endcard{
  position:relative;background:var(--cream);
  padding:26px 30px 30px;max-width:min(560px,94vw);text-align:center;
  border:2px solid var(--ink);
  filter:drop-shadow(4px 6px 0 rgba(58,36,22,.4));
  /* torn edge */
  clip-path:polygon(0 3%,4% 0,9% 3%,15% 0,22% 3%,30% 0,38% 3%,47% 0,56% 3%,65% 0,74% 3%,83% 0,91% 3%,97% 0,100% 3%,
                    100% 97%,96% 100%,89% 97%,82% 100%,74% 97%,66% 100%,57% 97%,48% 100%,39% 97%,30% 100%,21% 97%,13% 100%,6% 97%,0 100%);
}
.endcard h1{font-size:40px;margin:6px 0 10px;color:var(--ink)}
.endcard-inner{position:relative;z-index:2}
.end-art{height:130px;display:flex;align-items:center;justify-content:center;margin:0 0 8px}
.end-art canvas{display:block}
.end-msg{font-size:15px;margin:2px 0 6px}
.end-stats{font-size:14px;opacity:.85;margin-bottom:16px}
.gameover-stamp{
  position:absolute;top:34%;left:50%;
  transform:translate(-50%,-50%) rotate(-13deg);
  font-family:'Alfa Slab One';font-size:34px;color:var(--tomato);
  border:5px solid var(--tomato);border-radius:10px;padding:4px 18px;
  text-transform:lowercase;letter-spacing:.1em;
  box-shadow:0 0 0 2px rgba(216,64,43,.35) inset;opacity:.92;pointer-events:none
}
.confetti{position:absolute;inset:0;width:100%;height:100%;pointer-events:none;z-index:1}

/* ---------- narrow: shop along the bottom ---------- */
/* ---------- compact top bar on narrow screens ---------- */
@media (max-width: 620px){
  #topbar{gap:6px 8px;padding:7px 10px;min-height:54px;flex-wrap:wrap}
  .topbar-right{width:100%;margin-left:0;justify-content:flex-end;gap:8px}
  #startWave{flex:1 1 auto;max-width:260px;font-size:17px;padding:11px 24px}
  .hud-num{font-size:24px}
  .hud-coins .hud-num{font-size:30px}
  .hud-lives .hud-num{font-size:30px}
  .hud-lives .hud-label{display:none}
  .hud-label{font-size:10px}
  .hud-wave,.hud-lives,.hud-coins{padding:3px 9px}
  .coin-icon{width:24px;height:24px}
  .lives-bowl{width:64px;height:32px}
  .stamp-btn{font-size:14px;padding:8px 14px}
  .stamp-btn.small{font-size:15px;padding:7px 9px}
  #shop{width:100%}
}
@media (max-width: 400px){
  .hud-num{font-size:22px}
  .hud-coins .hud-num{font-size:28px}
  .hud-lives .hud-num{font-size:28px}
  .lives-bowl{width:58px;height:29px}
  .coin-icon{width:22px;height:22px}
}

/* ---------- portrait / tall: shop along the bottom ---------- */
@media (max-aspect-ratio: 1/1){
  #stage{flex-direction:column}
  #shop{width:100%;height:auto;max-height:44vh;border-left:none;border-top:3px solid var(--ink);
        box-shadow:inset 0 5px 0 rgba(58,36,22,.08);display:flex;flex-direction:column;min-height:0}
  .shop-shelf-label{padding:5px 14px 5px;flex:0 0 auto;font-size:15px}
  #shopCards{display:grid;grid-template-columns:1fr 1fr;gap:10px;padding:10px 12px;
             overflow-y:auto;overflow-x:hidden;align-items:stretch}
  .tag{width:auto;height:auto;min-height:116px;padding:24px 12px 12px;align-items:center;gap:12px}
  .tag-portrait{width:54px;height:54px}
  .tag-name{font-size:15px}
  .tag-role{font-size:11px}
  .tag-cost{font-size:20px;margin-top:3px}
  .help-inner{top:auto;right:8px;left:8px;bottom:8px;max-width:none;max-height:54vh}
}
