/* 블록숲 — UI 스타일 */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Malgun Gothic', '맑은 고딕', 'Segoe UI', system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  /* 웨일북/크롬북: 가로 스와이프가 '뒤로가기 제스처'로 새어 페이지를 벗어나는 것 방지 */
  overscroll-behavior: none;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  display: block;
  cursor: default;
  /* 시점 드래그·터치 제스처가 브라우저 앞뒤 이동으로 해석되지 않게 */
  touch-action: none;
  overscroll-behavior: none;
}

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }

#crosshair {
  position: absolute;
  left: 50%; top: 50%;
  width: 22px; height: 22px;
  transform: translate(-50%, -50%);
  mix-blend-mode: difference;
}
#crosshair::before, #crosshair::after {
  content: '';
  position: absolute;
  background: #ddd;
}
#crosshair::before { left: 50%; top: 0; width: 2px; height: 100%; transform: translateX(-50%); }
#crosshair::after { top: 50%; left: 0; height: 2px; width: 100%; transform: translateY(-50%); }

#vignette {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 62%, rgba(0,0,0,0.28) 100%);
}

#underwater-overlay {
  position: absolute; inset: 0;
  background: rgba(28, 70, 160, 0.22);
}

#hotbar {
  position: absolute;
  left: 50%; bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(0, 0, 0, 0.65);
  border-radius: 4px;
}
.slot {
  position: relative;
  width: 52px; height: 52px;
  background: rgba(60, 60, 60, 0.7);
  border: 2px solid #1a1a1a;
  box-shadow: inset 1px 1px 0 rgba(255,255,255,0.18), inset -1px -1px 0 rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
}
.slot.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.85), inset 0 0 6px rgba(255,255,255,0.25);
}
.slot canvas { width: 44px; height: 44px; image-rendering: pixelated; }
.slot-num {
  position: absolute;
  left: 3px; top: 1px;
  font-size: 10px;
  color: rgba(255,255,255,0.75);
  text-shadow: 1px 1px 0 #000;
}

#item-name {
  position: absolute;
  left: 50%; bottom: 84px;
  transform: translateX(-50%);
  color: #fff;
  font-size: 17px;
  font-weight: bold;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.7);
  opacity: 0;
  transition: opacity 0.4s;
}
#item-name.show { opacity: 1; }

#debug {
  position: absolute;
  left: 8px; top: 8px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.5);
  color: #e6e6e6;
  font-family: Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
  border-radius: 3px;
}

#toast {
  position: absolute;
  left: 50%; bottom: 130px;
  transform: translateX(-50%);
  padding: 8px 18px;
  background: rgba(0, 0, 0, 0.72);
  color: #ffe98a;
  font-size: 15px;
  font-weight: bold;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
#toast.show { opacity: 1; }

#help-hint {
  position: absolute;
  right: 10px; bottom: 10px;
  color: rgba(255,255,255,0.55);
  font-size: 12px;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.8);
}

/* ---------- 공용 패널/버튼 ---------- */
.panel {
  background: rgba(22, 22, 24, 0.92);
  border: 2px solid #000;
  box-shadow: inset 1px 1px 0 rgba(255,255,255,0.12), 0 10px 40px rgba(0,0,0,0.6);
  border-radius: 6px;
  padding: 26px 34px;
  color: #eee;
  text-align: center;
  max-width: min(92vw, 560px);
  max-height: 88vh;
  overflow-y: auto;
}
.panel h2 { margin-bottom: 16px; font-size: 24px; text-shadow: 2px 2px 0 #000; }

.mc-btn {
  display: block;
  width: 300px;
  max-width: 80vw;
  margin: 8px auto;
  padding: 12px 0;
  font-size: 17px;
  font-weight: bold;
  font-family: inherit;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.6);
  background: linear-gradient(#8d8d8d, #6f6f6f 45%, #5a5a5a);
  border: 2px solid #000;
  box-shadow: inset 2px 2px 0 rgba(255,255,255,0.35), inset -2px -2px 0 rgba(0,0,0,0.35);
  cursor: pointer;
}
.mc-btn:hover {
  background: linear-gradient(#a0b8e8, #7d97cf 45%, #6a83bb);
  border-color: #fff;
}
.mc-btn:active { transform: translateY(1px); }
.mc-btn.small { width: 230px; padding: 9px 0; font-size: 15px; }
.mc-btn.danger { background: linear-gradient(#d86a5a, #b84a3a 45%, #9c3a2c); }

.mc-select {
  font-family: inherit;
  font-size: 14px;
  padding: 6px 10px;
  background: #444;
  color: #fff;
  border: 2px solid #000;
}

.row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 10px 0;
  font-size: 15px;
}

/* ---------- 타이틀 ---------- */
#title-screen {
  position: absolute; inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.55) 100%);
}
.title-inner { text-align: center; }
.logo {
  font-size: clamp(64px, 12vw, 130px);
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow:
    3px 3px 0 #3e7a24,
    6px 6px 0 #2c5717,
    9px 9px 0 rgba(0,0,0,0.45),
    0 0 40px rgba(120, 200, 90, 0.35);
}
.subtitle {
  margin-top: 2px;
  color: #cfe8bd;
  font-size: clamp(12px, 2vw, 18px);
  letter-spacing: 0.4em;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.7);
}
.splash {
  display: inline-block;
  margin-top: 14px;
  color: #ffff55;
  font-size: 18px;
  font-weight: bold;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.7);
  transform: rotate(-6deg);
  animation: splashPulse 0.9s ease-in-out infinite alternate;
}
@keyframes splashPulse {
  from { transform: rotate(-6deg) scale(1); }
  to { transform: rotate(-6deg) scale(1.08); }
}
.menu { margin-top: 34px; }
.note {
  margin-top: 26px;
  color: rgba(255,255,255,0.82);
  font-size: 13.5px;
  line-height: 1.7;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.8);
}
.version {
  position: absolute;
  left: 10px; bottom: 8px;
  color: rgba(255,255,255,0.5);
  font-size: 12px;
  text-shadow: 1px 1px 0 #000;
}

