:root {
  --bg: #0b1324;
  --fg: #e5e7eb;
  --mut: #94a3b8;
  --card: #0f172a;
  --bd: #1f2937;
  --acc: #3b82f6;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  line-height: 1.5;
}
.controls-section {
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 8px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(8px);
}
h1 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 700;
  color: #ffffff;
}
.controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 4px;
}
.btn {
  background: linear-gradient(135deg, var(--acc), #2563eb);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 13px;
  text-decoration: none;
  display: inline-block;
  user-select: none;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}
.btn:hover {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}
.btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}
.btn.gray {
  background: linear-gradient(135deg, #4b5563, #374151);
  box-shadow: 0 2px 4px rgba(75, 85, 99, 0.2);
}
.btn.gray:hover {
  background: linear-gradient(135deg, #374151, #1f2937);
  box-shadow: 0 4px 12px rgba(75, 85, 99, 0.4);
}
.btn:has(input:disabled) {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Special styling for small/compact buttons */
.btn.small {
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 6px;
}

/* Interactive color swatch styling */
#pickedSwatch {
  background: #000;
  border: 2px solid #444;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#pickedSwatch:hover {
  border-color: var(--acc);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3), 0 4px 8px rgba(0, 0, 0, 0.3);
  transform: scale(1.05);
}

#pickedSwatch:active {
  transform: scale(0.95);
}

/* Enhanced pills for region controls */
.pill {
  background: linear-gradient(
    135deg,
    rgba(59, 130, 246, 0.15),
    rgba(59, 130, 246, 0.25)
  );
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 12px;
  padding: 4px 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
}

.pill:hover {
  background: linear-gradient(
    135deg,
    rgba(59, 130, 246, 0.25),
    rgba(59, 130, 246, 0.35)
  );
  border-color: rgba(59, 130, 246, 0.5);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
}
small {
  color: var(--mut);
  font-size: 12px;
  opacity: 0.8;
}
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 8px;
}
@media (min-width: 980px) {
  .grid {
    grid-template-columns: 340px 1fr 340px;
    gap: 12px;
    padding: 12px;
  }
}
.card {
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(8px);
  transition: box-shadow 0.3s ease;
}
.card:hover {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
label span {
  font-size: 12px;
  color: var(--mut);
}
input[type="file"] {
  display: none;
}
select,
input[type="range"],
input[type="text"],
input[type="color"] {
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--bd);
  border-radius: 6px;
  padding: 6px 10px;
  transition: all 0.2s ease;
  font-size: 13px;
}

/* Better range slider styling */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bd);
  border-radius: 3px;
  padding: 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--acc);
  cursor: pointer;
  transition: all 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: #2563eb;
  transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--acc);
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

input[type="range"]::-moz-range-thumb:hover {
  background: #2563eb;
  transform: scale(1.1);
}
select:focus,
input[type="text"]:focus,
input[type="range"]:focus {
  outline: none;
  border-color: var(--acc);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Fix sourceSel dropdown styling to override btn.gray */
#sourceSel {
  background: var(--bg) !important;
  color: var(--fg) !important;
  border: 1px solid var(--bd) !important;
  border-radius: 6px !important;
  padding: 6px 10px !important;
  font-size: 13px !important;
  font-weight: normal !important;
  box-shadow: none !important;
  transform: none !important;
  transition: all 0.2s ease !important;
}

#sourceSel:hover {
  background: var(--bg) !important;
  transform: none !important;
  border-color: var(--acc) !important;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
}

#sourceSel:focus {
  outline: none !important;
  border-color: var(--acc) !important;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
}

/* Style dropdown options */
#sourceSel option {
  background: var(--bg);
  color: var(--fg);
  padding: 8px;
}
fieldset {
  border: 1px solid var(--bd);
  border-radius: 8px;
  margin: 8px 0;
  padding: 12px;
  background: var(--card);
  backdrop-filter: blur(4px);
}
legend {
  padding: 0 8px;
  font-weight: 600;
  color: var(--fg);
  font-size: 13px;
}
.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.kv {
  display: grid;
  grid-template-columns: 100px 1fr 40px;
  gap: 6px;
  align-items: center;
  margin-bottom: 4px;
}

