* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0d1f3c;
  font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: crosshair;
}

.hidden { display: none !important; }

/* === Tela inicial === */
#boot {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0d47a1 0%, #1b5e20 50%, #0d47a1 100%);
  background-size: 300% 300%;
  animation: bg 8s ease infinite;
  z-index: 9999;
  padding: 20px;
}
@keyframes bg {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}
#boot h1 {
  font-size: clamp(28px, 6vw, 56px);
  margin: 0 0 6px;
  text-shadow: 0 0 20px #4CAF50, 0 0 40px #4CAF5044;
  animation: glow 2.4s ease-in-out infinite;
}
#boot h2 {
  font-size: clamp(16px, 3vw, 28px);
  margin: 0 0 4px;
  color: #FFD700;
  font-weight: 500;
}
@keyframes glow {
  0%, 100% { text-shadow: 0 0 20px #4CAF50, 0 0 40px #4CAF5044; }
  50%      { text-shadow: 0 0 40px #FFD700, 0 0 80px #FFD70066; }
}
#boot .sub {
  color: #a5d6a7;
  margin: 4px 0 28px;
  font-size: clamp(12px, 2vw, 16px);
}
#boot button#play {
  background: linear-gradient(135deg, #4CAF50, #2E7D32);
  color: #fff;
  border: none;
  padding: 14px 56px;
  font-size: clamp(15px, 2.4vw, 20px);
  letter-spacing: 1.5px;
  font-weight: bold;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 4px 20px #4CAF5088;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
#boot button#play:hover { transform: scale(1.06); box-shadow: 0 8px 32px #4CAF50aa; }
#boot button#play:active { transform: scale(0.98); }
#boot .creditos {
  margin-top: 22px;
  color: #ffffff44;
  font-size: 11px;
}
#boot .controles-help {
  margin-top: 26px;
  background: rgba(0, 0, 0, 0.35);
  padding: 14px 22px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  max-width: 520px;
}
#boot .controles-help table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
#boot .controles-help th {
  color: #FFD700;
  text-align: center;
  padding-bottom: 8px;
  border-bottom: 1px solid #ffffff22;
}
#boot .controles-help td {
  padding: 4px 8px;
  color: #e0e0e0;
}
#boot .controles-help td:first-child { color: #fff; font-weight: bold; min-width: 110px; }
kbd {
  background: #222;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: monospace;
  font-size: 11px;
  color: #fff;
}

/* === HUD === */
#hud {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 100;
}
#hud .hud-btn,
#hud #hotbar,
#hud .painel,
#hud #morte {
  pointer-events: auto;
}

#crosshair {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px;
  color: #fff;
  text-shadow: 0 0 6px rgba(0,0,0,0.8);
  font-family: monospace;
  font-weight: bold;
  line-height: 1;
}

#topo {
  position: absolute;
  top: 12px; left: 12px;
  background: rgba(0,0,0,0.55);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-family: monospace;
  display: flex;
  gap: 14px;
  align-items: center;
}
#topo #modo { color: #FFD700; font-weight: bold; }
#topo #relogio { color: #FFAB91; }
#topo #fps { color: #80CBC4; }

#bars {
  position: absolute;
  top: 48px; left: 12px;
  background: rgba(0,0,0,0.45);
  padding: 6px 8px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bar {
  display: flex;
  gap: 1px;
  font-size: 11px;
  line-height: 1;
}
.bar span { display: inline-block; width: 12px; text-align: center; }

/* Hotbar */
#hotbar {
  position: absolute;
  bottom: 14px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  background: rgba(0,0,0,0.55);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid #ffffff22;
}
.slot {
  width: 48px; height: 48px;
  background: rgba(255,255,255,0.08);
  border: 1px solid #ffffff22;
  border-radius: 5px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.12s;
}
.slot.sel {
  border-color: #FFD700;
  border-width: 2px;
  background: rgba(255,255,255,0.18);
  width: 56px; height: 56px;
  margin-top: -8px;
  font-size: 22px;
  box-shadow: 0 0 12px #FFD70066;
}
.slot .qtd {
  position: absolute;
  bottom: 2px; right: 4px;
  font-size: 11px;
  font-weight: bold;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

#toast {
  position: absolute;
  top: 80px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: bold;
  border: 1px solid #ffffff22;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
#toast.show { opacity: 1; }

.hud-btn {
  position: absolute;
  background: rgba(50, 50, 60, 0.7);
  border: 1px solid #ffffff33;
  color: #fff;
  width: 44px; height: 44px;
  border-radius: 8px;
  font-size: 22px;
  cursor: pointer;
  transition: background 0.12s;
}
.hud-btn:hover { background: rgba(80, 80, 100, 0.85); }
#btn-bag   { right: 14px; top: 14px; }
#btn-craft { right: 14px; top: 64px; }
#btn-modo  { right: 14px; top: 114px; }
#btn-save  { right: 14px; top: 164px; }
#btn-transp { right: 14px; top: 214px; }
#btn-transp.solido {
  background: rgba(255, 200, 60, 0.85);
  border-color: rgba(255, 200, 60, 0.95);
  box-shadow: 0 0 8px rgba(255, 200, 60, 0.4);
}

