/* ============ CASTLE CHORUME — estilos ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --slime: #7cb342;
  --slime-dark: #4a6b1f;
  --gunk: #8d6e63;
  --rot: #b0a11e;
  --bg: #1a120b;
  --panel: #2a2018;
  --danger: #c0392b;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Trebuchet MS', 'Segoe UI', Verdana, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

#game-wrap {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 40%, #3a2c1a 0%, #120c06 80%);
}

#game-wrap canvas {
  display: block;
  background: var(--bg);
  box-shadow: 0 0 60px rgba(124, 179, 66, .15);
}

.hidden { display: none !important; }

/* ============ HUD ============ */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; }

#hud-top-left {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 8px;
}

#portrait {
  width: 52px; height: 52px; border-radius: 10px;
  border: 3px solid #4a6b1f;
  background: #2a2018 center/cover no-repeat;
  box-shadow: 0 2px 8px rgba(0,0,0,.6);
}

#bars { display: flex; flex-direction: column; gap: 4px; }

.bar {
  position: relative; width: min(220px, 32vw); height: 14px;
  background: #14100a; border: 2px solid #000;
  border-radius: 7px; overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.7), 0 1px 0 rgba(255,255,255,.08);
}
.bar .fill {
  height: 100%; width: 100%;
  transition: width .15s ease-out;
  border-radius: 5px;
}
.bar.hp .fill { background: linear-gradient(#9ccc65, #558b2f); }
.bar.mp { height: 10px; width: min(180px, 26vw); }
.bar.mp .fill { background: linear-gradient(#d8a860, #96602a); }
.bar.xp { height: 8px; width: min(150px, 21vw); }
.bar.xp .fill { background: linear-gradient(#cddc39, #9e9d24); width: 0%; }
.bar span {
  position: absolute; inset: 0; text-align: center;
  font-size: 10px; font-weight: bold; color: #fff;
  text-shadow: 1px 1px 0 #000; line-height: 12px;
}

#level-badge {
  background: linear-gradient(#7cb342, #4a6b1f);
  color: #fff; font-weight: bold; font-size: 13px;
  padding: 4px 8px; border-radius: 8px; border: 2px solid #2f4a12;
  text-shadow: 1px 1px 0 #000; box-shadow: 0 2px 6px rgba(0,0,0,.5);
}

#hud-top-right {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right));
  text-align: right; color: #d7c9a8;
  text-shadow: 1px 1px 0 #000;
}
#score { font-size: 20px; font-weight: bold; }
#hi-score { font-size: 11px; opacity: .8; }

#boss-bar-wrap {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  width: min(520px, 74vw); text-align: center;
}
#boss-name {
  color: #ff8a80; font-weight: bold; letter-spacing: 3px; font-size: 14px;
  text-shadow: 1px 1px 0 #000, 0 0 12px rgba(192,57,43,.8);
  margin-bottom: 3px;
}
.bar.boss { width: 100%; height: 16px; border-color: #4e0d06; }
.bar.boss .fill { background: linear-gradient(#e57373, #b71c1c); transition: width .1s; }

#wave-banner {
  position: absolute; top: 22%; left: 50%; transform: translateX(-50%);
  font-size: clamp(22px, 5vw, 42px); font-weight: 900; color: #cddc39;
  text-shadow: 2px 2px 0 #000, 0 0 24px rgba(124,179,66,.9);
  letter-spacing: 2px; white-space: nowrap;
  animation: banner-pop .5s ease-out;
}
@keyframes banner-pop {
  0% { transform: translateX(-50%) scale(.3); opacity: 0; }
  70% { transform: translateX(-50%) scale(1.15); }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

#objective {
  position: absolute; top: max(64px, calc(env(safe-area-inset-top) + 56px)); left: 50%; transform: translateX(-50%);
  color: #efe6c8; font-size: 14px; font-weight: bold;
  text-shadow: 1px 1px 0 #000; opacity: .9; white-space: nowrap;
}

/* ============ Controles touch ============ */
#touch-ui { position: absolute; inset: 0; z-index: 8; pointer-events: none; }

#joystick-zone {
  position: absolute; left: 0; bottom: 0;
  width: 45%; height: 62%;
  pointer-events: auto;
}
#joystick-base {
  position: absolute; width: 110px; height: 110px; border-radius: 50%;
  background: radial-gradient(circle, rgba(124,179,66,.12) 0%, rgba(124,179,66,.05) 60%, transparent 70%);
  border: 2px solid rgba(124,179,66,.35);
  left: 40px; bottom: 46px;
  opacity: .85; display: none;
}
#joystick-knob {
  position: absolute; width: 52px; height: 52px; border-radius: 50%;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 30%, #9ccc65, #4a6b1f);
  border: 2px solid #2f4a12;
  box-shadow: 0 3px 10px rgba(0,0,0,.6);
}

#buttons-zone {
  position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: 26px;
  width: 190px; height: 170px;
  pointer-events: auto;
}
.tbtn {
  position: absolute; border-radius: 50%;
  border-top: 3px solid rgba(255,255,255,.35);
  border-left: 2px solid rgba(255,255,255,.2);
  border-right: 2px solid rgba(0,0,0,.4);
  border-bottom: 4px solid rgba(0,0,0,.65);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 5px 0 rgba(0,0,0,.45), 0 8px 14px rgba(0,0,0,.5);
  opacity: .92;
  cursor: pointer;
  transition: transform .05s ease, box-shadow .05s ease, filter .05s ease;
  -webkit-user-select: none; user-select: none; touch-action: none;
}
.tbtn:active, .tbtn.pressed {
  transform: translateY(4px) scale(.95);
  box-shadow: 0 1px 0 rgba(0,0,0,.5), 0 2px 5px rgba(0,0,0,.4);
  filter: brightness(1.25);
}
.btn-icon {
  display: block;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.6));
}
.tbtn.atk   { width: 74px; height: 74px; right: 0;   bottom: 34px; background: radial-gradient(circle at 35% 30%, #bcaaa4, #4e342e); }
.tbtn.heavy { width: 60px; height: 60px; right: 84px; bottom: 10px; background: radial-gradient(circle at 35% 30%, #ef5350, #b71c1c); }
.tbtn.jump  { width: 60px; height: 60px; right: 90px; bottom: 82px; background: radial-gradient(circle at 35% 30%, #64b5f6, #0d47a1); }
.tbtn.magic { width: 56px; height: 56px; right: 22px; bottom: 116px; background: radial-gradient(circle at 35% 30%, #d4e157, #689f38); }

/* ============ Botões de sistema ============ */
#sys-btns {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right));
  z-index: 20; display: flex; gap: 8px;
  transform: translateY(56px);
}
.sbtn {
  width: 44px; height: 44px; border-radius: 10px;
  background: rgba(110,71,38,.9); color: #ffedbe;
  border: 2px solid #38220f; font-size: 18px;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
}
.sbtn:active { filter: brightness(1.4); }

/* ============ Overlay ============ */
#overlay {
  position: absolute; inset: 0; z-index: 15;
  display: flex; align-items: center; justify-content: center;
  background: rgba(22, 14, 6, .62);
  backdrop-filter: blur(3px);
  padding: 16px;
}
#overlay-card {
  max-width: 560px; width: 100%;
  max-height: 94%; overflow-y: auto;
  touch-action: pan-y; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background: linear-gradient(160deg, #96683a, #6e4726);
  border: 4px solid #38220f; border-radius: 18px;
  padding: 22px 26px; text-align: center;
  box-shadow: 0 10px 50px rgba(0,0,0,.7), inset 0 2px 0 rgba(255,235,190,.35), inset 0 0 60px rgba(60,32,10,.35);
  color: #fff1d2;
}
#ov-title {
  font-size: clamp(34px, 8vw, 54px); font-weight: 900; line-height: .95;
  color: #ffedbe; letter-spacing: 2px;
  text-shadow: 3px 3px 0 #38220f, -1px -1px 0 #38220f, 1px -1px 0 #38220f, -1px 1px 0 #38220f;
}
#ov-title span {
  color: #b8e04e;
  text-shadow: 3px 3px 0 #38220f, -1px -1px 0 #38220f, 1px -1px 0 #38220f, -1px 1px 0 #38220f, 0 0 26px rgba(168,224,74,.8);
}
#ov-text { font-size: 14px; margin: 14px 0; line-height: 1.5; opacity: .92; }
#ov-stats {
  margin: 10px 0; font-size: 15px; line-height: 1.7;
  background: rgba(50,28,10,.45); border-radius: 10px; padding: 10px;
}
#ov-stats b { color: #e8f05a; }
#ov-help { display: flex; gap: 10px; margin: 12px 0 18px; flex-wrap: wrap; }
.help-col {
  flex: 1 1 130px; min-width: 120px; background: rgba(50,28,10,.4); border-radius: 10px; padding: 8px 10px;
  font-size: 11px; line-height: 1.5;
}
.help-col h3 { font-size: 12px; margin-bottom: 4px; color: #d8f06a; }
.big-btn {
  display: block; width: 100%; margin-top: 10px;
  padding: 15px; font-size: 19px; font-weight: 900; letter-spacing: 1px;
  color: #1a120b; background: linear-gradient(#9ccc65, #558b2f);
  border: 3px solid #2f4a12; border-radius: 14px; cursor: pointer;
  text-shadow: 0 1px 0 rgba(255,255,255,.35);
  box-shadow: 0 5px 0 #2f4a12, 0 8px 16px rgba(0,0,0,.5);
  transition: transform .06s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #2f4a12; }
.big-btn.ghost {
  background: transparent; color: #9ccc65; text-shadow: none;
  box-shadow: none; font-size: 14px; padding: 10px;
}
#ov-hi { margin-top: 12px; font-size: 12px; color: #ffe08a; }

/* ============ Chip da arma equipada ============ */
#weapon-chip {
  position: absolute; top: max(72px, calc(env(safe-area-inset-top) + 64px)); left: max(12px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 8px;
  background: rgba(50,28,10,.85); border: 2px solid #38220f; border-radius: 12px;
  padding: 5px 10px; color: #ffe082; font-size: 11px; font-weight: bold;
  text-shadow: 1px 1px 0 #000; box-shadow: 0 2px 8px rgba(0,0,0,.5);
  max-width: min(46vw, 220px);
}
#weapon-chip span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#weapon-chip img { width: 30px; height: 30px; image-rendering: pixelated; object-fit: contain; }

/* ============ Seleção de personagem / Loja ============ */
#char-select, #shop {
  position: absolute; inset: 0; z-index: 16;
  display: flex; align-items: center; justify-content: center;
  background: rgba(22,14,6,.62); backdrop-filter: blur(3px);
  padding: 12px;
}
#shop { z-index: 17; }
.cs-card, .shop-card {
  max-width: 640px; width: 100%; max-height: 94%; overflow-y: auto;
  touch-action: pan-y; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background: linear-gradient(160deg, #96683a, #6e4726);
  border: 4px solid #38220f; border-radius: 18px;
  padding: 18px 20px; text-align: center;
  box-shadow: 0 10px 50px rgba(0,0,0,.7), inset 0 2px 0 rgba(255,235,190,.35), inset 0 0 60px rgba(60,32,10,.35);
  color: #fff1d2;
}
.shop-card { max-width: 560px; }
/* loja mobile-first: coluna flex — a lista de itens rola e o rodapé (SAIR DA LOJA) fica sempre visível */
.shop-card { display: flex; flex-direction: column; overflow: hidden; }
#shop-items { flex: 1 1 auto; min-height: 0; overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.shop-btns { flex: 0 0 auto; }
.cs-card h2, .shop-card h2 {
  color: #ffedbe; font-size: clamp(20px, 4.6vw, 28px); font-weight: 900; letter-spacing: 2px;
  text-shadow: 2px 2px 0 #38220f;
}
.cs-card p { margin-top: 8px; font-size: 14px; }

#char-cards { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 14px 0; }
.char-card {
  width: 108px; padding: 8px 6px;
  background: rgba(50,28,10,.5); border: 3px solid #38220f; border-radius: 12px;
  color: #fff1d2; cursor: pointer; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: transform .08s, box-shadow .08s;
}
.char-card img {
  width: 64px; height: 64px; border-radius: 8px;
  image-rendering: pixelated; border: 2px solid #38220f;
}
.char-card b { font-size: 10.5px; letter-spacing: .5px; }
.char-card span { font-size: 9px; opacity: .85; line-height: 1.25; min-height: 32px; }
.char-card .pips { font-size: 11px; color: #d8f06a; white-space: nowrap; }
.char-card.sel {
  border-color: #b8e04e; background: rgba(124,179,66,.28);
  box-shadow: 0 0 18px rgba(184,224,78,.65); transform: translateY(-4px);
}
.cs-btns { display: flex; gap: 10px; }
.cs-btns .big-btn { margin-top: 0; }
.cs-btns .big-btn.ghost { flex: 0 0 32%; }

/* ============ Loja ============ */
.shop-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#shop-gold { font-size: 20px; font-weight: 900; color: #ffe082; text-shadow: 1px 1px 0 #000; }
#shop-items { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.shop-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px;
  background: rgba(50,28,10,.5); border: 3px solid #38220f; border-radius: 12px;
  color: #fff1d2; font-family: inherit; text-align: left;
}
.shop-item img { width: 40px; height: 40px; image-rendering: pixelated; object-fit: contain; flex: 0 0 40px; }
.shop-item .si-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.shop-item .si-info b { font-size: 14px; letter-spacing: .5px; }
.shop-item .si-info em { font-size: 11px; opacity: .9; font-style: normal; color: #d8f06a; }
.shop-item .si-info small { font-size: 10px; opacity: .7; }
.shop-item .si-buy {
  flex: 0 0 auto; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 2px solid #2f4a12;
  background: linear-gradient(#9ccc65, #558b2f); color: #1a120b;
  font-weight: 900; font-size: 13px; font-family: inherit; cursor: pointer; white-space: nowrap;
}
.shop-item .si-buy:active { transform: translateY(2px); }
.shop-item .si-buy:disabled { background: linear-gradient(#9e9e9e, #616161); border-color: #424242; color: #eee; cursor: default; }
.shop-item.owned { opacity: .62; }
.shop-btns { display: flex; gap: 10px; justify-content: center; }
.shop-btns .big-btn { margin-top: 0; width: auto; padding: 12px 26px; }

/* ============ Ouro / poção / armas do pause ============ */
#gold { font-size: 16px; font-weight: 900; color: #ffe082; margin-top: 2px; text-shadow: 1px 1px 0 #000; }
#potion-chip {
  position: absolute; top: max(112px, calc(env(safe-area-inset-top) + 104px)); left: max(12px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 4px;
  background: rgba(50,28,10,.85); border: 2px solid #38220f; border-radius: 12px;
  padding: 4px 10px; font-size: 16px; font-weight: 900; color: #ff8a80;
  text-shadow: 1px 1px 0 #000;
}
#pause-weapons { margin: 12px 0 4px; }
#pause-weapons .pw-title { font-size: 12px; letter-spacing: 1px; color: #ffedbe; margin-bottom: 6px; }
#pause-weapons .pw-list { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pw-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 72px; padding: 6px 4px; cursor: pointer; font-family: inherit;
  background: rgba(50,28,10,.5); border: 3px solid #38220f; border-radius: 10px; color: #fff1d2;
}
.pw-item img { width: 34px; height: 34px; image-rendering: pixelated; object-fit: contain; }
.pw-item span { font-size: 8.5px; line-height: 1.1; }
.tbtn.item { width: 48px; height: 48px; right: 150px; bottom: 44px; background: radial-gradient(circle at 35% 30%, #ff5252, #c62828); }

/* ============ Dica de rotação ============ */
#rotate-hint {
  display: none;
  position: fixed; inset: 0; z-index: 99;
  background: #14100a; color: #cddc39;
  font-size: 20px; font-weight: bold; text-align: center;
  padding-top: 40vh;
}
@media (orientation: portrait) and (pointer: coarse) and (max-width: 700px) {
  #rotate-hint { display: block; }
}

/* ============ Mobile-first: telas estreitas ============ */
@media (max-width: 600px) {
  #overlay-card, .cs-card, .shop-card { padding: 14px; }
  #ov-help { flex-direction: column; }
  #ov-text { font-size: 13px; }
  .help-col { font-size: 11px; }
  .char-card { width: 96px; }
  .char-card img { width: 56px; height: 56px; }
  .shop-item { gap: 8px; padding: 8px 10px; }
}

/* ações principais sempre visíveis (sticky) em telas pequenas */
@media (max-width: 600px), (max-height: 480px) {
  #ov-actions { position: sticky; bottom: 0; z-index: 3; background: linear-gradient(to bottom, rgba(110,71,38,0), #6e4726 45%); margin: 8px -14px -14px; padding: 10px 14px 14px; }
  .cs-btns { position: sticky; bottom: 0; z-index: 3; background: linear-gradient(to bottom, rgba(110,71,38,0), #6e4726 45%); margin: 8px -14px -14px; padding: 10px 14px 14px; }
}

/* ============ Mobile-first: altura reduzida (paisagem de celular) ============ */
@media (max-height: 480px) {
  #overlay-card, .cs-card, .shop-card { padding: 10px 14px; max-height: 97%; }
  #ov-title { font-size: clamp(26px, 7vw, 40px); }
  #ov-text { margin: 8px 0; font-size: 12px; }
  #ov-help { margin: 8px 0 10px; }
  .big-btn { padding: 11px; font-size: 16px; }
  .cs-card p { margin-top: 4px; }
}