/* Compact value spans */
.kv span:last-child {
  font-size: 11px;
  font-weight: 500;
  color: var(--mut);
  text-align: right;
  min-width: 35px;
}
.kv-onecol {
  grid-template-columns: 1fr !important;
  gap: 8px;
}
.preview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.canvasWrap {
  position: relative;
}
canvas {
  background: #fff;
  width: 100%;
  aspect-ratio: 1/1;
  border: 2px solid var(--bd);
  border-radius: 8px;
  image-rendering: pixelated;
  transition: border-color 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
canvas:hover {
  border-color: var(--acc);
}
.debugOverlay {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
  display: none;
}
#status {
  font-size: 12px;
  color: var(--fg);
  margin-top: 6px;
  padding: 8px 12px;
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: 6px;
  font-weight: 500;
  min-height: 32px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list {
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--bd);
  border-radius: 8px;
  background: #0f172a;
  padding: 6px;
}
.item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 8px;
}
.item:hover {
  background: #0b253f;
}
.item code {
  background: #111827;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid #334155;
  color: #e5e7eb;
}
.bad {
  color: #fca5a5;
  font-weight: 600;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--bd);
  background: #0f1b33;
  color: var(--fg);
  font-size: 12px;
}
.chip .sw {
  width: 22px;
  height: 16px;
  border: 1px solid #334155;
  border-radius: 4px;
}
.chip.sel {
  outline: 2px solid var(--acc);
}
.famCard {
  border: 1px solid var(--bd);
  border-radius: 10px;
  background: var(--card);
  padding: 8px;
  margin-bottom: 8px;
}
.famHdr {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  color: var(--mut);
}
.sheet {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #0b1020;
  color: #e5e7eb;
  border-top: 1px solid #334155;
  padding: 12px;
  z-index: 9998;
  box-shadow: 0 -10px 30px #0008;
}
.sheet h3 {
  margin: 0 0 8px 0;
  font-size: 16px;
}
.sheet .row {
  justify-content: space-between;
}
.sheet .section {
  margin-top: 8px;
}
hr {
  border: 0;
  border-top: 1px solid var(--bd);
  margin: 8px 0;
}
input[type="color"] {
  background: #0b1628;
  border: 1px solid #334155;
  border-radius: 6px;
  height: 20px;
  cursor: pointer;
}

input[type="color"]:hover {
  border-color: var(--acc);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

/* Zoom overlay styling */
.zoomOverlay {
  position: fixed !important;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 2px solid #111;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.2) inset, 0 4px 12px rgba(0, 0, 0, 0.5);
  background: #000;
  display: none;
  pointer-events: none;
  overflow: hidden;
  z-index: 1000;
  backdrop-filter: blur(1px);
}

.zoomOverlay canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

/* Make canvas wrappers relative for zoom overlay positioning */
.canvasWrap {
  position: relative;
}

/* Loading indicator styles */
.loadingIndicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  display: none;
  z-index: 10;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.loadingIndicator.show {
  display: flex;
  align-items: center;
  gap: 8px;
}

.loadingSpinner {
  width: 16px;
  height: 16px;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Hotkey Modal Specific Styles */
#hotkeyModal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#hotkeyModal.show {
  display: flex;
}

#hotkeyModal .sheet-content {
  background: #0b1020;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 20px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

#hotkeyModal .kv {
  grid-template-columns: 200px 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

#hotkeyModal .kv label {
  color: var(--fg);
  font-weight: 500;
  padding: 8px 0;
}

#hotkeyModal .kv input[type="text"] {
  padding: 8px 12px;
  font-size: 14px;
  border-radius: 6px;
  background: var(--card);
  border: 1px solid var(--bd);
  color: var(--fg);
}

#hotkeyModal .kv input[type="text"]:focus {
  outline: none;
  border-color: var(--acc);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

#hotkeyModal .section {
  margin-bottom: 20px;
}

#hotkeyModal .section:last-child {
  margin-bottom: 0;
  text-align: center;
}

#hotkeyModal .row {
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

/* Tutorial Modal Specific Styles */
#tutorialModal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#tutorialModal.show {
  display: flex;
}

#tutorialModal .sheet-content {
  background: #0b1020;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 20px;
  max-width: 800px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

#tutorialModal .row {
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.tutorial-section {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--bd);
}

.tutorial-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.tutorial-section h4 {
  color: var(--acc);
  font-size: 18px;
  margin: 0 0 12px 0;
  font-weight: 600;
}

.tutorial-section h5 {
  color: var(--fg);
  font-size: 14px;
  margin: 0 0 6px 0;
  font-weight: 500;
}

