:root {
  /* Warm, playful palette */
  --bg-color: #e8e4d9;
  --panel: #fffbfa;
  --border: #232220;
  --primary: #4a7c59;
  --secondary: #6b8ea5;
  --danger: #b55a5a;
  --text: #232220;
  --text-muted: #5c5a55;
  --path: #d4a373;
}

* {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg-color);
  color: var(--text);
  font-family: "Courier New", Courier, monospace;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

/* Fullscreen viewport */
#viewport {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background: var(--bg-color);
}

canvas {
  display: block;
}

/* UI Layer covering the screen, but letting clicks pass through to canvas */
#ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none; /* Let clicks fall through to 3D scene */
  padding: 16px;
}

/* Modular Panels */
.panel {
  position: absolute;
  pointer-events: auto; /* Re-enable clicks on the UI itself */
  background: var(--panel);
  border: 4px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 4px 6px 0 rgba(35, 34, 32, 0.2);
}

/* Positioning the distinct modules */
.top-left {
  top: 16px;
  left: 16px;
  max-width: 280px;
}

.top-right {
  top: 16px;
  right: 16px;
  width: 240px;
}

.middle-left {
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  border-radius: 24px;
}

.bottom-center {
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  border-radius: 24px;
  padding: 12px 16px;
}

h1 {
  margin: 0 0 12px;
  font-size: 1.2rem;
  font-weight: 900;
  text-transform: uppercase;
}

.section {
  margin-bottom: 16px;
}
.section:last-child {
  margin-bottom: 0;
}

label {
  display: block;
  margin: 0 0 6px;
  font-size: 0.8rem;
  font-weight: bold;
}

/* Toy-like Form Elements */
select, button, input {
  font: inherit;
  border: 3px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

select {
  width: 100%;
  padding: 6px 10px;
  outline: none;
  box-shadow: 2px 3px 0 var(--border);
  cursor: pointer;
  font-weight: bold;
}

select:active {
  transform: translate(1px, 2px);
  box-shadow: 1px 1px 0 var(--border);
}

/* Chunky tactile buttons */
button {
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 900;
  box-shadow: 2px 3px 0 var(--border);
  transition: all 0.05s ease;
}

button:hover { background: #eae8e1; }
button:active {
  transform: translate(2px, 3px);
  box-shadow: 0px 0px 0 var(--border);
}

/* Tool Palette specific styling */
.tool {
  font-size: 1.5rem;
  padding: 10px;
  border-radius: 12px; /* Extra round */
  display: flex;
  align-items: center;
  justify-content: center;
}

.tool.active {
  background: #facc15;
  box-shadow: inset 3px 3px 0 rgba(0,0,0,0.1), 0 0 0 var(--border);
  transform: translate(2px, 3px);
  border-color: var(--border);
}

.primary { background: var(--primary); color: #fff; }
.primary:hover { background: #3a6346; }

.danger { background: var(--danger); color: #fff; }
.danger:hover { background: #964848; }

input[type="range"] {
  width: 100%;
  accent-color: var(--border);
}

/* Sticky note style status */
#status {
  padding: 10px;
  background: #fff6c9;
  border: 2px dashed #d4b855;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: bold;
  margin-bottom: 12px;
}

.legend {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  font-size: 0.75rem;
  font-weight: bold;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-radius: 4px;
}


/* Bottom Right Module */
.bottom-right {
  bottom: 16px;
  right: 16px;
  width: 240px;
}

.sub-heading {
  margin: 0 0 8px;
  font-size: 0.9rem;
  font-weight: 900;
  text-transform: uppercase;
  border-bottom: 2px dashed #ccc8bd;
  padding-bottom: 6px;
}

.control-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.8;
}

.control-list li {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Adjust top-left panel now that it has less content */
.top-left {
  max-width: auto;
  display: inline-block;
  /* shrink-wraps to fit the content */
}

#status {
  margin-bottom: 0;
  /* Remove bottom margin since legend is gone */
}



.start-color { background: var(--primary); }
.goal-color { background: var(--danger); }
.explored-color { background: var(--secondary); }
.path-color { background: var(--path); }

@media (max-width: 800px) {
  .top-right { display: none; /* Hide settings on small screens */ }
  .bottom-center { width: 90%; flex-wrap: wrap; justify-content: center; bottom: 8px; }
  .middle-left { flex-direction: row; top: auto; bottom: 70px; left: 50%; transform: translateX(-50%); }
}

/* Make sure it hides gracefully on small screens to avoid clutter */
@media (max-width: 800px) {
  .bottom-right {
    display: none;
  }
}