:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #05070b;
  color: #101113;
  --panel-surface: rgba(248, 248, 248, 0.9);
  --control-surface: linear-gradient(to bottom, rgba(255, 255, 255, 0.92), rgba(239, 240, 242, 0.92));
  --control-active: linear-gradient(to bottom, #e8e9eb, #f8f8f9);
  --track-surface: linear-gradient(to bottom, #e3e4e6, #f5f6f7);
  --menu-line: rgba(255, 255, 255, 0.74);
  --text-muted: rgba(16, 17, 19, 0.48);
  --control-height: 32px;
  --slider-thumb-size: 22px;
  --elastic-ease: cubic-bezier(0.2, 1.35, 0.32, 1);
  --soft-shadow: 0 0 0 1px rgba(0, 0, 0, 0.035), 0 8px 20px rgba(0, 0, 0, 0.1);
  --soft-raised: 0 1px 0 rgba(255, 255, 255, 0.82), 0 3px 9px rgba(0, 0, 0, 0.07);
  --soft-inset: inset 0 1px 3px rgba(0, 0, 0, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

@keyframes pop-bounce {
  0% {
    opacity: 0;
    transform: translateY(-4px) scale(0.96, 1.04);
  }

  62% {
    opacity: 1;
    transform: translateY(1px) scale(1.02, 0.98);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes accordion-drop {
  0% {
    opacity: 0;
    grid-template-rows: 0fr;
    transform: translateY(-5px) scale(0.98, 0.94);
  }

  64% {
    opacity: 1;
    grid-template-rows: 1fr;
    transform: translateY(1px) scale(1.01, 1.02);
  }

  100% {
    opacity: 1;
    grid-template-rows: 1fr;
    transform: translateY(0) scale(1);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #05070b;
}

button,
input,
select {
  font: inherit;
}

#app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #05070b;
}

#canvas-wrap {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

#p5-capture-bridge {
  position: fixed !important;
  left: -9999px !important;
  top: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0;
  pointer-events: none;
}

#brush-preview {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2;
  border: 2px solid rgba(255, 255, 255, 0.88);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 1px rgba(16, 17, 19, 0.2), 0 12px 32px rgba(0, 0, 0, 0.22), inset 0 0 24px rgba(255, 255, 255, 0.1);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, width 120ms ease, height 120ms ease, transform 120ms ease;
}

#brush-preview.visible {
  opacity: 1;
}

#top-actions {
  position: fixed;
  top: clamp(16px, 4vh, 34px);
  right: clamp(14px, 4vw, 42px);
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-button,
.top-action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: max-content;
  min-height: var(--control-height);
  border: 1px solid var(--menu-line);
  border-radius: 14px;
  background: var(--control-surface);
  box-shadow: var(--soft-raised);
  color: rgba(16, 17, 19, 0.74);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  cursor: pointer;
  backdrop-filter: blur(18px);
  transform-origin: center;
  transition:
    background 180ms var(--elastic-ease),
    box-shadow 180ms var(--elastic-ease),
    color 160ms ease,
    transform 220ms var(--elastic-ease);
}

.menu-button {
  gap: 6px;
  padding: 0 13px;
}

.top-action-button {
  width: var(--control-height);
  min-width: var(--control-height);
  padding: 0;
}

.menu-button i,
.top-action-button i {
  font-size: 1rem;
  line-height: 1;
}

.menu-button:hover,
.menu-button[aria-expanded="true"],
.top-action-button:hover,
.top-action-button.active {
  color: rgba(16, 17, 19, 0.88);
  background: var(--control-active);
  box-shadow: var(--soft-inset);
}

.top-action-button.recording {
  color: #c92334;
  box-shadow: inset 0 1px 3px rgba(146, 19, 35, 0.2), 0 0 0 1px rgba(201, 35, 52, 0.2);
}

.top-action-button.busy {
  opacity: 0.72;
  cursor: wait;
}

.menu-button:hover,
.top-action-button:hover {
  transform: translateY(-1px) scale(1.025, 0.985);
}

.menu-button:active,
.top-action-button:active,
button:active {
  transform: scale(0.96, 1.04);
}

#controls {
  position: fixed;
  top: clamp(58px, 9vh, 80px);
  right: clamp(14px, 4vw, 42px);
  z-index: 3;
  width: min(340px, calc(100vw - 32px));
  max-height: min(84vh, 680px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--menu-line);
  border-radius: 18px;
  background: var(--panel-surface);
  box-shadow: var(--soft-shadow);
  color: #101113;
  backdrop-filter: blur(18px);
  scrollbar-width: none;
}

#controls::-webkit-scrollbar {
  display: none;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--text-muted);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: rgba(16, 17, 19, 0.9);
  font-size: 1rem;
  line-height: 1.08;
  letter-spacing: 0;
}

