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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: #f0f8ff;
  color: #333333;
  height: 100vh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 100vw;
}

#header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  z-index: 10;
  flex-shrink: 0;
}

#gameTitle {
  font-size: 20px;
  font-weight: bold;
  color: #388e3c;
}

#statusBar {
  display: flex;
  gap: 16px;
  font-size: 14px;
  color: #555;
  font-weight: 500;
}

#gameArea {
  flex: 1;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  overflow: hidden;
}

#gameCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 42%;
  z-index: 2;
}

.card {
  background: #ffffff;
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  font-size: 15px;
  line-height: 1.4;
  border: 2px solid transparent;
  user-select: none;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.12);
}

.card.selected {
  border-color: #4caf50;
  background-color: #e8f5e9;
  transform: scale(1.03);
}

.card.matched {
  background-color: #c8e6c9;
  border-color: #388e3c;
  opacity: 0.85;
  pointer-events: none;
}

.card.error {
  border-color: #e53935;
  animation: shake 0.4s ease-in-out;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(240, 248, 255, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: opacity 0.3s ease;
}

.overlay-content {
  background: #ffffff;
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  max-width: 90%;
  width: 360px;
  animation: popIn 0.3s ease;
}

.overlay-content h2 {
  font-size: 24px;
  color: #388e3c;
  margin-bottom: 12px;
}

.overlay-content p {
  font-size: 16px;
  color: #555;
  margin-bottom: 24px;
  line-height: 1.5;
}

.popup {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
}

.popup-inner {
  background: #ffffff;
  border-radius: 16px;
  padding: 20px;
  max-width: 85%;
  width: 320px;
  text-align: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
  animation: popIn 0.25s ease;
}

#tipTitle {
  font-size: 18px;
  color: #4caf50;
  margin-bottom: 8px;
}

#tipContent {
  font-size: 15px;
  color: #333;
  line-height: 1.5;
  margin-bottom: 16px;
}

.btn-primary,
.btn-large {
  background: #4caf50;
  color: #ffffff;
  border: none;
  border-radius: 24px;
  padding: 12px 28px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  box-shadow: 0 4px 10px rgba(76, 175, 80, 0.3);
}

.btn-primary:hover,
.btn-large:hover {
  background: #43a047;
  transform: translateY(-1px);
}

.btn-primary:active,
.btn-large:active {
  transform: scale(0.98);
}

.hidden {
  display: none !important;
}

.hidden-control {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

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

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

@media (max-width: 600px) {
  #header { padding: 10px 12px; }
  #gameTitle { font-size: 18px; }
  #statusBar { font-size: 13px; gap: 10px; }
  .panel { width: 44%; gap: 10px; }
  .card { padding: 10px; font-size: 14px; min-height: 50px; border-radius: 10px; }
  .overlay-content, .popup-inner { padding: 20px 16px; width: 90%; }
}