/**
 * Crossy Roads 3D Game - Styles
 * Customizable CSS variables for easy theming
 */

/* CSS Custom Properties for easy customization */
:root {
  /* Typography */
  --game-font-family: "Press Start 2P", cursive;
  --game-font-size: 2em;
  --game-text-color: white;

  /* Loading screen configurable colors */
  --loading-background: linear-gradient(135deg,
      #1e3c72 0%,
      #2a5298 50%,
      #667eea 100%);
  --loading-text-color: white;
  --loading-progress-bar: linear-gradient(90deg, #fff, #f0f0f0, #fff);
  --loading-spinner-primary: #fff;
  --loading-spinner-secondary: rgba(255, 255, 255, 0.6);
  --loading-spinner-background: rgba(255, 255, 255, 0.2);
  --loading-particles-color: rgba(255, 255, 255, 0.6);

  /* UI Colors */
  --ui-background-color: transparent;
  --button-background-color: white;
  --button-border-color: lightgray;
  --button-shadow: 3px 5px 0px 0px rgba(0, 0, 0, 0.75);
  --game-over-background: red;
  --counter-background: rgba(0, 0, 0, 0.3);

  /* Layout */
  --counter-top: 20px;
  --counter-right: 20px;
  --counter-padding: 10px 15px;
  --counter-border-radius: 5px;

  --controls-button-size: 40px;
  --controls-gap: 8px;
  --controls-margin-bottom: 15px;
  --controls-button-border-width: 1px;
  --controls-button-border-radius: 5px;

  --game-over-padding: 20px 50px;
  --game-over-border-radius: 10px;
  --game-over-font-size: inherit;

  /* Responsive breakpoints */
  --mobile-breakpoint: 768px;
  --small-mobile-breakpoint: 480px;
}

/* Base styles */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--game-font-family);
  font-size: var(--game-font-size);
  color: var(--game-text-color);
  background: var(--ui-background-color);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* Button base styles */
button {
  outline: none;
  cursor: pointer;
  border: none;
  box-shadow: var(--button-shadow);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  font-family: inherit;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 3px 7px 0px 0px rgba(0, 0, 0, 0.75);
}

button:active {
  transform: translateY(1px);
  box-shadow: 1px 3px 0px 0px rgba(0, 0, 0, 0.75);
}

button:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

/* Score counter */
#counter {
  position: absolute;
  top: var(--counter-top);
  right: var(--counter-right);
  background: var(--counter-background);
  padding: var(--counter-padding);
  border-radius: var(--counter-border-radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 100;
  font-weight: bold;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

/* Timer display */
#timer {
  position: absolute;
  top: var(--counter-top);
  left: var(--counter-right);
  background: var(--counter-background);
  padding: var(--counter-padding);
  border-radius: var(--counter-border-radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 100;
  font-weight: bold;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
  font-size: 0.9em;
  min-width: 80px;
  text-align: center;
  transition: color 0.3s ease;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }
}

/* Game over screen */
#end {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 200;
}

/* Game over score displays */
.game-over-score,
.game-over-time {
  margin: 1em 0;
  font-size: 1.2em;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.game-over-score {
  font-size: 1.5em;
  margin-bottom: 0.5em;
}

#final-score {
  font-weight: bold;
  color: #ffeb3b;
}

#time-left {
  font-weight: bold;
  color: #4caf50;
}

#end button {
  background-color: var(--game-over-background);
  color: var(--game-text-color);
  padding: var(--game-over-padding);
  font-family: inherit;
  font-size: var(--game-over-font-size);
  border-radius: var(--game-over-border-radius);
  text-transform: uppercase;
  letter-spacing: 2px;
  min-width: 200px;
}

#end button:hover {
  background-color: #cc1f1f;
}

#end button:active {
  background-color: #991818;
}

/* Game controls */
#controlls {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
  z-index: 50;
}

#controlls>div {
  pointer-events: all;
  display: grid;
  grid-template-columns: repeat(3, var(--controls-button-size));
  grid-template-rows: repeat(3, var(--controls-button-size));
  grid-column-gap: var(--controls-gap);
  grid-row-gap: var(--controls-gap);
  margin-bottom: var(--controls-margin-bottom);
  padding: 10px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#controlls button {
  width: var(--controls-button-size);
  height: var(--controls-button-size);
  background-color: var(--button-background-color);
  border: var(--controls-button-border-width) solid var(--button-border-color);
  border-radius: var(--controls-button-border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
}

#controlls button:hover {
  opacity: 1;
  background-color: #f0f0f0;
}

#controlls button:active {
  background-color: #e0e0e0;
}

/* Button grid positioning for proper alignment */
#controlls button:nth-child(1) {
  /* Forward button */
  grid-column: 2;
  grid-row: 1;
}

#controlls button:nth-child(2) {
  /* Left button */
  grid-column: 1;
  grid-row: 2;
}

