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

body {
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
}

canvas {
  display: block;
}

#ui {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 200px;
  padding: 14px 16px;
  background: rgba(255, 250, 240, 0.9);
  border-radius: 14px;
  box-shadow: 0 4px 18px rgba(80, 60, 30, 0.18);
  user-select: none;
}

#ui-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

#ui h1 {
  font-size: 16px;
  color: #5a4632;
}

#ui-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

#ui #help,
#ui #hideui {
  padding: 2px 6px;
  font-size: 11px;
  line-height: 1;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #a08c6e;
}

#ui #help {
  font-size: 13px;
  font-weight: 700;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
}

#ui #help:hover,
#ui #hideui:hover {
  background: #f2e7d0;
  color: #5a4632;
}

/* Leaf button left behind when the toolbar is hidden — same corner spot. */
#showui {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  width: 42px;
  height: 42px;
  font-size: 20px;
  border: 1px solid #d8c9ae;
  border-radius: 12px;
  background: rgba(255, 250, 240, 0.9);
  box-shadow: 0 4px 18px rgba(80, 60, 30, 0.18);
  cursor: pointer;
}

#showui:hover {
  background: #f2e7d0;
}

body.uihidden #ui {
  display: none;
}

body.uihidden #showui {
  display: block;
}

body.photo #showui {
  display: none;
}

/* Toolbar sections: a slim uppercase heading over each group, separated by
   soft dividers. Each group is a <details> so its heading collapses it —
   handy when the window is too short for the full toolbar. */
.group {
  padding-top: 8px;
  margin-top: 8px;
  border-top: 1px solid rgba(122, 106, 83, 0.18);
}

.group:first-of-type {
  padding-top: 0;
  margin-top: 0;
  border-top: none;
}

.group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  cursor: pointer;
}

.group summary::-webkit-details-marker {
  display: none;
}

.group summary::after {
  content: "▸";
  font-size: 9px;
  color: #a08c6e;
  transition: transform 0.15s;
}

.group[open] summary::after {
  transform: rotate(90deg);
}

.group[open] summary {
  margin-bottom: 6px;
}

.group h2 {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #a08c6e;
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.tools button {
  flex: 1 1 calc(50% - 6px);
}

#ui button {
  font: inherit;
  font-size: 12px;
  padding: 7px 8px;
  border: 1px solid #d8c9ae;
  border-radius: 9px;
  background: #fdf8ee;
  color: #5a4632;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#ui button:hover {
  background: #f2e7d0;
}

#ui button.active {
  background: #7d9c5b;
  border-color: #6b8a4c;
  color: #fff;
}

.submenu {
  display: none;
  position: absolute;
  z-index: 10;
  gap: 4px;
  padding: 5px;
  flex-wrap: wrap;
  max-width: 180px;
  background: #fffdf7;
  border: 1px solid #d8c9ae;
  border-radius: 10px;
  box-shadow: 0 6px 16px rgba(80, 60, 30, 0.25);
}

.submenu.open {
  display: flex;
}

.row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.row button {
  flex: 1;
}

#ui button:disabled {
  opacity: 0.45;
  cursor: default;
}

#ui button:disabled:hover {
  background: #fdf8ee;
}

#clear {
  width: 100%;
}

/* Palette swatch row: small colored dots that set the plant color mood. */
.palette {
  display: flex;
  align-items: center;
  gap: 8px;
}

.palette span {
  font-size: 11px;
  font-weight: 600;
  color: #7a6a53;
}

.swatches {
  display: flex;
  gap: 6px;
}

#ui .swatches button {
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 1px 3px rgba(80, 60, 30, 0.3);
}

#ui .swatches button:hover {
  background: var(--c);
  transform: scale(1.12);
}

#ui .swatches button.active {
  border-color: #5a4632;
  background: var(--c);
}

/* Ambient wildlife toggle switches (Wildlife Spawner section). */
.switches {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 600;
  color: #7a6a53;
  cursor: pointer;
}

.switch input {
  display: none;
}

.switch .slider {
  flex-shrink: 0;
  width: 26px;
  height: 14px;
  border-radius: 7px;
  background: #d8c9ae;
  position: relative;
  transition: background 0.15s;
}

.switch .slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fffdf7;
  box-shadow: 0 1px 2px rgba(80, 60, 30, 0.3);
  transition: left 0.15s;
}

.switch input:checked + .slider {
  background: #7d9c5b;
}

.switch input:checked + .slider::after {
  left: 14px;
}