.tutorial-section p {
  color: var(--fg);
  line-height: 1.5;
  margin: 0 0 8px 0;
  font-size: 14px;
}

.tutorial-section em {
  color: var(--acc);
  font-style: normal;
}

/* About Modal Specific Styles */
#aboutModal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#aboutModal.show {
  display: flex;
}

#aboutModal .sheet-content {
  background: #0b1020;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 20px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

#aboutModal .row {
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

#aboutModal .section {
  margin-bottom: 20px;
}

#aboutModal .section:last-child {
  margin-bottom: 0;
}

#aboutModal h4 {
  color: var(--acc);
  font-size: 16px;
  margin: 0 0 8px 0;
  font-weight: 600;
}

#aboutModal p {
  color: var(--fg);
  line-height: 1.5;
  margin: 0 0 16px 0;
  font-size: 14px;
}

#aboutModal .kv {
  grid-template-columns: 180px 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

#aboutModal .kv label {
  color: var(--mut);
  font-weight: 500;
  padding: 4px 0;
  font-size: 14px;
}

#aboutModal .kv span {
  color: var(--fg);
  padding: 4px 0;
  font-size: 14px;
  text-align: left;
}

#aboutModal .kv a {
  color: var(--acc);
  text-decoration: none;
  padding: 4px 0;
  font-size: 14px;
  text-align: left;
}

#aboutModal .kv a:hover {
  text-decoration: underline;
}

.tutorial-section code {
  background: var(--bg2);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "Courier New", monospace;
  font-size: 13px;
  color: var(--acc);
}

.tutorial-item {
  margin-bottom: 16px;
}

.tutorial-section ul {
  margin: 8px 0;
  padding-left: 20px;
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
}

.tutorial-section ol {
  margin: 8px 0;
  padding-left: 20px;
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
}

.tutorial-section li {
  margin-bottom: 4px;
}

.tutorial-section ul ul {
  margin: 4px 0;
}

/* Unified slider section styling for Settings and Experimental */
.settings-controls,
.experimental-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-item,
.experimental-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-header,
.experimental-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.settings-header label,
.experimental-header label {
  margin: 0;
  font-weight: 500;
  color: var(--fg);
}

.settings-header span,
.experimental-header span {
  color: var(--mut);
  font-size: 12px;
  font-weight: 500;
  min-width: 35px;
  text-align: right;
}

.settings-item input[type="range"],
.experimental-item input[type="range"] {
  width: 100%;
}

/* Multi-seed preview styles */
#multiSeedMode {
  border: 2px solid var(--acc);
  border-radius: 8px;
  padding: 8px;
  background: rgba(59, 130, 246, 0.05);
}

#multiSeedMode canvas {
  border: 2px solid transparent;
  border-radius: 4px;
  transition: border-color 0.2s ease, transform 0.1s ease;
  image-rendering: pixelated;
  max-width: 100%;
  height: auto;
}

#multiSeedMode canvas:hover {
  border-color: var(--acc);
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

#multiSeedMode .seed-display {
  font-family: monospace;
  font-size: 10px;
  color: var(--mut);
  margin-top: 2px;
  word-break: break-all;
}

/* Texture list styles */
#texList {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--bd);
  border-radius: 6px;
  padding: 8px;
}

#texList .item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(31, 41, 55, 0.3);
  font-size: 12px;
}

#texList .item:last-child {
  border-bottom: none;
}

/* Pulse animation for loading states */
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

.loading #status {
  animation: pulse 1.5s ease-in-out infinite;
}

/* Smooth transitions for all interactive elements */
.btn,
.card,
fieldset,
input,
select {
  transition: all 0.2s ease;
}

/* Better grid layout with reduced spacing */
@media (min-width: 980px) {
  .grid {
    grid-template-columns: 340px 1fr 340px;
    gap: 12px;
    padding: 12px;
  }
}

/* Compact toggle styling */
.toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 0;
}

.toggle input[type="checkbox"] {
  width: auto;
  margin: 0;
  transform: scale(1.1);
  accent-color: var(--acc);
}

/* Better toast styling */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--card);
  color: var(--fg);
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--bd);
  z-index: 10000;
  animation: slideInRight 0.3s ease-out;
  backdrop-filter: blur(8px);
  font-weight: 500;
  max-width: 400px;
  font-size: 14px;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}