#admin-link {
  position: absolute;
  right: 12px; bottom: 8px;
  color: rgba(185, 232, 166, 0.85);
  font-size: 13px;
  text-decoration: none;
  text-shadow: 1px 1px 0 #000;
}
#admin-link:hover { color: #d2f5c0; text-decoration: underline; }

/* ---------- 일시정지/오류 ---------- */
#pause-screen, #error-screen {
  position: absolute; inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}
.controls-help {
  margin-top: 16px;
  font-size: 13px;
  line-height: 1.8;
  color: #c8c8c8;
}
.controls-help b { color: #ffe98a; }
.seed {
  margin-top: 12px;
  font-size: 12px;
  color: #8a8a8a;
  font-family: Consolas, monospace;
}
#error-msg { color: #ff9c8a; margin: 10px 0; }

/* ---------- 팔레트 ---------- */
#palette {
  position: absolute; inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  z-index: 10;
}
.palette-tip { font-size: 13px; color: #a8a8a8; margin-bottom: 14px; }
#palette-grid {
  display: grid;
  grid-template-columns: repeat(7, 64px);
  gap: 6px;
  justify-content: center;
}
.pal-item {
  width: 64px; height: 76px;
  background: rgba(70, 70, 70, 0.75);
  border: 2px solid #1a1a1a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  box-shadow: inset 1px 1px 0 rgba(255,255,255,0.15);
}
.pal-item:hover, .pal-item.hover {
  border-color: #fff;
  background: rgba(110, 110, 110, 0.85);
}
.pal-item canvas { width: 40px; height: 40px; image-rendering: pixelated; pointer-events: none; }
.pal-item span {
  font-size: 10.5px;
  color: #eee;
  text-shadow: 1px 1px 0 #000;
  pointer-events: none;
  white-space: nowrap;
}

#vcursor {
  position: absolute;
  width: 0; height: 0;
  z-index: 20;
  pointer-events: none;
}
#vcursor::after {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 0; height: 0;
  border-left: 12px solid #fff;
  border-bottom: 12px solid transparent;
  border-right: 5px solid transparent;
  filter: drop-shadow(1px 1px 1px rgba(0,0,0,0.9));
}

@media (max-width: 620px) {
  #palette-grid { grid-template-columns: repeat(4, 64px); }
}

/* ---------- 협업/캐릭터 UI ---------- */
#nickname, #roompass, #roomname, #masterkey {
  display: block;
  width: 300px;
  max-width: 80vw;
  margin: 0 auto 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 15px;
  text-align: center;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: 2px solid #000;
  box-shadow: inset 2px 2px 0 rgba(0,0,0,0.5);
  outline: none;
}
#nickname:focus, #roompass:focus, #roomname:focus, #masterkey:focus { border-color: #fff; }
#nickname::placeholder, #roompass::placeholder, #roomname::placeholder, #masterkey::placeholder { color: rgba(255,255,255,0.45); }
#masterkey { margin-bottom: 12px; border-color: #3a3a20; }

