@viewport {
  orientation: portrait;
}



:root {
  /* Base Physical Unit */
  --mm: 1mm;
  /* Default fallback, overridden by JavaScript */

  /* Viewport-based Design System */
  --space-xs: 1vw;
  --space-sm: 2vw;
  --space-md: 4vw;
  --space-lg: 5vw;
  --space-xl: 8vw;

  /* Viewport sizing scale */
  --size-xs: 1vw;
  --size-sm: 6vw;
  --size-md: 10vw;
  --size-lg: 15vw;
  --size-xl: 20vw;

  /* Border radius in viewport units */
  --radius-xs: 0.5vw;
  --radius-sm: 2vw;
  --radius-md: 2.5vw;
  --radius-lg: 10vw;
  --radius-full: 50%;

  /* Physical millimeter-based dimensions */
  --controller-width: calc(var(--mm) * 68);
  --controller-height: calc(var(--mm) * 40);
  --controller-radius: calc(var(--mm) * 5);
  --controller-min-height: 80px;
  /* Minimum for usability */

  /* Physical button dimensions */
  --btn-round-large: calc(var(--mm) * 13);
  --btn-round-small: calc(var(--mm) * 9);
  --btn-round-medium: calc(var(--mm) * 10);
  --dpad-container: calc(var(--mm) * 22);
  --dpad-button: calc(var(--mm) * 8);
  --dpad-button-offset: calc((var(--dpad-container) - var(--dpad-button)) / 2);
  /* Center buttons perfectly */
  --home-button: calc(var(--mm) * 5);

  /* Physical positioning offsets */
  --offset-xs: calc(var(--mm) * 4);
  --offset-sm: calc(var(--mm) * 5);
  --offset-md: calc(var(--mm) * 6.25);
  --offset-lg: calc(var(--mm) * 14);
  --offset-xl: calc(var(--mm) * 18);
  --offset-xxl: calc(var(--mm) * 35);

  /* Color System */
  --color_dark: rgb(40, 42, 44);
  --color_light: rgb(0, 0, 0);
  --color_primary: rgb(16, 229, 221);
  --color_secondary: rgb(0, 0, 0);
  --color_accent: rgb(230, 65, 85);
  --color_main_btn: rgb(0, 0, 0);
  --color_secondary_btn: rgb(0, 0, 0);

  /* PWA Theme Colors */
  --pwa-primary: var(--color_primary);
  --pwa-primary-dark: var(--color_primary);
  --pwa-secondary: var(--color_secondary);
  --pwa-secondary-dark: var(--color_secondary);
  --pwa-success: #00aa00;
  --pwa-success-dark: #008800;

  /* UI Colors */
  --color-white: #ffffff;
  --color-black: #000000;
  --color-gray-dark: #333;
  --color-gray-medium: #444;
  --color-gray-light: #ccc;
  --color-gray-button: rgb(53 53 53);
  --color-overlay: rgba(26, 26, 26, 0.95);
  --color-transparent: #00000000;

  /* Z-index Scale */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 9998;
  --z-modal: 9999;

  /* Transition System */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s ease;

  /* Shadow System */
  --shadow-sm: 0 var(--space-xs) var(--space-md);
  --shadow-md: 0 var(--space-sm) var(--space-lg);
  --shadow-lg: 0 var(--space-md) var(--space-xl);
}

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

* {
  margin: 0;
}

html {
  background-image: url(../ui-cable.svg);
  background-color: black;
  background-repeat: repeat-y;
  background-position: center;
  background-size: 177px 57px;
}

/* Dragging state background */
.dragging-wavy-noodle {
  background-image: url(../wavy-noodle.png);
  background-color: black;
  background-repeat: repeat-y;
  background-position: center;
  background-size: 101px 57px;
}

body {
  /* Typography */
  line-height: 1.5;
  font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
  font-weight: 300;
  color: var(--color-white);
  -webkit-font-smoothing: antialiased;

  /* Layout */
  margin: 0;
  padding: 0;
  /*position: fixed;*/
  top: 0;
  left: 0;
  max-width: 100vw;

  /* Safe area insets for notch/home indicator */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);

  /* Flex container */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  align-content: center;
  flex-wrap: nowrap;

  /* Appearance */
  background: var(--color-transparent);
  overflow: hidden;

  /* Touch and interaction */
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

