/* 네모네모월드 — 3D 복셀 샌드박스 UI */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; }
body {
  font-family: 'Noto Sans KR', system-ui, sans-serif;
  color: #fff;
  -webkit-user-select: none; user-select: none;
}
canvas { display: block; }
#game { position: fixed; inset: 0; }
#game canvas { width: 100vw; height: 100vh; }

/* ---------- 상단 HUD ---------- */
#topbar {
  /* z-index 46: #pause(45) 위 — 일시정지 중에도 돌아가기·HUD 버튼 클릭 가능.
     #loading(50)·#menu(55)·모달(60+) 아래라 그 화면에선 정상적으로 가려진다. */
  position: fixed; top: 0; left: 0; right: 0; z-index: 46;
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .7rem;
  pointer-events: none; /* 빈 영역 클릭은 캔버스로 통과(포인터 락) */
}
#topbar > * { pointer-events: auto; }
#topbar .back-pill {
  position: static; /* 공유 css의 플로팅 위치 무력화 */
  margin: 0;
}
#title {
  font-family: 'Do Hyeon', sans-serif;
  font-size: 1.05rem; letter-spacing: .02em;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
}
#hud-right { margin-left: auto; display: flex; align-items: center; gap: .45rem; }
.hud-info {
  font-size: .78rem; font-variant-numeric: tabular-nums;
  padding: .2rem .5rem; border-radius: 8px;
  background: rgba(10,16,30,.5); backdrop-filter: blur(4px);
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
}
.hud-btn {
  width: 34px; height: 34px; border: 0; border-radius: 9px;
  background: rgba(10,16,30,.55); color: #fff; font-size: 1rem; cursor: pointer;
  backdrop-filter: blur(4px); transition: background .15s;
}
.hud-btn:hover { background: #2563eb; }

/* ---------- 조준점 ---------- */
#crosshair {
  position: fixed; top: 50%; left: 50%; width: 22px; height: 22px;
  transform: translate(-50%, -50%); z-index: 9; pointer-events: none;
  mix-blend-mode: difference;
}
#crosshair::before, #crosshair::after {
  content: ''; position: absolute; background: #fff;
}
#crosshair::before { left: 50%; top: 3px; width: 2px; height: 16px; transform: translateX(-50%); }
#crosshair::after { top: 50%; left: 3px; height: 2px; width: 16px; transform: translateY(-50%); }

