:root {
    --bg-color-start: #2a3d66;
    --bg-color-end: #4a4a7c;
    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-bg-hover: rgba(255, 255, 255, 0.15);
     --glass-bg-active: rgba(255, 255, 255, 0.25);
    --glass-border: rgba(255, 255, 255, 0.18);
    --glass-shadow: 0 8px 32px rgba(0, 20, 80, 0.2);
    --text-color: rgba(255, 255, 255, 0.9);
    --text-shadow: 0 1px 3px rgba(0,0,0,0.2);
    --blur-amount: 15px;
    --border-radius: 18px;
    --cell-size: 25px;
     --cell-gap: 1px;
     --panel-padding: 15px;
}

body {
    font-family: "Roboto", "Noto Sans SC", -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    margin: 0;
    background: linear-gradient(135deg, var(--bg-color-start), var(--bg-color-end));
    background-attachment: fixed;
    color: var(--text-color);
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
     box-sizing: border-box;
}

/* 背景模糊光斑和噪点效果 (可选, 增加质感) */
 .background-blur {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(circle at 20% 20%, rgba(100, 180, 255, 0.4), transparent 50%),
                radial-gradient(circle at 80% 70%, rgba(200, 100, 255, 0.3), transparent 40%),
                 radial-gradient(circle at 50% 90%, rgba(100, 255, 200, 0.2), transparent 60%);
     filter: blur(80px);
     opacity: 0.7;
    z-index: -2;
     pointer-events: none;
 }
  /* https://css-tricks.com/snippets/css/animated-noise-background/ */
 .noise-overlay {
     position: fixed;
      top: -50%; left: -50%; right: -50%; bottom: -50%;
      z-index: -1;
      background: transparent url('data:image/svg+xml,%3Csvg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"%3E%3Cfilter id="noiseFilter"%3E%3CfeTurbulence type="fractalNoise" baseFrequency="0.65" numOctaves="3" stitchTiles="stitch"/%3E%3C/filter%3E%3Crect width="100%25" height="100%25" filter="url(%23noiseFilter)"/%3E%3C/svg%3E') repeat;
      opacity: .03;
      pointer-events: none;
      animation: noise .2s steps(6) infinite;
 }
 @keyframes noise { to { background-position: 200px 0; } }


/* --- Glassmorphism Base --- */
.glass-panel, .glass-button {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount)); /* Safari */
    border-radius: var(--border-radius);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    box-sizing: border-box;
     transition: background 0.2s ease-out, transform 0.2s ease-out;
}

h1 {
    text-align: center;
    font-weight: 300;
    letter-spacing: 1px;
     margin-top: 10px;
     margin-bottom: 20px;
     text-shadow: var(--text-shadow);
}

.container {
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
     max-width: 800px;
     margin: 10px;
}

.game-layout {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 20px;
}

.game-board-container {
     padding: var(--panel-padding);
     position: relative; /* For message overlay */
}

#game-board {
    display: grid;
    grid-template-columns: repeat(10, var(--cell-size));
    grid-template-rows: repeat(20, var(--cell-size));
    gap: var(--cell-gap);
    background: rgba(0, 0, 0, 0.1); /* Darker background for contrast */
    border-radius: 8px;
     border: 1px solid rgba(255,255,255, 0.05);
     overflow: hidden; /* clip cells */
}

#game-message {
     position: absolute;
     top: 50%;
     left: 50%;
     transform: translate(-50%, -50%);
     padding: 20px 30px;
     font-size: 1.5em;
     font-weight: 500;
      text-align: center;
     z-index: 10;
     display: none; /* Hidden by default */
     background: rgba(10,10,30,0.6);
      backdrop-filter: blur(5px);
     -webkit-backdrop-filter: blur(5px);
      text-shadow: 0 2px 4px rgba(0,0,0,0.5);
       min-width: 160px;
}

.side-panel {
    padding: var(--panel-padding);
    display: flex;
    flex-direction: column;
    gap: 25px;
    width: 140px;
     text-shadow: var(--text-shadow);
}
 .left-panel { align-items: flex-end; text-align: right; }
 .right-panel { align-items: flex-start; }


.info-group label {
    display: block;
    font-size: 0.8em;
    font-weight: 300;
    opacity: 0.8;
    margin-bottom: 5px;
     text-transform: uppercase;
     letter-spacing: 0.5px;
}
.info-group .info-value {
     font-size: 1.6em;
     font-weight: 500;
}

#next-piece {
     display: grid;
     grid-template-columns: repeat(4, calc(var(--cell-size) * 0.7));
     grid-template-rows: repeat(4, calc(var(--cell-size) * 0.7));
      gap: var(--cell-gap);
      width: calc(4 * (var(--cell-size) * 0.7 + var(--cell-gap)));
      height: calc(4 * (var(--cell-size) * 0.7 + var(--cell-gap)));
      margin-top: 5px;
      /* Center the grid itself */
       display: flex;
       flex-wrap: wrap;
       align-content: center;
       justify-content: center;
}
 /* For Next Piece cells */
