* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: #1a1a22;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #eee;
  overflow-x: auto;
  overflow-y: hidden;
}

#world {
  position: relative;
  height: 100vh;
  width: max-content;
  min-width: 100vw;
}

#bgCanvas {
  display: block;
  height: 100vh;
  width: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#objectsLayer, #playerLayer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#surfacesCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: none;
}
body.admin-open #surfacesCanvas { display: block; }
body.drawing-mode #world,
body.drawing-mode .game-obj,
body.drawing-mode .player { cursor: crosshair !important; }
body.drawing-mode .game-obj,
body.drawing-mode .player { pointer-events: none; }

#surfacesList .surface-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  margin-top: 6px;
  background: #2a2a38;
  border-radius: 5px;
  font-size: 0.8em;
}
#surfacesList .surface-item button {
  background: #8a4a4a;
  padding: 4px 8px;
  font-size: 0.75em;
}
#btnDrawSurface.active { background: #6a8a4a; }

.game-obj, .player {
  position: absolute;
  pointer-events: auto;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.game-obj:active, .player:active { cursor: grabbing; }
body.drawing-mode #world { touch-action: none; }

#emptyHint {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.6);
  padding: 1.5em 2em;
  border-radius: 8px;
  text-align: center;
  font-size: 1.1em;
  pointer-events: none;
}
#emptyHint.hidden { display: none; }

#topBar {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  z-index: 100;
  background: rgba(20, 20, 30, 0.85);
  padding: 8px 12px;
  border-radius: 8px;
  backdrop-filter: blur(6px);
}
#topBar button, #poseSwitcher button {
  background: #3a3a52;
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9em;
}
#topBar button:hover, #poseSwitcher button:hover { background: #4a4a6a; }
#poseSwitcher { display: flex; gap: 6px; }
#poseSwitcher button.active { background: #6a8a4a; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal.hidden, .hidden { display: none; }
.modal-content {
  background: #2a2a3a;
  padding: 24px;
  border-radius: 12px;
  min-width: 320px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-content.wide { min-width: 500px; }
.modal-content h2 { margin-bottom: 16px; }
.modal-content label { display: block; margin: 12px 0; font-size: 0.9em; color: #bbb; }
.modal-content input[type="text"],
.modal-content input[type="password"],
.modal-content input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  background: #1a1a22;
  border: 1px solid #444;
  color: #fff;
  border-radius: 6px;
  font-size: 1em;
}
.modal-actions {
  margin-top: 20px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.modal-actions button {
  background: #4a6a8a;
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  cursor: pointer;
}
.modal-actions button.danger { background: #8a4a4a; }
.modal-actions button:hover { filter: brightness(1.2); }

.error { color: #ff8a8a; margin-top: 10px; }

#adminPanel {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  height: 100vh;
  background: #22222e;
  padding: 20px;
  overflow-y: auto;
  z-index: 500;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
}
#adminPanel.hidden { display: none; }
.admin-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.admin-header button { background: #444; color: #fff; border: none; padding: 6px 12px; border-radius: 4px; cursor: pointer; }
#adminPanel section { margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid #333; }
#adminPanel h3 { margin-bottom: 10px; font-size: 1em; color: #aaa; }
#adminPanel button {
  background: #3a5a8a;
  color: #fff;
  border: none;
  padding: 8px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.9em;
}
#adminPanel button:hover { background: #4a6a9a; }
.info { font-size: 0.8em; color: #888; margin-top: 6px; }
.hint { font-size: 0.8em; color: #888; line-height: 1.5; }
.hint-inline { font-size: 0.78em; color: #777; font-weight: normal; }
.scale-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}
.scale-row label { flex: 1; }
.scale-row button { white-space: nowrap; flex-shrink: 0; }

#objectsList .item, #posesList .item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  margin-top: 6px;
  background: #2a2a38;
  border-radius: 5px;
  cursor: pointer;
}
#objectsList .item:hover, #posesList .item:hover { background: #34344a; }
#objectsList .item canvas, #posesList .item canvas {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  background: #111;
  border-radius: 3px;
}
.item-name { flex: 1; margin-left: 10px; font-size: 0.9em; }

.state-row { display: flex; gap: 16px; margin-top: 16px; }
.state-col { flex: 1; text-align: center; }
.state-col h4 { margin-bottom: 8px; font-size: 0.9em; color: #aaa; }
.preview {
  display: block;
  width: 100%;
  max-height: 160px;
  background: #111;
  border-radius: 6px;
  margin-top: 8px;
  image-rendering: pixelated;
}

/* ============== MOBILE / NARROW VIEWPORTS ============== */
@media (max-width: 700px) {
  #adminPanel {
    width: 100%;
    max-width: 100%;
  }
  .modal-content {
    min-width: 0;
    width: 92vw;
  }
  .modal-content.wide { min-width: 0; width: 92vw; }
  .state-row { flex-direction: column; gap: 12px; }
  #topBar {
    top: 8px;
    right: 8px;
    left: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    padding: 6px 8px;
  }
  #topBar button, #poseSwitcher button {
    padding: 6px 10px;
    font-size: 0.8em;
  }
}