button {
  min-height: var(--control-height);
  border: 1px solid var(--menu-line);
  border-radius: 12px;
  background: var(--control-surface);
  box-shadow: var(--soft-raised);
  color: rgba(16, 17, 19, 0.74);
  cursor: pointer;
  transform-origin: center;
  transition:
    background 180ms var(--elastic-ease),
    box-shadow 180ms var(--elastic-ease),
    color 160ms ease,
    transform 220ms var(--elastic-ease);
}

button:hover,
button.active,
.wide-button[aria-expanded="true"] {
  color: rgba(16, 17, 19, 0.88);
  background: var(--control-active);
  box-shadow: var(--soft-inset);
}

.control-grid,
.advanced {
  display: grid;
  gap: 8px;
}

.advanced {
  margin-top: 8px;
}

.wide-button {
  width: 100%;
  min-height: var(--control-height);
  margin-top: 8px;
  color: rgba(16, 17, 19, 0.58);
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.advanced[hidden] {
  display: none;
}

.color-options-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.color-options-toggle i {
  font-size: 0.9rem;
  transition: transform 260ms var(--elastic-ease);
}

.color-options-toggle[aria-expanded="true"] i {
  transform: rotate(180deg);
}

.color-options-panel {
  display: grid;
  grid-template-rows: 1fr;
  margin-top: 8px;
  overflow: hidden;
  transform-origin: top center;
  animation: accordion-drop 360ms var(--elastic-ease);
}

.color-options-inner {
  display: grid;
  min-height: 0;
  gap: 8px;
  overflow: hidden;
}

.color-options-panel[hidden] {
  display: none;
}

.mode-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.mode-controls button {
  min-height: var(--control-height);
  padding: 0 9px;
  font-size: 0.82rem;
  white-space: nowrap;
}

.mode-controls button:hover,
.color-swatch-button:hover,
.select-button:hover,
.select-option:hover {
  transform: translateY(-1px) scale(1.015, 0.99);
}

.color-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.color-swatch-button {
  position: relative;
  height: 28px;
  min-height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 10px;
  background: var(--swatch-color);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 2px 7px rgba(0, 0, 0, 0.11);
  transition:
    box-shadow 180ms var(--elastic-ease),
    outline-color 160ms ease,
    transform 220ms var(--elastic-ease);
}

.color-swatch-button::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.18), rgba(0, 0, 0, 0.08));
  pointer-events: none;
}

.color-swatch-button:hover,
.color-swatch-button.editing,
.color-swatch-button:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.9);
  outline-offset: 2px;
  background: var(--swatch-color);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.26), 0 0 0 1px rgba(7, 94, 200, 0.36), 0 5px 14px rgba(0, 0, 0, 0.16);
}

.color-editor-popover {
  position: fixed;
  z-index: 6;
  width: 220px;
  padding: 11px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 16px;
  background: rgba(250, 250, 250, 0.96);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(0, 0, 0, 0.04);
  color: #101113;
  backdrop-filter: blur(18px);
  transform-origin: top right;
  animation: pop-bounce 260ms var(--elastic-ease);
}

.color-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 0.8rem;
  font-weight: 750;
}

.color-editor-close {
  width: 26px;
  min-width: 26px;
  min-height: 26px;
  padding: 0;
  border-radius: 10px;
  font-size: 1rem;
  line-height: 1;
}

.color-editor-preview {
  height: 38px;
  margin-bottom: 8px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  background: var(--swatch-color);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.color-field {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  color: rgba(16, 17, 19, 0.58);
  font-size: 0.74rem;
  font-weight: 700;
}

.color-picker-area {
  position: relative;
  height: 112px;
  margin-bottom: 8px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  background:
    linear-gradient(to top, #000000, rgba(0, 0, 0, 0)),
    linear-gradient(to right, #ffffff, hsl(var(--picker-hue), 100%, 50%));
  box-shadow: var(--soft-inset);
  cursor: crosshair;
  touch-action: none;
}

.color-picker-cursor,
.color-hue-cursor {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.42), 0 2px 7px rgba(0, 0, 0, 0.24);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.color-hue-slider {
  position: relative;
  height: 18px;
  margin-bottom: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  background: linear-gradient(to right, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000);
  box-shadow: var(--soft-inset);
  cursor: ew-resize;
  touch-action: none;
}

.color-hue-cursor {
  top: 50%;
}

.color-hex-input {
  min-height: 30px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--soft-inset);
}

.color-hex-input {
  width: 100%;
  padding: 0 9px;
  color: rgba(16, 17, 19, 0.82);
  font-size: 0.82rem;
  font-weight: 650;
  text-transform: lowercase;
}

.color-hex-input.invalid {
  border-color: rgba(210, 52, 64, 0.65);
  box-shadow: 0 0 0 2px rgba(210, 52, 64, 0.12);
}

.slider-control {
  display: grid;
  gap: 5px;
}

.slider-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px;
}

.slider-label-row span {
  min-width: 0;
  overflow: hidden;
  color: rgba(16, 17, 19, 0.5);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slider-label-row output {
  color: rgba(16, 17, 19, 0.6);
  font-size: 0.72rem;
  font-weight: 650;
}

.slider-track {
  position: relative;
  height: 28px;
  overflow: visible;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  background: var(--track-surface);
  box-shadow: var(--soft-inset);
}

.slider-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  min-width: 0;
  overflow: hidden;
  border-radius: inherit;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.105), rgba(0, 0, 0, 0.045));
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08);
  pointer-events: none;
  transition: width 180ms var(--elastic-ease);
}

