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

:root {
  --ink: #1c2333;
  --panel: rgba(255, 255, 255, 0.94);
  --accent: #ff4757;
  --accent-dark: #d63447;
  --mustard: #ffd32a;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #0d1322;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

#stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#frame {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
}
#cv { width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---------- overlays / shared ---------- */
#overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#overlay.gone { display: none; }

.panel {
  pointer-events: auto;
  background: var(--panel);
  border-radius: 24px;
  padding: 36px 44px;
  width: min(440px, calc(100vw - 32px));
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 2px 0 rgba(255,255,255,0.6) inset;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.title {
  font-family: 'Titan One', 'Nunito', sans-serif;
  font-size: 46px;
  line-height: 0.95;
  color: var(--accent);
  text-shadow: 0 3px 0 var(--accent-dark), 0 8px 18px rgba(214, 52, 71, 0.35);
}
.title::after { content: " ⚔️"; font-size: 36px; text-shadow: none; }

.tagline { font-weight: 700; color: #7a8296; font-size: 14px; }

input {
  font-family: inherit; font-weight: 800; font-size: 18px; text-align: center;
  padding: 13px 16px; border-radius: 14px; border: 3px solid #dfe4ee;
  background: #f4f6fb; color: var(--ink); width: 100%; outline: none;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: #aab2c5; font-weight: 700; }
#codeInput { text-transform: uppercase; letter-spacing: 6px; width: 130px; }

.btn {
  font-family: inherit; font-weight: 900; font-size: 17px; letter-spacing: 0.5px;
  padding: 13px 22px; border: none; border-radius: 14px;
  background: var(--accent); color: #fff; cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-dark), 0 10px 20px rgba(214, 52, 71, 0.3);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn:disabled { filter: grayscale(0.7) brightness(0.95); cursor: default; box-shadow: 0 4px 0 #9aa1b1; }
.btn.big { width: 100%; font-size: 19px; padding: 15px 22px; }
.btn.ghost { background: #eef1f8; color: #55607a; box-shadow: 0 3px 0 #d4dae8; font-size: 14px; padding: 10px 18px; }
.btn.ghost:active { box-shadow: 0 1px 0 #d4dae8; }

.divider { width: 100%; display: flex; align-items: center; gap: 10px; color: #aab2c5; font-weight: 700; font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 2px; background: #e6eaf3; border-radius: 2px; }
.joinrow { display: flex; gap: 10px; width: 100%; justify-content: center; }
.error { color: var(--accent-dark); font-weight: 800; font-size: 14px; }
.hint { color: #97a0b5; font-weight: 700; font-size: 13px; }

.lobbylabel { font-weight: 900; font-size: 13px; letter-spacing: 3px; color: #97a0b5; }
#codeBig { font-family: 'Titan One', sans-serif; font-size: 64px; letter-spacing: 14px; padding-left: 14px; line-height: 1; }
#playerList { width: 100%; display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.prow { display: flex; align-items: center; gap: 12px; background: #f4f6fb; border-radius: 12px; padding: 10px 16px; font-weight: 800; font-size: 16px; }
.pdot { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 3px rgba(0,0,0,0.08) inset; }
.pcrown { margin-left: auto; }

#overEmoji { font-size: 64px; }
#gameover h2 { font-family: 'Titan One', sans-serif; font-size: 28px; }
#overStats { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.srow { display: flex; gap: 10px; align-items: center; background: #f4f6fb; border-radius: 10px; padding: 8px 14px; font-weight: 800; font-size: 14px; }
.srow .sright { margin-left: auto; color: #7a8296; }

/* ---------- big panels (chargen / shop) ---------- */
.bigpanel {
  position: absolute; inset: 0;
  background: rgba(13, 19, 34, 0.72);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 20px;
  z-index: 5;
}
.ptitle { font-family: 'Titan One', sans-serif; font-size: clamp(24px, 4vw, 38px); color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,0.4); }
.psub { font-weight: 800; color: #c8d2e8; font-size: 15px; }
.psub b { color: var(--mustard); }

#cgStats { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; max-width: 900px; }
.statbox {
  background: var(--panel); border-radius: 14px; padding: 10px 12px; width: 110px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.statbox .sname { font-weight: 900; font-size: 11px; letter-spacing: 1px; color: #97a0b5; }
.statbox .sval { font-family: 'Titan One', sans-serif; font-size: 26px; }
.statbox .sdesc { font-weight: 700; font-size: 9.5px; color: #7a8296; text-align: center; line-height: 1.2; height: 24px; }
.statbox .srowbtns { display: flex; gap: 6px; }
.sbtn {
  width: 28px; height: 28px; border-radius: 8px; border: none; cursor: pointer;
  font-weight: 900; font-size: 16px; background: #eef1f8; color: var(--ink);
  box-shadow: 0 2px 0 #d4dae8;
}
.sbtn:active { transform: translateY(2px); box-shadow: none; }
.sbtn.plus { background: var(--accent); color: #fff; box-shadow: 0 2px 0 var(--accent-dark); }
.sbtn:disabled { opacity: 0.35; cursor: default; }

#cgWeapons { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.wcard {
  background: var(--panel); border: 3px solid transparent; border-radius: 14px;
  padding: 12px 14px; width: 132px; cursor: pointer; text-align: center;
  display: flex; flex-direction: column; gap: 3px; font-family: inherit;
}
.wcard .wicon { font-size: 30px; }
.wcard .wname { font-weight: 900; font-size: 13px; }
.wcard .wtrait { font-weight: 700; font-size: 10.5px; color: #7a8296; }
.wcard.sel { border-color: var(--mustard); box-shadow: 0 0 16px rgba(255, 211, 42, 0.4); }

#cgReady, #shopReady { max-width: 340px; }

/* ---------- shop ---------- */
#shopRow { display: flex; gap: 16px; max-width: 1050px; width: 100%; justify-content: center; min-height: 0; }
#shopCatalog {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  overflow-y: auto; max-height: 56vh; padding: 4px; flex: 1; max-width: 720px;
}
.item {
  background: var(--panel); border-radius: 12px; padding: 10px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px; text-align: center; border: 2px solid transparent;
  font-family: inherit;
}
.item:hover { border-color: var(--mustard); }
.item.owned { border-color: #2ed573; opacity: 0.75; }
.item.poor { opacity: 0.45; }
.item .iicon { font-size: 24px; }
.item .iname { font-weight: 900; font-size: 11.5px; line-height: 1.15; }
.item .istat { font-weight: 700; font-size: 10px; color: #7a8296; }
.item .icost { font-weight: 900; font-size: 12px; color: #b8860b; }
#shopSide { display: flex; flex-direction: column; gap: 10px; width: 260px; }
#shopGold {
  background: var(--panel); border-radius: 14px; padding: 12px 16px;
  font-weight: 900; font-size: 20px; text-align: center; color: #b8860b;
}
#shopStats { background: var(--panel); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 5px; }
.shoprow { display: flex; align-items: center; font-weight: 800; font-size: 13px; gap: 8px; }
.shoprow .sv { margin-left: auto; font-family: 'Titan One', sans-serif; font-size: 15px; }
.shoprow .sbtn { width: 24px; height: 24px; font-size: 14px; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
#hud > * { pointer-events: auto; }

#bosstop {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  width: min(560px, 60%);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  pointer-events: none;
}
#bossname {
  font-family: 'Titan One', sans-serif; font-size: 22px; color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,0.45); letter-spacing: 1px;
}
#bosshpwrap {
  width: 100%; height: 20px; border-radius: 999px; overflow: hidden; position: relative;
  background: rgba(13, 19, 34, 0.8); border: 2px solid rgba(255,255,255,0.25);
}
#bosshpbar { height: 100%; width: 100%; background: linear-gradient(90deg, #ff4757, #ff6b81); transition: width 0.5s; }
#bosshptext {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 12px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.7);
}
#bossarmour { font-weight: 900; font-size: 12px; color: #c8d2e8; text-shadow: 0 1px 2px rgba(0,0,0,0.6); }

#champpill {
  position: absolute; top: 14px; left: 16px;
  background: rgba(13, 19, 34, 0.75); color: #fff; border-radius: 999px;
  padding: 8px 16px; font-weight: 900; font-size: 14px;
  pointer-events: none;
}
#timerpill {
  position: absolute; top: 14px; right: 16px;
  background: rgba(13, 19, 34, 0.75); color: var(--mustard); border-radius: 999px;
  padding: 8px 16px; font-family: 'Titan One', sans-serif; font-size: 18px;
  pointer-events: none;
}
#timerpill.low { color: var(--accent); animation: pulse 0.5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }

#banner {
  position: absolute; top: 30%; left: 50%; transform: translateX(-50%);
  font-family: 'Titan One', sans-serif; font-size: clamp(26px, 4.5vw, 44px); color: #fff;
  text-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 12px 30px rgba(0,0,0,0.4);
  animation: bannerIn 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
  white-space: nowrap; pointer-events: none; z-index: 3;
}
@keyframes bannerIn { from { transform: translateX(-50%) scale(0.4); opacity: 0; } }

#telegraph {
  position: absolute; top: 86px; left: 50%; transform: translateX(-50%);
  background: rgba(120, 20, 30, 0.88); border: 2px solid #ff6b81;
  color: #fff; border-radius: 14px; padding: 8px 20px;
  font-weight: 900; font-size: 15px; text-align: center;
  pointer-events: none;
  animation: bannerIn 0.3s ease-out;
}
#telegraph .tgmove { color: var(--mustard); font-family: 'Titan One', sans-serif; letter-spacing: 1px; }

#party {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.pcard {
  background: rgba(13, 19, 34, 0.8); border-radius: 12px; padding: 8px 12px;
  width: 170px; color: #fff; border-left: 4px solid transparent;
}
.pcard.me { box-shadow: 0 0 0 2px var(--mustard); }
.pcard.dead { opacity: 0.5; }
.pcard .pcname { font-weight: 900; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.pcard .pcbar { height: 6px; border-radius: 4px; background: rgba(255,255,255,0.15); margin-top: 4px; overflow: hidden; }
.pcard .pcfill { height: 100%; border-radius: 4px; transition: width 0.4s; }
.pcard .pcmeta { font-weight: 700; font-size: 10px; color: #8fa0c4; margin-top: 3px; }
.pcard .lockin { color: #2ed573; }

#actionbar {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; flex-wrap: nowrap; justify-content: center;
  max-width: 98%;
}
.abtn {
  font-family: inherit; font-weight: 800; font-size: 12.5px; color: #fff;
  background: rgba(13, 19, 34, 0.85); border: 2px solid rgba(255,255,255,0.18);
  border-radius: 13px; padding: 8px 13px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  transition: transform 0.08s, border-color 0.1s;
  position: relative;
}
.abtn .aicon { font-size: 20px; }
.abtn .acost { font-size: 10px; color: #8fa0c4; }
.abtn:hover:not(:disabled) { transform: translateY(-3px); border-color: var(--mustard); }
.abtn:disabled { opacity: 0.35; cursor: default; }
.abtn.sel { border-color: #2ed573; box-shadow: 0 0 12px rgba(46, 213, 115, 0.4); }

#movehint {
  position: absolute; bottom: 92px; left: 50%; transform: translateX(-50%);
  color: #fff; font-weight: 800; font-size: 13px;
  background: rgba(13, 19, 34, 0.8); padding: 6px 16px; border-radius: 999px;
  pointer-events: none;
}
#movehint b { color: var(--mustard); }

#narrator {
  position: absolute; bottom: 225px; left: 50%; transform: translateX(-50%);
  background: rgba(13, 19, 34, 0.85); color: #fff;
  border: 1px solid rgba(255, 211, 42, 0.35);
  border-radius: 999px; padding: 7px 22px;
  font-weight: 800; font-size: 15px;
  white-space: nowrap; pointer-events: none;
}

#cgHow {
  display: flex; flex-direction: column; gap: 4px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px; padding: 12px 20px;
  color: #dfe6f5; font-weight: 700; font-size: 13px;
  max-width: 640px; text-align: left;
}
#cgHow b { color: var(--mustard); }

#toasts {
  position: absolute; bottom: 90px; right: 14px;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end; pointer-events: none;
}
.toast {
  background: rgba(13, 19, 34, 0.85); color: #fff; border-radius: 10px;
  padding: 8px 14px; font-weight: 800; font-size: 13px;
  animation: toastIn 0.25s ease-out;
}
@keyframes toastIn { from { transform: translateX(30px); opacity: 0; } }

/* small-window safety: shrink the action bar instead of overflowing */
@media (max-width: 1150px) {
  #actionbar { transform: translateX(-50%) scale(0.72); transform-origin: bottom center; }
  #party { transform: translateY(-50%) scale(0.8); transform-origin: left center; }
}
