html {
  margin: 0;
  height: 100%;
}

body {
  margin: 0;
}

/* Default: dark centered layout (update pages, etc.) */
body:not(.config-page-theme) {
  height: 100%;
  min-height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: Arial, sans-serif;
  background-color: #000000;
}

/* Config / shutdownfix: about-style light page + animated background */
body.config-page-theme {
  --purple: #6600ff;
  --text: #3a3a3a;
  --text-light: #6a6a6a;
  --bg: #fafafa;
  min-height: 100vh;
  height: auto;
  display: block;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}

html:has(body.config-page-theme) {
  height: auto;
  min-height: 100%;
  scroll-behavior: smooth;
}

#bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

body.config-page-theme main {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  min-height: 100vh;
  padding: 24px 16px 48px;
  box-sizing: border-box;
}

/* Preview → config card → footer (p5 appends #centered-content after static nodes) */
body.config-page-theme .animation-preview-wrap {
  order: 1;
}

#centered-content {
  text-align: center;
  width: 48%;
  min-width: 256px;
  max-width: 320px;
  margin: 40px auto 70px auto;
  border: 1px solid #e0e0e0;
  padding: 20px;
  border-radius: 12px;
  background: linear-gradient(135deg, #f9f9f9 0%, #f0f0f0 100%);
  box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.15);
  font-size: 12px;
}

body.config-page-theme #centered-content {
  order: 2;
  margin: 0.55rem auto 0.35rem;
  border: 1px solid rgba(102, 0, 255, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(102, 0, 255, 0.08), 0 2px 16px rgba(0, 0, 0, 0.04);
  color: var(--text);
}

/* p5 preview — circular feather mask (smooth fade to transparent) + frosted overlay */
.animation-preview-wrap {
  --preview-pad: clamp(20px, 5.5vw, 40px);
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: fit-content;
  max-width: min(100%, calc(100vw - 24px));
  margin: 0 auto 16px;
  padding: var(--preview-pad);
  box-sizing: content-box;
  background: transparent;
  box-shadow: none;
  border: none;
  overflow: visible;
  z-index: 10;
  /* Circle crop + tighter rim fade; canvas blur softens stair-stepped cells */
  -webkit-mask-image: radial-gradient(
    circle closest-side at 50% 50%,
    #000 0%,
    #000 64%,
    rgba(0, 0, 0, 0.72) 71%,
    rgba(0, 0, 0, 0.22) 80%,
    transparent 87%
  );
  mask-image: radial-gradient(
    circle closest-side at 50% 50%,
    #000 0%,
    #000 64%,
    rgba(0, 0, 0, 0.72) 71%,
    rgba(0, 0, 0, 0.22) 80%,
    transparent 87%
  );
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
}

.animation-preview-wrap canvas {
  display: block;
  max-width: 100%;
  height: auto;
  background: transparent !important;
  filter: blur(1.35px);
  -webkit-filter: blur(1.35px);
}

.animation-preview-wrap::after {
  content: '';
  position: absolute;
  inset: var(--preview-pad);
  pointer-events: none;
  z-index: 1;
  border-radius: 0;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.07);
  -webkit-mask-image: radial-gradient(
    circle closest-side at 50% 50%,
    #000 0%,
    #000 66%,
    rgba(0, 0, 0, 0.4) 78%,
    transparent 87%
  );
  mask-image: radial-gradient(
    circle closest-side at 50% 50%,
    #000 0%,
    #000 66%,
    rgba(0, 0, 0, 0.4) 78%,
    transparent 87%
  );
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

body.config-page-theme #centered-content span:not(.slider):not(.loading-spinner),
body.config-page-theme #centered-content label {
  color: var(--text-light);
}

body.config-page-theme .config-page-label {
  color: var(--purple) !important;
  font-size: 0.72rem !important;
  font-weight: 500 !important;
  letter-spacing: 0.2em !important;
  text-transform: uppercase !important;
}

/* Footer link (matches big_cartel_pages/links.html) */
body.config-page-theme footer.config-page-footer {
  order: 3;
  position: relative;
  z-index: 10;
  text-align: center;
  margin: 8px auto 0;
  width: 100%;
  max-width: 400px;
  padding-top: 6px;
  padding-left: 16px;
  padding-right: 16px;
  box-sizing: border-box;
  border-top: none;
}