/* ---------- 핫바 ---------- */
#held {
  position: fixed; bottom: 86px; left: 50%; transform: translateX(-50%);
  z-index: 10; font-size: .9rem; font-weight: 700; pointer-events: none;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
  padding: .15rem .6rem; border-radius: 8px; background: rgba(10,16,30,.35);
}
#hotbar {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  z-index: 10; display: flex; gap: 5px;
  padding: 5px; border-radius: 12px;
  background: rgba(10,16,30,.5); backdrop-filter: blur(6px);
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.slot {
  position: relative; width: 52px; height: 52px; border-radius: 8px;
  background: rgba(255,255,255,.06);
  border: 2px solid rgba(255,255,255,.12);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.slot.active { border-color: #f59e0b; box-shadow: 0 0 0 2px rgba(245,158,11,.4); transform: scale(1.06); }
.slot canvas { width: 40px; height: 40px; image-rendering: pixelated; }
.slot .num {
  position: absolute; top: 1px; left: 4px; font-size: .62rem; opacity: .7;
  text-shadow: 0 1px 2px #000;
}

/* ---------- 로딩 ---------- */
#loading {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem;
  background: radial-gradient(circle at 50% 35%, #1b2b52, #070b18 70%);
}
.load-logo { font-family: 'Do Hyeon', sans-serif; font-size: 2.4rem; color: #fff; letter-spacing: .04em; text-shadow: 0 3px 0 #2563eb; }
.load-sub { color: #9fb3d8; font-size: .95rem; }
.load-track { width: min(360px, 70vw); height: 12px; border-radius: 99px; background: rgba(255,255,255,.12); overflow: hidden; }
#loadbar { height: 100%; width: 0; background: linear-gradient(90deg, #2563eb, #16a34a); transition: width .15s; }
#loadpct { font-variant-numeric: tabular-nums; color: #cdd9f0; }

/* ---------- 일시정지 / 시작 ---------- */
#pause {
  position: fixed; inset: 0; z-index: 45; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: rgba(7,11,24,.55); backdrop-filter: blur(3px);
}
.pause-card { text-align: center; padding: 2rem; }
.pause-card h1 { font-family: 'Do Hyeon', sans-serif; font-size: 2.6rem; margin: 0 0 .3rem; text-shadow: 0 3px 0 #2563eb; }
.pause-card .big { font-size: 1.15rem; color: #cfe0ff; margin: 0 0 1.2rem; }
.pause-card .quick { list-style: none; padding: 0; margin: 0 auto; max-width: 360px; line-height: 1.9; color: #d6def0; font-size: .9rem; }
.pause-card .quick b { color: #f59e0b; }
.pause-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; margin-top: 1.4rem; }
.pause-card .pause-exit, .pause-card .pause-save {
  display: inline-block; margin: 0;
  padding: .6rem 1.2rem; border-radius: 11px;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.22);
  color: #fff; text-decoration: none; font-weight: 700; font-size: .95rem; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.pause-card .pause-save:hover { background: #16a34a; border-color: #16a34a; }
.pause-card .pause-exit:hover { background: #ef4444; border-color: #ef4444; }

/* ---------- 모달 ---------- */
#modal-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.55); }
.modal {
  position: fixed; z-index: 70; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(520px, 92vw); max-height: 84vh; overflow-y: auto;
  background: #121a2e; border: 1px solid rgba(255,255,255,.1); border-radius: 16px;
  padding: 1.1rem 1.3rem 1.4rem; box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { font-family: 'Do Hyeon', sans-serif; font-size: 1.3rem; margin: .1rem 0 .4rem; }
.modal .x { border: 0; background: rgba(255,255,255,.08); color: #fff; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: .9rem; }
.modal .x:hover { background: #ef4444; }
.modal-hint { color: #93a4c8; font-size: .82rem; margin: .2rem 0 .8rem; }
.keys { width: 100%; border-collapse: collapse; }
.keys td { padding: .35rem .4rem; border-bottom: 1px solid rgba(255,255,255,.07); font-size: .9rem; vertical-align: top; }
.keys td:first-child { white-space: nowrap; color: #cfe0ff; width: 38%; }
.keys b { color: #f59e0b; }
.row { display: flex; align-items: center; gap: .7rem; margin: .7rem 0; font-size: .95rem; }
.row input[type=range] { flex: 1; accent-color: #2563eb; }
.row.check { gap: .5rem; }
.row.check input { width: 18px; height: 18px; accent-color: #16a34a; }

#inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: .5rem; }
.inv-cell {
  display: flex; flex-direction: column; align-items: center; gap: .25rem;
  padding: .5rem .3rem; border-radius: 10px; cursor: pointer;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08); color: #d6def0;
}
.inv-cell:hover { background: #2563eb; color: #fff; border-color: #2563eb; }
.inv-cell canvas { width: 44px; height: 44px; image-rendering: pixelated; }
.inv-cell span { font-size: .72rem; }

/* ---------- 터치 안내 ---------- */
#touch-note {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%); z-index: 80;
  background: rgba(18,26,46,.95); border: 1px solid rgba(255,255,255,.12);
  padding: .6rem .9rem; border-radius: 12px; font-size: .82rem; max-width: 90vw; text-align: center;
}
#touch-note button { margin-left: .5rem; border: 0; border-radius: 7px; background: #2563eb; color: #fff; padding: .25rem .7rem; cursor: pointer; }

.hidden { display: none !important; }

@media (max-width: 560px) {
  #title { display: none; }
  .hud-info { display: none; }
  .slot { width: 44px; height: 44px; }
  .slot canvas { width: 34px; height: 34px; }
}

/* ---------- 시작 메뉴 ---------- */
#menu {
  position: fixed; inset: 0; z-index: 55;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #1b2b52, #070b18 72%);
}
.menu-card {
  width: min(380px, 90vw); text-align: center;
  background: rgba(18,26,46,.7); border: 1px solid rgba(255,255,255,.1);
  border-radius: 18px; padding: 1.8rem 1.6rem; backdrop-filter: blur(6px);
}
.menu-card h1 { font-family: 'Do Hyeon', sans-serif; font-size: 2.2rem; margin: 0 0 .2rem; text-shadow: 0 3px 0 #2563eb; }
.menu-sub { color: #9fb3d8; font-size: .9rem; margin: 0 0 1.4rem; }
.menu-field { display: block; text-align: left; font-size: .82rem; color: #cdd9f0; margin: 0 0 .8rem; }
.menu-field .dim { color: #7e8cab; }
.menu-field input {
  display: block; width: 100%; margin-top: .3rem; padding: .55rem .7rem; box-sizing: border-box;
  border-radius: 9px; border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.06); color: #fff; font-size: 1rem;
}
.menu-field input:focus { outline: none; border-color: #2563eb; }
.menu-btns { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.menu-btn {
  padding: .7rem; border: 0; border-radius: 11px; font-size: 1rem; font-weight: 700;
  color: #fff; cursor: pointer; transition: transform .1s, filter .15s;
}
.menu-btn:hover:not(:disabled) { filter: brightness(1.12); transform: translateY(-1px); }
.menu-btn:disabled { opacity: .55; cursor: default; }
.menu-btn.solo { background: #334155; }
.menu-btn.public { background: #2563eb; }
.menu-btn.klass { background: #16a34a; }
.menu-msg { min-height: 1.2em; margin-top: .8rem; font-size: .85rem; color: #fca5a5; }

/* 2단계 메뉴: 모드 선택 → 모드별 패널 */
.menu-step { display: flex; flex-direction: column; }
.mode-grid { display: flex; gap: .5rem; margin-top: 1rem; }
.mode-card {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: .25rem;
  padding: .95rem .4rem; border: 1px solid rgba(255,255,255,.12); border-radius: 13px;
  background: rgba(255,255,255,.06); color: #fff; cursor: pointer;
  transition: transform .1s, background .15s, border-color .15s;
}
.mode-card:hover { background: rgba(37,99,235,.22); border-color: rgba(37,99,235,.6); transform: translateY(-2px); }
.mode-ico { font-size: 1.85rem; line-height: 1; }
.mode-name { font-size: .92rem; font-weight: 700; }
.mode-desc { font-size: .68rem; color: #9fb3d8; }
.step-back {
  align-self: flex-start; background: transparent; border: 0; color: #9fb3d8;
  font-size: .82rem; cursor: pointer; padding: .2rem .1rem; margin-bottom: .2rem;
}
.step-back:hover { color: #e6edfb; }
.step-title { font-size: 1.15rem; margin: .1rem 0 1rem; color: #e6edfb; }

/* ---------- 저장된 월드(C1) ---------- */
.save-section { margin-top: 1rem; text-align: left; }
.save-head { font-size: .8rem; color: #9fb3d8; margin: 0 0 .5rem; }
.menu-btn.continue { background: #0ea5e9; }
.save-list { display: flex; flex-direction: column; gap: .35rem; margin: .5rem 0; max-height: 168px; overflow-y: auto; }
.save-row { display: flex; align-items: center; gap: .4rem; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); border-radius: 9px; padding: .35rem .5rem; }
.save-name { flex: 1; font-size: .82rem; color: #e6edfb; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-act { border: 0; background: rgba(255,255,255,.1); color: #fff; border-radius: 7px; padding: .25rem .5rem; cursor: pointer; font-size: .85rem; }
.save-act:hover { background: #2563eb; }
.save-mini { width: 100%; margin-top: .3rem; padding: .5rem; border: 1px dashed rgba(255,255,255,.25); background: transparent; color: #cdd9f0; border-radius: 9px; cursor: pointer; font-size: .85rem; }
.save-mini:hover { background: rgba(255,255,255,.06); }

/* ---------- 채팅 ---------- */
#chat-wrap { position: fixed; left: 12px; bottom: 92px; z-index: 11; width: min(360px, 60vw); pointer-events: none; }
#chat-log { max-height: 168px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; font-size: .82rem; line-height: 1.35; margin-bottom: 6px; }
#chat-log:empty { display: none; }
.chat-line {
  align-self: flex-start; max-width: 100%; padding: .12rem .5rem; border-radius: 8px;
  background: rgba(10,16,30,.5); color: #eaf0fb; word-break: break-word; text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.chat-line b { color: #7dd3fc; }
#chat-input {
  pointer-events: auto; width: 100%; box-sizing: border-box; padding: .5rem .7rem;
  border-radius: 9px; border: 1px solid #2563eb; background: rgba(10,16,30,.85); color: #fff; font-size: .95rem;
}
#chat-input:focus { outline: none; }
#hint-chat { position: fixed; left: 12px; bottom: 64px; z-index: 10; pointer-events: none; font-size: .72rem; color: #cbd5e1; opacity: .7; text-shadow: 0 1px 2px #000; }

/* ---------- 토스트 / 방 배지 ---------- */
#toast {
  position: fixed; top: 56px; left: 50%; transform: translateX(-50%); z-index: 40;
  background: rgba(10,16,30,.9); border: 1px solid rgba(255,255,255,.14); color: #fff;
  padding: .5rem .9rem; border-radius: 99px; font-size: .85rem; pointer-events: none; box-shadow: 0 6px 18px rgba(0,0,0,.4);
}
#mp-badge { background: rgba(37,99,235,.5); }

/* ---------- 자원 모드: 핫바 카운트 / 빈 슬롯 ---------- */
.slot .count {
  position: absolute; bottom: 1px; right: 4px;
  font-size: .72rem; font-weight: 700; font-variant-numeric: tabular-nums;
  color: #fff; text-shadow: 0 1px 2px #000, 0 0 3px #000; pointer-events: none;
}
.slot.empty canvas { opacity: .3; }
.slot.empty .count { color: #fca5a5; }
.inv-empty { grid-column: 1 / -1; text-align: center; color: #9fb3d8; font-size: .9rem; padding: 1.4rem .5rem; margin: 0; }

/* 솔로 모드 선택 버튼 */
.solo-modes { display: flex; gap: .5rem; }
.solo-modes .menu-btn { flex: 1; }
.menu-btn.solo-res { background: #16a34a; }
.mode-note { font-size: .72rem; color: #7e8cab; margin: .55rem 0 0; line-height: 1.45; text-align: left; }

/* ---------- 제작 모달 (3×3 그리드) ---------- */
.craft-top { display: flex; align-items: center; justify-content: center; gap: .8rem; margin: .2rem 0 1rem; }
.craft-grid { display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px); gap: 4px; }
.craft-cell { width: 48px; height: 48px; padding: 0; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,.06); border: 2px solid rgba(255,255,255,.12); }
.craft-cell:hover { border-color: #2563eb; }
.craft-cell canvas { width: 38px; height: 38px; image-rendering: pixelated; }
.craft-eq { font-size: 1.6rem; color: #16a34a; font-weight: 700; }
.craft-out-slot { position: relative; width: 60px; height: 60px; padding: 0; border-radius: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; background: rgba(245,158,11,.16); border: 2px solid rgba(245,158,11,.55); }
.craft-out-slot:disabled { opacity: .4; cursor: default; background: rgba(255,255,255,.05); border-color: rgba(255,255,255,.12); }
.craft-out-slot:not(:disabled):hover { background: rgba(245,158,11,.32); }
.craft-out-slot canvas { width: 46px; height: 46px; image-rendering: pixelated; }
.craft-out-slot .out-n { position: absolute; right: 3px; bottom: 1px; font-size: .72rem; font-weight: 700; text-shadow: 0 1px 2px #000; }
.craft-label { font-size: .82rem; color: #9fb3d8; margin: 0 0 .4rem; }
.craft-inv { display: grid; grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); gap: .4rem; max-height: 160px; overflow-y: auto; }
.craft-mat { position: relative; height: 50px; padding: 0; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,.05); border: 2px solid rgba(255,255,255,.1); }
.craft-mat:hover { border-color: #2563eb; }
.craft-mat.sel { border-color: #f59e0b; box-shadow: 0 0 0 2px rgba(245,158,11,.4); }
.craft-mat canvas { width: 36px; height: 36px; image-rendering: pixelated; }
.craft-mat .count { position: absolute; right: 3px; bottom: 1px; font-size: .7rem; font-weight: 700; text-shadow: 0 1px 2px #000; }
.craft-recipes { margin-top: 1rem; }
.craft-recipes summary { cursor: pointer; color: #cdd9f0; font-size: .85rem; }
#craft-help { display: flex; flex-direction: column; gap: .35rem; margin-top: .5rem; }
.help-row { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.help-item { display: inline-flex; align-items: center; gap: .1rem; }
.help-item canvas { width: 24px; height: 24px; image-rendering: pixelated; }
.help-item b { font-size: .72rem; color: #cfe0ff; }
.help-arr { color: #16a34a; font-weight: 700; margin: 0 .15rem; }
