:root {
  --cell-size: 10vh; /* default: 10% of window height */
  --gap: 4px; /* thin line between tiles */
  --bottom-controls-height: 64px; /* height of the bottom controls area */
}
/* Utility hidden class used by modal/preview */
.hidden {
  display: none !important;
}
* {
  box-sizing: border-box;
}
body {
  font-family: system-ui, Segoe UI, Roboto, Arial;
  margin: 0;
  background: #000;
  color: #fff;
  overflow: hidden;
}

#app {
  height: 100vh;
  width: 100%;
  min-width: 0;
}
#grid-wrap {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  overflow-x: auto;
  overflow-y: auto;
  scrollbar-gutter: stable both-edges;
  position: relative;
  padding: 0;
}

#grid {
  display: grid;
  grid-auto-rows: var(--cell-size);
  gap: var(--gap);
  background: #000;
  margin-inline: auto;
  margin-block: 0;
  min-width: 0;
  width: max-content;
}
/* Each cell is a white tile. The grid's black background shows through the gap as the thin line between tiles. */
.cell {
  width: var(--cell-size);
  aspect-ratio: 1/1;
  border: none;
  background: black;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.cell.phantom {
  background: rgb(37, 37, 37); /* muted grey so phantom tiles don't stand out */
  cursor: pointer;
}
.cell.phantom .label {
  color: white;
}
.cell.placed {
  background: black;
}
.cell.absent {
  background: transparent;
  pointer-events: none;
}
.cell .label {
  pointer-events: none;
  color: #111;
  font-size: 1rem;
}
.cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border: none;
  padding: 0;
  margin: 0;
}

/* Modal */
#modal.hidden {
  display: none;
}
#modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}
.modal-content {
  position: relative;
  z-index: 51;
  background: #fff;
  padding: 18px;
  border-radius: 8px;
  max-width: 900px;
  width: 92%;
  max-height: 90vh;
  overflow: auto;
  color: #111;
}
.modal-content h3 {
  margin-top: 0;
}
#gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.thumb {
  width: 110px;
  height: 110px;
  border: none;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px;
  background: transparent;
}
.thumb img {
  max-width: 64px;
  max-height: 64px;
  background: transparent;
}
.thumb .controls {
  margin-top: 8px;
  display: flex;
  gap: 6px;
}
.thumb button {
  padding: 4px 8px;
}

#preview {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#preview-inner {
  background: #fff;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid #ccc;
  display: flex;
  flex-direction: column;
  align-items: center;
}
#preview img {
  width: 160px;
  height: 160px;
  object-fit: contain;
}
.preview-controls {
  margin-top: 10px;
  display: flex;
  gap: 10px;
}

.close {
  position: absolute;
  right: 8px;
  top: 8px;
  border: none;
  background: transparent;
  font-size: 18px;
}

@media (max-width: 480px) {
  .thumb {
    width: 80px;
    height: 80px;
  }
}

/* Visual target highlight when moving connectors */
.move-target {
  outline: 3px solid rgba(0, 200, 0, 0.9);
  box-shadow: 0 0 8px rgba(0, 200, 0, 0.4) inset;
  cursor: pointer;
}

/* Bottom controls fixed to the bottom; always on top of icons */
#bottom-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--bottom-controls-height);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 49; /* sits above grid icons but below the modal (modal z-index=50) */
  background: rgba(0, 0, 0, 0.85);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding: 8px 12px;
}

/* Inner wrapping for consistent spacing */
#bottom-controls .controls-inner {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Slight visual polish for the select and button so they remain readable */
#bottom-controls select,
#bottom-controls button {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#save-btn:disabled {
  opacity: 0.2;
}

#save-btn.saving {
  background: green;
  opacity: 1;
}

.level-btn {
  font-size: 1em;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.level-btn.active {
  background: rgba(255, 255, 255, 0.2);
}

@media (max-width: 480px) {
  :root {
    --bottom-controls-height: 72px;
  }
  #bottom-controls {
    padding: 10px 6px;
  }
}
