:root {
  /* =========================================
     THEME CONFIGURATION
     Change these RGB values to update the app's look
     ========================================= */
  
  /* 1. Primary Brand Color (Green) */
  --primary-rgb: 64, 197, 116;  /* #40c574 */
  --primary: rgb(var(--primary-rgb));

  /* 2. Accent / Hightlight Color (Teal) */
  --accent-rgb: 76, 232, 205;   /* #4ce8cd */
  --accent: rgb(var(--accent-rgb));

  /* 3. Background Colors (Dark Mode) */
  --bg-dark: #051a14;
  --bg-darker: #020d0a;
  
  /* 4. Text Colors */
  --text-main: #e8f5f1;
  --text-muted: #b8d4c9;
  
  /* 5. UI Elements */
  --glass-bg: #051a14;
  --glass-border: rgba(var(--accent-rgb), 0.2);
  
  /* Dimensions & Spacing */
  --sidebar-width: 360px;
  --header-base-height: 70px;
  --header-height: calc(var(--header-base-height) + env(safe-area-inset-top, 0px));
  --footer-height: 40px;
  --radius: 8px;
  
  /* Transitions */
  --transition-speed: 300ms;
  --ease: cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Roboto', sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  height: 100vh;
  width: 100vw;
  overflow: hidden; /* Prevent body scroll */
  display: flex;
  flex-direction: column;
}

h1, h2, h3 {
  font-family: 'Outfit', sans-serif;
  font-weight: 400;
  color: var(--accent);
}

a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s;
}

a:hover {
  color: var(--primary);
}

/* Header */
.app-header {
  height: var(--header-height);
  padding: 0 1.5rem;
  padding-top: env(safe-area-inset-top, 0px); /* Handle notch/status bar */
  background: var(--glass-bg);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between; /* Push items to edges */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  overflow: hidden; /* Prevent internal spill */
}

/* Removed .header-left */

.title-group {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0; /* flex-shrink fix */
}

.title-group h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin: 0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main Container */
.app-container {
  flex: 1;
  position: relative;
  /* Margin for header/footer handled by fixed positioning or flex logic? 
     Canvas handles full screen usually. */
  margin-top: var(--header-height);
  height: calc(100vh - var(--header-height));
  display: flex;
}

.canvas-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  background: var(--bg-darker); /* Solid flat background */
  transition: right var(--transition-speed) var(--ease);
}

@media (min-width: 768px) {
    .canvas-wrapper.pushed {
        right: var(--sidebar-width);
    }
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  right: 0; /* Move to right */
  height: 100vh;
  width: var(--sidebar-width);
  width: var(--sidebar-width);
  background: var(--glass-bg);
  border-left: 1px solid var(--glass-border); /* Border on left now */
  transform: translateX(100%); /* Start off-screen to the right */
  transition: transform var(--transition-speed) var(--ease);
  z-index: 100;
  display: flex;
  flex-direction: column;
  box-shadow: none; /* Shadow removed for flat design */
}

.sidebar.active {
  transform: translateX(0);
}

.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.8); /* Darker flat overlay */
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-speed) var(--ease);
  z-index: 90;
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.sidebar-header {
  height: var(--header-height);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--glass-border);
}

.sidebar-header h2 {
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.menu-btn {
  width: auto; /* Prevent full width */
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius);
  transition: all 0.2s;
}

.menu-btn:hover {
  color: var(--accent);
}

.close-btn {
  width: auto; /* Fix width here too */
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem;
  transition: color 0.2s;
}

.close-btn:hover {
  color: var(--accent);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) transparent;
}

.sidebar-content::-webkit-scrollbar {
  width: 6px;
}
.sidebar-content::-webkit-scrollbar-thumb {
  background-color: var(--primary);
  border-radius: 3px;
}

/* Control Sections */
.control-section {
  margin-bottom: 0.25rem;
}

.control-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  letter-spacing: 0.5px;
}

.separator {
  height: 1px;
  background: var(--glass-border);
  margin: 0.75rem 0;
}

/* Inputs & Form Elements */
.radio-group, .checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Custom Radio & Checkbox Styles */
.radio-custom, .checkbox-custom {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 1px 0;
  user-select: none;
}

