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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #2d5a3d;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ─── UI Layer ──────────────────────────────────────────────── */
#ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  pointer-events: none; /* Let clicks pass through except on active UI */
  z-index: 100;
}

/* ─── Header Bar ──────────────────────────────────────────────── */
#header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 40px;
  background: rgba(28, 38, 31, 0.85); /* Dark frosted */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(138, 112, 80, 0.4);
  padding: 0 16px;
  pointer-events: auto;
}

#app-title-container {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 4px 8px;
  margin-left: -8px;
  border-radius: 6px;
  transition: background 0.2s;
}
#app-title-container:hover {
  background: rgba(255, 255, 255, 0.1);
}

#app-title {
  font-family: Georgia, serif;
  font-size: 18px;
  font-weight: bold;
  color: #ede2c8;
  display: flex;
  align-items: center;
  gap: 8px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  margin: 0;
}

.title-icon {
  width: 22px;
  height: 22px;
  display: block;
}

.dropdown-caret {
  font-size: 10px;
  opacity: 0.7;
  transition: transform 0.2s;
}

#header-stats {
  font-family: Georgia, serif;
  font-size: 15px;
  color: #c0a870;
}

/* ─── Edgy Dropdown Selector (Adapted from Heck'n Sic) ────────── */
.edgy-dropdown {
  position: absolute;
  top: 48px; /* Below the header */
  left: 10px;
  background: rgba(30, 41, 33, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(192, 168, 112, 0.4);
  border-radius: 8px;
  padding: 12px 14px;
  width: 220px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 15px rgba(138, 112, 80, 0.2);
  z-index: 400;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), 
              transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: auto;
}

.edgy-dropdown.hidden {
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
}

.dropdown-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dropdown-header {
  font-family: Georgia, serif;
  font-size: 11px;
  letter-spacing: 1.5px;
  color: #c0a870;
  text-transform: uppercase;
  margin: 0 0 2px 4px;
  font-weight: bold;
}

.dropdown-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dropdown-btn {
  background: transparent;
  border: 1px solid transparent;
  padding: 10px 12px;
  border-radius: 6px;
  color: #ede2c8;
  font-family: Georgia, serif;
  font-size: 14px;
  font-weight: bold;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: all 0.2s ease;
}

.dropdown-btn .icon {
  margin-right: 12px;
  font-size: 16px;
  opacity: 0.8;
  width: 24px;
  text-align: center;
}

.dropdown-btn:hover {
  background: rgba(192, 168, 112, 0.15);
  color: #fff;
  transform: translateX(4px);
}

.dropdown-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(138, 112, 80, 0.4), transparent);
  margin: 12px 0;
}

/* ─── Floating Undo UI ────────────────────────────────────────── */
#undo-wrapper {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  pointer-events: none;
}

.floating-btn {
  background: rgba(30, 41, 33, 0.85); /* Matches edgy dark theme */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(192, 168, 112, 0.4);
  border-radius: 50%; /* Circle */
  color: #ede2c8;
  width: 50px;
  height: 50px;
  font-size: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  transition: transform 0.1s, background 0.2s;
  pointer-events: auto;
}

.floating-btn:active {
  transform: scale(0.92);
  background: rgba(192, 168, 112, 0.3);
}

.undo-dropdown {
  position: absolute;
  bottom: 60px; /* Above the button */
  left: 0;
  background: rgba(30, 41, 33, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(192, 168, 112, 0.4);
  border-radius: 8px;
  padding: 12px 14px;
  width: 200px;
  max-height: 250px;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 15px rgba(138, 112, 80, 0.2);
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), 
              transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transform-origin: bottom left;
  pointer-events: auto;
}

.undo-dropdown.hidden {
  opacity: 0;
  transform: scale(0.9) translateY(10px);
  pointer-events: none;
}

/* Custom scrollbar for undo-dropdown */
.undo-dropdown::-webkit-scrollbar {
  width: 6px;
}
.undo-dropdown::-webkit-scrollbar-track {
  background: transparent;
}
.undo-dropdown::-webkit-scrollbar-thumb {
  background-color: rgba(192, 168, 112, 0.3);
  border-radius: 10px;
}
.undo-dropdown::-webkit-scrollbar-thumb:hover {
  background-color: rgba(192, 168, 112, 0.6);
}

.seed-label {
  position: absolute;
  bottom: 24px;
  right: 24px;
  font-family: monospace;
  font-size: 11px;
  color: rgba(192, 168, 112, 0.6);
  pointer-events: none;
  z-index: 10;
}
.seed-label.hidden {
  display: none;
}

.mode-seed-input {
  position: absolute;
  width: 160px;
  height: 30px;
  background: rgba(30, 41, 33, 0.85);
  border: 1px solid rgba(138, 112, 80, 0.4);
  border-radius: 6px;
  color: #ede2c8;
  font-family: Georgia, serif;
  font-size: 13px;
  text-align: center;
  outline: none;
  pointer-events: auto;
  z-index: 600;
}
.mode-seed-input.hidden {
  display: none;
}
.mode-seed-input:focus {
  border-color: #c0a870;
  box-shadow: 0 0 5px rgba(192, 168, 112, 0.5);
  background: rgba(30, 41, 33, 0.95);
}
.mode-seed-input::placeholder {
  color: rgba(192, 168, 112, 0.5);
}
.mode-seed-input::-webkit-outer-spin-button,
.mode-seed-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.mode-seed-input[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}

#help-modal.hidden {
  display: none !important;
}

#help-modal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 85%;
  max-width: 400px;
  background: rgba(30, 41, 33, 0.98);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(192, 168, 112, 0.4);
  border-radius: 8px;
  padding: 24px;
  color: #ede2c8;
  font-family: Georgia, serif;
  z-index: 1000;
  pointer-events: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  max-height: 80%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#help-title {
  color: #c0a870;
  font-size: 20px;
  border-bottom: 1px solid rgba(192, 168, 112, 0.4);
  padding-bottom: 10px;
  margin-bottom: 15px;
  margin-top: 0;
  text-align: center;
}

#help-content {
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

#btn-close-help {
  margin-top: auto;
  width: 100%;
  padding: 12px;
  background: #4a3824;
  color: #f0e4cc;
  border: 1px solid #8a7050;
  border-radius: 6px;
  cursor: pointer;
  font-family: Georgia, serif;
  font-weight: bold;
  transition: background 0.2s;
}
#btn-close-help:hover {
  background: #5a4830;
}
