/* --- Beautiful Game UI Styling --- */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700;800&family=Orbitron:wght@400;700;900&display=swap");

/* Universal box-sizing and performance base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  /* Stunning Game Color Palette */
  --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  --success-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  --warning-gradient: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  --danger-gradient: linear-gradient(135deg, #fa709a 0%, #fee140 100%);

  /* Beautiful Dark Background */
  --bg-main: linear-gradient(
    135deg,
    #0c0c0c 0%,
    #1a1a2e 25%,
    #16213e 50%,
    #0f0f23 75%,
    #000000 100%
  );
  --bg-overlay: rgba(255, 255, 255, 0.1);

  /* Game UI Colors */
  --cell-bg: rgba(255, 255, 255, 0.95);
  --cell-clue: linear-gradient(135deg, #e9af51 0%, #f6d55c 100%);
  --cell-input: rgba(255, 255, 255, 0.9);
  --cell-border: rgba(255, 255, 255, 0.3);
  --cell-focus: rgba(255, 255, 255, 0.8);

  /* Text & Shadows */
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.8);
  --text-dark: #2d3748;
  --text-color: #ffffff;
  --success-color: #4facfe;
  --warning-color: #e9af51;
  --danger-color: #fa709a;
  --shadow-glow: 0 0 20px rgba(255, 255, 255, 0.3);
  --shadow-deep: 0 10px 30px rgba(0, 0, 0, 0.3);

  /* Fonts */
  --font-main: "Inter", sans-serif;
  --font-game: "Inter", sans-serif;
}

/* --- Amazing Background & Base Styling --- */
body {
  font-family: var(--font-main);
  background: var(--bg-main);
  background-size: 400% 400%;
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  position: relative;
  overflow-x: hidden;
  /* animation: gradientShift 15s ease infinite; */ /* DISABLED FOR TESTING */

  /* Performance optimizations */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;

  /* Disable background attachment on mobile for better performance */
  @media (max-width: 768px) {
    background-attachment: scroll;
  }
}

@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* Magical Background Pattern */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(
      circle at 20% 80%,
      rgba(120, 119, 198, 0.3),
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 20%,
      rgba(255, 255, 255, 0.15),
      transparent 50%
    ),
    radial-gradient(
      circle at 40% 40%,
      rgba(240, 147, 251, 0.2),
      transparent 50%
    ),
    radial-gradient(
      circle at 60% 60%,
      rgba(67, 233, 123, 0.15),
      transparent 50%
    );
  pointer-events: none;
  z-index: -1;
  /* animation: floatingOrbs 20s ease-in-out infinite; */ /* DISABLED FOR TESTING */
}

@keyframes floatingOrbs {
  0%,
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  50% {
    transform: scale(1.1) rotate(180deg);
    opacity: 0.8;
  }
}

/* Additional magical particles */
body::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(
      circle at 10% 20%,
      rgba(255, 255, 255, 0.1) 1px,
      transparent 1px
    ),
    radial-gradient(
      circle at 30% 60%,
      rgba(255, 255, 255, 0.08) 1px,
      transparent 1px
    ),
    radial-gradient(
      circle at 70% 30%,
      rgba(255, 255, 255, 0.06) 1px,
      transparent 1px
    ),
    radial-gradient(
      circle at 90% 80%,
      rgba(255, 255, 255, 0.1) 1px,
      transparent 1px
    );
  background-size: 200px 200px, 300px 300px, 250px 250px, 180px 180px;
  pointer-events: none;
  z-index: -1;
  /* animation: sparkle 8s linear infinite; */ /* DISABLED FOR TESTING */
}

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

/* --- Welcome Screen Styling --- */
.welcome-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  text-align: center;
  padding: 2rem;
  box-sizing: border-box;
}

.welcome-screen h3 {
  color: var(--text-primary);
  font-weight: 800;
  font-size: 2.5rem;
  margin-bottom: 2rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
}

.game-rules {
  text-align: left;
  margin: 2rem 0;
  padding: 2.5rem;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 2rem;
  border-left: 8px solid #e9af51;
  backdrop-filter: blur(25px);
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.1), 0 0 60px rgba(233, 175, 81, 0.2),
    inset 0 0 40px rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.3);
  max-width: 600px;
  position: relative;
  /* animation: rulesShimmer 6s ease-in-out infinite; */ /* DISABLED FOR TESTING */
}