#next-piece .cell {
     width: calc(var(--cell-size) * 0.7);
     height: calc(var(--cell-size) * 0.7);
}


.controls {
     display: flex;
     flex-direction: column;
     gap: 10px;
      width: 100%;
}

.glass-button {
     font-family: inherit;
     color: var(--text-color);
     padding: 10px 15px;
     cursor: pointer;
     text-align: center;
      font-size: 0.9em;
      text-shadow: var(--text-shadow);
}
 .glass-button:hover {
     background: var(--glass-bg-hover);
      transform: translateY(-1px);
 }
  .glass-button:active {
     background: var(--glass-bg-active);
     transform: translateY(0px);
     box-shadow: inset 0 1px 3px rgba(0,0,0, 0.1);
 }

/* --- Cell Styles --- */
.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background-color: rgba(255, 255, 255, 0.03); /* Empty cell */
    border-radius: 4px;
     box-sizing: border-box;
     transition: background-color 0.1s ease, box-shadow 0.1s ease;
}

/* Block styles - glassy tiles */
 .cell.filled {
     border: 1px solid rgba(255,255,255,0.3);
      box-shadow: 0 2px 5px rgba(0,0,0,0.2), inset 0 1px 1px rgba(255,255,255,0.4);
 }
 .cell.ghost {
      background-color: rgba(255, 255, 255, 0.15) !important;
      border: 1px dashed rgba(255, 255, 255, 0.3) !important;
       box-shadow: none !important;
 }

/* Tetromino Colors */
.cell.cyan    { background: linear-gradient(135deg, #00f2ff, #00bcd4); }
.cell.yellow  { background: linear-gradient(135deg, #ffff00, #ffeb3b); }
.cell.purple  { background: linear-gradient(135deg, #e040fb, #9c27b0); }
.cell.green   { background: linear-gradient(135deg, #69f0ae, #4caf50); }
.cell.red     { background: linear-gradient(135deg, #ff5252, #f44336); }
.cell.blue    { background: linear-gradient(135deg, #448aff, #2196f3); }
.cell.orange  { background: linear-gradient(135deg, #ffab40, #ff9800); }


/* --- Mobile Controls --- */
 #mobile-controls {
    display: none; /* Hidden on desktop */
    flex-direction: column;
     gap: 10px;
     padding: 15px;
     margin-top: 10px;
     width: 100%;
     max-width: calc(10 * (var(--cell-size) + var(--cell-gap)) + 2 * var(--panel-padding));
 }
 .ctrl-row {
      display: flex;
       justify-content: center;
       gap: 10px;
 }
 .ctrl-btn {
      flex-grow: 1;
      padding: 12px 8px;
      font-size: 1.1em;
      -webkit-tap-highlight-color: transparent; /* remove tap highlight */
 }
 .ctrl-row:first-child .ctrl-btn { flex-basis: 40%; }
 .ctrl-row:last-child .ctrl-btn { flex-basis: 30%; }


/* --- Responsive Design --- */
@media (max-width: 640px) {
     :root {
        --cell-size: 20px; /* Smaller cells */
         --panel-padding: 10px;
          --blur-amount: 10px;
          --border-radius: 12px;
     }
     body {
         padding: 10px;
         align-items: flex-start;
      }
      h1 {
         font-size: 1.4em;
         margin-bottom: 15px;
      }
      .container {
         padding: 15px;
          margin-top: 5px;
      }

    .game-layout {
        flex-direction: column;
        align-items: center;
         gap: 15px;
    }
     .game-board-container {
          order: 2; /* Board in middle */
           width: fit-content;
     }
     .side-panel {
         flex-direction: row;
         justify-content: space-around;
         align-items: center;
          width: 100%;
          max-width: calc(10 * (var(--cell-size) + var(--cell-gap)) + 2 * var(--panel-padding));
          gap: 10px;
          padding: 10px 15px;
     }
      .left-panel {
           order: 1; /* Score/Level/Lines on top */
            align-items: center;
             text-align: center;
      }
       .right-panel {
           order: 3; /* Next/Buttons on bottom */
            align-items: center;
             text-align: center;
             justify-content: space-between;
       }

      .info-group label { font-size: 0.7em;}
      .info-group .info-value { font-size: 1.1em;}

       #next-piece {
           transform: scale(0.9);
        }
       .controls {
          flex-direction: row;
           width: auto;
       }
        .glass-button {
           padding: 8px 12px;
            font-size: 0.8em;
        }

    #mobile-controls {
        display: flex; /* Show on mobile */
         order: 4;
    }
}
 /* Very small screens */
  @media (max-width: 360px) {
       :root {
        --cell-size: 16px;
     }
      .right-panel {
         flex-direction: column;
      }
       .ctrl-btn {
          font-size: 0.9em;
       }
  }
