:root {
  --bg-gradient-start: #0f2027;
  --bg-gradient-mid: #203a43;
  --bg-gradient-end: #2c5364;
  --card-bg: #ffffff;
  --card-back-grad-1: #1e3c72;
  --card-back-grad-2: #2a5298;
  --accent-gold: #ffb703;
  --accent-green: #2ec4b6;
  --accent-coral: #ff9f1c;
  --accent-red: #e63946;
  --text-main: #f8f9fa;
  --text-dark: #212529;
  --text-muted: #6c757d;
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 4px 10px rgba(0, 0, 0, 0.2);
  --radius-card: 14px;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-mid), var(--bg-gradient-end));
  min-height: 100vh;
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  padding: 12px;
}

/* Container */
.game-container {
  width: 100%;
  max-width: 920px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* Header & Controls */
.game-header {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

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

.logo-icon {
  font-size: 1.8rem;
}

.brand h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(45deg, #a8ff78, #78ffd6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stats-bar {
  display: flex;
  gap: 16px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(0, 0, 0, 0.25);
  padding: 6px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  min-width: 80px;
}

.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: #a0aec0;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: #ffffff;
}

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

/* Instruction banner */
.game-instruction {
  font-size: 0.92rem;
  color: #d1d5db;
  text-align: center;
  background: rgba(0, 0, 0, 0.2);
  padding: 6px 16px;
  border-radius: 20px;
}

.game-instruction strong {
  color: #78ffd6;
}

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  transition: transform 0.15s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

button:active {
  transform: scale(0.95) !important;
}

.btn-primary {
  background: linear-gradient(135deg, #2ec4b6, #209388);
  color: #fff;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(46, 196, 182, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #3adbca, #25a095);
  box-shadow: 0 6px 16px rgba(46, 196, 182, 0.4);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.22);
}

.btn-icon {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

/* Card Grid */
.grid-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 820px;
  perspective: 1000px;
  margin-top: 4px;
}

/* Card Component & 3D Flip */
.card {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.card.flipped, .card.matched {
  transform: rotateY(180deg);
}

.card.matched {
  cursor: default;
}

.card.mismatched {
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  20% { transform: rotateY(180deg) translateX(-8px); }
  40% { transform: rotateY(180deg) translateX(8px); }
  60% { transform: rotateY(180deg) translateX(-5px); }
  80% { transform: rotateY(180deg) translateX(5px); }
}

.card-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
  overflow: hidden;
}

/* Card Back */
.card-back {
  background: linear-gradient(145deg, var(--card-back-grad-1), var(--card-back-grad-2));
  border: 2px solid rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-back-pattern {
  width: 80%;
  height: 80%;
  border: 2px dashed rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: rgba(255, 255, 255, 0.5);
}

/* Card Front */
.card-front {
  background: var(--card-bg);
  color: var(--text-dark);
  transform: rotateY(180deg);
  border: 3px solid #e2e8f0;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.card.matched .card-front {
  border-color: #2ec4b6;
  box-shadow: 0 0 18px rgba(46, 196, 182, 0.6);
  background: #f0fdf4;
}

.card.mismatched .card-front {
  border-color: var(--accent-red);
  box-shadow: 0 0 14px rgba(230, 57, 70, 0.5);
  background: #fff5f5;
}

.card-type-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 12px;
  letter-spacing: 0.5px;
  align-self: flex-start;
}

.badge-category {
  background: #e0f2fe;
  color: #0369a1;
}

.badge-example {
  background: #fef3c7;
  color: #b45309;
}

.card-illustration {
  width: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.card-illustration svg {
  max-width: 100%;
  max-height: 85px;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.1));
}

.card-title {
  font-size: 0.95rem;
  font-weight: 800;
  text-align: center;
  line-height: 1.1;
  margin-top: 2px;
}

.card-subtext {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.15;
  margin-top: 2px;
}

/* Canvas overlay */
#fx-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 99;
}

/* Modals */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.3s ease;
  padding: 16px;
}

.modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  color: #fff;
  width: 100%;
  max-width: 480px;
  animation: modalPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  overflow: hidden;
}

@keyframes modalPop {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Victory Card */
.victory-card {
  text-align: center;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.trophy-icon {
  font-size: 3.5rem;
  animation: bounce 1s infinite alternate ease-in-out;
}

@keyframes bounce {
  0% { transform: translateY(0); }
  100% { transform: translateY(-10px); }
}

.victory-header h2 {
  font-size: 1.8rem;
  color: #38bdf8;
  margin-bottom: 4px;
}

.victory-header p {
  color: #94a3b8;
  font-size: 0.9rem;
}

.stars-container {
  display: flex;
  gap: 10px;
  font-size: 2.5rem;
}

.star {
  color: #475569;
  transition: color 0.4s ease, transform 0.4s ease;
}

.star.lit {
  color: var(--accent-gold);
  text-shadow: 0 0 12px rgba(255, 183, 3, 0.6);
  transform: scale(1.1);
}

.victory-stats {
  display: flex;
  justify-content: space-around;
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 12px;
}

.v-stat {
  display: flex;
  flex-direction: column;
}

.v-label {
  font-size: 0.75rem;
  color: #94a3b8;
}

.v-val {
  font-size: 1.2rem;
  font-weight: 700;
  color: #f8fafc;
}

.modal-actions {
  display: flex;
  gap: 12px;
  width: 100%;
}

.modal-actions button {
  flex: 1;
  padding: 12px;
  font-size: 0.95rem;
}

/* Guide Card */
.guide-card {
  max-width: 650px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.guide-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.guide-header h2 {
  font-size: 1.3rem;
  color: #38bdf8;
}

.btn-close {
  background: transparent;
  color: #94a3b8;
  font-size: 1.8rem;
  line-height: 1;
}

.btn-close:hover {
  color: #fff;
}

.guide-scroll-body {
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.guide-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.guide-item-img {
  width: 60px;
  height: 60px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.guide-item-img svg {
  max-width: 100%;
  max-height: 100%;
}

.guide-item-info h3 {
  font-size: 1.05rem;
  color: #78ffd6;
  margin-bottom: 2px;
}

.guide-item-info .guide-example-tag {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-gold);
  margin-bottom: 4px;
}

.guide-item-info p {
  font-size: 0.8rem;
  color: #cbd5e1;
  line-height: 1.3;
}

/* Responsive adjustments */
@media (max-width: 680px) {
  .game-header {
    padding: 10px 14px;
    flex-direction: column;
    align-items: stretch;
  }

  .brand {
    justify-content: center;
  }

  .stats-bar {
    justify-content: space-between;
  }

  .actions-bar {
    justify-content: center;
  }

  .grid-container {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .card-face {
    padding: 6px 4px;
  }

  .card-type-badge {
    font-size: 0.55rem;
    padding: 2px 4px;
  }

  .card-title {
    font-size: 0.75rem;
  }

  .card-subtext {
    font-size: 0.58rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .card-illustration svg {
    max-height: 55px;
  }
}

@media (max-width: 400px) {
  .grid-container {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  
  .card-title {
    font-size: 0.68rem;
  }
}