/* =================================================
   Color system
   ================================================= */
:root {
  --bg-page: #fdfcfb;
  --bg-editor: rgba(15, 17, 23, 0.95);
  --bg-card: rgba(255, 255, 255, 0.65);
  --text-dark: #111;
  --text-light: #eee;
  --accent: #4f8cff;
  --border-color-light: #dddddd;
  --shadow-light: 0 4px 12px rgba(0,0,0,0.15);
  
  /* Navbar */
  --navbar-bg: rgba(20, 20, 20, 0.85);
  --navbar-border: rgba(255, 255, 255, 0.08);
  
  /* Popup */
  --popup-bg: rgba(26, 28, 34, 0.95);
  --popup-border: rgba(255, 255, 255, 0.12);
  
  /* Inputs */
  --input-bg: rgba(11, 13, 18, 0.8);
  --input-border: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] {
  --bg-page: #111;
  --bg-editor: rgba(10, 12, 18, 0.95);
  --bg-card: rgba(30, 30, 40, 0.7);
  --text-dark: #eee;
  --text-light: #eee;
  --border-color-light: rgba(255, 255, 255, 0.1);
  --navbar-bg: rgba(15, 15, 20, 0.9);
  --navbar-border: rgba(255, 255, 255, 0.1);
  --popup-bg: rgba(20, 22, 30, 0.95);
  --popup-border: rgba(255, 255, 255, 0.08);
  --input-bg: rgba(5, 7, 12, 0.8);
  --input-border: rgba(255, 255, 255, 0.1);
}

/* =================================================
   Reset & Base
   ================================================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg-page);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text-dark);
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease;
}

/* =================================================
   Navbar
   ================================================= */
.navbar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--navbar-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--navbar-border);
  color: var(--text-light);
  position: sticky;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 100;
}

.nav-title {
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.4rem;
  font-weight: 600;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* =================================================
   Theme Toggle
   ================================================= */
.theme-toggle {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-light);
  transition: all 0.3s ease;
  backdrop-filter: blur(4px);
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  position: absolute;
  transition: transform 0.5s ease, opacity 0.5s ease;
}

[data-theme="light"] .icon-sun {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

[data-theme="light"] .icon-moon {
  opacity: 0;
  transform: rotate(-90deg) scale(0);
}

[data-theme="dark"] .icon-sun {
  opacity: 0;
  transform: rotate(90deg) scale(0);
}

[data-theme="dark"] .icon-moon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* =================================================
   Layout
   ================================================= */
.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  padding: 30px;
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* =================================================
   Editor
   ================================================= */
.editor {
  background: var(--bg-editor);
  padding: 25px;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color-light);
  box-shadow: var(--shadow-light);
  min-height: 600px;
}

.editor h3 {
  color: var(--text-light);
  margin-bottom: 15px;
  font-size: 1.2rem;
  font-weight: 600;
}

textarea {
  flex: 1;
  resize: none;
  border-radius: 12px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: #cdd6f4;
  padding: 18px;
  font-family: 'Courier New', monospace;
  font-size: 0.95rem;
  line-height: 1.5;
  margin-top: 15px;
  backdrop-filter: blur(4px);
  transition: border-color 0.3s ease;
  min-height: 500px;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.2);
}

/* =================================================
   Toolbar
   ================================================= */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 15px;
  position: relative;
  flex-wrap: wrap;
}

.toolbar button {
  cursor: pointer;
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(30, 30, 40, 0.7);
  color: var(--text-light);
  font-family: system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
}

.toolbar button:hover {
  background: rgba(40, 40, 50, 0.8);
  transform: translateY(-1px);
}

/* Group numbered buttons */
button.group-btn {
  min-width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  font-weight: 600;
  border-radius: 8px;
  font-size: 0.95rem;
}

/* =================================================
   New Group Dropdown
   ================================================= */
.new-group-wrapper {
  position: relative;
  display: inline-block;
}