/* === Painéis modais === */
.painel {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(20, 20, 38, 0.96);
  border: 2px solid #ffd60099;
  border-radius: 14px;
  padding: 16px;
  z-index: 200;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  min-width: 380px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}
.painel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 18px;
  font-weight: bold;
  color: #FFD700;
}
.fechar {
  background: #c62828;
  border: none;
  color: #fff;
  width: 26px; height: 26px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}
.dica {
  font-size: 10px;
  color: #ffffff77;
  margin: 8px 0 4px;
  text-align: center;
}
/* === Painel inventário com personagem === */
#bag-conteudo {
  display: grid;
  grid-template-columns: minmax(160px, auto) 1fr;
  gap: 18px;
  align-items: start;
}
#bag-armadura {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.armor-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.armor-row-baixo { gap: 14px; margin-top: 4px; }
.armor-slot {
  width: 44px; height: 44px;
  background: rgba(0, 0, 0, 0.4);
  border: 2px dashed rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: all 0.15s;
  font-size: 16px;
}
.armor-slot:hover {
  border-color: #FFD700;
  background: rgba(255, 215, 0, 0.12);
}
.armor-slot.equipado {
  border-style: solid;
  border-color: #FFD700;
  background: rgba(255, 215, 0, 0.18);
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.35);
}
.armor-slot .armor-icon {
  opacity: 0.4;
  font-size: 22px;
}
.armor-slot.equipado .armor-icon { display: none; }
.armor-slot .equip-display {
  font-size: 22px;
  text-align: center;
  width: 100%;
}
.armor-slot .equip-tier {
  position: absolute;
  bottom: 1px; right: 3px;
  font-size: 9px;
  color: #FFD700;
  font-weight: bold;
  text-shadow: 1px 1px 2px #000;
}
.armor-info {
  margin-top: 8px;
  font-size: 11px;
  color: #aaa;
  font-weight: bold;
}
#armor-defesa { color: #FFD700; }

/* Sprite do personagem (mini-boneco voxel) */
.player-sprite {
  width: 64px;
  height: 96px;
  position: relative;
  background: linear-gradient(135deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  border-radius: 4px;
  padding: 2px;
}
.ps-cabeca {
  width: 28px; height: 28px;
  background: #FFCDA4;          /* pele */
  border: 1px solid #B0855B;
  margin: 0 auto 1px;
  border-radius: 3px;
  position: relative;
}
.ps-cabeca::before, .ps-cabeca::after {
  content: '';
  position: absolute;
  top: 10px; width: 4px; height: 4px;
  background: #1A237E;
  border-radius: 1px;
}
.ps-cabeca::before { left: 5px; }
.ps-cabeca::after  { right: 5px; }
.ps-corpo {
  width: 32px; height: 28px;
  background: #E91E63;          /* camisa Rebeca */
  margin: 0 auto;
  border-radius: 2px;
}
.ps-bracos {
  position: absolute;
  top: 30px;
  left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 6px;
}
.ps-braco {
  width: 8px; height: 26px;
  background: #FFCDA4;
  border-radius: 1px;
}
.ps-pernas {
  display: flex;
  gap: 2px;
  justify-content: center;
  margin-top: 1px;
}
.ps-perna {
  width: 12px; height: 24px;
  background: #3F51B5;          /* calça azul */
  border-radius: 1px;
}

/* Layout da coluna direita */
#bag-direito {
  min-width: 0;
}
#bag-grid, #bag-hotbar {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}
#bag-grid .slot, #bag-hotbar .slot { width: 44px; height: 44px; }

/* Mobile: empilha personagem em cima da bag */
@media (max-width: 700px) {
  #bag-conteudo { grid-template-columns: 1fr; gap: 10px; }
  #bag-armadura { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .player-sprite { display: none; }
  #bag-grid .slot, #bag-hotbar .slot { width: 38px; height: 38px; }
}

