:root {
  --green-base: #00a74a;
  --green-glow: rgba(0, 167, 74, 0.7);
  --red-base: #9f0f17;
  --red-glow: rgba(159, 15, 23, 0.7);
  --yellow-base: #cca300;
  --yellow-glow: rgba(204, 163, 0, 0.7);
  --blue-base: #0033a0;
  --blue-glow: rgba(0, 51, 160, 0.7);
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
  padding: 1.5rem 1rem 5rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.game-container {
  width: min(420px, 88vw);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  gap: 0.5rem;
}

.game-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  letter-spacing: -0.02em;
}

.stats {
  display: flex;
  gap: 1.25rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.6;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.status-text {
  font-size: 0.95rem;
  color: var(--text-secondary);
  min-height: 1.5em;
  transition: color 0.3s;
  margin: 0;
}
.status-text.waiting { color: #ffd700; }
.status-text.input { color: #4ade80; }

.board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  aspect-ratio: 1;
  padding: 12px;
  background: rgba(255,255,255,0.03);
  border-radius: 24px;
  border: 1px solid rgba(255,255,255,0.04);
}

.tile {
  position: relative;
  border-radius: 18px;
  cursor: pointer;
  transition: filter 0.1s, transform 0.1s, box-shadow 0.15s;
  touch-action: manipulation;
  filter: brightness(0.65) saturate(0.8);
  box-shadow: inset 0 -4px 8px rgba(0,0,0,0.3), 0 2px 4px rgba(0,0,0,0.2);
}
.tile:active { transform: scale(0.95); }

.tile-0 { background: var(--green-base); }
.tile-1 { background: var(--red-base); }
.tile-2 { background: var(--yellow-base); }
.tile-3 { background: var(--blue-base); }

.tile.active {
  filter: brightness(1.3) saturate(1.1);
  transform: scale(1.03);
  box-shadow: 0 0 30px rgba(255,255,255,0.3);
}
.tile-0.active { box-shadow: 0 0 40px var(--green-glow), 0 0 80px var(--green-glow); }
.tile-1.active { box-shadow: 0 0 40px var(--red-glow), 0 0 80px var(--red-glow); }
.tile-2.active { box-shadow: 0 0 40px var(--yellow-glow), 0 0 80px var(--yellow-glow); }
.tile-3.active { box-shadow: 0 0 40px var(--blue-glow), 0 0 80px var(--blue-glow); }

.tile.wrong {
  filter: brightness(0.4) saturate(0.5);
  box-shadow: 0 0 50px rgba(255,0,0,0.5);
}

.start-btn {
  background: var(--gradient-blue);
  color: #fff;
  border: none;
  padding: 0.7rem 2rem;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: var(--button-shadow);
  transition: opacity 0.2s, transform 0.15s;
  min-width: 160px;
}
.start-btn:hover:not(:disabled) { transform: translateY(-1px); }
.start-btn:active { transform: scale(0.97); }
.start-btn:disabled { opacity: 0.4; cursor: default; }

.game-over-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.game-over-overlay.show { opacity: 1; pointer-events: auto; }

.game-over-card {
  background: var(--bg-secondary);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 2.5rem 2rem;
  text-align: center;
  max-width: 320px;
  width: 85%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: cardIn 0.3s ease-out;
}
@keyframes cardIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.game-over-card h2 { font-size: 1.4rem; margin: 0 0 1.5rem; color: var(--text-primary); }

.game-over-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 2rem;
}
.game-over-stat { display: flex; flex-direction: column; gap: 0.2rem; }
.game-over-stat .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  opacity: 0.6;
}
.game-over-stat .value { font-size: 2rem; font-weight: 800; color: var(--text-primary); }
.game-over-stat .value.best { color: #ffd700; }

.restart-btn {
  background: var(--gradient-blue);
  color: #fff;
  border: none;
  padding: 0.75rem 2rem;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: var(--button-shadow);
  transition: opacity 0.2s, transform 0.15s;
  width: 100%;
}
.restart-btn:hover { transform: translateY(-1px); }
.restart-btn:active { transform: scale(0.97); }

.info-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, color 0.2s;
}
.info-btn:hover { border-color: var(--text-primary); color: var(--text-primary); }

.info-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.info-overlay.show { opacity: 1; pointer-events: auto; }

.info-card {
  background: var(--bg-secondary);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 2rem;
  max-width: 360px;
  width: 85%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  text-align: left;
}
.info-card h2 { font-size: 1.2rem; margin: 0 0 1rem; color: var(--text-primary); }
.info-card p { color: var(--text-secondary); font-size: 0.9rem; line-height: 1.6; margin: 0 0 1rem; }
.info-card ul { color: var(--text-secondary); font-size: 0.85rem; line-height: 1.6; padding-left: 1.2rem; margin: 0 0 1.2rem; }
.info-card li { margin-bottom: 0.3rem; }
.info-card .key {
  display: inline-block;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 4px;
  padding: 0 6px;
  font-size: 0.8rem;
  font-family: monospace;
  color: var(--text-primary);
}
.info-close-btn {
  background: var(--gradient-blue);
  color: #fff;
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  width: 100%;
}

.footer-links {
  margin-top: 1.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  font-size: 0.8rem;
}
.footer-links a { color: var(--text-secondary); text-decoration: none; transition: color 0.2s; }
.footer-links a:hover { color: var(--text-primary); }

@media (max-width: 400px) {
  body { padding: 1rem 0.75rem 4rem; }
  .game-container { width: 92vw; gap: 1rem; }
  .board { gap: 8px; padding: 8px; border-radius: 18px; }
  .tile { border-radius: 14px; }
  .game-title { font-size: 1.25rem; }
  .game-over-card { padding: 2rem 1.5rem; }
}

@media (min-width: 900px) {
  .game-container { width: 450px; }
  .board { gap: 14px; padding: 14px; }
}

@media (min-width: 1600px) {
  html { font-size: 18px; }
  .game-container { width: 500px; }
}