/* PWA Install Prompt */
.install-prompt {
  position: fixed;
  bottom: var(--space-md);
  left: var(--space-md);
  right: var(--space-md);
  background: rgba(0, 0, 0, 0.95);
  /* Solid fallback for performance */
  border: var(--size-xs) solid var(--color-gray-dark);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  z-index: var(--z-modal-backdrop);
  display: none;
  color: var(--color-white);
  font-family: inherit;
  will-change: transform, opacity;
  /* Optimize for animations */
}

/* Mobile-Only Detection Overlay */
#desktop-warning {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  /* Fallback for old browsers */
  height: 100dvh;
  /* Modern browsers iOS 16.4+, Chrome 108+ */
  height: calc(var(--vh, 1vh) * 100);
  /* JS fallback for any iOS */
  background: rgba(0, 0, 0, 0.95);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.desktop-warning-content {
  text-align: center;
  color: white;
  padding: 2rem;
  max-width: 500px;
  line-height: 1.6;
}

.desktop-warning-content h1 {
  font-size: 2rem;
  margin-bottom: 1rem;
  color: #ff6b35;
}

.desktop-warning-content p {
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

.qr-placeholder {
  margin-top: 2rem;
  padding: 1rem;
  border: 2px dashed #666;
  border-radius: 8px;
}

.qr-code {
  font-size: 4rem;
  margin: 1rem 0;
}

.install-prompt.show {
  display: block;
  animation: slideUp var(--transition-normal) ease-out;
}

@keyframes slideUp {
  from {
    transform: translate3d(0, 100%, 0);
    /* Use 3D transforms for GPU acceleration */
    opacity: 0;
  }

  to {
    transform: translate3d(0, 0, 0);
    /* Explicit 3D transform */
    opacity: 1;
  }
}

.install-prompt h3 {
  margin: 0 0 var(--space-sm) 0;
  font-size: 18px;
  color: var(--pwa-primary);
}

.install-prompt p {
  margin: 0 0 var(--space-md) 0;
  font-size: 14px;
  color: var(--color-gray-light);
  line-height: 1.4;
}

.install-prompt-buttons {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
}

.install-prompt button {
  padding: var(--size-xs) var(--space-sm);
  border: none;
  border-radius: var(--radius-xs);
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition-fast);
}

.install-prompt .install-yes {
  background: var(--pwa-primary);
  color: var(--color-white);
}

.install-prompt .install-no {
  background: var(--color-gray-dark);
  color: var(--color-gray-light);
}

/* Hover states removed - mobile-only PWA */

#game {
  /* Fallback for older browsers */
  width: 100vw;
  height: 100vw;
  max-height: 50vh;
  max-width: 50vh;

  /* Modern browsers - dynamic viewport units account for browser chrome */
  width: 100dvw;
  height: 100dvw;
  max-height: 50dvh;
  max-width: 50dvh;

  /* Maintain square aspect ratio */
  aspect-ratio: 1 / 1;

  /* Center when constrained */
  margin-left: auto;
  margin-right: auto;

  touch-action: none;
  border: var(--size-xs) solid var(--color_primary);
  border-radius: var(--radius-sm);
  background: var(--color-black);
  contain: content;
}

#Agame {
  transform:
    perspective(900px) rotateX(60deg) scale(0.7);
  box-shadow: 0px 20px 100px #555;
  transition: 0.5s ease all;

  /* Hover removed - mobile-only PWA */
}

#game canvas {
  object-fit: contain;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  -webkit-interpolation-mode: nearest-neighbor;
  /* Fill parent container (which is constrained by max-height/max-width) */
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-sm);
  margin: 0;
  padding: 0;
  border: 0;
  touch-action: none;
  -ms-touch-action: none;
}

#bar {
  display: flex;
  width: 95vw;
  height: var(--size-md);
  align-items: center;
  flex-direction: row;
  justify-content: space-around;
}

#controller {
  width: var(--controller-width);
  height: var(--controller-height);
  min-height: var(--controller-min-height);
  position: relative;
  background-color: var(--color-black);
  border-radius: var(--controller-radius);
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  contain: layout style;
}