@keyframes rulesShimmer {
  0%,
  100% {
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.1), 0 0 60px rgba(233, 175, 81, 0.2),
      inset 0 0 40px rgba(255, 255, 255, 0.2);
  }
  50% {
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15),
      0 0 80px rgba(233, 175, 81, 0.3), inset 0 0 50px rgba(255, 255, 255, 0.25);
  }
}

.game-rules h3 {
  color: #e9af51;
  margin-top: 0;
  margin-bottom: 1rem;
  font-weight: 700;
  font-size: 1rem;
}

.game-rules li {
  color: var(--text-primary);
  margin-bottom: 0.8rem;
  font-weight: 500;
  font-size: 1.1rem;
}

/* --- Game UI Container --- */
.game-ui {
  position: relative;
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  box-sizing: border-box;
}

/* --- Game Content Wrapper --- */
.game-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
  padding: 0 1rem;
  margin: auto;
}

/* --- Left Side Controls --- */
.left-controls {
  position: fixed;
  top: 2rem;
  left: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  z-index: 1000;
}

/* --- Right Side Controls --- */
.right-controls {
  position: fixed;
  top: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  z-index: 1000;
}

/* --- Beautiful Timer --- */
.timer {
  background: var(--cell-clue);
  color: var(--text-dark);
  font-family: var(--font-main);
  font-size: 1.5rem;
  font-weight: 800;
  padding: 1rem 1.5rem;
  border-radius: 1rem;
  text-align: center;
  min-width: 120px;
  box-shadow: var(--shadow-deep), var(--shadow-glow);
  border: 2px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
  /* animation: timerGlow 2s ease-in-out infinite alternate; */ /* DISABLED FOR TESTING */
}

@keyframes timerGlow {
  0% {
    box-shadow: var(--shadow-deep), 0 0 20px rgba(233, 175, 81, 0.5);
  }
  100% {
    box-shadow: var(--shadow-deep), 0 0 30px rgba(233, 175, 81, 0.8);
  }
}

/* --- Action Buttons Column --- */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.icon-btn {
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  font-size: 1.8rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-deep);
  border: 2px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
}

.icon-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.1),
    rgba(255, 255, 255, 0.3)
  );
  opacity: 0;
  transition: opacity 0.3s ease;
}

.icon-btn:hover::before {
  opacity: 1;
}

.icon-btn:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: var(--shadow-deep), 0 0 25px rgba(255, 255, 255, 0.4);
}

.icon-btn:active {
  transform: translateY(-1px) scale(1.02);
}

/* Text Button Styling */
.text-btn {
  width: auto;
  height: 50px;
  border: none;
  border-radius: 25px;
  font-size: 1rem;
  font-weight: 600;
  padding: 0 1.5rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-deep);
  border: 2px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
}

.text-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.1),
    rgba(255, 255, 255, 0.3)
  );
  opacity: 0;
  transition: opacity 0.3s ease;
}

.text-btn:hover::before {
  opacity: 1;
}

.text-btn:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: var(--shadow-deep), 0 0 25px rgba(255, 255, 255, 0.4);
}

.text-btn:active {
  transform: translateY(-1px) scale(1.02);
}

/* Touch-specific improvements */
@media (pointer: coarse) {
  .cell {
    min-width: 48px;
    min-height: 48px;
  }

  .cell-content {
    /* Larger touch targets on touch devices */
    padding: 2px;
  }

  .cell-content input {
    /* Better touch interaction on mobile */
    font-size: 1.1rem;
  }

  .text-btn,
  .icon-btn {
    /* Larger touch targets for buttons */
    min-width: 44px;
    min-height: 44px;
  }

  .timer {
    /* Prevent accidental touches on timer */
    pointer-events: none;
  }
}

/* Button Specific Colors */
.icon-btn.reset,
.text-btn.reset {
  background: var(--secondary-gradient);
  color: white;
}

.icon-btn.check,
.text-btn.check {
  background: var(--success-gradient);
  color: white;
}

.icon-btn.next,
.text-btn.next {
  background: var(--warning-gradient);
  color: var(--text-dark);
}

.icon-btn.home,
.text-btn.home {
  background: var(--danger-gradient);
  color: white;
}