#newGroupBtn {
  padding: 9px 22px;
  min-width: 130px;
}

.new-group-wrapper .dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  width: 130px; /* Same width as button */
  background: rgba(26, 28, 34, 0.95);
  border: 1px solid var(--popup-border);
  border-radius: 8px;
  flex-direction: column;
  z-index: 20;
  backdrop-filter: blur(10px);
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.new-group-wrapper .dropdown div {
  padding: 11px 14px;
  cursor: pointer;
  color: var(--text-light);
  font-size: 0.95rem;
  transition: background-color 0.2s ease;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.new-group-wrapper .dropdown div:last-child {
  border-bottom: none;
}

.new-group-wrapper .dropdown div:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Show dropdown */
.new-group-wrapper.active .dropdown {
  display: flex;
}

/* =================================================
   Preview Section
   ================================================= */
.preview-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.preview-title {
  color: var(--text-dark);
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
}

[data-theme="dark"] .preview-title {
  color: var(--text-light);
}

.preview-card {
  background: var(--bg-card);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border-color-light);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  min-height: 300px;
  width: 100%;
}

/* Blob Layer */
.blob-layer {
  width: 100%;
  height: 100%;
  min-height: 300px;
}

#previewBlob {
  width: 100%;
  height: 100%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

/* =================================================
   Explanation
   ================================================= */
.explanation {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 25px;
  border: 1px solid var(--border-color-light);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.explanation h4 {
  color: var(--text-dark);
  font-size: 1.1rem;
  margin-bottom: 20px;
  font-weight: 600;
}

[data-theme="dark"] .explanation h4 {
  color: var(--text-light);
}

.explanation-content {
  display: flex;
  flex-direction: column;
  gap: 25px;
}

.explanation-section h5 {
  color: var(--text-dark);
  font-size: 1rem;
  margin-bottom: 12px;
  font-weight: 600;
}

[data-theme="dark"] .explanation-section h5 {
  color: var(--text-light);
}

.explanation-section p {
  color: var(--text-dark);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 8px;
}

[data-theme="dark"] .explanation-section p {
  color: rgba(255, 255, 255, 0.85);
}

.explanation-section .note {
  font-style: italic;
  opacity: 0.8;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-color-light);
}

.explanation-section ul {
  list-style-type: none;
  padding-left: 0;
  margin-top: 10px;
}

.explanation-section li {
  color: var(--text-dark);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 6px;
  padding-left: 16px;
  position: relative;
}

[data-theme="dark"] .explanation-section li {
  color: rgba(255, 255, 255, 0.85);
}

.explanation-section li:before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--accent);
}

.explanation-section code {
  background: rgba(79, 140, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
  color: var(--accent);
}

/* =================================================
   Footer
   ================================================= */
.site-footer {
  background: var(--navbar-bg);
  color: var(--text-light);
  padding: 15px 20px;
  text-align: center;
  border-top: 1px solid var(--navbar-border);
  margin-top: 30px;
  backdrop-filter: blur(6px);
}

.footer-content {
  max-width: 1400px;
  margin: 0 auto;
}

.footer-content p {
  font-size: 0.9rem;
  opacity: 0.8;
}

/* =================================================
   Group Popup
   ================================================= */
#groupPopupContainer {
  position: relative;
  width: 100%;
  pointer-events: none;
}

.group-popup {
  position: absolute;
  top: 48px;
  left: 0;
  min-width: 280px;
  max-width: 440px;
  background: var(--popup-bg);
  border: 1px solid var(--popup-border);
  border-radius: 12px;
  padding: 16px;
  color: var(--text-light);
  font-family: system-ui, sans-serif;
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
  transform-origin: top left;
  pointer-events: auto;
  visibility: hidden;
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  z-index: 1000;
  --arrow-left: 18px;
  backdrop-filter: blur(10px);
}

.group-popup.show {
  visibility: visible;
  opacity: 1;
  transform: translateY(0) scale(1);
}

