:root {
  --bg-primary: #313338;
  --bg-secondary: #2b2d31;
  --bg-tertiary: #1e1f22;
  --border-color: #3f4147;
  --border-active: #5865f2;
  
  --color-correct: #23a55a;
  --color-present: #f0b232;
  --color-absent: #4e5058;
  --color-key: #4e5058;
  --color-key-hover: #6d6f78;
  
  --text-normal: #f2f3f5;
  --text-muted: #949ba4;
  --blurple: #5865f2;
  --blurple-hover: #4752c4;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: 'gg sans', 'Noto Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-normal);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding: 10px;
}

/* Header */
header {
  width: 100%;
  max-width: 500px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-badge {
  background-color: var(--blurple);
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
  padding: 3px 7px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 1.5px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-normal);
}

.user-badge {
  display: none;
  align-items: center;
  gap: 6px;
  background: var(--bg-secondary);
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
  color: var(--text-normal);
}

.user-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
}

/* Board */
#board-container {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-grow: 1;
  padding: 12px 0;
}

#board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 350px;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.tile {
  aspect-ratio: 1 / 1;
  width: 100%;
  min-width: 48px;
  max-width: 62px;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.8rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-normal);
  background-color: var(--bg-secondary);
  transition: transform 0.1s ease;
}

.tile.active {
  border-color: var(--border-active);
  animation: popIn 0.1s ease-in-out;
}

.tile.correct {
  background-color: var(--color-correct) !important;
  border-color: var(--color-correct) !important;
  color: #fff;
}

.tile.present {
  background-color: var(--color-present) !important;
  border-color: var(--color-present) !important;
  color: #fff;
}

.tile.absent {
  background-color: var(--color-absent) !important;
  border-color: var(--color-absent) !important;
  color: #fff;
}

.tile.flip {
  animation: flipTile 0.5s ease forwards;
}

.board-row.shake {
  animation: shakeRow 0.5s ease-in-out;
}

.tile.bounce {
  animation: bounceTile 0.6s ease forwards;
}

/* Virtual Keyboard */
#keyboard {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 8px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  width: 100%;
}

.key {
  background-color: var(--color-key);
  color: var(--text-normal);
  border: none;
  border-radius: 4px;
  height: 52px;
  flex: 1;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, filter 0.15s ease;
}

.key:hover {
  background-color: var(--color-key-hover);
}

.key:active {
  transform: translateY(2px);
}

.key.wide {
  flex: 1.5;
  font-size: 0.85rem;
}

.key.correct {
  background-color: var(--color-correct);
  color: #fff;
}

.key.present {
  background-color: var(--color-present);
  color: #fff;
}

.key.absent {
  background-color: #2b2d31;
  color: var(--text-muted);
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  z-index: 1000;
}

.toast {
  background-color: #111214;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  animation: fadeInOut 2s ease forwards;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  justify-content: center;
  align-items: center;
  z-index: 2000;
  padding: 16px;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 100%;
  max-width: 420px;
  padding: 24px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: popIn 0.2s ease-out;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 1.3rem;
  font-weight: 800;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.close-btn:hover {
  color: var(--text-normal);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
  text-align: center;
}

.stat-item .stat-num {
  font-size: 1.8rem;
  font-weight: 800;
}

.stat-item .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.btn-primary {
  background-color: var(--blurple);
  color: #fff;
  border: none;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s ease;
}

.btn-primary:hover {
  background-color: var(--blurple-hover);
}

.btn-secondary {
  background-color: var(--bg-tertiary);
  color: var(--text-normal);
  border: 1px solid var(--border-color);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-secondary:hover {
  background-color: #232428;
}

/* Animations */
@keyframes popIn {
  0% { transform: scale(0.8); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

@keyframes flipTile {
  0% {
    transform: rotateX(0);
    background-color: var(--bg-secondary);
  }
  49% {
    background-color: var(--bg-secondary);
  }
  50% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0);
  }
}

@keyframes shakeRow {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

@keyframes bounceTile {
  0%, 20% { transform: translateY(0); }
  40% { transform: translateY(-20px); }
  50% { transform: translateY(0); }
  60% { transform: translateY(-10px); }
  80%, 100% { transform: translateY(0); }
}

@keyframes fadeInOut {
  0% { opacity: 0; transform: translateY(-10px); }
  15% { opacity: 1; transform: translateY(0); }
  85% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* Mobile adjustments */
@media (max-width: 480px) {
  .tile {
    min-width: 42px;
    max-width: 54px;
    font-size: 1.5rem;
  }
  .key {
    height: 48px;
    font-size: 0.9rem;
  }
  .key.wide {
    font-size: 0.75rem;
  }
}