/* --- Message Area --- */
#message-area {
  background: transparent;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.4rem;
  text-align: center;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
  min-height: 24px;
  margin-bottom: 1.5rem;
  padding: 0.5rem 1rem;
}

/* --- Stunning Puzzle Grid --- */
#puzzle-grid {
  display: grid;
  gap: 8px;
  padding: 1.5rem;
  border-radius: 2rem;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(20px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1), 0 0 50px rgba(255, 255, 255, 0.2),
    inset 0 0 40px rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.3);
  max-width: 400px;
  min-height: 300px;
  width: fit-content;
  margin: 0 auto;
  position: relative;
  /* animation: puzzleGlow 4s ease-in-out infinite alternate; */ /* DISABLED FOR TESTING */

  /* Prevent overflow and ensure proper containment */
  box-sizing: border-box;
  overflow: hidden;
  justify-self: center;
  align-self: center;
}

@keyframes puzzleGlow {
  0% {
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1),
      0 0 50px rgba(255, 255, 255, 0.2),
      inset 0 0 40px rgba(255, 255, 255, 0.15);
  }
  100% {
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15),
      0 0 70px rgba(255, 255, 255, 0.3), inset 0 0 50px rgba(255, 255, 255, 0.2);
  }
}

/* --- Beautiful Puzzle Cells --- */
.cell {
  /* Default size for desktop */
  width: 60px;
  height: 60px;
  position: relative;
  border-radius: 0.5rem;
  overflow: hidden;

  /* Enhanced touch target size */
  min-width: 44px;
  min-height: 44px;

  /* Performance optimizations */
  will-change: auto;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.cell-content {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--cell-bg);
  border: 2px solid var(--cell-border);
  border-radius: 0.5rem;
  font-size: 1.4rem;
  font-weight: 800;
  font-family: var(--font-main);
  color: var(--text-dark);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
  box-sizing: border-box;

  /* Performance optimizations */
  will-change: auto;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.cell-content:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2), inset 0 2px 4px rgba(0, 0, 0, 0.1);
  border-color: rgba(255, 255, 255, 0.6);
}

/* --- Input Styling --- */
.cell-content input {
  width: 100%;
  height: 100%;
  text-align: center;
  border: none;
  background-color: transparent;
  font-size: inherit;
  font-weight: inherit;
  font-family: inherit;
  color: inherit;
  padding: 0;
  border-radius: 0.5rem;
  outline: none;
  transition: all 0.3s ease;

  /* Enhanced touch support */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: text;
  user-select: text;
}

.cell-content input:focus {
  background: var(--cell-focus);
  box-shadow: 0 0 0 3px rgba(233, 175, 81, 0.6),
    0 0 20px rgba(233, 175, 81, 0.4);
}

/* Remove input arrows */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* --- Clue Cells (Golden Theme) --- */
.clue {
  background: var(--cell-clue) !important;
  color: var(--text-dark) !important;
  font-weight: 900 !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  border-color: rgba(233, 175, 81, 0.8) !important;
  /* animation: clueShine 3s ease-in-out infinite alternate; */ /* DISABLED FOR TESTING */
}

@keyframes clueShine {
  0% {
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1),
      0 0 15px rgba(233, 175, 81, 0.3);
  }
  100% {
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1),
      0 0 25px rgba(233, 175, 81, 0.6);
  }
}

/* --- Validation Styling --- */
.duplicate {
  background: var(--danger-gradient) !important;
  color: white !important;
  border-color: #ff6b6b !important;
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

/* --- Welcome Screen Buttons --- */
.btn {
  background: var(--primary-gradient);
  color: white;
  border: none;
  padding: 1rem 2rem;
  border-radius: 2rem;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-deep);
  border: 2px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
}

.btn:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-deep), 0 0 25px rgba(102, 126, 234, 0.5);
}

.btn:active {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--danger-gradient);
}

.btn-success {
  background: var(--success-gradient);
}

.btn-secondary {
  background: var(--secondary-gradient);
}