.radio-custom input, .checkbox-custom input {
  display: none;
}

.radio-mark, .checkbox-mark {
  width: 18px; /* Slightly smaller */
  height: 18px;
  border: 2px solid var(--text-muted);
  border-radius: 50%;
  position: relative;
  transition: all 0.2s;
  flex-shrink: 0;
}

.checkbox-mark {
  border-radius: 4px; /* Square for checkbox */
}

.radio-custom input:checked ~ .radio-mark,
.checkbox-custom input:checked ~ .checkbox-mark {
  border-color: var(--accent);
  box-shadow: none;
}

.radio-mark::after, .checkbox-mark::after {
  content: '';
  position: absolute;
  top: 50%; 
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.checkbox-mark::after {
  border-radius: 2px;
}

.radio-custom input:checked ~ .radio-mark::after,
.checkbox-custom input:checked ~ .checkbox-mark::after {
  transform: translate(-50%, -50%) scale(1);
}

.label-text {
  font-size: 0.9rem;
  color: var(--text-main);
}

/* Sliders */
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  gap: 1rem;
}

.control-row label {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 70px;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  background: transparent;
  height: 20px; /* Reduced height */
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 14px; /* Slightly smaller */
  width: 14px;
  border-radius: 50%;
  background: var(--primary);
  margin-top: -5px; /* offset */
  transition: transform 0.2s, background 0.2s;
}

input[type="range"]:hover::-webkit-slider-thumb {
  background: var(--accent);
  transform: scale(1.2);
}

input[type="range"]:focus::-webkit-slider-thumb {
  box-shadow: none;
}

.value-tag {
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--accent);
  min-width: 48px;
  text-align: center;
}

/* Dual Toggle (Animation) */
.toggle-switch-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 8px 12px;
  background: rgba(255,255,255,0.05);
  border-radius: var(--radius);
  transition: background 0.3s;
}

.toggle-switch-wrapper:hover {
  background: rgba(255,255,255,0.1);
}

.rotation-mode-radio {
  width: 16px;
  height: 16px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  position: relative;
}

.rotation-mode-radio::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  opacity: 0; /* Default off/fixed */
  transition: opacity 0.2s;
}

/* We handle the blink/state in JS, but let's assume class 'active' or attribute */
[data-mode="animation"] .rotation-mode-radio::after {
  opacity: 1; /* Wait, the JS updates text but not class on parent. 
                 The JS code adds .blink to radio. 
                 We will update JS later to handle visual state better. 
                 For now, keep compat. */
}

/* Need to match the existing JS logic:
   JS sets "blink" class on rotation-mode-radio.
*/

.rotation-mode-radio.blink::after {
  animation: blinkAnim 0.4s ease-out;
}

@keyframes blinkAnim {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  50% { transform: translate(-50%, -50%) scale(1.5); opacity: 0.5; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Buttons */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

button {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius);
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  font-family: 'Outfit', sans-serif;
}

.btn-primary {
  background: var(--primary);
  color: var(--bg-darker);
  box-shadow: none;
}

.btn-primary:hover {
  background: var(--accent);
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
}

.btn-secondary:hover {
  background: rgba(var(--primary-rgb), 0.1);
  color: var(--accent);
  border-color: var(--accent);
}

/* Footer */
.app-footer {
  position: absolute; /* or fixed bottom? */
  bottom: 0;
  left: 0;
  width: 100%;
  height: var(--footer-height);
  background: transparent; /* Cleaner look over canvas if canvas goes to bottom */
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none; /* Let clicks pass through to canvas if needed, but links need events */
  background: var(--bg-dark); /* Solid flat footer */
  z-index: 10;
}

.footer-content {
  pointer-events: auto;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.6);
}

.footer-content a {
  color: var(--accent);
}

.separator-dot {
  margin: 0 8px;
  opacity: 0.5;
}


/* Responsive */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
  }

  .title-group h1 {
    font-size: 1rem;
  }
  
  .subtitle {
    display: none; /* Hide subtitle on small screens to save space */
  }

  .sidebar {
    width: 100%; /* Full screen drawer on mobile */
  }
}

/* Helper for animation switch in Sidebar Content */
.flex-row-center {
  display: flex;
  justify-content: center;
  width: 100%;
}
