/* Bridgeworks — UI chrome. Canvas handles the world; DOM handles menus & HUD. */

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

html, body {
  height: 100%;
  background: #1a2029;
  overflow: hidden;
  font-family: "Trebuchet MS", "Segoe UI", Verdana, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

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

#game {
  display: block;
  background: #79b8d8;
}

#ui, #overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

#ui > *, #overlay > * { pointer-events: auto; }

/* ---------- shared bits ---------- */

.btn {
  display: inline-block;
  border: none;
  border-radius: 10px;
  padding: 10px 20px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(#5b8fb9, #41719b);
  box-shadow: 0 3px 0 #2c4f6e, 0 5px 10px rgba(0,0,0,.25);
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
  transition: transform .06s, filter .12s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #2c4f6e; }
.btn:disabled { opacity: .45; cursor: default; filter: grayscale(.4); }
.btn:disabled:hover { filter: grayscale(.4); }

.btn.big { font-size: 22px; padding: 14px 34px; border-radius: 13px; }
.btn.small { font-size: 14px; padding: 7px 13px; border-radius: 8px; }
.btn.green { background: linear-gradient(#67b25f, #488b42); box-shadow: 0 3px 0 #2e5e2b, 0 5px 10px rgba(0,0,0,.25); }
.btn.green:active { box-shadow: 0 1px 0 #2e5e2b; }
.btn.orange { background: linear-gradient(#e0983f, #bd7522); box-shadow: 0 3px 0 #8a5313, 0 5px 10px rgba(0,0,0,.25); }
.btn.orange:active { box-shadow: 0 1px 0 #8a5313; }
.btn.red { background: linear-gradient(#d66a5a, #b04434); box-shadow: 0 3px 0 #7e2f23, 0 5px 10px rgba(0,0,0,.25); }
.btn.ghost { background: rgba(20,30,44,.55); box-shadow: inset 0 0 0 2px rgba(255,255,255,.25); text-shadow: none; }

.iconbtn {
  width: 46px; height: 46px;
  border: none; border-radius: 10px;
  background: rgba(22,32,46,.72);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.18), 0 2px 6px rgba(0,0,0,.3);
  color: #fff; font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, transform .06s;
}
.iconbtn:hover { background: rgba(48,66,90,.85); }
.iconbtn:active { transform: scale(.93); }
.iconbtn.active { background: #3f7ab5; box-shadow: inset 0 0 0 2px #a8d4ff, 0 0 12px rgba(120,190,255,.5); }
.iconbtn:disabled { opacity: .4; cursor: default; }
.iconbtn .kb {
  position: absolute; font-size: 9px; right: 3px; bottom: 2px; opacity: .65; font-weight: 700;
}
.iconbtn { position: relative; }

/* ---------- screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.panel {
  background: rgba(16,24,35,.82);
  border-radius: 18px;
  padding: 34px 44px;
  box-shadow: 0 12px 44px rgba(0,0,0,.5), inset 0 0 0 2px rgba(255,255,255,.07);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: min(860px, 92vw);
  max-height: 92vh;
}

.gametitle {
  font-size: 64px;
  font-weight: 900;
  color: #ffd98a;
  text-shadow: 0 3px 0 #b5651d, 0 6px 0 rgba(0,0,0,.25), 0 10px 26px rgba(0,0,0,.5);
  letter-spacing: 1px;
}
.gametitle .spn { color: #a8d4ff; text-shadow: 0 3px 0 #2c5f8e, 0 6px 0 rgba(0,0,0,.25), 0 10px 26px rgba(0,0,0,.5); }
.subtitle { color: #cfe3f2; font-size: 17px; opacity: .9; margin-top: -8px; }

.menu-col { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; min-width: 300px; }
.menu-col .btn { width: 100%; }

/* ---------- level select ---------- */

.levelgrid {
  display: grid;
  grid-template-columns: repeat(4, 148px);
  gap: 14px;
  padding: 6px;
}
.lvlcard {
  border: none;
  border-radius: 14px;
  background: linear-gradient(#3d5a75, #2a4258);
  box-shadow: 0 4px 0 #1b2c3d, 0 6px 14px rgba(0,0,0,.35);
  color: #fff;
  padding: 12px 10px 10px;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 116px;
  transition: transform .08s, filter .12s;
  position: relative;
}
.lvlcard:hover:not(:disabled) { transform: translateY(-3px); filter: brightness(1.15); }
.lvlcard:disabled { opacity: .42; cursor: default; filter: grayscale(.7); }
.lvlcard .num { font-size: 24px; font-weight: 900; }
.lvlcard .lname { font-size: 12.5px; font-weight: 700; color: #cfe3f2; text-align: center; line-height: 1.15; min-height: 28px; }
.lvlcard .medal { font-size: 19px; line-height: 1; }
.lvlcard .cost { font-size: 10.5px; opacity: .85; }
.lvlcard .lock { font-size: 26px; }
.lvlcard.done { background: linear-gradient(#47704f, #31513a); box-shadow: 0 4px 0 #1e3323, 0 6px 14px rgba(0,0,0,.35); }
.lvlcard.sandbox { background: linear-gradient(#6a5a8c, #4a3f68); box-shadow: 0 4px 0 #322a45, 0 6px 14px rgba(0,0,0,.35); }

.screen h2 {
  color: #ffd98a; font-size: 34px; font-weight: 900;
  text-shadow: 0 2px 0 rgba(0,0,0,.35);
}
.screen .hintline { color: #cfe3f2; opacity: .8; font-size: 14px; }

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

.hud-top {
  position: absolute;
  top: 10px; left: 12px; right: 12px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }

.hudbox {
  background: rgba(16,24,35,.78);
  border-radius: 12px;
  color: #fff;
  padding: 8px 14px;
  box-shadow: 0 3px 10px rgba(0,0,0,.35), inset 0 0 0 1.5px rgba(255,255,255,.1);
  font-size: 14px;
}

.budgetbox { min-width: 170px; }
.budgetbox .lbl { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; opacity: .7; font-weight: 700; }
.budgetbox .val { font-size: 20px; font-weight: 900; }
.budgetbox .val.over { color: #ff7b6b; }
.budgetbox .val .par { font-size: 12px; opacity: .7; font-weight: 700; }

.matrow { display: flex; gap: 7px; align-items: stretch; }

.matbtn {
  border: none;
  width: 74px;
  border-radius: 10px;
  padding: 6px 4px 5px;
  font-family: inherit;
  cursor: pointer;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: rgba(22,32,46,.72);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.16), 0 2px 6px rgba(0,0,0,.3);
  transition: transform .06s, background .12s;
  position: relative;
}
.matbtn:hover:not(:disabled) { background: rgba(48,66,90,.85); }
.matbtn:active { transform: scale(.94); }
.matbtn.active { box-shadow: inset 0 0 0 2.5px #ffd98a, 0 0 14px rgba(255,215,140,.45); background: rgba(60,50,28,.85); }
.matbtn:disabled { opacity: .38; cursor: default; filter: grayscale(.6); }
.matbtn .swatch { width: 44px; height: 9px; border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.matbtn .mname { font-size: 11px; font-weight: 800; }
.matbtn .mprice { font-size: 9.5px; opacity: .8; }
.matbtn .kb { position: absolute; font-size: 9px; right: 4px; top: 3px; opacity: .6; font-weight: 700; }

.toolrow { display: flex; gap: 7px; }
.hud-right { margin-left: auto; display: flex; flex-direction: column; gap: 7px; align-items: flex-end; }

.hintbar {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(16,24,35,.72);
  color: #dcebf7;
  font-size: 13px;
  padding: 7px 16px;
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  pointer-events: none;
  white-space: nowrap;
  max-width: 90vw;
}

.lvlbanner {
  position: absolute;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,.6);
  animation: bannerin .5s ease-out;
}
.lvlbanner .bn { font-size: 30px; font-weight: 900; }
.lvlbanner .bd { font-size: 14px; opacity: .92; max-width: 560px; }
@keyframes bannerin { from { opacity: 0; transform: translate(-50%,-12px); } to { opacity: 1; transform: translate(-50%,0); } }

/* ---------- test-mode HUD ---------- */

.stresslegend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: rgba(16,24,35,.78);
  border-radius: 12px;
  padding: 9px 13px;
  color: #fff;
  font-size: 11px;
  pointer-events: none;
}
.stresslegend .bar {
  width: 150px; height: 9px; border-radius: 5px; margin: 5px 0 4px;
  background: linear-gradient(90deg, #2f8fe0 0%, #37c76a 34%, #e8d244 62%, #ef8f33 82%, #e33f2f 100%);
}
.stresslegend .lbls { display: flex; justify-content: space-between; opacity: .85; }

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

.veil {
  position: absolute; inset: 0;
  background: rgba(8,12,20,.45);
  display: flex; align-items: center; justify-content: center;
  animation: fadein .25s ease-out;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.resultpanel h2 { font-size: 36px; color: #ffd98a; text-shadow: 0 2px 0 rgba(0,0,0,.35); }
.resultpanel .bigemoji { font-size: 54px; }
.resultpanel .stats { display: flex; flex-direction: column; gap: 6px; font-size: 16px; color: #dcebf7; min-width: 300px; }
.resultpanel .stats .row { display: flex; justify-content: space-between; gap: 30px; border-bottom: 1px solid rgba(255,255,255,.12); padding-bottom: 5px; }
.resultpanel .stats .row b { color: #ffd98a; }
.resultpanel .medalshow { font-size: 44px; animation: medalpop .55s cubic-bezier(.2,2.2,.4,1); }
@keyframes medalpop { from { transform: scale(0) rotate(-40deg); } to { transform: scale(1) rotate(0); } }
.resultpanel .btnrow { display: flex; gap: 12px; margin-top: 6px; flex-wrap: wrap; justify-content: center; }
.failmsg { color: #ffb9ad; font-size: 15px; text-align: center; max-width: 460px; line-height: 1.4; }

.pausepanel .menu-col { min-width: 260px; }

/* ---------- misc ---------- */

.volrow { display: flex; gap: 7px; }
.hidden { display: none !important; }

.toast {
  position: absolute;
  top: 120px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20,30,44,.88);
  color: #ffe9b8;
  font-size: 15px;
  font-weight: 700;
  padding: 9px 22px;
  border-radius: 22px;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
  animation: toastin 2.4s ease-out forwards;
  pointer-events: none;
  z-index: 5;
}
@keyframes toastin {
  0% { opacity: 0; transform: translate(-50%,-10px); }
  8% { opacity: 1; transform: translate(-50%,0); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

.speedctl { display: flex; gap: 5px; }
.speedctl .iconbtn { width: 40px; height: 40px; font-size: 15px; }

@media (max-width: 700px) {
  .levelgrid { grid-template-columns: repeat(2, 148px); }
  .gametitle { font-size: 40px; }
}