/* --- Modal Styling --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  display: none;
}

.modal {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(15px);
  padding: 3rem;
  border-radius: 2rem;
  box-shadow: var(--shadow-deep), var(--shadow-glow);
  text-align: center;
  max-width: 400px;
  width: 90%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: var(--text-dark);
}

.modal h2 {
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
  margin-bottom: 1.5rem;
}

.result-category {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 1rem 0;
  padding: 1rem 2rem;
  border-radius: 2rem;
  backdrop-filter: blur(10px);
}

.result-excellent {
  background: var(--success-gradient);
  color: white;
}

.result-very-good {
  background: var(--warning-gradient);
  color: var(--text-dark);
}

.result-good {
  background: var(--secondary-gradient);
  color: white;
}

.result-poor {
  background: var(--danger-gradient);
  color: white;
}

.time-display {
  font-family: var(--font-game);
  font-size: 1.5rem;
  font-weight: 700;
  margin: 1rem 0;
  background: var(--cell-clue);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 2rem;
  flex-wrap: wrap;
}

/* --- Comprehensive Responsive Design --- */

/* Ultra-wide screens (1920px+) */
@media (min-width: 1920px) {
  #puzzle-grid {
    max-width: 500px;
    gap: 12px;
    padding: 2.5rem;
  }

  .cell {
    width: 75px;
    height: 75px;
  }

  .cell-content {
    font-size: 1.8rem;
  }

  .timer {
    font-size: 1.8rem;
    padding: 1.2rem 2rem;
    min-width: 150px;
  }

  .text-btn {
    height: 60px;
    font-size: 1.2rem;
    padding: 0 2rem;
  }

  .welcome-screen h3 {
    font-size: 3.5rem;
  }

  .game-rules {
    max-width: 800px;
    padding: 3rem;
    font-size: 1.3rem;
  }
}

/* Large desktop screens (1366px-1920px) */
@media (min-width: 1366px) and (max-width: 1919px) {
  #puzzle-grid {
    max-width: 450px;
    gap: 10px;
    padding: 2rem;
  }

  .cell {
    width: 70px;
    height: 70px;
  }

  .cell-content {
    font-size: 1.6rem;
  }

  .timer {
    font-size: 1.6rem;
    padding: 1.1rem 1.8rem;
    min-width: 140px;
  }

  .text-btn {
    height: 55px;
    font-size: 1.1rem;
    padding: 0 1.8rem;
  }

  .welcome-screen h3 {
    font-size: 3rem;
  }

  .game-rules {
    max-width: 700px;
    padding: 2.8rem;
  }
}

/* Tablet landscape (1024px-1366px) */
@media (min-width: 1024px) and (max-width: 1365px) {
  .game-ui {
    padding: 1.5rem;
  }

  .left-controls {
    top: 1.5rem;
    left: 1.5rem;
  }

  .right-controls {
    top: 1.5rem;
    right: 1.5rem;
  }

  #puzzle-grid {
    max-width: 420px;
    gap: 9px;
    padding: 1.8rem;
  }

  .cell {
    width: 65px;
    height: 65px;
  }

  .cell-content {
    font-size: 1.5rem;
  }

  .timer {
    font-size: 1.4rem;
    padding: 1rem 1.5rem;
    min-width: 130px;
  }

  .text-btn {
    height: 52px;
    font-size: 1rem;
    padding: 0 1.6rem;
  }

  .welcome-screen h3 {
    font-size: 2.8rem;
  }

  .game-rules {
    max-width: 650px;
    padding: 2.5rem;
  }

  .modal {
    max-width: 450px;
    padding: 2.5rem;
  }
}

/* Tablet portrait (768px-1024px) */
@media (min-width: 768px) and (max-width: 1023px) {
  .game-ui {
    padding: 1.2rem;
  }

  .left-controls {
    top: 1.2rem;
    left: 1.2rem;
    scale: 0.95;
  }

  .right-controls {
    top: 1.2rem;
    right: 1.2rem;
    scale: 0.95;
  }

  #puzzle-grid {
    max-width: 380px;
    gap: 8px;
    padding: 1.5rem;
  }

  .cell {
    width: 58px;
    height: 58px;
  }

  .cell-content {
    font-size: 1.3rem;
  }

  .timer {
    font-size: 1.3rem;
    padding: 0.9rem 1.3rem;
    min-width: 115px;
  }

  .text-btn {
    height: 48px;
    font-size: 0.95rem;
    padding: 0 1.4rem;
  }

  .welcome-screen {
    padding: 2rem;
  }

  .welcome-screen h3 {
    font-size: 2.5rem;
  }

  .game-rules {
    max-width: 600px;
    padding: 2.2rem;
  }

  .modal {
    max-width: 420px;
    padding: 2.2rem;
  }
}

