* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.game-bg {
  min-height: 100vh;
  background-color: #ffb703;
  background-image: radial-gradient(circle, rgba(255,255,255,0.35) 2px, transparent 2px);
  background-size: 22px 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.game-container {
  background: #fff8ec;
  border-radius: 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 880px;
  overflow: hidden;
}

.game-header {
  background: #ffca3a;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.game-title { font-size: 22px; font-weight: 800; color: #4a3200; text-align: center; }
.home-link {
  position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
  background: #2ecc71; color: #fff; text-decoration: none; font-size: 13px; font-weight: 700;
  padding: 7px 14px; border-radius: 10px;
}

.loading-state, .warning-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 60px 20px; gap: 14px; color: #7a5c00;
}
.spinner {
  width: 36px; height: 36px; border: 4px solid #ffe6a1; border-top-color: #ff9f1c;
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.warning-icon { font-size: 40px; }

.game-board { padding: 24px 28px 32px; }

.board-columns {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
}
.connector-svg {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0;
}
.column { display: flex; flex-direction: column; gap: 14px; z-index: 1; }

/* Fixed, equal card height for both columns so numbers and pictures always
   line up row-for-row regardless of how many objects a picture card holds. */
.card {
  background: #fff;
  border: 2px solid #f1e3c6;
  border-radius: 16px;
  padding: 10px 18px;
  height: 116px;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 3px 8px rgba(0,0,0,0.05);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 14px rgba(0,0,0,0.08); }
.card.selected { border-color: #5b8def; box-shadow: 0 0 0 3px rgba(91,141,239,0.25); }
.card.matched { border-color: #b8c4f5; }
.card.correct { border-color: #2ecc71; background: #f1fbf4; }
.card.incorrect { border-color: #e74c3c; background: #fdf2f1; animation: shake 0.4s; }
.card.locked { cursor: default; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.number-card { display: flex; align-items: center; justify-content: center; }
.number-text { font-size: 30px; font-weight: 800; color: #ff9f1c; pointer-events: none; }

.picture-card { display: flex; align-items: center; }
.card-pictures {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  height: 100%;
  pointer-events: none; /* clicks always resolve on the parent .card */
}

.connector-dot {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 12px; height: 12px; border-radius: 50%; background: #d8dcec;
  pointer-events: none;
}
.dot-right { right: -6px; }
.dot-left { left: -6px; }
.card.selected .connector-dot { background: #5b8def; }
.card.correct .connector-dot { background: #2ecc71; }
.card.incorrect .connector-dot { background: #e74c3c; }

.picture-grid { display: inline-grid; gap: 5px; justify-content: center; align-content: center; pointer-events: none; }
.picture-item { display: flex; align-items: center; justify-content: center; pointer-events: none; }

.score-display {
  text-align: center; font-size: 20px; font-weight: 800; color: #4a3200; margin-top: 22px;
}
.feedback-message {
  text-align: center; font-size: 16px; font-weight: 600; margin-top: 8px; padding: 10px; border-radius: 10px;
}
.feedback-great { background: #e6f9ee; color: #1e8449; }
.feedback-ok { background: #fff4e0; color: #a1670a; }

.game-actions {
  display: flex; justify-content: center; gap: 12px; margin-top: 26px; flex-wrap: wrap;
}
.btn {
  border: none; border-radius: 12px; padding: 12px 22px; font-size: 15px; font-weight: 700;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: transform 0.15s;
}
.btn:hover { transform: translateY(-2px); }
.btn-submit { background: #2ecc71; color: #fff; }
.btn-tryagain { background: #5b8def; color: #fff; }
.btn-showanswer { background: #a55eea; color: #fff; }
.btn-reset { background: #ff9f1c; color: #fff; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .game-container { max-width: 100%; }
}

@media (max-width: 640px) {
  .game-bg { padding: 10px; }
  .game-container { border-radius: 18px; }
  .game-header { padding: 14px 12px; }
  .game-board { padding: 12px 10px 20px; }

  /* Keep the desktop-style two-column layout, just tightened up. */
  .board-columns { gap: 18px; }
  .column { gap: 10px; }

  .game-title { font-size: 15px; line-height: 1.3; padding-right: 54px; }
  .home-link { right: 10px; padding: 5px 9px; font-size: 11px; }
  .card { height: 74px; padding: 6px 8px; border-radius: 12px; }
  .number-text { font-size: 20px; }

  .connector-dot { width: 9px; height: 9px; }
  .dot-right { right: -5px; }
  .dot-left { left: -5px; }

  .picture-grid { gap: 3px; }

  .score-display { font-size: 16px; margin-top: 16px; }
  .feedback-message { font-size: 13px; }

  .game-actions { flex-direction: column; margin-top: 16px; gap: 8px; }
  .btn { width: 100%; justify-content: center; padding: 12px 18px; font-size: 14px; }
}

@media (max-width: 380px) {
  .board-columns { gap: 12px; }
  .card { height: 64px; padding: 4px 6px; }
  .number-text { font-size: 17px; }
  .game-title { font-size: 14px; }
}
