/* Base styles */
    :root {
      --primary-color: #3b669d;
      --primary-hover: #4b77ae;
      --background-dark: #181f28;
      --panel-dark: #242c3b;
      --border-dark: #2a3545;
      --text-light: #e0e0e0;
      --success-color: #4CAF50;
      --highlight-color: #ff4500;
    }

    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    body {
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      background-color: var(--background-dark);
      color: var(--text-light);
      line-height: 1.6;
      transition: all 0.3s ease;
      padding: 1rem;
    }

    h1,
    h2,
    h3 {
      color: var(--primary-hover);
      text-align: center;
      margin-bottom: 0.5rem;
      animation: fadeIn 0.8s ease-in-out;
    }

    .ppx-header-container {
      /* Will center horizontally in any parent div */
      display: block;
      width: 100%;
      text-align: center;
      /* Self-contained styles */
      font-family: 'Courier New', monospace;
      padding: 20px 0;
      position: relative;
      overflow: hidden;
    }
    
    .ppx-header-glitch {
      font-size: 3rem;
      font-weight: bold;
      position: relative;
      display: inline-block;
      text-transform: uppercase;
      letter-spacing: 2px;
      color: var(--text-light, #e0e0e0);
      text-shadow: 
        0 0 5px var(--primary-color, #3b669d),
        0 0 10px var(--primary-hover, #4b77ae);
      margin: 0;
      padding: 10px;
    }
    
    .ppx-header-glitch::before,
    .ppx-header-glitch::after {
      content: "PP-X Web v2";
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      overflow: hidden;
      background: transparent;
      padding: 10px;
    }
    
    .ppx-header-glitch::before {
      left: 3px;
      text-shadow: -2px 0 #00e5ff;
      animation: glitch-anim-1 2s infinite linear alternate-reverse;
      clip-path: polygon(0 0, 100% 0, 100% 45%, 0 45%);
      -webkit-clip-path: polygon(0 0, 100% 0, 100% 45%, 0 45%);
    }
    
    .ppx-header-glitch::after {
      left: -3px;
      text-shadow: 2px 0 var(--success-color, #4CAF50);
      animation: glitch-anim-2 3s infinite linear alternate-reverse;
      clip-path: polygon(0 55%, 100% 55%, 100% 100%, 0 100%);
      -webkit-clip-path: polygon(0 55%, 100% 55%, 100% 100%, 0 100%);
    }
    
    .ppx-binary-rain {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      z-index: -1;
      opacity: 0.2;
    }
    
    .ppx-matrix-char {
      position: absolute;
      color: var(--primary-color, #3b669d);
      font-family: 'Courier New', monospace;
      font-size: 14px;
      line-height: 1;
      user-select: none;
      white-space: nowrap;
    }
    
    .ppx-scanning-line {
      position: absolute;
      height: 2px;
      width: 100%;
      background: #00e5ff;
      box-shadow: 0 0 10px 3px #00e5ff;
      opacity: 0.7;
      top: 50%;
      left: 0;
      animation: scanning 3s infinite;
    }
    
    .ppx-header-border {
      position: absolute;
      inset: 0;
      border: 2px solid var(--border-dark, #2a3545);
      pointer-events: none;
      animation: border-pulse 4s infinite;
    }
    
    @keyframes scanning {
      0%, 100% {
        top: 0;
      }
      50% {
        top: 100%;
      }
    }
    
    @keyframes glitch-anim-1 {
      0%, 100% { transform: translateX(0); }
      5%, 30% { transform: translateX(-5px); }
      10%, 25% { transform: translateX(5px); }
      15% { transform: translateX(-5px); }
      20% { transform: translateX(5px); }
    }
    
    @keyframes glitch-anim-2 {
      0%, 100% { transform: translateX(0); }
      5%, 30% { transform: translateX(5px); }
      10%, 25% { transform: translateX(-5px); }
      15% { transform: translateX(5px); }
      20% { transform: translateX(-5px); }
    }
    
    @keyframes border-pulse {
      0%, 100% {
        box-shadow: 0 0 0 rgba(0, 229, 255, 0);
      }
      50% {
        box-shadow: 0 0 15px rgba(0, 229, 255, 0.7);
      }
    }
    
    .ppx-terminal-line {
      position: absolute;
      bottom: 8px;
      width: 100%;
      font-family: 'Courier New', monospace;
      font-size: 12px;
      color: var(--primary-hover, #4b77ae);
      text-align: center;
      white-space: nowrap;
      overflow: hidden;
      opacity: 0.8;
    }
    
    .ppx-terminal-text {
      display: inline-block;
      white-space: nowrap;
      animation: typing 8s steps(60) infinite;
    }
    
    @keyframes typing {
      0% { width: 0; }
      40% { width: 100%; }
      60% { width: 100%; }
      100% { width: 0; }
    }

    .container {
      width: 100%;
      max-width: 1200px;
      margin: 0 auto;
    }

    /* Header section */
    .app-header {
      text-align: center;
      margin-bottom: 1rem;
      animation: slideDown 0.5s ease-in-out;
    }

    @keyframes slideDown {
      from {
        transform: translateY(-20px);
        opacity: 0;
      }

      to {
        transform: translateY(0);
        opacity: 1;
      }
    }

    @keyframes fadeIn {
      from {
        opacity: 0;
      }

      to {
        opacity: 1;
      }
    }

    /* Game grid section */
    .game-section {
      display: flex;
      flex-direction: column;
      align-items: center;
      animation: fadeIn 0.8s ease-in-out;
    }

    .game-container {
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
    }

    /* Make the grid container smaller */
    .grid-container {
      width: 100%;
      max-width: min(60vw, 60vh);
      /* Reduced from 80vw/80vh */
      aspect-ratio: 1;
      margin: 1rem auto;
    }

    #grid {
      width: 100%;
      aspect-ratio: 1;
      border-collapse: collapse;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
      border-radius: 8px;
      overflow: hidden;
    }

    td {
      position: relative;
      border: 1px solid var(--border-dark);
      text-align: center;
      cursor: pointer;
      transition: background-color 0.2s, transform 0.2s;
    }

    td:before {
      content: "";
      display: block;
      padding-top: 100%;
    }

    /* Ensure circles are in the middle */
    td>* {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    td:hover {
      background-color: rgba(255, 255, 255, 0.1);
      transform: scale(1.05);
    }

    /* Enhanced circle styling with animation */
    .circle {
      position: relative;
      width: 75%;
      height: 75%;
      border-radius: 50%;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
      transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275),
        box-shadow 0.3s ease;
      animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    }

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

      70% {
        transform: scale(1.1);
      }

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

    td:hover .circle {
      transform: scale(1.1);
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    }

    .circle:active {
      transform: scale(0.95);
    }

    .color-0 {
      background-color: #2d2d2d;
    }

    .color-1 {
      background-color: #4d7bd6;
      background-image: linear-gradient(135deg, #4d7bd6, #3b69d0);
    }

    .color-2 {
      background-color: #ff5c91;
      background-image: linear-gradient(135deg, #ff5c91, #ff4483);
    }

    .color-3 {
      background-color: #9c5dd5;
      background-image: linear-gradient(135deg, #9c5dd5, #8a4bc4);
    }

    .empty {
      background-color: var(--border-dark);
      animation: pulseEmpty 2s infinite alternate;
    }

    @keyframes pulseEmpty {
      from {
        opacity: 0.7;
      }

      to {
        opacity: 1;
      }
    }

    /* Mode controls with animations */
    .mode-controls {
      display: flex;
      gap: 0.5rem;
      justify-content: center;
      margin-bottom: 1rem;
      flex-wrap: wrap;
      animation: fadeIn 0.8s ease-in-out 0.2s both;
    }

    .instructions {
      text-align: center;
      margin-bottom: 1rem;
      padding: 0 1rem;
      animation: fadeIn 0.8s ease-in-out 0.3s both;
    }

    /* Enhanced buttons with animations */
    button,
    .mode-btn,
    .control-btn {
      padding: 0.5rem 1rem;
      font-size: 0.9rem;
      background-color: var(--primary-color);
      color: white;
      border: none;
      border-radius: 5px;
      cursor: pointer;
      transition: all 0.2s ease;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
      animation: fadeIn 0.5s ease-in-out;
      position: relative;
      overflow: hidden;
    }

    button:after,
    .mode-btn:after,
    .control-btn:after {
      content: '';
      position: absolute;
      top: 50%;
      left: 50%;
      width: 5px;
      height: 5px;
      background: rgba(255, 255, 255, 0.5);
      opacity: 0;
      border-radius: 100%;
      transform: scale(1, 1) translate(-50%);
      transform-origin: 50% 50%;
    }

    button:focus:not(:active):after,
    .mode-btn:focus:not(:active):after,
    .control-btn:focus:not(:active):after {
      animation: ripple 1s ease-out;
    }

    @keyframes ripple {
      0% {
        transform: scale(0, 0);
        opacity: 0.5;
      }

      20% {
        transform: scale(25, 25);
        opacity: 0.3;
      }

      100% {
        opacity: 0;
        transform: scale(40, 40);
      }
    }

    button:hover,
    .mode-btn:hover,
    .control-btn:hover {
      background-color: var(--primary-hover);
      transform: translateY(-2px);
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    }

    button:active,
    .mode-btn:active,
    .control-btn:active {
      transform: translateY(0);
      box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    }

    .mode-btn.active {
      background-color: var(--success-color);
      color: white;
      animation: pulse 2s infinite;
    }

    @keyframes pulse {
      0% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4);
      }

      70% {
        box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
      }

      100% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
      }
    }

    /* Solution section with animations */
    #solution {
      max-width: 100%;
      margin: 1rem 0;
      text-align: center;
      padding: 1rem;
      background-color: var(--panel-dark);
      border-radius: 8px;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
      animation: fadeIn 0.8s ease-in-out 0.4s both;
      transition: all 0.3s ease;
    }

    #solution:hover {
      box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
      transform: translateY(-2px);
    }

    #solutionControls {
      display: flex;
      gap: 0.5rem;
      margin-top: 1rem;
      flex-wrap: wrap;
      justify-content: center;
      align-items: center;
      animation: fadeIn 0.8s ease-in-out 0.5s both;
    }

    #stepCounter {
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 0.5rem;
      background-color: var(--panel-dark);
      border-radius: 5px;
      min-width: 100px;
      transition: all 0.3s ease;
      animation: fadeIn 0.8s ease-in-out 0.5s both;
    }

    /* Builder controls with animations */
    #builderControls {
      margin-top: 1rem;
      padding: 1rem;
      border: none;
      border-radius: 8px;
      background-color: var(--panel-dark);
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
      width: 100%;
      animation: slideUp 0.5s ease-in-out;
      transition: all 0.3s ease;
    }

    @keyframes slideUp {
      from {
        transform: translateY(20px);
        opacity: 0;
      }

      to {
        transform: translateY(0);
        opacity: 1;
      }
    }

    #builderControls:hover {
      box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
    }

    #colorPalette {
      display: flex;
      gap: 0.75rem;
      margin-bottom: 1rem;
      flex-wrap: wrap;
      justify-content: center;
      animation: fadeIn 0.8s ease-in-out 0.6s both;
    }

    .color-option {
      display: flex;
      flex-direction: column;
      align-items: center;
      cursor: pointer;
      padding: 0.5rem;
      border-radius: 8px;
      transition: all 0.3s ease;
      animation: fadeIn 0.5s ease;
    }

    .color-option:hover {
      background-color: var(--border-dark);
      transform: translateY(-2px);
    }

    .color-option.selected {
      background-color: #324156;
      box-shadow: 0 0 0 2px var(--primary-color);
      animation: bounce 0.5s ease;
    }

    @keyframes bounce {

      0%,
      100% {
        transform: translateY(0);
      }

      50% {
        transform: translateY(-5px);
      }
    }

    #levelControls,
    #savedLevels {
      display: flex;
      gap: 0.5rem;
      margin-bottom: 1rem;
      flex-wrap: wrap;
      justify-content: center;
      align-items: center;
      animation: fadeIn 0.8s ease-in-out 0.7s both;
    }

    /* Form inputs with animations */
    input[type="text"],
    input[type="number"],
    select {
      padding: 0.5rem;
      border-radius: 5px;
      border: 1px solid var(--primary-color);
      background-color: #1e2634;
      color: var(--text-light);
      font-size: 0.9rem;
      transition: all 0.3s ease;
      animation: fadeIn 0.5s ease;
    }

    input:focus,
    select:focus {
      border-color: var(--primary-hover);
      outline: none;
      box-shadow: 0 0 0 2px rgba(75, 119, 174, 0.3);
      transform: translateY(-2px);
    }

    /* Image loader section with animations */
    .settings-section {
      display: flex;
      flex-wrap: wrap;
      gap: 1.5rem;
      margin-top: 2rem;
      justify-content: center;
      animation: fadeIn 0.8s ease-in-out 0.8s both;
    }

    .image-container {
      background-color: var(--panel-dark);
      padding: 1rem;
      border-radius: 8px;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
      flex: 1;
      min-width: 280px;
      max-width: 400px;
      transition: all 0.3s ease;
      animation: fadeIn 0.8s ease;
    }

    .image-container:hover {
      box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
      transform: translateY(-3px);
    }

    .form-group {
      margin-bottom: 0.75rem;
      animation: fadeIn 0.5s ease;
    }

    .form-group label {
      display: block;
      margin-bottom: 0.25rem;
    }

    #previewContainer {
      margin-top: 1rem;
      border: 2px solid var(--primary-color);
      border-radius: 4px;
      overflow: hidden;
      max-width: 100%;
      transition: all 0.3s ease;
      animation: fadeIn 0.8s ease;
    }

    #previewCanvas {
      max-width: 100%;
      height: auto;
    }

    /* Solution markers with enhanced animations */
    .solution-marker {
      position: absolute;
      width: 20px;
      height: 20px;
      background-color: var(--highlight-color);
      color: white;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 12px;
      font-weight: bold;
      z-index: 10;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
      animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    }

    /* Add these positioning classes for the markers */
    .top-right {
      top: 0;
      right: 0;
    }

    .top-left {
      top: 0;
      left: 0;
    }

    .bottom-right {
      bottom: 0;
      right: 0;
    }

    .bottom-left {
      bottom: 0;
      left: 0;
    }

    .markers-container {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      pointer-events: none;
    }

    /* Optional: Make the cell highlight more visible when it has solution steps */
    .solution-cell {
      position: relative;
    }

    .solution-highlight {
      background-color: rgba(255, 69, 0, 0.2);
    }

    /* Media query for mobile devices */
    @media screen and (max-width: 768px) {
      .grid-container {
        max-width: 100%;
        width: 100%;
      }
    }
    .file-drop-area {
              position: relative;
              display: flex;
              flex-direction: column;
              align-items: center;
              padding: 20px;
              border: 2px dashed var(--primary-color, #3b669d);
              border-radius: 8px;
              background-color: rgba(59, 102, 157, 0.1);
              transition: all 0.3s ease;
              cursor: pointer;
            }
            
            .file-drop-area.highlight {
              border-color: var(--primary-hover, #4b77ae);
              background-color: rgba(59, 102, 157, 0.2);
              box-shadow: 0 0 10px rgba(0, 229, 255, 0.5);
            }
            
            .file-msg {
              margin-bottom: 10px;
              color: var(--text-light, #e0e0e0);
              font-size: 0.9rem;
            }
            
            .file-input-label {
              padding: 8px 16px;
              background-color: var(--primary-color, #3b669d);
              color: var(--text-light, #e0e0e0);
              border-radius: 5px;
              cursor: pointer;
              transition: all 0.3s ease;
            }
            
            .file-input-label:hover {
              background-color: var(--primary-hover, #4b77ae);
              transform: translateY(-2px);
            }
            
            .file-input {
              position: absolute;
              left: 0;
              top: 0;
              height: 100%;
              width: 100%;
              opacity: 0;
              cursor: pointer;
            }
            
            #preview-filename {
              margin-top: 10px;
              font-size: 0.8rem;
              color: var(--success-color, #4CAF50);
              word-break: break-all;
              text-align: center;
            }