/* Small tablet (600px-768px) */
@media (min-width: 600px) and (max-width: 767px) {
  .game-ui {
    padding: 1rem;
  }

  .left-controls {
    top: 1rem;
    left: 1rem;
    scale: 0.9;
  }

  .right-controls {
    top: 1rem;
    right: 1rem;
    scale: 0.9;
  }

  #puzzle-grid {
    max-width: 350px;
    gap: 7px;
    padding: 1.3rem;
  }

  .cell {
    width: 52px;
    height: 52px;
  }

  .cell-content {
    font-size: 1.2rem;
  }

  .timer {
    font-size: 1.2rem;
    padding: 0.8rem 1.2rem;
    min-width: 105px;
  }

  .text-btn {
    height: 45px;
    font-size: 0.9rem;
    padding: 0 1.3rem;
  }

  .welcome-screen {
    padding: 1.8rem;
  }

  .welcome-screen h3 {
    font-size: 2.2rem;
  }

  .game-rules {
    max-width: 550px;
    padding: 2rem;
  }

  .modal {
    max-width: 380px;
    padding: 2rem;
  }
}

/* Large mobile (480px-600px) */
@media (min-width: 480px) and (max-width: 599px) {
  .game-ui {
    padding: 0.8rem;
    justify-content: center;
    align-items: center;
    position: relative;
    height: 100vh;
  }

  .game-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 90vw;
    justify-content: center;
    align-items: center;
    margin: auto;
  }

  .left-controls {
    top: 0.8rem;
    left: 0.8rem;
    scale: 0.85;
  }

  .right-controls {
    top: 0.8rem;
    right: 0.8rem;
    scale: 0.85;
  }

  .icon-btn {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
  }

  .text-btn {
    height: 42px;
    font-size: 0.85rem;
    padding: 0 1.1rem;
  }

  .timer {
    font-size: 1.1rem;
    padding: 0.7rem 1rem;
    min-width: 95px;
  }

  #puzzle-grid {
    gap: 6px;
    padding: 1.1rem;
    max-width: 320px;
  }

  .cell {
    width: 48px;
    height: 48px;
  }

  .cell-content {
    font-size: 1.1rem;
  }

  .welcome-screen {
    padding: 1.5rem;
  }

  .welcome-screen h3 {
    font-size: 2rem;
  }

  .game-rules {
    padding: 1.8rem;
    margin: 1.5rem 0;
    max-width: 480px;
  }

  .modal {
    padding: 1.8rem;
    margin: 1rem;
    max-width: 350px;
  }
}

/* Standard mobile (320px-480px) */
@media (min-width: 320px) and (max-width: 479px) {
  .game-ui {
    padding: 0.5rem;
    justify-content: center;
    align-items: center;
    position: relative;
    height: 100vh;
  }

  .game-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 90vw;
    justify-content: center;
    align-items: center;
    margin: auto;
  }

  .left-controls {
    top: 0.5rem;
    left: 0.5rem;
    scale: 0.8;
  }

  .right-controls {
    top: 0.5rem;
    right: 0.5rem;
    scale: 0.8;
  }

  .icon-btn {
    width: 45px;
    height: 45px;
    font-size: 1.3rem;
  }

  .text-btn {
    height: 38px;
    font-size: 0.8rem;
    padding: 0 1rem;
  }

  .timer {
    font-size: 1rem;
    padding: 0.6rem 0.8rem;
    min-width: 85px;
  }

  #puzzle-grid {
    gap: 4px;
    padding: 0.8rem;
    max-width: 280px;
  }

  .cell {
    width: 42px;
    height: 42px;
  }

  .cell-content {
    font-size: 1rem;
  }

  .modal-buttons {
    flex-direction: column;
    gap: 0.8rem;
  }

  #message-area {
    font-size: 1.1rem;
    margin-bottom: 1rem;
  }

  .welcome-screen {
    padding: 1rem;
  }

  .welcome-screen h3 {
    font-size: 1.8rem;
  }

  .game-rules {
    padding: 1.2rem;
    margin: 1rem 0;
    max-width: 300px;
  }

  .game-rules h3 {
    font-size: 1.2rem;
  }

  .game-rules li {
    font-size: 0.95rem;
    margin-bottom: 0.6rem;
  }

  .modal {
    padding: 1.5rem;
    margin: 0.8rem;
    max-width: 280px;
  }

  .btn {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
  }
}