#controlls button:nth-child(3) {
  /* Backward button */
  grid-column: 2;
  grid-row: 3;
}

#controlls button:nth-child(4) {
  /* Right button */
  grid-column: 3;
  grid-row: 2;
}

/* SVG icons in buttons */
#controlls button svg {
  width: 16px;
  height: 16px;
  fill: #333;
  pointer-events: none;
}

/* Canvas container */
canvas {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}

/* Enhanced Loading Screen */
.loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--loading-background);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--loading-text-color);
  font-family: var(--game-font-family);
  z-index: 1000;
  overflow: hidden;
}

.loading-screen::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at 20% 80%,
      rgba(120, 119, 198, 0.3) 0%,
      transparent 50%),
    radial-gradient(circle at 80% 20%,
      rgba(255, 119, 198, 0.3) 0%,
      transparent 50%);
  animation: backgroundFloat 6s ease-in-out infinite alternate;
}

.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 2;
  animation: loadingFadeIn 1s ease-out;
}

.loading-logo {
  font-size: 3em;
  margin-bottom: 10px;
  animation: logoFloat 2s ease-in-out infinite alternate;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

.loading-title {
  font-size: 1.5em;
  margin-bottom: 10px;
  background: linear-gradient(45deg, #fff, #f0f0f0, #fff);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmer 2s ease-in-out infinite;
}

.loading-subtitle {
  font-size: 0.8em;
  opacity: 0.8;
  margin-bottom: 30px;
  animation: subtitlePulse 2s ease-in-out infinite;
}

.loading-spinner-container {
  position: relative;
  margin-bottom: 30px;
}

.loading-spinner {
  width: 60px;
  height: 60px;
  border: 4px solid var(--loading-spinner-background);
  border-top: 4px solid var(--loading-spinner-primary);
  border-right: 4px solid var(--loading-spinner-secondary);
  border-radius: 50%;
  animation: spin 1.2s linear infinite;
  position: relative;
}

.loading-spinner::after {
  content: "";
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border: 2px solid transparent;
  border-top: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  animation: spin 2s linear infinite reverse;
}

.loading-progress {
  width: 200px;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 20px;
}

.loading-progress-bar {
  height: 100%;
  background: var(--loading-progress-bar);
  background-size: 200% 100%;
  border-radius: 2px;
  width: 0%;
  animation: progressFill 3s ease-out forwards,
    shimmer 1.5s ease-in-out infinite;
}

.loading-tips {
  font-size: 0.7em;
  opacity: 0.7;
  max-width: 300px;
  text-align: center;
  line-height: 1.4;
  animation: tipsFade 4s ease-in-out infinite;
}

/* Floating particles */
.loading-particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--loading-particles-color);
  border-radius: 50%;
  animation: particleFloat 8s linear infinite;
}

.loading-particle:nth-child(1) {
  left: 10%;
  animation-delay: 0s;
}

.loading-particle:nth-child(2) {
  left: 20%;
  animation-delay: 1s;
}

.loading-particle:nth-child(3) {
  left: 30%;
  animation-delay: 2s;
}

.loading-particle:nth-child(4) {
  left: 70%;
  animation-delay: 3s;
}

.loading-particle:nth-child(5) {
  left: 80%;
  animation-delay: 4s;
}

.loading-particle:nth-child(6) {
  left: 90%;
  animation-delay: 5s;
}

/* Enhanced Animations */
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

@keyframes backgroundFloat {
  0% {
    transform: translateY(0px) rotate(0deg);
  }

  100% {
    transform: translateY(-20px) rotate(5deg);
  }
}

@keyframes loadingFadeIn {
  0% {
    opacity: 0;
    transform: translateY(30px);
  }

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

@keyframes logoFloat {
  0% {
    transform: translateY(0px);
  }

  100% {
    transform: translateY(-10px);
  }
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }

  100% {
    background-position: 200% 0;
  }
}

@keyframes subtitlePulse {

  0%,
  100% {
    opacity: 0.8;
  }

  50% {
    opacity: 1;
  }
}

@keyframes progressFill {
  0% {
    width: 0%;
  }

  100% {
    width: 100%;
  }
}

@keyframes tipsFade {

  0%,
  90%,
  100% {
    opacity: 0.7;
  }

  45%,
  55% {
    opacity: 1;
  }
}

@keyframes particleFloat {
  0% {
    transform: translateY(100vh) rotate(0deg);
    opacity: 0;
  }

  10% {
    opacity: 0.6;
  }

  90% {
    opacity: 0.6;
  }

  100% {
    transform: translateY(-100px) rotate(360deg);
    opacity: 0;
  }
}

