*,
*::before,
*::after {
  box-sizing: border-box;
  user-select: none;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  font-family: 'verdana';
  overflow: hidden;
}

canvas {
  width: 100%;
  height: 100%;
}

.simple-button {
  cursor: pointer;
  color: #fff;
  font-size: 12px;
  text-align: center;
  padding: 5px;
  background: #424242;
  border-radius: 3px;
  margin: 5px;
}

.simple-button:hover {
  background: #4f4f4f;
  user-select: none;
}

.lil-gui.root {
  max-height: 100%;
}

/* Old fixed-position curve editor styles removed - now using modal */

.draggable-points {
  width: 300px;
  height: 200px;
  position: absolute;
  top: 0;
  left: 0;
  cursor: auto !important;
}

.draggable-point {
  cursor: pointer !important;
  background: #ffffff55;
  border-radius: 50%;
  left: 0;
  top: 0;
  position: absolute;
  border: 1px solid #ffffff55;
}

.bezier-point {
  position: absolute;
  background: #ffff0055;
  width: 20px;
  height: 20px;
  transform: translate(-10px, -10px);
}

.control-point {
  position: absolute;
  width: 10px;
  height: 10px;
  transform: translate(5px, 5px);
}

/* Old preset list styles removed - now using modal with new button-based presets */

/* Gradient Editor Modal */
.gradient-editor-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  pointer-events: none;
}

.gradient-editor-modal__content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #222;
  border: 2px solid #444;
  border-radius: 8px;
  padding: 20px;
  max-width: 600px;
  width: 90%;
  color: #fff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
  pointer-events: auto;
  cursor: grab;
}

.gradient-editor-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid #444;
  padding-bottom: 10px;
  user-select: none;
}

.gradient-editor-modal__header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.gradient-editor-modal__header-buttons {
  display: flex;
  gap: 5px;
}

.gradient-editor-modal__info,
.gradient-editor-modal__close {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.gradient-editor-modal__info {
  font-size: 16px;
  font-weight: bold;
}

.gradient-editor-modal__close {
  font-size: 28px;
}

.gradient-editor-modal__info:hover,
.gradient-editor-modal__close:hover {
  background: #444;
}

.gradient-editor-modal__body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.gradient-editor-wrapper {
  position: relative;
  width: 100%;
  height: 80px;
  background: #333;
  border-radius: 4px;
  padding: 10px;
  cursor: auto !important;
}

.gradient-editor-canvas {
  width: 100%;
  display: block;
  border-radius: 4px;
  cursor: crosshair !important;
}

.gradient-stop-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid white;
  cursor: pointer !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: transform 0.1s;
}

.gradient-stop-handle:hover {
  transform: scale(1.2);
}

.gradient-editor-info {
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 12px;
  font-size: 12px;
  color: #aaa;
  line-height: 1.6;
}

.gradient-editor-info p {
  margin: 4px 0;
}

.gradient-editor-info strong {
  color: #4a9eff;
}

.gradient-editor-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
  padding: 10px;
  background: #2a2a2a;
  border-radius: 6px;
  border: 1px solid #444;
  cursor: auto !important;
}

.gradient-preset-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px;
  font-size: 11px;
  cursor: pointer !important;
  border: 2px solid #666;
  background: #333;
  color: #fff;
  border-radius: 4px;
  transition: all 0.15s;
  min-width: 70px;
}

.gradient-preset-button:hover {
  background: #3a3a3a;
  border-color: #888;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.gradient-preset-button:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.gradient-save-button:hover {
  background: #333 !important;
  border-color: #6bb3ff !important;
}

.gradient-preset-delete {
  position: absolute;
  top: 0;
  right: 0;
  width: 18px;
  height: 18px;
  border: none;
  background: #ff4444;
  color: white;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
}

.gradient-preset-delete:hover {
  background: #ff6666;
}

/* Bezier Editor Modal */
.bezier-editor-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  pointer-events: none;
}

.bezier-editor-modal__content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #222;
  border: 2px solid #444;
  border-radius: 8px;
  padding: 20px;
  max-width: 600px;
  width: 90%;
  color: #fff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
  pointer-events: auto;
  cursor: grab;
}

.bezier-editor-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid #444;
  padding-bottom: 10px;
  user-select: none;
}

.bezier-editor-modal__header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.bezier-editor-modal__header-buttons {
  display: flex;
  gap: 5px;
}

.bezier-editor-modal__info,
.bezier-editor-modal__close {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.bezier-editor-modal__info {
  font-size: 16px;
  font-weight: bold;
}

.bezier-editor-modal__close {
  font-size: 28px;
}

.bezier-editor-modal__info:hover,
.bezier-editor-modal__close:hover {
  background: #444;
}

.bezier-editor-modal__body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.bezier-editor__content {
  position: relative;
  width: 300px;
  height: 200px;
  background: #1a1a1a;
  border-radius: 4px;
  padding: 10px;
  margin: 0 auto;
  cursor: auto !important;
}

.bezier-editor__canvas {
  display: block;
  border: 1px solid #444;
  border-radius: 4px;
  background: #1a1a1a;
  cursor: auto !important;
}

.bezier-editor-info {
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 12px;
  font-size: 12px;
  line-height: 1.6;
}

.bezier-editor-info p {
  margin: 4px 0;
}

.bezier-editor-info strong {
  color: #4a9eff;
}

.bezier-editor-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
  padding: 10px;
  background: #2a2a2a;
  border-radius: 6px;
  border: 1px solid #444;
  cursor: auto !important;
}

