* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #eee;
  font-family: 'SF Mono', 'Fira Code', 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  -webkit-text-size-adjust: 100%;
}

#starCanvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000;
  /* Suppress iOS native long-press callout / selection / image save menu */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* --- Bottom info --- */
#bottomInfos {
  position: fixed;
  bottom: 8px;
  right: 12px;
  z-index: 10;
  pointer-events: none;
}
.simpleText {
  font-size: 10px;
  color: #555;
  letter-spacing: 0.5px;
}

/* --- Glass control panel (matches caostar /chaos-follows-you/) --- */
.cp-panel {
  position: fixed;
  left: 16px;
  top: 16px;
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  color: #eee;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  z-index: 10000;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  user-select: none;
  min-width: 44px;
  transition: width 0.2s ease;
}

.cp-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  border-radius: 12px 12px 0 0;
}
.cp-tab:hover { background: rgba(255, 255, 255, 0.04); }
.cp-panel.collapsed .cp-tab { border-radius: 12px; border-bottom-color: transparent; }
.cp-panel:not(.collapsed) .cp-tab { border-bottom-color: rgba(255, 255, 255, 0.1); }

.cp-tab-icon {
  font-size: 16px;
  color: #4fc3f7;
}
.cp-tab-label {
  font-weight: bold;
  font-size: 14px;
}
.cp-tab-status {
  margin-left: auto;
  font-size: 11px;
  color: #4fc3f7;
  transition: opacity 0.2s;
  opacity: 0.4;
}
.cp-tab-status.active {
  opacity: 1;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.cp-body {
  padding: 10px 14px;
  width: 280px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}
.cp-panel.collapsed .cp-body { display: none; }

.cp-body::-webkit-scrollbar { width: 5px; }
.cp-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 3px; }

