:root {
  --bg: #0b0e11;
  --panel: #12171d;
  --grid-line: rgba(255,255,255,0.08);
  --grid-line-strong: rgba(255,255,255,0.14);
  --text: #e8edf4;
  --muted: #9aa7b6;
  --accent: #6fc29a;      /* tactical green/teal */
  --accent-2: #5bc28a;
  --danger: #e57373;
  --item-weapon: #4a5a4f;  /* gunmetal green */
  --item-med: #c9a8a5;     /* muted medic red/cream */
  --item-mag: #9c8b5f;     /* brass/olive */
  --item-bag: #5f6b44;     /* ranger green */
  --item-misc: #b69759;    /* coyote brown */
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 10% 15%, rgba(111,194,154,0.04), transparent 28%),
              radial-gradient(circle at 80% 10%, rgba(91,194,138,0.05), transparent 30%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#app { max-width: 1200px; margin: 0 auto; padding: 16px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--panel); border: 1px solid var(--grid-line);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.brand { font-weight: 700; letter-spacing: 0.5px; }
.controls { display: flex; gap: 10px; align-items: center; }
button {
  background: #2a3040; color: var(--text); border: 1px solid var(--grid-line);
  border-radius: 8px; padding: 8px 12px; cursor: pointer; transition: transform 0.12s ease, border-color 0.2s;
}
button:hover { transform: translateY(-1px); border-color: var(--accent); }
button.primary { background: linear-gradient(120deg, #4fd1c5, #667eea); color: #0a0c12; font-weight: 700; }

.layout {
  display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-top: 16px;
  align-items: start;
}
.inventory-panel, .side-panel {
  background: var(--panel); border: 1px solid var(--grid-line); border-radius: 12px;
  padding: 12px; box-shadow: 0 12px 32px rgba(0,0,0,0.25);
  min-height: 560px;
}
.inventory-panel h2, .side-panel h3 { margin: 4px 0 12px; }
.grid {
  position: relative;
  background: #0d1117;
  border: 1px solid var(--grid-line);
  border-radius: 10px;
  display: block;
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: var(--cs, 42px) var(--cs, 42px);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04), 0 12px 28px rgba(0,0,0,0.35);
}
.grid.placeholder { display: grid; place-items: center; color: var(--muted); }
#mainGrid { --cs: 42px; }
.container-view .grid { --cs: 36px; }

.item-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow: auto; padding-right: 4px; }
.item-tile {
  position: relative;
  padding: 10px; background: #202633; border: 1px solid var(--grid-line);
  border-radius: 8px; cursor: grab; display: flex; justify-content: space-between;
  align-items: center; user-select: none;
}
.item-tile .meta { font-size: 12px; color: var(--muted); }

.cell {
  border: 1px solid var(--grid-line);
  background: rgba(255,255,255,0.018);
  transition: box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
.blocked-cell {
  position: absolute;
  background: linear-gradient(135deg, rgba(255,255,255,0.05) 25%, rgba(0,0,0,0.2) 25%, rgba(0,0,0,0.2) 50%, rgba(255,255,255,0.05) 50%, rgba(255,255,255,0.05) 75%, rgba(0,0,0,0.2) 75%, rgba(0,0,0,0.2) 100%);
  background-size: 12px 12px;
  border: 1px dashed rgba(255,255,255,0.12);
  box-sizing: border-box;
  pointer-events: none;
}

.item-rect {
  position: absolute;
  border-radius: 6px; color: #0b0d13; font-size: 12px;
  font-weight: 700; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 4px; box-shadow: 0 8px 18px rgba(0,0,0,0.35);
  border: 2px solid rgba(255,255,255,0.85); /* solid outline covers full grid footprint */
  box-sizing: border-box;
}
.grid .item-rect {
  width: 100%;
  height: 100%;
}
.item-rect.weapon { background: var(--item-weapon); color: #e6ebee; }
.item-rect.med { background: var(--item-med); color: #1a0f0f; }
.item-rect.mag { background: var(--item-mag); color: #0e0c06; }
.item-rect.ammo { background: #d9c07a; color: #0e0c05; }
.item-rect.armor { background: #4a6279; color: #eef3f8; }
.item-rect.bag { background: var(--item-bag); color: #e7eddc; }
.item-rect.misc { background: var(--item-misc); color: #0f0c06; }
.item-rect.dragging { opacity: 0.7; pointer-events: none; z-index: 20; }
.item-rect.invalid { outline: 2px solid var(--danger); }
.item-rect.dragging { width: auto; height: auto; }
.item-rect.immovable { border-color: rgba(255,255,255,0.35); background: #555b6a; color: #e5e9f0; cursor: default; }
.item-rect .item-icon {
  position: absolute;
  inset: 4px;
  width: calc(100% - 8px);
  height: calc(100% - 8px);
  object-fit: contain;
  opacity: 0.9;
  pointer-events: none;
  mix-blend-mode: screen;
}
.item-badge {
  position: absolute;
  bottom: 4px;
  left: 4px;
  right: 4px;
  font-size: 10px;
  background: rgba(0,0,0,0.5);
  color: #e8edf4;
  border-radius: 5px;
  padding: 2px 4px;
  line-height: 1.2;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  pointer-events: none;
}

.side-panel { display: flex; flex-direction: column; gap: 12px; height: 100%; }
.unplaced { flex: 0 0 240px; }
.container-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--grid-line);
  border-radius: 10px;
  padding: 8px;
  min-height: 420px;
}
.container-view .grid {
  align-self: center;
}
.container-header { display: flex; align-items: center; justify-content: space-between; }
.breadcrumb { color: var(--muted); font-size: 12px; }

.modal {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: rgba(0,0,0,0.45); backdrop-filter: blur(3px);
}
.modal.hidden { display: none; }
.modal-content {
  background: #141821; padding: 18px; border-radius: 12px; border: 1px solid var(--grid-line);
  min-width: 280px; text-align: center; box-shadow: 0 16px 40px rgba(0,0,0,0.4);
}
.modal-actions { display: flex; justify-content: center; gap: 10px; margin-top: 12px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1f2532; border: 1px solid var(--grid-line); padding: 10px 14px;
  border-radius: 10px; color: var(--text); box-shadow: 0 10px 24px rgba(0,0,0,0.3);
  opacity: 0; transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }

.valid-highlight { box-shadow: 0 0 0 2px var(--accent-2), 0 0 12px rgba(91,194,138,0.55); }
.invalid-highlight { box-shadow: 0 0 0 2px var(--danger), 0 0 12px rgba(229,115,115,0.55); }

@media (max-width: 960px) {
  #app { padding: 10px; }
  .layout { grid-template-columns: 1fr; }
  .side-panel { grid-template-rows: auto auto; }
}

/* Footprint overlay for drag preview */
.footprint {
  position: absolute;
  pointer-events: none;
  border: 2px dashed var(--accent-2);
  background: rgba(91, 194, 138, 0.14);
  border-radius: 6px;
  z-index: 5;
  box-shadow: 0 0 12px rgba(91,194,138,0.35);
}
.footprint.invalid {
  border-color: var(--danger);
  background: rgba(255, 107, 107, 0.12);
}

/* Loading overlay */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  z-index: 100;
}
.loading.hidden { display: none; }
.loading-card {
  background: #141821;
  border: 1px solid var(--grid-line);
  border-radius: 12px;
  padding: 16px 20px;
  box-shadow: 0 18px 48px rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  gap: 12px;
}
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255,255,255,0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.loading-text { color: var(--text); font-weight: 600; }
@keyframes spin { to { transform: rotate(360deg); } }
