:root {
  /* Dark Mode (Default) */
  --bg-primary: #152026; /* page background - darkest */
  --bg-secondary: #142426; /* panels - slightly lighter than primary */
  --bg-tertiary: #224040; /* inner panels - distinct dark green-blue */
  --text-primary: #e0e6eb; /* very light gray for main text */
  --text-secondary: #aabcc4; /* slightly darker light gray for secondary text */
  --text-muted: #7f909c; /* muted gray for less prominent text */
  --border-primary: #334155; /* dark blue-gray for primary borders */
  --border-secondary: #475569; /* slightly lighter blue-gray for secondary borders */
  --tile-bg: url("assets/map/floor_bg.png"); /* Dark mode specific tile background */
  --tile-blocked: url("assets/map/wall_tree_dark_a.png"); /* Dark mode specific blocked tile */
}
body.light-mode {
  /* Light Mode Overrides */
  --bg-primary: #f5f9e0; /* A very light yellow-green, derived from #EBF2B3 */
  --bg-secondary: #fcfdf7; /* A clean, slightly warm off-white for panels */
  --bg-tertiary: #ebf2b3; /* The lightest of the provided colors for inner panels */
  --text-primary: #525936; /* A dark olive green for high contrast text */
  --text-secondary: #73804a; /* A medium olive green for secondary text */
  --text-muted: #93a16c; /* A softer olive for muted text */
  --border-primary: #afbf75; /* The mid-tone green for primary borders */
  --border-secondary: #c8d98b; /* The lighter green for secondary borders */
  --tile-bg: url("assets/map/floor_bg.png"); /* Light mode specific tile background */
  --tile-blocked: url("assets/map/wall_tree_a.png"); /* Light mode specific blocked tile */
}

html {
  height: 100%;
}
body {
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
  min-height: 100%;
  font-family: "Pretendard", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  background-image: url("assets/background/forest_tile_dark.png");
  background-repeat: repeat;
  background-size: 256px 256px; /* 필요시 192~320로 조절 */
}
body.light-mode {
  background-image: url("assets/background/forest_tile_light.png");
}

main {
  flex-grow: 1;
}
.font-orbitron {
  font-family: "Orbitron", sans-serif;
}
.bg-main {
  background-color: var(--bg-secondary);
}
.bg-sub {
  background-color: var(--bg-tertiary);
}
.border-main {
  border-color: var(--border-primary);
}
.border-sub {
  border-color: var(--border-secondary);
}
.text-main {
  color: var(--text-primary);
}
.text-sub {
  color: var(--text-secondary);
}
.text-muted {
  color: var(--text-muted);
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-size), 1fr);
  grid-template-rows: repeat(var(--grid-size), 1fr);
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-primary);
}

#map-grid {
  background-image: var(--tile-bg);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

.grid-cell {
  position: relative;
  background: transparent;
}
/* 지나갈 수 없는 타일에만 안쪽 그림자로 부드러운 경계 효과(vignette)를 적용합니다. */
.grid-cell:not(.passable) {
  box-shadow: inset 0 0 12px 4px rgba(0, 0, 0, 0.25);
}

.grid-cell.passable {
  /* 지나갈 수 있는 타일에 아주 은은한 비네팅 효과를 추가합니다. */
  box-shadow: inset 0 0 10px 4px rgba(0, 0, 0, 0.1);
}

.grid-cell:not(.passable)::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(
    --wall-img,
    var(--tile-blocked)
  ); /* per-cell 변수, 없으면 기본값 */
  background-repeat: no-repeat;
  background-position: center;
  background-size: 90% 90%; /* 80~95% 사이 취향대로 */
  transform: rotate(var(--wall-rot, 0deg)) scaleX(var(--wall-flip, 1));
  transform-origin: center center;
  pointer-events: none; /* 드래그/클릭 간섭 방지 */
}

.grid-cell,
#map-grid {
  image-rendering: auto;
}

#player,
.map-item {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--cell-size);
  height: var(--cell-size);
  transition: transform 0.5s ease-in-out;
  will-change: transform;
  display: flex;
  align-items: center;
  justify-content: center;
}
#player {
  z-index: 10;
}

#target {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--cell-size);
  height: var(--cell-size);
  transition: transform 0.5s ease-in-out;
  will-change: transform;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: var(--tw-translate, translate(0, 0));
}

