* {
  box-sizing: border-box;
  font-family: system-ui, sans-serif;
}
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: #121213;
  color: white;
}
#app {
  width: 100%;
  height: 100%;
  position: relative;
}
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}
.screen.active {
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
}
.start-card {
  background: #1a1a1b;
  padding: 40px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(90%, 400px);
}
.start-card h1 {
  margin: 0 0 16px 0;
  text-align: center;
}
.start-card button {
  padding: 16px;
  background: #3a3a3c;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.start-card button:hover {
  background: #4a4a4c;
}
#screen-game {
  flex-direction: row;
}
#screen-game.active {
  display: flex;
}
#drawer {
  width: 280px;
  background: #1a1a1b;
  padding: 20px;
  display: none;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
@media (min-width: 900px) {
  #drawer {
    display: flex;
  }
}
#drawer h3 {
  margin: 0 0 8px 0;
}
#drawer button {
  background: #3a3a3c;
  border: none;
  color: white;
  padding: 12px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
#drawer button:hover {
  background: #4a4a4c;
}
#suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
#suggestions button {
  background: #2a2a2c;
  border: none;
  color: white;
  padding: 10px;
  border-radius: 4px;
  cursor: pointer;
  text-transform: uppercase;
  font-weight: bold;
}
#suggestions button:hover {
  background: #3a3a3c;
}
.menu-section {
  border-top: 1px solid #3a3a3c;
  padding-top: 16px;
}
.menu-section h4 {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: #aaa;
}
.difficulty-buttons {
  display: flex;
  gap: 8px;
}
.difficulty-buttons button {
  flex: 1;
  padding: 8px;
  font-size: 14px;
}
.difficulty-buttons button.active {
  background: #538d4e;
}
#game {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 10px;
  justify-content: space-between;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
}
#menu-btn {
  position: absolute;
  top: 10px;
  left: 20px;
  background: #3a3a3c;
  border: none;
  color: white;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}
#menu-btn:hover {
  background: #4a4a4c;
}
@media (min-width: 900px) {
  #menu-btn {
    display: none;
  }
}
#mode-indicator {
  font-size: 18px;
  font-weight: bold;
  color: #aaa;
  margin-bottom: 20px;
}
#grid {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 8px;
}
.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.tile {
  width: min(12vw, 60px);
  aspect-ratio: 1;
  background: #3a3a3c;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(20px, 5vw, 32px);
  font-weight: bold;
  border: 2px solid #3a3a3c;
  transition: all 0.3s ease;
  transform: scale(1);
}
.tile:hover {
  border-color: #565758;
  transform: scale(1.05);
}
.tile.clickable {
  cursor: pointer;
}
.tile.flip {
  animation: flip 0.5s ease;
}
@keyframes flip {
  0% { transform: scaleY(1); }
  50% { transform: scaleY(0); }
  100% { transform: scaleY(1); }
}
.tile.g {
  background: #538d4e;
  border-color: #538d4e;
}
.tile.y {
  background: #b59f3b;
  border-color: #b59f3b;
}
.tile.b {
  background: #3a3a3c;
  border-color: #3a3a3c;
}
#keyboard {
  margin-top: 40px;
  margin-bottom: 25px;
  display: grid;
  gap: 5px;
  width: 100%;
  max-width: 400px; /* Changed from 500px (20% smaller) */
  padding: 0 5px;
  flex-shrink: 0;
  box-sizing: border-box;
}
#keyboard.hidden {
  display: none;
}
.key-row {
  display: flex;
  justify-content: center;
  gap: 3px;
  width: 100%;
}
.key {
  background: #818384;
  color: white;
  border-radius: 4px;
  padding: 10px 5px; /* Changed from 12px 6px */
  min-width: 20px; /* Changed from 24px */
  flex: 1;
  max-width: 34px; /* Changed from 43px */
  text-align: center;
  cursor: pointer;
  font-weight: bold;
  user-select: none;
  transition: all 0.2s ease;
  transform: scale(1);
  font-size: clamp(8px, 2.2vw, 12px); /* Adjusted font size */
  box-sizing: border-box;
}
.key:hover {
  background: #9a9a9c;
  transform: scale(1.1);
}
.key:active {
  transform: scale(0.95);
}
.key.wide {
  flex: 1.5;
  max-width: 60px;
  font-size: clamp(8px, 2vw, 11px);
  padding: 12px 4px;
}
.end-card {
  background: #1a1a1b;
  padding: 32px;
  border-radius: 12px;
  width: min(90%, 450px);
  text-align: center;
}
.end-card h2 {
  margin: 0 0 20px 0;
}
#end-grid {
  margin: 24px 0;
  display: flex;
  justify-content: center;
}
#end-grid #grid {
  margin: 0;
}
.end-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 24px;
}
.end-actions button {
  padding: 14px;
  background: #3a3a3c;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.end-actions button:hover {
  background: #4a4a4c;
}
#speedrun-info {
  margin-bottom: 16px;
  font-size: 18px;
  color: #b59f3b;
}
@media (max-width: 899px) {
  #drawer {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 1000;
    transform: translateX(-100%) scale(0.9);
    transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55), opacity 0.3s ease;
    opacity: 0;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
  }
  #drawer.open {
    display: flex;
    transform: translateX(0) scale(1);
    opacity: 1;
  }
  #close-drawer {
    display: flex !important;
  }
}

/* Backdrop overlay for mobile menu */
#drawer-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease;
}
#drawer-backdrop.active {
  display: block;
  opacity: 1;
}
#mobile-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.confetti {
  position: fixed;
  width: 10px;
  height: 10px;
  background: #f0f;
  position: absolute;
  animation: confetti-fall 3s linear forwards;
  z-index: 9999;
}
@keyframes confetti-fall {
  to {
    transform: translateY(100vh) rotate(360deg);
    opacity: 0;
  }
}