.bezier-preset-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px;
  font-size: 11px;
  cursor: pointer !important;
  border: 2px solid #666;
  background: #333;
  color: #fff;
  border-radius: 4px;
  transition: all 0.15s;
  min-width: 70px;
}

.bezier-preset-button:hover {
  background: #3a3a3a;
  border-color: #888;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.bezier-preset-button:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.bezier-save-button:hover {
  background: #333 !important;
  border-color: #6bb3ff !important;
}

.bezier-preset-delete {
  position: absolute;
  top: 0;
  right: 0;
  width: 18px;
  height: 18px;
  border: none;
  background: #ff4444;
  color: white;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
}

.bezier-preset-delete:hover {
  background: #ff6666;
}

/* Texture Selector Modal */
.texture-selector-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  pointer-events: none;
}

.texture-selector-modal__content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #222;
  border: 2px solid #444;
  border-radius: 8px;
  padding: 20px;
  max-width: 650px;
  width: 85%;
  max-height: 75vh;
  color: #fff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
  pointer-events: auto;
  cursor: grab;
  display: flex;
  flex-direction: column;
}

.texture-selector-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid #444;
  padding-bottom: 10px;
  user-select: none;
}

.texture-selector-modal__header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.texture-selector-modal__header-buttons {
  display: flex;
  gap: 5px;
}

.texture-selector-modal__close {
  background: none;
  border: none;
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.texture-selector-modal__close:hover {
  background: #444;
}

.texture-selector-modal__body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.texture-selector-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 6px;
}

.texture-selector-search-icon {
  color: #888;
  font-size: 20px;
  user-select: none;
}

.texture-selector-search-input {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 14px;
  outline: none;
  padding: 4px;
}

.texture-selector-search-input::placeholder {
  color: #666;
}

.texture-selector-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: minmax(140px, auto);
  gap: 12px;
  overflow-y: auto;
  padding: 10px;
  background: #2a2a2a;
  border-radius: 6px;
  border: 1px solid #444;
  cursor: auto !important;
  max-height: calc(75vh - 180px);
}

.texture-selector-item {
  display: flex;
  flex-direction: column;
  background: #333;
  border: 2px solid #555;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.15s;
}

.texture-selector-item:hover {
  border-color: #888;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.texture-selector-item--selected {
  border-color: #4a9eff;
  background: #3a3a3a;
}

.texture-selector-item--selected:hover {
  border-color: #6bb3ff;
}

.texture-selector-preview {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 100%;
  background: #1a1a1a;
  flex-shrink: 0;
}

.texture-selector-transparent-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url(./static/transparent.webp);
  background-repeat: repeat;
  background-size: 20%;
}

.texture-selector-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.texture-selector-circle-preview {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 1px dashed rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  pointer-events: none;
}

.texture-selector-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  background: #2a2a2a;
  gap: 8px;
}

.texture-selector-name {
  flex: 1;
  font-size: 11px;
  color: #ccc;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.texture-selector-download {
  background: #4a9eff;
  border: none;
  color: white;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  transition: background 0.15s;
  flex-shrink: 0;
}

.texture-selector-download:hover {
  background: #6bb3ff;
}

/* The safe-area insets, readable from script (the HUD reports them). */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

/*
  Presentation mode (presentation.ts): this window is the display for a while.
  Everything but the canvas and the frame counter is hidden; the canvas is
  sized by the renderer to the output camera's aspect and centred, the bars
  around it being the page showing through, as in player.html.
*/
body.presenting {
  background: #000;
  touch-action: manipulation;
}

body.presenting > .wrapper:not(:has(#three-particles-editor)),
body.presenting > .wrapper:has(#three-particles-editor) > :not(#three-particles-editor):not(.stats),
body.presenting > .lil-gui,
body.presenting .player-window-toggle,
body.presenting .presentation-toggle,
body.presenting .player-suspend-card {
  display: none !important;
}

body.presenting #three-particles-editor {
  position: fixed;
  inset: 0;
  bottom: auto;
  /* Reaches into the strip iOS 26 leaves above or below the layout viewport
     (world.ts): shifted up by the top gap, tall enough for both. */
  top: calc(-1 * var(--viewport-top-gap, 0px));
  height: calc(100% + var(--viewport-top-gap, 0px) + var(--viewport-gap, 0px));
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

body.presenting #three-particles-editor canvas {
  display: block;
}

body.presenting .stats {
  position: fixed !important;
  left: env(safe-area-inset-left) !important;
  top: env(safe-area-inset-top) !important;
  z-index: 1001;
}

body.presenting .stats > div {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
}

body.presenting .stats.is-hidden {
  display: none;
}

.presentation-bar {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom) - var(--viewport-gap, 0px));
  z-index: 1002;
  display: flex;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.presentation-bar.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.presentation-bar button {
  padding: 12px 18px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font: 500 15px/1 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  cursor: pointer;
}
