.settings-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 50000;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-modal-content {
    background-color: rgba(30, 30, 30, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text-color);
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    border: 1px solid var(--primary-color);
    position: relative;
    box-shadow: 0 5px 25px rgba(0,0,0,0.5);
}

.settings-close-button {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
}

.settings-modal-content h2 {
    color: var(--primary-color) !important;
    text-align: center;
    margin-top: 0;
    margin-bottom: 25px;
    cursor: move;
    
    /* New styles to center the logo image inside h2 */
    display: flex;
    justify-content: center;
    align-items: center;
    height: 43px; /* Ensure H2 height accommodates the logo */
}

.settings-logo-img {
    width: 150px; /* Requested width */
    height: 43px; /* Requested height */
    
    /* Use theme primary color as background color */
    background-color: var(--primary-color);
    
    /* Use 6w-200.png as mask for the white shape */
    -webkit-mask-image: url('/6d-200.png');
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-position: center;
    -webkit-mask-size: contain;
    mask-image: url('/6d-200.png');
    mask-repeat: no-repeat;
    mask-position: center;
    mask-size: contain;
}

.settings-section {
    margin-bottom: 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 20px;
}

.settings-section:first-of-type {
    border-top: none;
    padding-top: 0;
}

.settings-section h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: var(--lighter-primary-color);
    cursor: pointer;
    text-transform: uppercase;
    background-color: var(--secondary-color);
    border: 1px solid var(--primary-color);
    padding: 10px 15px;
    border-radius: 8px;
    transition: all 0.2s ease;
    text-align: center;
}

.settings-section h3:hover {
    background-color: var(--primary-color);
    color: #000000 !important;
    box-shadow: 0 0 10px rgba(var(--primary-color-rgb), 0.5);
}

/* NEW: Light theme overrides for section title bars (reverse hover contrast) */
[data-theme^="light"] .settings-section h3 {
    /* Darker by default for better readability on light themes */
    background-color: var(--primary-color);
    color: #000000 !important;
}

[data-theme^="light"] .settings-section h3:hover {
    /* Lighter on hover for visual feedback */
    background-color: var(--secondary-color);
    color: var(--lighter-primary-color) !important;
    box-shadow: 0 0 10px rgba(var(--primary-color-rgb), 0.5);
}

/* NEW: Collapsible subsections with smaller title bars */
.settings-subsection {
    margin-top: 12px;
}

.settings-subsection .subsection-header {
    margin: 0 0 10px 0;
    text-transform: uppercase;
    color: var(--lighter-primary-color);
    background-color: var(--secondary-color);
    border: 1px solid var(--primary-color);
    padding: 8px 12px;           /* smaller than h3 */
    border-radius: 6px;          /* smaller radius */
    font-size: 0.95rem;          /* smaller font than h3 */
    text-align: left;            /* differentiate from main */
    transition: all 0.2s ease;
}

.settings-subsection .subsection-header:hover {
    background-color: var(--primary-color);
    color: #000000 !important;
    box-shadow: 0 0 8px rgba(var(--primary-color-rgb), 0.5);
}

/* NEW: Light theme overrides for subsection title bars (reverse hover contrast) */
[data-theme^="light"] .settings-subsection .subsection-header {
    /* Darker by default for better readability on light themes */
    background-color: var(--primary-color);
    color: #000000 !important;
}

[data-theme^="light"] .settings-subsection .subsection-header:hover {
    /* Lighter on hover for visual feedback */
    background-color: var(--secondary-color);
    color: var(--lighter-primary-color) !important;
    box-shadow: 0 0 8px rgba(var(--primary-color-rgb), 0.5);
}

/* Light theme tweaks for subsection headers */
[data-theme^="light"] .settings-subsection .subsection-header {
    color: var(--lighter-primary-color) !important;
    font-weight: 700;
}

/* NEW: Styles for sub-section titles (h4) - ensuring uppercase and matching color */
.settings-modal-content h4 {
    text-transform: uppercase;
    color: var(--lighter-primary-color);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    gap: 15px; /* Add gap for spacing */
}

.setting-item label {
    font-size: 1rem;
    flex-shrink: 0; /* Prevent label from shrinking */
}

/* Remove default number input */
.setting-item input[type="number"] {
   display: none;
}

.setting-item select {
    background: rgba(0,0,0,0.5);
    color: var(--text-color);
    border: 1px solid var(--primary-color);
    border-radius: 4px;
    padding: 5px 8px;
    width: 120px; /* Increased width */
    appearance: none;
    -webkit-appearance: none;
}

.setting-item input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: var(--secondary-color);
    outline: none;
    border-radius: 4px;
    border: 1px solid rgba(var(--primary-color-rgb), 0.5);
}

.setting-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid #fff;
}

.setting-item input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid #fff;
}