.mc-btn.collab {
  background: linear-gradient(#6fbf5a, #4f9c3e 45%, #3d7d2f);
}
.mc-btn.collab:hover { background: linear-gradient(#87d970, #61b34e 45%, #4c9440); border-color: #fff; }
.mc-btn.collab:disabled {
  background: #555;
  color: #999;
  cursor: not-allowed;
  border-color: #333;
}

.collab-note {
  margin-top: 6px;
  font-size: 12.5px;
  color: #b9e8a6;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.8);
  line-height: 1.6;
}

.chk-label {
  font-size: 14px;
  color: #ddd;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}
.chk-label input { width: 16px; height: 16px; accent-color: #6fbf5a; cursor: pointer; }

#online-count {
  position: absolute;
  right: 10px; top: 8px;
  padding: 5px 12px;
  background: rgba(0, 0, 0, 0.5);
  color: #b9e8a6;
  font-size: 13px;
  font-weight: bold;
  border-radius: 3px;
  text-shadow: 1px 1px 0 #000;
}

#nametags { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.nametag {
  position: absolute;
  transform: translate(-50%, -100%);
  padding: 2px 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  border-radius: 3px;
  white-space: nowrap;
  text-shadow: 1px 1px 0 #000;
}

#chat-box {
  position: absolute;
  left: 10px; bottom: 86px;
  width: min(46vw, 440px);
  pointer-events: none;
}
#chat-messages {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
  margin-bottom: 6px;
  max-height: 220px;
  overflow: hidden;
}
.chat-msg {
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 13.5px;
  border-radius: 3px;
  text-shadow: 1px 1px 0 #000;
  animation: chatFade 12s forwards;
  word-break: break-all;
}
.chat-msg b { color: #ffe98a; }
.chat-msg.system { color: #b9e8a6; font-style: italic; }
@keyframes chatFade {
  0%, 75% { opacity: 1; }
  100% { opacity: 0; }
}
#chat-input {
  pointer-events: auto;
  width: 100%;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border: 2px solid rgba(255,255,255,0.6);
  outline: none;
}

/* ---------- 서바이벌 HUD ---------- */
#hearts {
  position: absolute;
  left: 50%; bottom: 72px;
  transform: translateX(-50%);
  display: none;
  gap: 2px;
}
.heart {
  width: 18px; height: 16px;
  background-size: contain;
  background-repeat: no-repeat;
  /* 하트 픽셀아트 (CSS만으로): 빈 하트 테두리 + 채움 오버레이 */
  position: relative;
  filter: drop-shadow(1px 1px 0 rgba(0,0,0,0.7));
}
.heart::before, .heart::after {
  content: '';
  position: absolute;
  width: 8px; height: 13px;
  top: 1px;
  border-radius: 8px 8px 0 0;
  background: #4a1a1a;
}
.heart::before { left: 1px; transform: rotate(-30deg); transform-origin: bottom right; }
.heart::after { right: 1px; transform: rotate(30deg); transform-origin: bottom left; }
.heart.full::before, .heart.full::after { background: #e23b3b; }
.heart.half::before { background: #e23b3b; }
.heart.half::after { background: #4a1a1a; }

/* 허기 (닭다리) — 하트 위 줄 */
#hunger {
  position: absolute;
  left: 50%; bottom: 92px;
  transform: translateX(-50%);
  display: none;
  gap: 2px;
  flex-direction: row-reverse;
}
.drumstick {
  width: 17px; height: 16px;
  position: relative;
  filter: drop-shadow(1px 1px 0 rgba(0,0,0,0.7));
}
/* 닭다리 픽셀아트 근사: 살(둥근 위) + 뼈(아래 막대) */
.drumstick::before {
  content: '';
  position: absolute;
  left: 2px; top: 1px;
  width: 12px; height: 10px;
  border-radius: 7px 7px 5px 5px;
  background: #5a3a1c;
}
.drumstick::after {
  content: '';
  position: absolute;
  left: 5px; bottom: 0;
  width: 6px; height: 7px;
  border-radius: 0 0 3px 3px;
  background: #e7ddc6;
}
.drumstick.full::before { background: #a9662b; }
.drumstick.full::after { background: #f2ead4; }
.drumstick.half::before { background: #a9662b; width: 7px; }
.drumstick.half::after { background: #f2ead4; }

#soak-meter {
  position: absolute;
  left: 50%; bottom: 116px;
  transform: translateX(-50%);
  width: 180px; height: 10px;
  background: rgba(0,0,0,0.5);
  border: 2px solid rgba(0,0,0,0.6);
  border-radius: 6px;
  overflow: hidden;
}
#soak-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #4a9ff0, #2f6 fd0 60%, #7ecbff);
  background: linear-gradient(90deg, #4a9ff0, #2f6fd0 60%, #7ecbff);
  transition: width 0.15s;
}

#boss-bar {
  position: absolute;
  left: 50%; top: 16px;
  transform: translateX(-50%);
  width: min(60vw, 520px);
  text-align: center;
}
#boss-name {
  color: #d9b6ff;
  font-size: 15px;
  font-weight: bold;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.8);
  margin-bottom: 3px;
}
#boss-track {
  height: 12px;
  background: rgba(0,0,0,0.55);
  border: 2px solid #2a1840;
  border-radius: 3px;
  overflow: hidden;
}
#boss-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #7a3dc9, #b06bff);
  transition: width 0.15s;
}

#scoreboard {
  position: absolute;
  right: 10px; top: 44px;
  min-width: 150px;
  padding: 8px 12px;
  background: rgba(0,0,0,0.5);
  color: #eee;
  font-size: 13px;
  border-radius: 4px;
  text-shadow: 1px 1px 0 #000;
}
#scoreboard b { color: #b9e8ff; display: block; margin-bottom: 4px; }
.score-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  line-height: 1.6;
}
.score-row span:last-child { color: #ffe98a; font-weight: bold; }
.team-row { display: flex; justify-content: space-between; gap: 12px; line-height: 1.7; font-weight: bold; }
.team-row .t-red { color: #ff8a8a; }
.team-row .t-blue { color: #8ab6ff; }
.team-row span:last-child { color: #fff; }
.my-team { margin: 4px 0; font-size: 12px; color: #ddd; }
.score-sep { margin-top: 5px; font-size: 11px; color: #9aa; border-top: 1px solid rgba(255,255,255,0.15); padding-top: 3px; }

.mc-btn.summon { background: linear-gradient(#7a3dc9, #5f2ca0 45%, #4a2080); }
.mc-btn.summon:hover { background: linear-gradient(#9a5de9, #7a3dc9 45%, #602ca0); border-color: #fff; }

/* ---------- 인벤토리 ---------- */
#inventory {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  z-index: 10;
}
.inv-panel { max-width: min(94vw, 640px); }
.inv-section-label {
  text-align: left;
  font-size: 12px;
  color: #a8b0bc;
  margin: 10px 0 4px;
}
.opt-section-label {
  font-size: 13px;
  color: #ffd479;
  margin: 12px 0 4px;
  border-top: 1px solid rgba(255,255,255,0.12);
  padding-top: 8px;
}
#inv-creative, #inv-bag, #inv-hotbar, #inv-chest {
  display: grid;
  grid-template-columns: repeat(9, 50px);
  gap: 4px;
  justify-content: center;
}
#inv-chest { grid-auto-rows: 50px; margin-bottom: 4px; }
#inv-creative { grid-auto-rows: 50px; max-height: 260px; overflow-y: auto; padding: 2px; }
#inv-hotbar { margin-top: 2px; }
.inv-slot {
  position: relative;
  width: 50px; height: 50px;
  background: rgba(70, 70, 70, 0.7);
  border: 2px solid #1a1a1a;
  box-shadow: inset 1px 1px 0 rgba(255,255,255,0.15);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.inv-slot.hbslot { background: rgba(90, 80, 60, 0.75); }
.inv-slot:hover, .inv-slot.hover { border-color: #fff; background: rgba(110,110,110,0.85); }
.inv-slot canvas { width: 42px; height: 42px; image-rendering: pixelated; pointer-events: none; }
.inv-slot .count {
  position: absolute; right: 2px; bottom: 0;
  font-size: 12px; font-weight: bold; color: #fff;
  text-shadow: 1px 1px 0 #000; pointer-events: none;
}
.inv-tip { font-size: 12px; color: #a8a8a8; margin-top: 12px; }

#inv-cursor {
  position: absolute;
  width: 42px; height: 42px;
  z-index: 30;
  pointer-events: none;
  transform: translate(-50%, -50%);
  image-rendering: pixelated;
}
#inv-cursor canvas { width: 42px; height: 42px; image-rendering: pixelated; }

/* ---------- 아이템 툴팁 ---------- */
#item-tooltip {
  position: absolute;
  z-index: 40;
  max-width: 240px;
  padding: 8px 11px;
  background: rgba(12, 12, 16, 0.96);
  border: 2px solid #3a3a44;
  border-radius: 5px;
  pointer-events: none;
  box-shadow: 0 6px 20px rgba(0,0,0,0.55);
}
#item-tooltip .tt-name {
  font-size: 14px; font-weight: bold; color: #fff;
  text-shadow: 1px 1px 0 #000;
}
#item-tooltip .tt-kind {
  font-size: 11px; font-weight: normal; color: #9ab;
  border: 1px solid #45505c; border-radius: 3px; padding: 0 4px; margin-left: 4px;
}
#item-tooltip .tt-heal { font-size: 12px; color: #ff9a9a; margin-top: 3px; }
#item-tooltip .tt-desc { font-size: 12px; color: #c8ccd2; margin-top: 4px; line-height: 1.45; }