#Pcontroller::after {
  content: "";
  position: absolute;
  bottom: 0%;
  left: 50%;
  transform: translate(-50%, 50px);
  width: 100px;
  height: 100px;
  background-image: url(../ui-scaling.png);
  background-size: 100%, 100%;
}

.btnPressed {
  box-shadow: 0 0 var(--space-md) 0 var(--color-white);
}

.roundBtn,
.capsuleBtn,
#controller_left,
#controller_right,
#controller_up,
#controller_down {
  background: #353535;
  cursor: pointer;
  border-radius: 50%;
}

.capsuleBtn {
  background: var(--color-gray-button);
}

#controller_dpad:before,
#controller_left,
#controller_right,
#controller_up,
#controller_down {
  width: var(--dpad-button);
  height: var(--dpad-button);
  position: absolute;
  touch-action: manipulation;
}

#controller_dpad {
  position: absolute;
  top: var(--offset-sm);
  left: var(--offset-xs);
  width: var(--dpad-container);
  height: var(--dpad-container);
  border-radius: var(--radius-full);
}

#controller_left {
  top: var(--dpad-button-offset);
  left: 0;
  border-right: 0 none;
}

#controller_right {
  right: 0;
  top: var(--dpad-button-offset);
  border-left: 0 none;
}

#controller_up {
  left: var(--dpad-button-offset);
  top: 0;
  border-bottom: 0 none;
}

#controller_down {
  left: var(--dpad-button-offset);
  bottom: 0;
  border-top: 0 none;
}



#controller_a {
  position: absolute;
  top: var(--offset-md);
  right: var(--offset-xs);
  width: var(--btn-round-large);
  height: var(--btn-round-large);
  border-radius: var(--btn-round-large);
}

#controller_b {
  position: absolute;
  top: var(--offset-lg);
  right: var(--offset-xl);
  width: var(--btn-round-small);
  height: var(--btn-round-small);
  border-radius: var(--btn-round-small);
}

/* Diamond layout button positions */
.layout-diamond #controller_x {
  position: absolute;
  top: calc(var(--offset-xs) + var(--btn-round-small));
  right: calc(var(--offset-xs) + var(--btn-round-small) + var(--btn-round-small));
  width: var(--btn-round-small);
  height: var(--btn-round-small);
  border-radius: var(--btn-round-small);
}

.layout-diamond #controller_y {
  position: absolute;
  top: var(--offset-xs);
  right: calc(var(--offset-xs) + var(--btn-round-small));
  width: var(--btn-round-small);
  height: var(--btn-round-small);
  border-radius: var(--btn-round-small);
}

.layout-diamond #controller_a {
  position: absolute;
  top: calc(var(--offset-xs) + var(--btn-round-small));
  right: var(--offset-xs);
  width: var(--btn-round-small);
  height: var(--btn-round-small);
  border-radius: var(--btn-round-small);
}

.layout-diamond #controller_b {
  position: absolute;
  top: calc(var(--offset-xs) + var(--btn-round-small) * 2);
  right: calc(var(--offset-xs) + var(--btn-round-small));
  width: var(--btn-round-small);
  height: var(--btn-round-small);
  border-radius: var(--btn-round-small);
}

.layout-playtiles #controller_a {
  position: absolute;
  top: calc(var(--mm) * 15);
  right: calc(var(--mm) * 5);
  width: var(--btn-round-large);
  height: var(--btn-round-large);
  border-radius: var(--btn-round-large);
}

.layout-playtiles #controller_b {
  position: absolute;
  top: calc(var(--mm) * 5.5);
  right: calc(var(--mm) * 14.5);
  width: calc(var(--mm) * 10);
  height: calc(var(--mm) * 10);
  border-radius: calc(var(--mm) * 10);
}

.layout-playtiles #controller_dpad {
  position: absolute;
  top: calc(var(--mm) * 6);
  left: calc(var(--mm) * 5);
  width: var(--dpad-container);
  height: var(--dpad-container);
  border-radius: var(--radius-full);
}

/* Dead CSS removed - layout selector was unused */

/* Smooth transitions for button position changes (disabled for performance) */
/* #controller .roundBtn {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
} */

/* Responsive adjustments for layout selector removed - was unused */

.roundBtn {
  display: flex;
  justify-content: center;
  align-items: center;
  width: var(--btn-round-medium);
  height: var(--btn-round-medium);
  border-radius: var(--btn-round-medium);
  contain: layout style paint;
  touch-action: manipulation;
  background-color: #353535;
}