.group-popup::before {
  content: "";
  position: absolute;
  top: -8px;
  left: var(--arrow-left);
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid var(--popup-bg);
  transform: translateX(-50%);
}

/* Popup rows */
.group-popup .row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.group-popup label {
  font-size: 0.85rem;
  opacity: 0.9;
  min-width: 80px;
  font-weight: 500;
}

/* Position controls */
.position-controls {
  margin-bottom: 12px;
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.slider-group input[type="range"] {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
  -webkit-appearance: none;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.slider-value {
  min-width: 40px;
  font-size: 0.85rem;
  opacity: 0.9;
}

/* Color stops */
.stops-list {
  margin-bottom: 8px;
}

.group-popup .stop {
  display: flex;
  gap: 10px;
  align-items: center;
  background: rgba(11, 13, 18, 0.6);
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 8px;
}

.group-popup input[type="color"] {
  width: 44px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 4px;
  overflow: hidden;
}

.group-popup input[type="number"] {
  padding: 8px;
  background: rgba(5, 7, 12, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  color: var(--text-light);
  font-family: system-ui, sans-serif;
  width: 70px;
  font-size: 0.9rem;
}

.group-popup input[type="range"].stop-opacity {
  width: 90px;
  margin: 0;
}

.group-popup button[data-action="remove-stop"] {
  background: rgba(255, 50, 50, 0.2);
  border: 1px solid rgba(255, 50, 50, 0.3);
  color: #ff6b6b;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.group-popup button[data-action="remove-stop"]:hover {
  background: rgba(255, 50, 50, 0.3);
}

/* Add stop button - UPDATED: removed gap and margin */
.group-popup button[data-action="add-stop"] {
  background: rgba(79, 140, 255, 0.1);
  border: 1px solid rgba(79, 140, 255, 0.3);
  color: var(--accent);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
  width: 40px;
  height: 40px;
}

.group-popup button[data-action="add-stop"]:hover {
  background: rgba(79, 140, 255, 0.2);
}

.group-popup button[data-action="add-stop"] svg {
  width: 20px;
  height: 20px;
  stroke: var(--accent);
}

/* Popup actions */
.group-popup .actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.group-popup button {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(30, 30, 40, 0.7);
  color: var(--text-light);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.group-popup button:hover {
  background: rgba(40, 40, 50, 0.8);
}

.group-popup button.primary {
  background: var(--accent);
  border-color: rgba(79, 140, 255, 0.9);
  color: white;
}

.group-popup button.primary:hover {
  background: #3a7cff;
}

/* =================================================
   Select & Input Styling
   ================================================= */
.group-popup select {
  flex: 1;
  padding: 8px 12px;
  background: rgba(11, 13, 18, 0.8);
  color: var(--text-light);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  backdrop-filter: blur(4px);
}

.group-popup input[type="text"] {
  flex: 1;
  padding: 8px 12px;
  background: rgba(11, 13, 18, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: var(--text-light);
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  backdrop-filter: blur(4px);
}

/* =================================================
   Responsive
   ================================================= */
@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 25px;
    padding: 25px;
  }
  
  .editor {
    min-height: 500px;
  }
  
  textarea {
    min-height: 400px;
  }
}

@media (max-width: 640px) {
  .group-popup {
    min-width: 280px;
    max-width: calc(100% - 32px);
    left: 12px;
    right: 12px;
  }
  
  .group-popup::before {
    left: calc(50%);
    transform: translateX(-50%);
  }
  
  .navbar {
    padding: 0 16px;
  }
  
  .layout {
    padding: 20px 16px;
    gap: 20px;
  }
  
  .editor {
    padding: 20px;
  }
  
  .explanation {
    padding: 20px;
  }
  
  .explanation-content {
    gap: 20px;
  }
}

/* Chrome, Safari, Edge, Opera */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Firefox */
input[type=number] {
    -moz-appearance: textfield;
}