/* Floating rotate/size panel for the Adjust tool. */
#gizmo {
  display: none;
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: 250px;
  padding: 12px 14px;
  background: rgba(255, 250, 240, 0.94);
  border-radius: 12px;
  box-shadow: 0 4px 18px rgba(80, 60, 30, 0.22);
  user-select: none;
}

#gizmo.open {
  display: block;
}

#gizmo label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #7a6a53;
  margin-bottom: 6px;
}

#gizmo input {
  width: 100%;
  accent-color: #7d9c5b;
  cursor: pointer;
}

#gizmo button {
  font: inherit;
  font-size: 12px;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d8c9ae;
  border-radius: 9px;
  background: #fdf8ee;
  color: #5a4632;
  cursor: pointer;
}

#gizmo button:hover {
  background: #f2e7d0;
}

/* Photo mode: the toolbar disappears, a soft grade + vignette dresses the
   scene, and a minimal capture bar floats at the bottom. */
#photobar {
  display: none;
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  gap: 8px;
  padding: 8px;
  background: rgba(255, 250, 240, 0.85);
  border-radius: 12px;
  box-shadow: 0 4px 18px rgba(80, 60, 30, 0.22);
  z-index: 20;
}

#photobar button {
  font: inherit;
  font-size: 13px;
  padding: 8px 14px;
  border: 1px solid #d8c9ae;
  border-radius: 9px;
  background: #fdf8ee;
  color: #5a4632;
  cursor: pointer;
}

#photobar button:hover {
  background: #f2e7d0;
}

#vignette {
  display: none;
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(25, 20, 35, 0.34) 100%);
  z-index: 15;
}

body.photo #ui,
body.photo #gizmo {
  display: none;
}

body.photo #photobar {
  display: flex;
}

body.photo #vignette {
  display: block;
}

/* No CSS filter on the live canvas — capture applies its own grade so
   photo-mode preview matches the downloaded PNG. */

.timeofday {
  margin-bottom: 8px;
}

.timeofday label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #7a6a53;
  margin-bottom: 2px;
}

.timeofday input {
  width: 100%;
  accent-color: #7d9c5b;
  cursor: pointer;
}

#clear {
  margin-bottom: 6px;
}

/* Help overlay: dimmed scrim + centered parchment card. */
#helpscrim {
  position: fixed;
  inset: 0;
  background: rgba(40, 30, 15, 0.35);
  z-index: 30;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s;
}

#helppanel {
  display: flex;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -48%) scale(0.96);
  width: min(480px, calc(100vw - 32px));
  max-height: 80vh;
  flex-direction: column;
  background: rgba(255, 250, 240, 0.97);
  border: 1px solid #d8c9ae;
  border-radius: 14px;
  box-shadow: 0 10px 36px rgba(80, 60, 30, 0.28);
  z-index: 31;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
  user-select: text;
}

body.helpopen #helpscrim {
  opacity: 1;
  visibility: visible;
}

body.helpopen #helppanel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

#help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(122, 106, 83, 0.18);
  flex-shrink: 0;
}

#help-header h2 {
  font-size: 16px;
  color: #5a4632;
}

#closehelp {
  font: inherit;
  font-size: 11px;
  line-height: 1;
  padding: 2px 6px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #a08c6e;
  cursor: pointer;
}

#closehelp:hover {
  background: #f2e7d0;
  color: #5a4632;
}

#help-body {
  overflow-y: auto;
  padding: 8px 16px 16px;
}

#help-body section {
  padding: 10px 0;
  border-bottom: 1px solid rgba(122, 106, 83, 0.12);
}

#help-body section:last-child {
  border-bottom: none;
  padding-bottom: 4px;
}

#help-body h3 {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #a08c6e;
  margin-bottom: 5px;
}

#help-body p {
  font-size: 12px;
  line-height: 1.5;
  color: #8a7a63;
}

#help-body strong {
  color: #5a4632;
  font-weight: 600;
}

#helppanel kbd {
  display: inline-block;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 5px;
  border: 1px solid #d8c9ae;
  border-radius: 5px;
  background: #fdf8ee;
  color: #5a4632;
  box-shadow: 0 1px 0 #d8c9ae;
}

.help-keys {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  color: #8a7a63;
}

.help-keys td {
  padding: 4px 0;
  vertical-align: middle;
}

.help-keys td:first-child {
  width: 42%;
  white-space: nowrap;
  padding-right: 12px;
}