.slider-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0));
  pointer-events: none;
}

.slider-thumb {
  position: absolute;
  top: 50%;
  left: 0;
  --slider-thumb-shift: -50%;
  width: var(--slider-thumb-size);
  height: var(--slider-thumb-size);
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 999px;
  background: linear-gradient(145deg, #ffffff, #e8e8e8);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.16), 0 1px 2px rgba(0, 0, 0, 0.1), inset 0 1px 1px rgba(255, 255, 255, 0.9);
  pointer-events: none;
  transform: translate(var(--slider-thumb-shift), -50%);
  transition:
    left 180ms var(--elastic-ease),
    transform 180ms var(--elastic-ease),
    box-shadow 180ms var(--elastic-ease);
}

.slider-track input[type="range"] {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
}

.control-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(118px, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 40px;
  overflow: hidden;
  padding: 0 4px 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.34);
  box-shadow: var(--soft-inset);
  color: #111214;
  font-size: 0.82rem;
}

.control-row span,
.control-row output,
.control-row .select-button {
  position: relative;
  z-index: 1;
}

.control-row span {
  min-width: 0;
  overflow: hidden;
  font-weight: 650;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-row input[type="range"] {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
}

.select-button {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 30px;
  min-width: max-content;
  padding: 0 8px 0 12px;
  border-radius: 12px;
  color: rgba(16, 17, 19, 0.74);
  font-size: 0.82rem;
  font-weight: 500;
  transition:
    background 180ms var(--elastic-ease),
    box-shadow 180ms var(--elastic-ease),
    transform 220ms var(--elastic-ease),
    color 160ms ease;
}

.select-button i {
  flex: 0 0 auto;
  color: rgba(16, 17, 19, 0.68);
  font-size: 0.9rem;
}

.select-button.open {
  color: rgba(16, 17, 19, 0.88);
  background: var(--control-active);
  box-shadow: var(--soft-inset);
}

.select-popover {
  position: fixed;
  z-index: 7;
  display: grid;
  gap: 2px;
  padding: 5px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 14px;
  background: rgba(250, 250, 250, 0.96);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(0, 0, 0, 0.04);
  color: #101113;
  backdrop-filter: blur(18px);
  transform-origin: top right;
  animation: pop-bounce 260ms var(--elastic-ease);
}

.select-option {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 7px;
  align-items: center;
  min-height: 30px;
  padding: 0 10px 0 7px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  box-shadow: none;
  color: rgba(16, 17, 19, 0.78);
  font-size: 0.82rem;
  text-align: left;
  transition:
    background 160ms var(--elastic-ease),
    transform 200ms var(--elastic-ease),
    color 140ms ease;
}

.select-option i {
  color: rgba(16, 17, 19, 0.82);
  font-size: 0.9rem;
  opacity: 0;
}

.select-option[aria-selected="true"] {
  background: var(--control-active);
  color: rgba(16, 17, 19, 0.9);
}

.select-option[aria-selected="true"] i {
  opacity: 1;
}

.select-option:hover,
.select-option:focus-visible {
  outline: none;
  background: rgba(16, 17, 19, 0.06);
  box-shadow: none;
  color: rgba(16, 17, 19, 0.9);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.34);
  box-shadow: var(--soft-inset);
  color: #111214;
  font-size: 0.82rem;
}

#reset-button {
  min-width: max-content;
  min-height: 32px;
  padding: 0 13px;
  border-radius: 13px;
  font-size: 0.84rem;
}

.toggle-row input {
  width: 19px;
  height: 19px;
  accent-color: #111214;
}

#canvas-wrap.unsupported {
  display: grid;
  place-items: center;
  padding: 24px;
  color: #f6f8fb;
  background: #05070b;
  text-align: center;
}

@media (max-width: 820px) {
  html,
  body {
    overflow: auto;
  }

  #app-shell {
    min-height: 100vh;
  }

  #top-actions {
    top: 12px;
    right: 12px;
    gap: 6px;
  }

  .menu-button {
    min-width: max-content;
    min-height: var(--control-height);
    padding: 0 12px;
    font-size: 0.74rem;
  }

  #controls {
    top: auto;
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
    max-height: min(84vh, 680px);
    padding: 14px;
    border-radius: 18px;
  }

  .panel-header {
    margin-bottom: 12px;
  }

  .control-grid,
  .advanced {
    gap: 8px;
  }

  .control-row {
    grid-template-columns: minmax(104px, 1fr) auto;
  }

  .control-row,
  .toggle-row {
    min-height: 38px;
    padding: 0 4px 0 10px;
    font-size: 0.8rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
