:root {
  --bg-dark: #0f172a;
  --bg-panel: #1e293b;
  --bg-hover: #334155;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --danger: #ef4444;
  --border: #334155;
  --toolbar-width: 60px;
  --props-width: 280px;
}

body, html {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: 'Inter', system-ui, sans-serif;
}

.app-layout {
  display: grid;
  grid-template-columns: var(--toolbar-width) 1fr var(--props-width);
  height: calc(100vh - 60px); /* Adjust based on header height if any */
}

/* Toolbar */
.toolbar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 12px;
  z-index: 10;
}

.brand {
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.tool-btn {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  position: relative; /* For tooltip positioning if we added custom ones */
}

.tool-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.tool-btn.active {
  background: var(--accent);
  color: #0f172a;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

.tool-btn svg {
  width: 22px;
  height: 22px;
}

.toolbar-spacer {
  flex: 1;
}

/* Canvas Area */
.canvas-area {
  position: relative;
  background: #0b1120;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* Ensure area takes full available space from grid */
  width: 100%; 
  height: 100%;
}

.canvas-toolbar-top {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  padding: 8px 16px;
  border-radius: 99px;
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 5;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-controls button {
  background: var(--bg-hover);
  border: none;
  color: var(--text-main);
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
}

.zoom-controls span {
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  text-align: center;
}

.helper-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  border-left: 1px solid var(--border);
  padding-left: 16px;
}

.viewport {
  /* The viewport is the scrollable/pannable area container */
  width: 100%;
  height: 100%;
  overflow: auto;
  position: relative;
  background: #0b1120;
  display: flex;
  align-items: center;
  justify-content: center;
}

#mapCanvas {
  display: block;
  width: 800px; /* Fixed size: 800px × 800px */
  height: 800px;
  background: #0f172a;
  box-shadow: 0 0 30px rgba(0,0,0,0.6); /* Stronger shadow for depth */
  border: 1px solid #334155;
  flex: 0 0 800px; /* Prevent flex shrinking */
  position: relative;
}

/* Canvas Container with Resize Handles */
.canvas-container {
  position: relative;
  display: inline-block;
}

/* Resize Handles */
.resize-handle {
  position: absolute;
  background: var(--accent);
  z-index: 20;
  opacity: 0;
  transition: opacity 0.2s;
}

.canvas-container:hover .resize-handle {
  opacity: 0.7;
}

.resize-handle:hover {
  opacity: 1 !important;
  background: var(--accent-hover);
}

/* Right Handle */
.resize-handle-right {
  right: -4px;
  top: 0;
  width: 8px;
  height: 100%;
  cursor: ew-resize;
}

/* Bottom Handle */
.resize-handle-bottom {
  bottom: -4px;
  left: 0;
  width: 100%;
  height: 8px;
  cursor: ns-resize;
}

/* Corner Handle (Bottom-Right) */
.resize-handle-corner {
  right: -4px;
  bottom: -4px;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  border-radius: 50%;
}

/* Active resizing state */
.canvas-container.resizing .resize-handle {
  opacity: 1 !important;
}

.canvas-container.resizing #mapCanvas {
  pointer-events: none;
}

/* Properties Panel */
.properties {
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  height: 100%;
}

/* Layers Section */
.layers-section {
  flex: 0 0 35%; /* Take top part */
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 150px;
}

.layers-section header {
  padding: 16px 20px 10px;
}

.layers-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 10px;
}

.layers-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.layers-list li {
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--bg-dark);
  font-size: 0.85rem;
  cursor: pointer;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 8px;
}

.layers-list li:hover {
  background: var(--bg-hover);
}

.layers-list li.active {
  background: rgba(56, 189, 248, 0.15);
  border-color: rgba(56, 189, 248, 0.3);
  color: var(--accent);
}

.layer-icon {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.empty-msg {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 20px !important;
  background: transparent !important;
  cursor: default !important;
}

.props-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.properties h2 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

#properties-content {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1;
}

/* Quick Guide Styling */
.quick-guide-container {
  padding: 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-dark);
}

.quick-guide h4 {
  margin: 0 0 12px 0;
  font-size: 0.85rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.quick-guide ul {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.85rem;
}

.quick-guide li {
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-muted);
}

kbd {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--text-main);
  min-width: 24px;
  text-align: center;
  display: inline-block;
}

.prop-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.prop-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.prop-group select,
.prop-group input[type="text"],
.prop-group input[type="number"] {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 8px;
  border-radius: 6px;
  font-family: inherit;
}

.prop-group input[type="color"] {
  width: 100%;
  height: 36px;
  background: transparent;
  border: none;
  cursor: pointer;
}

.prop-group input[type="range"] {
  width: 100%;
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.icon-option {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-option:hover {
  border-color: var(--accent);
}

.icon-option.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f172a;
}

.btn-danger {
  width: 100%;
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-danger:hover {
  background: var(--danger);
  color: white;
}

.muted {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  margin-top: 40px;
}

/* Modal Animation & Styling */
@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, -45%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

.modal {
  animation: fadeIn 0.2s ease-out;
}

/* Responsive */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .toolbar {
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
    overflow-x: auto;
  }
  .properties {
    display: none; /* Or a modal/toggle */
  }
  .canvas-area {
    height: 100%;
  }
}