body.config-page-theme footer.config-page-footer::before {
  content: '';
  display: block;
  width: min(96px, 28vw);
  height: 1px;
  margin: 0 auto 8px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(102, 0, 255, 0.14) 20%,
    rgba(102, 0, 255, 0.14) 80%,
    transparent
  );
}

body.config-page-theme footer.config-page-footer a {
  font-size: 0.75rem;
  color: var(--text-light);
  text-decoration: none;
  transition: color 0.2s;
}

body.config-page-theme footer.config-page-footer a:hover {
  color: var(--purple);
}

/* Serial connect — instruction step before browser picker */
.serial-connect-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(250, 250, 250, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.serial-connect-modal.is-open {
  display: flex;
}

.serial-connect-modal__card {
  width: min(400px, 100%);
  padding: 28px 24px 22px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(102, 0, 255, 0.14);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(102, 0, 255, 0.12);
  text-align: center;
}

.serial-connect-modal__title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 0 0 12px;
}

.serial-connect-modal__text {
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--text-light);
  margin: 0 0 22px;
}

.serial-connect-modal__text strong {
  color: var(--purple);
  font-weight: 600;
}

.serial-connect-modal__actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.serial-connect-modal__cancel {
  border: none;
  background: none;
  font-family: inherit;
  font-size: 0.78rem;
  color: var(--text-light);
  cursor: pointer;
  padding: 4px 8px;
}

.serial-connect-modal__cancel:hover {
  color: var(--purple);
}

  /* Update page specific: position white box at bottom */
  body:has(#centered-content[style*="position: absolute"]) #centered-content {
    margin: 0;
  }

/* CSS */
.button-36 {
background-image: linear-gradient(92.88deg, #6600ff 9.16%, #6600ff 43.89%, #6600ff 64.72%);
border-radius: 6px;
border-style: none;
box-sizing: border-box;
color: #FFFFFF;
cursor: pointer;
flex-shrink: 0;
font-family: "Inter UI","SF Pro Display",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Open Sans","Helvetica Neue",sans-serif;
font-size: 13px;
font-weight: 500;
height: 1.6rem;
padding: 0 1.3rem;
text-align: center;
text-shadow: rgba(0, 0, 0, 0.25) 0 2px 6px;
transition: all .5s;
user-select: none;
-webkit-user-select: none;
touch-action: manipulation;
}

.button-36:hover {
box-shadow: rgba(102, 0, 255, 0.45) 0 1px 30px;
transition-duration: .1s;
}

@media (min-width: 768px) {
  .button-36 {
    padding: 0 1.0rem;
  }
}

.switch {
  font-size: 10px;
  position: relative;
  display: inline-block;
  width: 2.8em;
  height: 1.6em;
  vertical-align: middle;
  line-height: 1.6em;
  text-align: center;
}

/* Hide default HTML checkbox */
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

/* The slider */
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: white;
  border-radius: 50px;
  overflow: hidden;
  transition: all 0.4s cubic-bezier(0.215, 0.610, 0.355, 1);
}

.slider:before {
  position: absolute;
  content: "";
  height: 1.1em;
  width: 1.1em;
  right: 0.25em;
  bottom: 0.25em;
  transform: translateX(150%);
  background-color: #6600ff;
  border-radius: inherit;
  transition: all 0.4s cubic-bezier(0.215, 0.610, 0.355, 1);
}

.slider:after {
  position: absolute;
  content: "";
  height: 1.1em;
  width: 1.1em;
  left: 0.25em;
  bottom: 0.25em;
  background-color: #cccccc;
  border-radius: inherit;
  transition: all 0.4s cubic-bezier(0.215, 0.610, 0.355, 1);
}

.switch input:focus + .slider {
  box-shadow: 0 0 1px #59d102;
}

.switch input:checked + .slider:before {
  transform: translateY(0);
}

.switch input:checked + .slider::after {
  transform: translateX(-150%);
}

