:root {
  --bg-deep: #0a0a12;
  --bg-panel: rgba(255, 255, 255, 0.04);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --text-primary: #f0f0f5;
  --text-muted: #8888a0;
  --accent-cyan: #00e5ff;
  --tile-empty: rgba(255, 255, 255, 0.16);
  --tile-filled: rgba(255, 255, 255, 0.35);
  --state-correct: #22c55e;
  --state-present: #eab308;
  --state-absent: #3a3a4a;
  --font: 'Outfit', system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
}

.game-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.game-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border-subtle);
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.back-link:hover {
  color: var(--accent-cyan);
}

.game-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.new-game-btn {
  margin-left: auto;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 1.1rem;
  border: 1px solid var(--border-subtle);
  border-radius: 100px;
  background: var(--bg-panel);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.new-game-btn:hover {
  border-color: rgba(0, 229, 255, 0.4);
  color: var(--accent-cyan);
}

.game-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1.5rem 1rem;
  min-height: 0;
}

/* ---- Board ---- */
.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  flex: 1;
  min-height: 0;
  aspect-ratio: 5 / 6;
  max-height: 420px;
  margin: auto 0;
}

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

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  border: 2px solid var(--tile-empty);
  border-radius: 8px;
  font-size: 2rem;
  font-weight: 700;
  text-transform: uppercase;
  user-select: none;
  transition: border-color 0.15s ease;
}

.tile--filled {
  border-color: var(--tile-filled);
  animation: pop 0.12s ease;
}

.tile--correct,
.tile--present,
.tile--absent {
  border-color: transparent;
  color: #fff;
}

.tile--correct { background: var(--state-correct); }
.tile--present { background: var(--state-present); color: #1a1a2e; }
.tile--absent  { background: var(--state-absent); }

/* Flip reveal on submit */
.tile--reveal {
  animation: flip 0.5s ease forwards;
}

@keyframes pop {
  0%   { transform: scale(0.9); }
  100% { transform: scale(1); }
}

@keyframes flip {
  0%   { transform: rotateX(0); }
  50%  { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

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

.board-row--invalid {
  animation: shake 0.4s ease;
}

@keyframes bounce {
  0%   { transform: translateY(0); }
  40%  { transform: translateY(-24px); }
  60%  { transform: translateY(-12px); }
  100% { transform: translateY(0); }
}

.tile--win {
  animation: bounce 0.6s ease;
}

/* ---- Keyboard ---- */
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 520px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key {
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  height: 52px;
  min-width: 30px;
  flex: 1;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

.key:hover {
  background: rgba(255, 255, 255, 0.2);
}

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

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

.key--correct { background: var(--state-correct); color: #fff; }
.key--present { background: var(--state-present); color: #1a1a2e; }
.key--absent  { background: var(--state-absent); color: var(--text-muted); }

/* ---- Toast ---- */
.toast {
  position: fixed;
  top: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--bg-deep);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.7rem 1.2rem;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 20;
}

.toast--show {
  opacity: 1;
}

/* ---- End overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 18, 0.75);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.overlay--hidden {
  display: none;
}

.overlay-content {
  text-align: center;
  padding: 2rem;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  backdrop-filter: blur(12px);
  max-width: 90vw;
}

.overlay-content h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.overlay-content p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.end-stats {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.end-stat {
  text-align: center;
}

.end-stat__value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent-cyan);
}

.end-stat__label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.btn-start {
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.75rem 2rem;
  border: none;
  border-radius: 100px;
  background: linear-gradient(135deg, #00e5ff, #0099cc);
  color: #0a0a12;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-start:hover {
  transform: scale(1.05);
  box-shadow: 0 0 30px rgba(0, 229, 255, 0.4);
}

@media (max-width: 520px) {
  .game-header {
    padding: 0.8rem 1rem;
    gap: 1rem;
  }

  .game-header h1 {
    font-size: 1.2rem;
  }

  .tile {
    font-size: 1.6rem;
  }

  .key {
    height: 48px;
    font-size: 0.85rem;
  }
}