/* Very small mobile (below 320px) */
@media (max-width: 319px) {
  .game-ui {
    padding: 0.3rem;
    justify-content: center;
    align-items: center;
    position: relative;
    height: 100vh;
  }

  .game-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 90vw;
    justify-content: center;
    align-items: center;
    margin: auto;
  }

  .left-controls {
    top: 0.3rem;
    left: 0.3rem;
    scale: 0.7;
  }

  .right-controls {
    top: 0.3rem;
    right: 0.3rem;
    scale: 0.7;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
  }

  .text-btn {
    height: 35px;
    font-size: 0.7rem;
    padding: 0 0.8rem;
  }

  .timer {
    font-size: 0.9rem;
    padding: 0.5rem 0.6rem;
    min-width: 75px;
  }

  #puzzle-grid {
    gap: 3px;
    padding: 0.6rem;
    max-width: 250px;
  }

  .cell {
    width: 38px;
    height: 38px;
  }

  .cell-content {
    font-size: 0.9rem;
  }

  .welcome-screen {
    padding: 0.8rem;
  }

  .welcome-screen h3 {
    font-size: 1.5rem;
  }

  .game-rules {
    padding: 1rem;
    margin: 0.8rem 0;
    max-width: 250px;
  }

  .game-rules h3 {
    font-size: 1.1rem;
  }

  .game-rules li {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
  }

  .modal {
    padding: 1.2rem;
    margin: 0.5rem;
    max-width: 240px;
  }

  .btn {
    padding: 0.7rem 1.2rem;
    font-size: 0.9rem;
  }

  #message-area {
    font-size: 1rem;
    margin-bottom: 0.8rem;
  }
}

/* Performance optimizations for mobile */
@media (max-width: 768px) {
  /* Reduce animations on mobile for better performance */
  body {
    animation: none; /* Disable background animation on mobile */
  }

  /* Center game content perfectly on mobile */
  .game-ui {
    justify-content: center;
    align-items: center;
    position: relative;
    height: 100vh;
    display: flex;
    flex-direction: column;
  }

  .game-content {
    justify-content: center;
    align-items: center;
    margin: auto;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 90vw;
  }

  /* Adjust controls to not interfere with centering */
  .left-controls,
  .right-controls {
    position: absolute;
    z-index: 1000;
  }

  body::before {
    animation: none; /* Disable floating orbs on mobile */
    opacity: 0.3; /* Static background instead */
  }

  body::after {
    display: none; /* Remove particles on mobile */
  }

  /* Optimize grid performance */
  #puzzle-grid {
    animation: none; /* Disable glow animation on mobile */
    will-change: auto;
    transform: translateZ(0);
    backface-visibility: hidden;
  }

  .cell-content {
    will-change: auto;
    backface-visibility: hidden;
    transform: translateZ(0);
  }

  .timer {
    animation: none; /* Disable timer glow on mobile */
  }

  .game-rules {
    animation: none; /* Disable rules shimmer on mobile */
  }

  .clue {
    animation: none; /* Disable clue shine on mobile */
  }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .timer {
    animation: none;
  }

  .game-rules {
    animation: none;
  }

  #puzzle-grid {
    animation: none;
  }

  .clue {
    animation: none;
  }

  body::before,
  body::after {
    animation: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --cell-border: #ffffff;
    --text-primary: #ffffff;
    --text-dark: #000000;
    --cell-bg: #ffffff;
    --cell-focus: #ffffff;
  }

  .cell-content {
    border: 2px solid #000000;
  }
}

/* Print styles */
@media print {
  body::before,
  body::after {
    display: none;
  }

  .left-controls,
  .right-controls {
    display: none;
  }

  .modal-overlay {
    display: none !important;
  }

  .welcome-screen {
    display: none;
  }

  #puzzle-grid {
    box-shadow: none;
    background: white;
    border: 2px solid #000;
  }

  .cell-content {
    color: #000;
    background: white;
    border: 1px solid #000;
  }
}
