:root {
  --lego-yellow: #f9d01e;
  --lego-red: #d62828;
  --lego-blue: #0077b6;
  --lego-green: #2a9d8f;
  --lego-gray: #2f2f2f;
  --lego-light: #f6f9fc;
  --lego-dark: #1a1a1a;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Fredoka', 'Segoe UI', sans-serif;
  background: linear-gradient(160deg, var(--lego-blue) 0%, #4cc9f0 100%);
  color: var(--lego-light);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.game-shell {
  width: min(960px, 100%);
  background: rgba(0, 0, 0, 0.35);
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  box-shadow: 0 28px 60px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
  padding: 1.75rem;
}

.game-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.game-header h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.game-header p {
  margin: 0.5rem auto 0;
  max-width: 600px;
  font-weight: 400;
}

.game-stage {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 250px;
  gap: 1.5rem;
  align-items: start;
}

.canvas-wrapper {
  position: relative;
  max-width: 340px;
  margin: 0 auto;
  border-radius: 18px;
  overflow: hidden;
  background: radial-gradient(circle at top, rgba(255, 255, 255, 0.18), rgba(0, 0, 0, 0.4));
  border: 6px solid rgba(0, 0, 0, 0.25);
  box-shadow: inset 0 0 0 4px rgba(0, 0, 0, 0.4);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  max-width: 320px;
  background: repeating-linear-gradient(
      0deg,
      #1f3d7a,
      #1f3d7a 32px,
      #1a356c 32px,
      #1a356c 64px
    );
}

.touch-controls {
  display: none;
  padding: 1rem 1rem 1.25rem;
  background: rgba(0, 0, 0, 0.45);
  border-top: 4px solid rgba(0, 0, 0, 0.5);
}

.touch-controls.visible {
  display: block;
}

.d-pad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.arrow-grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.arrow-grid .row {
  display: flex;
  gap: 0.5rem;
}

.control-btn {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  border: none;
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--lego-dark);
  background: linear-gradient(135deg, var(--lego-yellow), #ffe066);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.control-btn:active {
  transform: translateY(2px);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}

.toggle-controls {
  width: 100%;
  margin: 0;
  padding: 0.75rem 1rem;
  border: none;
  border-top: 4px solid rgba(0, 0, 0, 0.45);
  background: linear-gradient(135deg, rgba(255, 208, 30, 0.95), rgba(255, 214, 102, 0.95));
  color: var(--lego-dark);
  font-family: 'Fredoka', 'Segoe UI', sans-serif;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  transition: filter 0.2s ease, transform 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.toggle-controls:focus-visible {
  outline: 3px solid rgba(255, 208, 30, 0.8);
  outline-offset: 2px;
}

.toggle-controls:hover {
  filter: brightness(1.05);
}

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

.status-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  text-align: center;
}

.status-overlay.hidden {
  display: none;
}

.status-overlay button {
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  background: linear-gradient(135deg, var(--lego-yellow), #ffd500);
  color: var(--lego-dark);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.status-overlay button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.35);
}

.game-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.game-sidebar section {
  background: rgba(12, 25, 60, 0.6);
  padding: 1rem 1.25rem;
  border-radius: 18px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.25);
}

.game-sidebar h2 {
  margin-top: 0;
  margin-bottom: 0.75rem;
  font-size: 1.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.scoreboard .label {
  color: var(--lego-yellow);
  font-weight: 600;
}

.next-piece canvas {
  width: 100%;
  height: auto;
  background: #19304f;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.12);
}

.instructions ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.3rem;
}

.instructions li {
  background: rgba(0, 0, 0, 0.35);
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  border-left: 4px solid var(--lego-yellow);
}

.game-footer {
  margin-top: 2rem;
  text-align: center;
  font-size: 0.95rem;
  background: rgba(0, 0, 0, 0.3);
  padding: 0.75rem 1rem;
  border-radius: 12px;
}

@media (max-width: 960px) {
  body {
    padding: 1rem;
  }

  .game-stage {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  .game-sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .game-sidebar section {
    flex: 1 1 220px;
  }
}

@media (max-width: 640px) {
  .game-shell {
    padding: 1.25rem 1rem;
  }

  .game-sidebar {
    flex-direction: column;
    margin-top: 1rem;
    gap: 1rem;
  }

  .canvas-wrapper {
    max-width: 100%;
  }

  .game-sidebar section {
    width: 100%;
  }

  .next-piece canvas {
    max-width: 80px;
    margin: 0 auto;
    display: block;
  }
}