/* Responsive Design */
@media (max-width: 768px) {
  :root {
    --game-font-size: 1.5em;
    --controls-button-size: 36px;
    --controls-gap: 6px;
    --counter-top: 15px;
    --counter-right: 15px;
    --counter-padding: 8px 12px;
  }

  #controlls>div {
    margin-bottom: 12px;
    padding: 8px;
  }

  #end button {
    padding: 15px 30px;
    font-size: 1.2em;
    min-width: 150px;
  }

  /* Mobile loading screen adjustments */
  .loading-logo {
    font-size: 2.5em;
  }

  .loading-title {
    font-size: 1.2em;
  }

  .loading-subtitle {
    font-size: 0.7em;
  }

  .loading-spinner {
    width: 50px;
    height: 50px;
  }

  .loading-progress {
    width: 150px;
  }

  .loading-tips {
    font-size: 0.6em;
    max-width: 250px;
  }
}

@media (max-width: 480px) {
  :root {
    --game-font-size: 1.2em;
    --controls-button-size: 32px;
    --controls-gap: 5px;
    --counter-padding: 6px 10px;
  }

  #controlls>div {
    margin-bottom: 8px;
    padding: 6px;
  }

  #controlls button svg {
    width: 14px;
    height: 14px;
  }

  #end button {
    padding: 12px 25px;
    font-size: 1em;
    min-width: 120px;
  }

  /* Small mobile loading screen adjustments */
  .loading-logo {
    font-size: 2em;
  }

  .loading-title {
    font-size: 1em;
  }

  .loading-subtitle {
    font-size: 0.6em;
  }

  .loading-spinner {
    width: 40px;
    height: 40px;
  }

  .loading-progress {
    width: 120px;
    height: 3px;
  }

  .loading-tips {
    font-size: 0.55em;
    max-width: 200px;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --button-background-color: #ffffff;
    --button-border-color: #000000;
    --game-text-color: #ffffff;
    --counter-background: rgba(0, 0, 0, 0.8);
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  button {
    transition: none;
  }

  button:hover {
    transform: none;
  }

  button:active {
    transform: none;
  }

  .loading-spinner {
    animation: none;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --button-background-color: #2a2a2a;
    --button-border-color: #555555;
    --game-text-color: #ffffff;
  }

  #controlls button svg {
    fill: #ffffff;
  }
}

/* Print styles (hide interactive elements) */
@media print {

  #controlls,
  #end,
  canvas {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  #counter {
    position: static;
    background: transparent;
    color: black;
  }
}

/* Focus styles for accessibility */
@media (any-hover: none) {

  /* Touch device styles */
  button:hover {
    transform: none;
    box-shadow: var(--button-shadow);
  }
}

/* Landscape orientation adjustments for mobile */
@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --game-font-size: 1em;
    --controls-button-size: 35px;
    --controls-margin-bottom: 10px;
  }

  #controlls>div {
    padding: 8px;
    margin-bottom: 5px;
  }

  #counter {
    top: 10px;
    right: 10px;
    padding: 5px 8px;
    font-size: 0.8em;
  }
}

/* UI Size Variants */

/* Large UI */
.large-ui {
  --controls-button-size: 60px;
  --controls-gap: 12px;
  --controls-margin-bottom: 25px;
}

.large-ui #controlls>div {
  padding: 20px;
}

.large-ui #controlls button svg {
  width: 24px;
  height: 24px;
}

.large-ui #counter {
  padding: 12px 18px;
  font-size: 2.2em;
}

/* Normal UI (default) */
.normal-ui {
  --controls-button-size: 50px;
  --controls-gap: 10px;
  --controls-margin-bottom: 20px;
}

/* Compact UI (current default) */
.compact-ui {
  --controls-button-size: 40px;
  --controls-gap: 8px;
  --controls-margin-bottom: 15px;
}

/* Minimal UI */
.minimal-ui {
  --controls-button-size: 35px;
  --controls-gap: 6px;
  --controls-margin-bottom: 10px;
}

.minimal-ui #controlls>div {
  padding: 6px;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 8px;
}

.minimal-ui #controlls button {
  opacity: 0.8;
  border-width: 0.5px;
}

.minimal-ui #controlls button:hover {
  opacity: 1;
}

.minimal-ui #controlls button svg {
  width: 12px;
  height: 12px;
}

.minimal-ui #counter {
  padding: 6px 10px;
  font-size: 0.9em;
}

/* Animation classes for dynamic elements */
.fade-in {
  animation: fadeIn 0.5s ease-in;
}

.fade-out {
  animation: fadeOut 0.5s ease-out;
}

.bounce-in {
  animation: bounceIn 0.6s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}

@keyframes bounceIn {
  0% {
    transform: scale(0.3);
    opacity: 0;
  }

  50% {
    transform: scale(1.05);
    opacity: 0.8;
  }

  70% {
    transform: scale(0.9);
    opacity: 0.9;
  }

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

/* Custom scrollbar for any overflow content */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}