.capsuleBtn {
  font-weight: bold;
  font-size: 10px;
  color: var(--color-white);
  display: flex;
  align-items: center;
  text-transform: uppercase;
  width: var(--size-lg);
  height: var(--space-xl);
  border-radius: var(--radius-lg);
  align-content: center;
  justify-content: center;
  contain: layout style paint;
  touch-action: manipulation;
}

/* Install button state - color cycling animation */
#homeButton.install-state {
  background: #34D8D6;
  /* Start with lagoon cyan */
  color: #000000;
  /* Dark text for contrast */
  animation: colorCycle 6s ease-in-out infinite;
  contain: none;
  /* Remove containment to allow animation */
  will-change: background-color;
  /* Optimize for color animation */
}

/*#homeButton.install-state::before {
  content: '⬇ ';
  font-size: 12px;
}*/

/* Color cycle animation for install button - with pauses on each color */
@keyframes colorCycle {

  0%,
  20% {
    background-color: #34D8D6;
    /* Lagoon - cyan (hold) */
  }

  30%,
  50% {
    background-color: #F6385C;
    /* Crayola - pink/red (hold) */
  }

  60%,
  80% {
    background-color: rgb(255, 200, 88);
    /* Sunglow - yellow (hold) */
  }

  90%,
  100% {
    background-color: #34D8D6;
    /* Back to lagoon - seamless loop */
  }
}

#Pcontroller_start {
  position: absolute;
  top: var(--offset-xxl);
  right: var(--offset-xs);
}

#controller_home {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, 0);
  background-color: var(--color_primary);
  background-position: center;
  border-radius: 0 0 var(--radius-full) var(--radius-full);
  width: var(--home-button);
  height: var(--home-button);
  text-align: center;
  font-size: calc(var(--mm) * 3);
}

#Pcontroller_select {
  position: absolute;
  top: var(--offset-xxl);
  right: var(--offset-xl);
}

#debug {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-sm);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

#debug div {
  background: var(--color-white);
  color: var(--color-black);
  border: var(--size-xs) solid #ddd;
  border-radius: var(--space-xs);
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  display: flex;
  align-items: center;
}

#debug span {
  padding: var(--space-sm) var(--size-xs);
}

#debug button {
  background: transparent;
  border: none;
  border-left: var(--size-xs) solid #ddd;
  display: flex;
  align-items: center;
  height: 100%;
}

/* Hover removed - mobile-only PWA */

#debug button:active {
  background: #ddd;
}



#debug-info {
  position: fixed;
  bottom: 0;
  left: 0;
  padding: var(--space-sm);
  background: rgba(0, 0, 0, 0.7);
  color: var(--color-white);
  font-size: 14px;
  font-family: monospace;
  z-index: var(--z-modal);
}

#debug-info span {
  display: block;
}

#calibration-overlay {
  position: fixed;
  bottom: var(--space-sm);
  left: 50%;
  justify-content: center;
  z-index: var(--z-modal);
  align-content: center;
  flex-wrap: nowrap;
  transform: translateX(-50%);
}

#diagonalInches {
  width: var(--size-lg);
}

input[type="range"] {
  appearance: none;
  height: 18vh;
  background-color: #55555500;
  background-repeat: no-repeat;
  cursor: pointer;
  writing-mode: vertical-lr;
  transform: rotate(180deg);
}

.hide {
  display: none !important;
}

#cable {
  position: absolute;
  bottom: -88px;
  left: 50%;
  cursor: ns-resize;
  z-index: var(--z-dropdown);
  text-align: center;
  user-select: none;
  touch-action: none;
  transform: translate(-50%, 0);
  width: 100px;
  height: 100px;
  background-image: url(../ui-scaling.png);
  background-size: 100%, 100%;
}

#cable.cable-active {
  background-image: url(../ui-scaling-hover.svg);
  background-size: 100%, 100%;
}

/* iOS touch offset compensation */
/* iOS applies upward offset to touch coordinates to compensate for finger position */
/* Shift d-pad UP to counter this offset for more accurate button detection */
.platform-ios #controller_dpad {
  transform: translateY(calc(var(--mm) * -2));
}