#craft-status {
  text-align: center;
  font-size: 12px;
  color: #aaa;
  padding: 6px;
  margin-bottom: 8px;
}
#craft-lista {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.receita {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.05);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
}
.receita:hover { background: rgba(255,255,255,0.12); }
.receita .icone { font-size: 22px; width: 32px; text-align: center; }
.receita .info { flex: 1; }
.receita .info .nome { font-weight: bold; font-size: 13px; }
.receita .info .custo { font-size: 10px; color: #aaa; }

/* Tela de morte */
#morte {
  position: fixed; inset: 0;
  background: rgba(150, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 300;
  cursor: pointer;
}
.morte-icone { font-size: 96px; }
#morte h2 { font-size: 38px; margin: 8px 0; text-shadow: 0 2px 12px #000; }
#morte p { color: #ffe0e0; }

/* Mobile: esconde help de teclado e mostra controles touch.
   Reposiciona os 5 .hud-btn em uma FILEIRA horizontal no topo direito
   pra não colidirem com a coluna de botões touch (que ocupa a parte
   inferior direita da tela). */
@media (max-width: 700px), (pointer: coarse) {
  #boot .controles-help { display: none; }
  .hud-btn { width: 38px; height: 38px; font-size: 18px; }
  #btn-bag    { top: 8px; right: 8px; }
  #btn-craft  { top: 8px; right: 54px; }
  #btn-modo   { top: 8px; right: 100px; }
  #btn-save   { top: 8px; right: 146px; }
  #btn-transp { top: 8px; right: 192px; }
  /* HUD topo desce um pouco pra não sobrepor a fileira de botões */
  #topo { top: 52px; }
  #bars { top: 90px; }
}

/* === Controles touch === */
#touch-controls {
  position: fixed; inset: 0;
  z-index: 150;
  pointer-events: none; /* só zonas filhas pegam */
}
#touch-controls .touch-zone,
#touch-controls .t-btn { pointer-events: auto; }

/* Zona de movimento (joystick) à esquerda */
#touch-joy {
  position: absolute;
  left: 16px; bottom: 80px;
  width: 160px; height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Aceita o toque mesmo sem o knob estar exatamente no dedo */
  touch-action: none;
}
.joy-base {
  width: 130px; height: 130px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.30);
  border: 2px solid rgba(255, 255, 255, 0.4);
  position: relative;
  box-shadow: 0 0 14px rgba(0,0,0,0.4) inset;
}
.joy-knob {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  border: 2px solid #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
  pointer-events: none;
  transition: background 0.1s;
}
.joy-knob.ativo { background: rgba(255, 215, 0, 0.85); }

/* Zona de olhar (drag para girar câmera) — ocupa lado direito */
#touch-look {
  position: absolute;
  left: 200px;   /* depois do joystick */
  right: 110px;  /* antes da coluna de botões */
  top: 60px;
  bottom: 60px;
  /* Invisível mas captura toques */
  background: transparent;
  touch-action: none;
}

/* Botões de ação à direita */
#touch-buttons {
  position: absolute;
  right: 14px;
  bottom: 80px;
  display: grid;
  grid-template-columns: repeat(2, 64px);
  gap: 8px;
  touch-action: none;
}
.t-btn {
  width: 64px; height: 64px;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  background: rgba(40, 40, 50, 0.7);
  color: #fff;
  font-size: 26px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 3px 10px rgba(0,0,0,0.4);
  transition: transform 0.1s, background 0.1s;
}
.t-btn:active, .t-btn.pressionado {
  transform: scale(0.95);
  background: rgba(80, 80, 100, 0.95);
  border-color: rgba(255, 215, 0, 0.8);
}
.t-jump   { background: rgba(80, 160, 240, 0.7); }
.t-break  { background: rgba(220, 130, 50, 0.7); }
.t-place  { background: rgba(80, 180, 90, 0.7); }
.t-attack { background: rgba(200, 60, 60, 0.7); }
.t-down   { background: rgba(80, 120, 200, 0.7); }

/* Em paisagem só, esconde botões em portrait pra forçar landscape */
@media (orientation: portrait) and (pointer: coarse) {
  #touch-controls::after {
    content: '🔄  Por favor, gire o aparelho para paisagem';
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.85);
    color: #FFD700;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
  }
}

/* Telas pequenas: hotbar mais compacta */
@media (max-width: 500px) {
  #hotbar { gap: 2px; padding: 2px; }
  .slot { width: 38px; height: 38px; font-size: 14px; }
  .slot.sel { width: 46px; height: 46px; font-size: 18px; margin-top: -6px; }
  #touch-buttons { grid-template-columns: repeat(2, 56px); gap: 6px; bottom: 70px; }
  .t-btn { width: 56px; height: 56px; font-size: 22px; }
  #touch-joy { width: 140px; height: 140px; left: 10px; bottom: 70px; }
  .joy-base { width: 110px; height: 110px; }
  .joy-knob { width: 48px; height: 48px; }
  #touch-look { left: 170px; right: 90px; }
}