/* Toggle Switch Styles */
.switch { position: relative; display: inline-block; width: 78px; height: 30px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background-color: #dc3545; transition: .25s; border-radius: 30px; }
.slider:before { position: absolute; content: ""; height: 24px; width: 24px; left: 4px; bottom: 3px; background-color: white; transition: .25s; border-radius: 50%; }
input:checked + .slider { background-color: #28a745; }
input:focus + .slider { box-shadow: 0 0 0 2px rgba(var(--primary-color-rgb), 0.25); }
input:checked + .slider:before { transform: translateX(48px); }
.slider.round { border-radius: 30px; }
.slider.round:before { border-radius: 50%; }
/* ON/OFF label inside switch - centered and slightly larger */
.slider::after { 
  content: "OFF"; position: absolute; top: 50%; left: 75%; transform: translate(-50%, -50%);
  color: #fff; font-size: 13px; font-weight: 800; letter-spacing: 0.5px; pointer-events: none;
}
input:checked + .slider::after { content: "ON"; left: 25%; }

#castSizeValue {
    display: inline-block; /* Show current Cast Image Size value at end of row */
}

.setting-value-display {
    width: 100px; /* Increased width for better text fit */
    text-align: right;
    font-weight: bold;
    color: var(--lighter-primary-color);
}

/* NEW: Number input with buttons */
.number-input-container {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}
.number-input-container input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
    display: inline-block; /* Make it visible again */
    width: 64px;
    text-align: center;
    border: 1px solid var(--primary-color);
    background: rgba(0,0,0,0.5);
    color: var(--text-color);
    border-radius: 6px;
    padding: 2px 2px; /* 2px spacing around each side */
    font-weight: 700;
}
.number-input-container input[type="number"]:focus {
  box-shadow: 0 0 0 2px rgba(var(--primary-color-rgb), 0.25);
}
.number-input-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #000;
    border: none;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.number-input-btn:hover {
    opacity: 0.8;
}

/* NEW: Hide inner spinner arrows for settings number inputs (desktop & mobile) */
.settings-modal-content input[type="number"]::-webkit-inner-spin-button,
.settings-modal-content input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.settings-modal-content input[type="number"] {
    -moz-appearance: textfield;
}

/* NEW: Wrapper for custom select arrow */
.select-wrapper {
    position: relative;
    width: 160px;
}
.select-wrapper select {
  background: rgba(0,0,0,0.5);
  color: var(--text-color);
  border: 1px solid var(--primary-color);
  border-radius: 6px;
  padding: 8px 30px 8px 10px;
  width: 100%;
}
.select-wrapper::after {
  content: '▾';
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  font-size: 0.9rem;
  color: var(--primary-color);
  pointer-events: none;
}

/* NEW: Slider container to group slider and value */
.slider-container {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 70%; /* Occupy remaining space */
}
.slider-container input[type="range"] {
    flex-grow: 1;
}
.slider-container .setting-value-display {
    flex-shrink: 0;
}

/* Light theme readability tweaks */
[data-theme^="light"] .settings-modal-content {
    background-color: rgba(255, 255, 255, 0.95);
}
[data-theme^="light"] .settings-modal-content h2,
[data-theme^="light"] .settings-modal-content .settings-section h3,
[data-theme^="light"] .settings-modal-content .setting-item label {
  color: var(--lighter-primary-color) !important;
  font-weight: 700;
}

/* NEW: Per-theme font color overrides for Settings (light-yellow, light-gray, light-orange) */
[data-theme="light-yellow"] .settings-modal-content h2,
[data-theme="light-yellow"] .settings-modal-content .settings-section h3,
[data-theme="light-yellow"] .settings-modal-content .settings-subsection .subsection-header,
[data-theme="light-yellow"] .settings-modal-content .setting-item label {
  color: #fbc02d !important; /* dark yellow */
}

[data-theme="light-gray"] .settings-modal-content h2,
[data-theme="light-gray"] .settings-modal-content .settings-section h3,
[data-theme="light-gray"] .settings-modal-content .settings-subsection .subsection-header,
[data-theme="light-gray"] .settings-modal-content .setting-item label {
  color: #424242 !important; /* dark gray */
}

[data-theme="light-orange"] .settings-modal-content h2,
[data-theme="light-orange"] .settings-modal-content .settings-section h3,
[data-theme="light-orange"] .settings-modal-content .settings-subsection .subsection-header,
[data-theme="light-orange"] .settings-modal-content .setting-item label {
  color: #e65100 !important; /* dark orange */
}

/* NEW: collapsed state hides settings within the section */
.settings-section.collapsed > .setting-item {
    display: none;
}
/* Keep subsection independence: subsection collapse still controls its own items */
.settings-subsection.collapsed .setting-item {
    display: none;
}