input[type="color"] {
	-webkit-appearance: none;
	appearance: none;
	border: none;
	width: 40px;
	height: 16px;
}
input[type="color"]::-webkit-color-swatch-wrapper {
	padding: 0;
}
input[type="color"]::-webkit-color-swatch {
	border: none;
}

input[type=text] {
  border: none;
  font-size: 11px;
}

input[type="range"] {
  font-size: 11px;
}

select {
  font-size: 11px;
}

span {
  font-size: 11px;
}

/* Visual separators */
.section-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, #e0e0e0 50%, transparent 100%);
  margin: 6px 0 12px 0;
}

body.config-page-theme .section-divider {
  background: linear-gradient(90deg, transparent, rgba(102, 0, 255, 0.15), transparent);
}

/* Update button styling */
.update-button {
  background-image: linear-gradient(92.88deg, #FF5722 9.16%, #FF9800 43.89%, #FFC107 64.72%);
  border-radius: 8px;
  border-style: none;
  box-sizing: border-box;
  color: #FFFFFF;
  cursor: pointer;
  flex-shrink: 0;
  font-family: "Inter UI","SF Pro Display",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Open Sans","Helvetica Neue",sans-serif;
  font-size: 16px;
  font-weight: 600;
  height: 3rem;
  padding: 0 2rem;
  text-align: center;
  text-shadow: rgba(0, 0, 0, 0.25) 0 3px 8px;
  transition: all .5s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.update-button:hover {
  box-shadow: rgba(255, 152, 0, 0.5) 0 1px 30px;
  background-image: linear-gradient(92.88deg, #FF9800 9.16%, #FFC107 43.89%, #FFEB3B 64.72%);
  transition-duration: .1s;
}

@media (max-width: 600px) {
  #centered-content {
    width: 95vw;
    min-width: 0;
    margin: 16px auto 0 auto;
    padding: 8px;
    font-size: 10px;
  }
  .button-36 {
    width: 100%;
    font-size: 10px;
    padding: 0.4rem 0;
  }
  input[type="range"] {
    width: 80px !important;
  }
  input[type=text], select, span {
    font-size: 10px;
  }
}

#defaultCanvas0 {
  display: block;
  margin: 0 auto;
  margin-bottom: 200px;
}

body.config-page-theme #defaultCanvas0 {
  position: relative;
  z-index: 0;
  margin: 0;
  display: block;
  background: transparent !important;
}

@media (max-width: 600px) {
  #defaultCanvas0 {
    width: 95vw !important;
    height: auto !important;
    margin: 10px auto 0 auto;
    display: block;
  }

  body.config-page-theme #defaultCanvas0 {
    margin: 0;
  }

  .animation-preview-wrap {
    margin-bottom: 12px;
  }
}

.button-connected {
  background-image: linear-gradient(92.88deg, #11998e 9.16%, #38ef7d 64.72%);
  border-radius: 6px;
  border-style: none;
  box-sizing: border-box;
  color: #FFFFFF;
  cursor: default;
  flex-shrink: 0;
  font-family: "Inter UI","SF Pro Display",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Open Sans","Helvetica Neue",sans-serif;
  font-size: 13px;
  font-weight: 500;
  height: 1.6rem;
  padding: 0 1.3rem;
  text-align: center;
  text-shadow: rgba(0, 0, 0, 0.25) 0 2px 6px;
  transition: all .5s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  opacity: 0.92;
}

/* Loading animation styles */
.loading-spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin 1s ease-in-out infinite;
  margin-right: 5px;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.button-loading {
  background-image: linear-gradient(92.88deg, #FF9800 9.16%, #FFC107 64.72%);
  border-radius: 6px;
  border-style: none;
  box-sizing: border-box;
  color: #FFFFFF;
  cursor: default;
  flex-shrink: 0;
  font-family: "Inter UI","SF Pro Display",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Open Sans","Helvetica Neue",sans-serif;
  font-size: 13px;
  font-weight: 500;
  height: 1.6rem;
  padding: 0 1.3rem;
  text-align: center;
  text-shadow: rgba(0, 0, 0, 0.25) 0 2px 6px;
  transition: all .5s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  opacity: 0.92;
}