:root {
  --bg-color: #f0f2f5;
  --board-bg: #4a3b2b;
  --board-border: #d4b483;
  --block-gap: 2px;
  --unit-size: 80px; /* Base size for a 1x1 block */
  --shadow-color: rgba(0, 0, 0, 0.4);
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--bg-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
  user-select: none;
}

h1 {
  color: #333;
  margin-bottom: 1rem;
}

.controls {
  margin-bottom: 20px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

button {
  padding: 10px 20px;
  font-size: 1rem;
  cursor: pointer;
  background-color: #ffffff;
  border: 1px solid #ccc;
  border-radius: 5px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: all 0.2s;
}

button:hover {
  background-color: #e9ecef;
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

.game-container {
  padding: 10px;
  background-color: var(--board-border);
  border-radius: 10px;
  position: relative;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}

#board {
  width: calc(4 * var(--unit-size));
  height: calc(5 * var(--unit-size));
  background-color: var(--board-bg);
  position: relative;
  border: 2px solid #2c241b;
  box-sizing: content-box; /* Important for exact grid math */
}

/* The exit zone at the bottom */
#board::after {
  content: "EXIT";
  position: absolute;
  bottom: -4px; /* Border overlap */
  left: 50%;
  transform: translateX(-50%);
  width: calc(2 * var(--unit-size));
  height: 4px;
  background-color: transparent; /* Or a marker color */
  border-bottom: 4px solid #fff;
  color: #fff;
  font-size: 10px;
  text-align: center;
  line-height: 4px; /* Hide text, just for accessibility if needed */
  z-index: 0;
}

.block {
  position: absolute;
  box-sizing: border-box;
  border-radius: 4px;
  /* Use transform for smooth sliding */
  transition: transform 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  /* Inner visual styling */
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
  color: rgba(255,255,255,0.2);
  cursor: grab;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.2), 1px 1px 4px var(--shadow-color);
  border: 1px solid rgba(255,255,255,0.3);
  
  /* Text Styling */
  font-family: "KaiTi", "Kaiti TC", "STKaiti", "BiauKai", serif; /* Classic Chinese font */
  font-size: 2rem;
  color: #333; /* Dark text for legibility on lighter blocks */
  text-shadow: 0 1px 0 rgba(255,255,255,0.4);
}

.block.red {
  color: #fff; /* White text on Red */
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.block.blue {
    color: #fff;
    font-size: 1.5rem;
}

/* Vertical Text for 1x2 blocks */
.vertical-text {
  writing-mode: vertical-rl;
  text-orientation: upright;
  letter-spacing: 5px;
}

.block:active {
  cursor: grabbing;
}

/* Block Types & Colors */
.block.red {
  background: linear-gradient(135deg, #ff6b6b, #ee5253);
  z-index: 10; /* Main block slightly higher */
}

.block.yellow {
  background: linear-gradient(135deg, #feca57, #ff9f43);
}

.block.green {
  background: linear-gradient(135deg, #1dd1a1, #10ac84);
}

.block.blue {
  background: linear-gradient(135deg, #54a0ff, #2e86de);
}

.block.wood {
  background: #eccc68; /* Fallback */
  /* Could add texture here if requested */
}

/* Dimensions */
.w1 { width: var(--unit-size); }
.w2 { width: calc(2 * var(--unit-size)); }
.h1 { height: var(--unit-size); }
.h2 { height: calc(2 * var(--unit-size)); }

/* Level Selector */
select {
  padding: 10px;
  border-radius: 5px;
  border: 1px solid #ccc;
  font-size: 1rem;
}

.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.modal.visible {
  opacity: 1;
  pointer-events: all;
}

.modal-content {
  background: #fff;
  padding: 40px;
  border-radius: 10px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.modal h2 {
  font-size: 2rem;
  color: #2eeb2e;
  margin-top: 0;
}
.modal.visible
 opacity: 1; pointer-events: all; 