/* --- Tabs inside panel --- */
.ctrl-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 10px;
}
.ctrl-tab {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #888;
  padding: 5px 4px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 10px;
  font-family: inherit;
  transition: all 0.15s;
}
.ctrl-tab:hover { background: rgba(255, 255, 255, 0.1); color: #ccc; }
.ctrl-tab.active {
  background: rgba(79, 195, 247, 0.12);
  color: #4fc3f7;
  border-color: rgba(79, 195, 247, 0.3);
}

.ctrl-tab-content { display: none; }
.ctrl-tab-content.active { display: block; }

/* --- Control rows --- */
.cs-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.cs-label {
  font-size: 10px;
  color: #aaa;
  letter-spacing: 0.5px;
}
.cs-slider-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cs-slider {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.cs-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: #4fc3f7;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
.cs-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: #4fc3f7;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
.cs-val {
  font-size: 10px;
  color: #4fc3f7;
  min-width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Buttons */
.cp-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #ddd;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
  transition: all 0.15s;
  width: 100%;
  margin-bottom: 6px;
}
.cp-btn:hover { background: rgba(255, 255, 255, 0.15); border-color: rgba(255, 255, 255, 0.25); }

.cp-btn-start {
  background: rgba(79, 195, 247, 0.12);
  border-color: rgba(79, 195, 247, 0.3);
  color: #4fc3f7;
  font-weight: bold;
  padding: 10px 12px;
}
.cp-btn-start:hover { background: rgba(79, 195, 247, 0.22); }
.cp-btn-start.active {
  background: rgba(79, 195, 247, 0.25);
  color: #fff;
  border-color: #4fc3f7;
  animation: pulse 1.5s ease-in-out infinite;
}

/* Toggle */
.cs-toggle-wrap {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.cs-toggle { display: none; }
.cs-toggle-indicator {
  width: 28px;
  height: 14px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.cs-toggle-indicator::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  background: #888;
  border-radius: 50%;
  transition: all 0.2s;
}
.cs-toggle:checked + .cs-toggle-indicator { background: rgba(79, 195, 247, 0.3); }
.cs-toggle:checked + .cs-toggle-indicator::after { left: 16px; background: #4fc3f7; }

/* Select dropdown */
.cs-select {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #ccc;
  padding: 5px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-family: inherit;
  outline: none;
  text-transform: capitalize;
  cursor: pointer;
}
.cs-select:focus { border-color: rgba(79, 195, 247, 0.5); }

/* Color input */
.cs-color {
  -webkit-appearance: none;
  appearance: none;
  width: 36px;
  height: 22px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  cursor: pointer;
  background: none;
  padding: 0;
  flex-shrink: 0;
}
.cs-color::-webkit-color-swatch-wrapper { padding: 2px; }
.cs-color::-webkit-color-swatch { border: none; border-radius: 2px; }
.cs-color::-moz-color-swatch { border: none; border-radius: 2px; }

/* Color row layout */
.cs-color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.cs-color-row .cs-label { margin-bottom: 0; flex: 1; }

/* Gradient editor */
.gradient-preview {
  height: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  margin: 6px 0;
}
.gradient-stops-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 160px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}
.gradient-stop-row {
  display: grid;
  grid-template-columns: 30px 1fr 32px 18px;
  align-items: center;
  gap: 6px;
}
.gradient-stop-row .cs-color {
  width: 100%;
  height: 18px;
}
.gradient-pos-slider {
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  width: 100%;
}
.gradient-pos-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  background: #4fc3f7;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
.gradient-pos-slider::-moz-range-thumb {
  width: 10px;
  height: 10px;
  background: #4fc3f7;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
.gradient-pos-label {
  font-size: 9.5px;
  color: #888;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.btn-remove {
  background: transparent;
  border: none;
  color: #666;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  line-height: 1;
}
.btn-remove:hover:not(:disabled) { color: #ff5555; }
.btn-remove:disabled { opacity: 0.25; cursor: default; }

.dg-add-stop {
  margin-top: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #aaa;
  font-family: inherit;
  font-size: 10px;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  width: 100%;
  transition: all 0.15s;
}
.dg-add-stop:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ddd;
}

/* Keyboard shortcut rows */
.ctrl-keys {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 10px;
}
.ctrl-key-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
}
.ctrl-key-row kbd {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 3px;
  padding: 2px 6px;
  font-size: 10px;
  font-family: inherit;
  color: #4fc3f7;
  min-width: 50px;
  text-align: center;
}
.ctrl-key-row span { color: #aaa; }

.ctrl-key-row.clickable {
  cursor: pointer;
  padding: 4px 6px;
  margin: 0 -6px;
  border-radius: 4px;
  transition: background 0.15s;
  user-select: none;
}
.ctrl-key-row.clickable:hover { background: rgba(79, 195, 247, 0.08); }
.ctrl-key-row.clickable:hover span { color: #4fc3f7; }
.ctrl-key-row.clickable:active { background: rgba(79, 195, 247, 0.18); }

/* --- Texture tab --- */
.tx-mode-row {
  display: flex;
  gap: 4px;
}
.tx-mode-row .ctrl-tab { padding: 5px 6px; }

.tx-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin: 8px 0 12px;
  max-height: 220px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}
.tx-cell {
  aspect-ratio: 1;
  background-size: cover;
  background-position: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  transition: border-color 0.15s, box-shadow 0.15s, filter 0.15s;
}
.tx-cell:hover {
  border-color: rgba(79, 195, 247, 0.6);
  box-shadow: 0 0 0 2px rgba(79, 195, 247, 0.3);
  filter: brightness(1.15);
}
.tx-cell.active {
  border-color: #4fc3f7;
  box-shadow: 0 0 0 2px #4fc3f7;
}

/* Drag mode cursor */
body.texture-drag #starCanvas { cursor: grab; }
body.texture-drag #starCanvas:active { cursor: grabbing; }

/* Hide controls (H key) */
.controls-hidden #controls-panel,
.controls-hidden #bottomInfos { display: none; }

/* Toast */
#toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: rgba(0, 0, 0, 0.85);
  color: #4fc3f7;
  border: 1px solid rgba(79, 195, 247, 0.3);
  padding: 10px 32px 10px 18px;
  border-radius: 8px;
  font-size: 11px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  pointer-events: none;
  z-index: 1000;
  max-width: calc(100vw - 40px);
  cursor: pointer;
}
#toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
#toast.show::after {
  content: '×';
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: 16px;
  color: #888;
  line-height: 1;
}
#toast:hover::after { color: #fff; }

/* --- Welcome modal (matches caostar /chaos-follows-you/) --- */
#welcome-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 50000;
  opacity: 0;
  transition: opacity 0.4s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#welcome-modal.visible { opacity: 1; }

.wm-card {
  position: relative;
  background: rgba(10, 10, 15, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 32px 36px;
  max-width: 520px;
  width: calc(100vw - 40px);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  color: #ddd;
  font-family: 'SF Mono', 'Fira Code', monospace;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.wm-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: #666;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  transition: color 0.15s;
}
.wm-close:hover { color: #eee; }

.wm-title {
  font-size: 22px;
  font-weight: bold;
  color: #fff;
  margin: 0 0 6px;
}
.wm-subtitle {
  font-size: 12px;
  color: #888;
  margin: 0 0 20px;
  line-height: 1.5;
}

.wm-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}
.wm-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  color: #ddd;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}
.wm-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
}
.wm-btn-icon { font-size: 24px; color: #4fc3f7; }
.wm-btn-label { font-size: 12px; font-weight: bold; color: #eee; }
.wm-btn-desc { font-size: 9px; color: #666; text-align: center; }

.wm-btn-stream:hover { border-color: rgba(79, 195, 247, 0.4); }
.wm-btn-hand:hover { border-color: rgba(129, 199, 132, 0.4); }
.wm-btn-random:hover { border-color: rgba(255, 183, 77, 0.4); }

.wm-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 0 0 16px;
}

.wm-featured {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}
.wm-feat {
  flex: 1;
  background: rgba(79, 195, 247, 0.06);
  border: 1px solid rgba(79, 195, 247, 0.15);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 11px;
  color: #aaa;
  text-align: center;
}
.wm-feat kbd {
  background: rgba(79, 195, 247, 0.15);
  border: 1px solid rgba(79, 195, 247, 0.3);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-family: inherit;
  color: #4fc3f7;
}

.wm-sections {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
}
.wm-section { flex: 1; }
.wm-section h3 {
  font-size: 11px;
  color: #888;
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: bold;
}
.wm-keys {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.wm-key-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}
.wm-key-row kbd {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 10px;
  font-family: inherit;
  color: #4fc3f7;
  min-width: 48px;
  text-align: center;
}
.wm-key-row span { color: #999; }

.wm-footer {
  font-size: 10px;
  color: #555;
  text-align: center;
  margin: 0 0 12px;
}
.wm-links {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 12px;
}
.wm-links p {
  font-size: 10px;
  color: #666;
  margin: 0;
  text-align: center;
}
.wm-links a {
  color: #4fc3f7;
  text-decoration: none;
  transition: color 0.15s;
}
.wm-links a:hover { color: #81d4fa; }

/* "?" help icon on the panel header */
.cp-help-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #aaa;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  padding: 0;
  transition: all 0.15s;
}
.cp-help-btn:hover {
  background: rgba(79, 195, 247, 0.2);
  border-color: rgba(79, 195, 247, 0.4);
  color: #4fc3f7;
}

@media (max-width: 700px) {
  .hiddenOnMobile { display: none; }

  .cp-panel {
    left: 8px;
    top: 8px;
    right: 8px;
    width: auto;
    max-width: calc(100vw - 16px);
  }
  .cp-body {
    width: 100%;
    max-height: calc(100vh - 80px);
    max-height: calc(100dvh - 80px);
    padding: 12px 14px;
  }

  /* Bigger touch targets on mobile */
  .ctrl-tab { padding: 8px 6px; font-size: 12px; }
  .cs-slider { height: 8px; border-radius: 4px; }
  .cs-slider::-webkit-slider-thumb { width: 20px; height: 20px; }
  .cs-slider::-moz-range-thumb { width: 20px; height: 20px; }
  .gradient-pos-slider { height: 6px; }
  .gradient-pos-slider::-webkit-slider-thumb { width: 16px; height: 16px; }
  .gradient-pos-slider::-moz-range-thumb { width: 16px; height: 16px; }
  .cs-toggle-indicator { width: 36px; height: 18px; border-radius: 9px; }
  .cs-toggle-indicator::after { width: 14px; height: 14px; }
  .cs-toggle:checked + .cs-toggle-indicator::after { left: 20px; }
  .cs-color { height: 28px; }
  .cp-btn { padding: 10px 14px; font-size: 12px; }
  .cs-val { font-size: 11px; }
  .cs-label { font-size: 11px; }

  .gradient-stops-list { max-height: 180px; }
  .gradient-stop-row { grid-template-columns: 36px 1fr 36px 24px; gap: 8px; }

  #bottomInfos { display: none; }

  /* Welcome modal */
  .wm-card {
    padding: 20px 18px;
    border-radius: 12px;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
  }
  .wm-title { font-size: 18px; }
  .wm-actions { flex-direction: column; gap: 8px; }
  .wm-btn { flex-direction: row; gap: 10px; padding: 12px 16px; align-items: center; }
  .wm-btn-icon { font-size: 22px; }
  .wm-btn-label { font-size: 14px; }
  .wm-btn-desc { font-size: 11px; text-align: left; }
  .wm-sections { flex-direction: column; gap: 8px; }
  .wm-featured { flex-direction: column; gap: 6px; }
}

/* Prevent iOS-style page scroll bounce */
html, body { overscroll-behavior: none; touch-action: none; }
#controls-panel, #welcome-modal { touch-action: auto; }
.cs-slider, .gradient-pos-slider, .cs-color, .cs-select, input, button, select, label {
  touch-action: manipulation;
}