.slot {
  background-color: var(--bg-tertiary);
  border: 2px dashed var(--border-primary);
  aspect-ratio: 1 / 1;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.slot.over {
  background-color: #4b5563;
  border-color: #6b7280;
}
body.light-mode .slot.over {
  background-color: #d1d5db;
  border-color: #9ca3af;
}

.item {
  width: 100%;
  height: 100%;
  cursor: grab;
  user-select: none;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1px;
  padding: 2px;
  border-radius: 0.375rem;
  position: relative;
  touch-action: none;
}

.item.vector {
  background: transparent !important;
  border: none !important;
}
.item.vector img {
  image-rendering: auto;
}
.item.dragging-source {
  opacity: 0.3;
}

.item img {
  max-width: 85%;
  max-height: 85%;
  image-rendering: auto;
}

.ghost-item {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  transform: translate(-50%, -50%) scale(1.1);
  opacity: 0.8;
}
.item:active {
  cursor: grabbing;
}
.pouch {
  animation: pulse-pouch 2.5s infinite;
}
@keyframes pulse-pouch {
  0% {
    box-shadow: 0 0 8px #d9aa8f;
  }
  50% {
    box-shadow: 0 0 20px #d9aa8f;
  }
  100% {
    box-shadow: 0 0 8px #d9aa8f;
  }
}

.message-box {
  position: fixed;
  bottom: -100px;
  left: 50%;
  transform: translateX(-50%);
  transition: bottom 0.5s ease-in-out;
  z-index: 100;
}
.message-box.show {
  bottom: 20px;
}
#ending-popup,
#gameover-popup,
#help-modal,
#confirm-reset-popup {
  transition: opacity 0.5s, visibility 0.5s;
}

.map-coord {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-family: "Orbitron", sans-serif;
  text-align: center;
}

.count-badge {
  position: absolute;
  top: 4px;
  right: 6px;
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  border-radius: 9999px;
  padding: 2px 6px;
}

.tab-btn {
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
}
.tab-btn.active {
  background-color: #4f46e5;
  color: white;
}

#workbench-panel {
  background-image: url("assets/background/wood_tile.png");
  background-size: 320px 320px;
  background-repeat: repeat;
  border-color: #b48a5a !important; /* warm brown border */
  box-shadow: inset 0 0 0 2px rgba(136, 94, 52, 0.15),
    0 10px 24px rgba(0, 0, 0, 0.12);
}
#workbench-panel .slot {
  background-color: rgba(255, 255, 255, 0.65);
  border-color: rgba(180, 138, 90, 0.55);
}

/* --- Item Specific Styles --- */

/* 마법서 (Recycler) */
.item.recycler {
  background-color: #f2c166;
  border-color: #a67449;
  border-width: 2px;
}
.item.recycler .count-badge {
  background-color: #a67449;
  color: white;
}
.item.recycler .item-name {
  color: #6b4d30;
}

/* 소환구슬 (Pouch) */
.item.pouch {
  background-color: #f2d7b6;
  border-color: #d9aa8f;
  border-width: 2px;
}
.item.pouch .count-badge {
  background-color: #b08c75;
  color: white;
}
.item.pouch .item-name {
  color: #8c6f5c;
}

/* 정령 결정 (Residue) */
.item.residue-1 {
  background-color: #edced4;
  border-color: #c6acbf;
  border-width: 2px;
}
.item.residue-1 .count-badge {
  background-color: #c6acbf;
  color: white;
}
.item.residue-1 .item-name {
  color: #4a3c4d;
}

.item.residue-2 {
  background-color: #c6acbf;
  border-color: #9f85a6;
  border-width: 2px;
}
.item.residue-2 .count-badge {
  background-color: #9f85a6;
  color: white;
}
.item.residue-2 .item-name {
  color: #4a3c4d;
}

.item.residue-3 {
  background-color: #9f85a6;
  border-color: #7a6880;
  border-width: 2px;
}
.item.residue-3 .count-badge {
  background-color: #7a6880;
  color: #e0e0e0;
}
.item.residue-3 .item-name {
  color: white;
}

/* 스칼라 (Scalar) */
.item.scalar {
  background-color: #f3f4f6; /* bg-gray-100 */
  border-color: #9ca3af; /* border-gray-400 */
  border-width: 2px;
}