.settings-theme-ball {
    position: absolute;
    right: 15px;
    bottom: 15px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary-color);
    opacity: 0.5; /* 50% transparent */
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.2);
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
.settings-theme-ball:hover {
    transform: scale(1.06);
    box-shadow: 0 4px 14px rgba(0,0,0,0.5);
    opacity: 0.6;
}
/* Ensure visibility on light themes */
[data-theme^="light"] .settings-theme-ball {
    border-color: rgba(0,0,0,0.2);
}

/* Range slider polish: thicker track, filled color, and value bubble */
.setting-item input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 10px;
  background: var(--secondary-color);
  border-radius: 6px;
  outline: none;
  border: 1px solid rgba(var(--primary-color-rgb), 0.4);
  background-image: linear-gradient(var(--primary-color), var(--primary-color));
  background-size: 0% 100%;
  background-repeat: no-repeat;
}
.setting-item input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  background: #fff;
  border: 2px solid var(--primary-color);
  border-radius: 50%;
  cursor: pointer;
  transition: transform .15s ease;
}
.setting-item input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.06); }
.setting-item input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px; background: #fff; border: 2px solid var(--primary-color); border-radius: 50%; cursor: pointer;
}
.setting-item input[type="range"]::-moz-range-track { height: 10px; background: transparent; border: none; }
.range-bubble {
  position: absolute;
  top: -34px;
  left: 0;
  transform: translateX(-50%);
  padding: 4px 8px;
  background: rgba(0,0,0,0.85);
  color: #fff;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--primary-color);
  pointer-events: none;
  white-space: nowrap;
}

/* Number input: larger field and clearer focus */
.number-input-container input[type="number"] {
  display: inline-block;
  width: 64px;
  text-align: center;
  border: 1px solid var(--primary-color);
  background: rgba(0,0,0,0.5);
  color: var(--text-color);
  border-radius: 6px;
  padding: 2px 2px; /* consistent 2px padding */
  font-weight: 700;
}
.number-input-container input[type="number"]:focus {
  box-shadow: 0 0 0 2px rgba(var(--primary-color-rgb), 0.25);
}

/* Bigger buttons for steppers */
.number-input-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-color);
  color: #000;
  border: none;
  font-size: 1.2rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Selects: slightly wider and clearer arrow */
.select-wrapper { position: relative; width: 160px; }
.select-wrapper select {
  background: rgba(0,0,0,0.5);
  color: var(--text-color);
  border: 1px solid var(--primary-color);
  border-radius: 6px;
  padding: 8px 30px 8px 10px;
  width: 100%;
}
.select-wrapper::after {
  content: '▾';
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  font-size: 0.9rem;
  color: var(--primary-color);
  pointer-events: none;
}

/* --- NEW: Mobile tweaks to match compact desktop layout --- */
@media (max-width: 768px) {
  .settings-modal-content {
    width: 80%;
    max-width: 80%;
    /* Let height be driven by content but clamp inside viewport */
    height: auto;
    max-height: calc(100vh - 40px);
    border-radius: 12px;
    padding: 15px 15px 25px 15px;
    box-sizing: border-box;
    font-size: 0.8rem; /* overall slightly smaller like desktop */
    /* Ensure the top and bottom of the window are visible within the screen */
    margin: 0; /* center via flex on overlay */
  }

  .settings-modal-content h2 {
    margin-bottom: 18px;
  }

  .settings-section {
    margin-bottom: 15px;
    padding-top: 15px;
  }

  .settings-section h3 {
    font-size: 0.9rem;
    padding: 8px 10px;
  }

  .settings-subsection .subsection-header {
    font-size: 0.8rem;
    padding: 6px 8px;
  }

  .setting-item {
    gap: 10px;
    margin-bottom: 10px;
  }

  .setting-item label {
    font-size: 0.85rem;
  }

  .setting-value-display {
    font-size: 0.8rem;
  }

  .number-input-container input[type="number"] {
    width: 56px;
    padding: 2px 2px; /* keep 2px padding on mobile too */
    font-size: 0.8rem;
  }

  .number-input-btn {
    width: 26px;
    height: 26px;
    font-size: 1rem;
  }

  .slider-container {
    gap: 8px;
  }

  .setting-item input[type="range"] {
    height: 8px;
  }

  .select-wrapper {
    width: 140px;
  }

  .select-wrapper select {
    padding: 6px 26px 6px 8px;
    font-size: 0.8rem;
  }

  .settings-theme-ball {
    width: 40px;
    height: 40px;
    right: 10px;
    bottom: 10px;
  }
}

/* NEW: Narrower slider just for the Desktop Single Listing Cast Image Size row */
.slider-container.slider-cast-size {
    width: 50%; /* Make this specific slider container smaller than the default 70% */
}

.slider-container.slider-cast-size input[type="range"] {
    max-width: 140px; /* Visibly shorter slider track */
}