/* ===================================================
   MEMORY MATCH — COMPLETE STYLESHEET
   style.css — Vanilla CSS · Mobile-First · Production
   =================================================== */

/* ===================================================
   SECTION 1: CSS CUSTOM PROPERTIES (DESIGN TOKENS)
   =================================================== */

:root {
  /* Colors — Light Theme */
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text2: #64748b;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --accent: #f59e0b;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);

  /* Spacing */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-full: 50%;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  /* Safe Areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* Dark Theme */
[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --text2: #94a3b8;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* ===================================================
   SECTION 2: CSS RESET
   =================================================== */

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

html {
  height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img {
  display: block;
  max-width: 100%;
}

button {
  cursor: pointer;
  font-family: inherit;
}

input,
select {
  font-family: inherit;
  font-size: inherit;
}

/* ===================================================
   SECTION 3: APPLICATION SHELL
   =================================================== */

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.screen.active {
  display: flex;
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.overlay.active {
  display: flex;
}

.scrollable {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}

/* ===================================================
   SECTION 4: HEADER
   =================================================== */

.header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  min-height: 56px;
  flex-shrink: 0;
}

.header h2 {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  border-radius: var(--radius);
  padding: 4px;
  transition: background 0.15s;
}

.header-user:hover,
.header-user:focus-visible {
  background: var(--border);
  outline: none;
}

.header-name {
  font-weight: 600;
  font-size: 14px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-coins {
  font-weight: 700;
  color: var(--accent);
  font-size: 14px;
}

.avatar-sm {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  object-fit: cover;
  flex-shrink: 0;
}

.avatar-lg {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-full);
  object-fit: cover;
}

/* ===================================================
   SECTION 5: BUTTONS
   =================================================== */

.btn-primary,
.btn-secondary,
.btn-danger,
.btn-play,
.btn-sm,
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  transition: all 0.15s ease;
  text-decoration: none;
  gap: 8px;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  padding: 14px 24px;
  border-radius: var(--radius);
  font-size: 16px;
  width: 100%;
}

.btn-primary:active {
  background: var(--primary-dark);
  transform: scale(0.97);
}

.btn-primary:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  width: 100%;
}

.btn-secondary:active {
  background: var(--primary);
  color: #ffffff;
}

.btn-danger {
  background: var(--error);
  color: #ffffff;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  width: 100%;
}

.btn-danger:active {
  filter: brightness(0.9);
}

.btn-play {
  background: var(--accent);
  color: #ffffff;
  padding: 20px 48px;
  border-radius: 50px;
  font-size: 22px;
  box-shadow: 0 4px 16px rgba(245, 158, 11, 0.4);
  animation: pulse 2s infinite;
  width: auto;
  margin: 0 auto;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.btn-play:active {
  transform: scale(0.95) !important;
}

.btn-sm {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--primary);
  color: #ffffff;
}

.btn-sm:active {
  background: var(--primary-dark);
}

.btn-icon {
  background: transparent;
  font-size: 20px;
  padding: 8px;
  border-radius: var(--radius-full);
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.btn-icon:active {
  background: var(--border);
}

.btn-icon:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* ===================================================
   SECTION 6: SPLASH SCREEN
   =================================================== */

.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 20px;
  padding: 40px;
}

.splash-logo {
  font-size: 80px;
  animation: bounce 1s ease-in-out infinite;
}

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

.splash-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
}

.splash-loader {
  width: 200px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.loader-bar {
  width: 40%;
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

.splash-status {
  color: var(--text2);
  font-size: 14px;
  text-align: center;
  min-height: 20px;
}

/* ===================================================
   SECTION 7: STATS & PLAY SECTION
   =================================================== */

.stats-row {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  flex: 1;
  background: var(--surface);
  padding: 14px;
  border-radius: var(--radius);
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-label {
  display: block;
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
}

.play-section {
  text-align: center;
  margin: 20px 0;
}

.difficulty-select {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
}

.diff-btn {
  padding: 8px 20px;
  border-radius: 20px;
  border: 2px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.15s;
}

.diff-btn.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.diff-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ===================================================
   SECTION 8: CARDS & SECTIONS
   =================================================== */

.daily-reward {
  margin: 16px 0;
}

.reward-card {
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}

.reward-icon {
  font-size: 32px;
  flex-shrink: 0;
}

.reward-text {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.action-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: var(--radius);
  font-size: 15px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  color: var(--text);
  font-weight: 500;
}

.action-btn:active {
  transform: scale(0.96);
  background: var(--border);
}

.action-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.ad-section {
  margin-top: 8px;
}

.ad-reward-btn {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #ffffff;
  border: none;
  font-weight: 600;
}

/* ===================================================
   SECTION 9: GAME BOARD
   =================================================== */

.game-header {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface);
  gap: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.game-stats {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 14px;
}

.game-stats b {
  color: var(--primary);
}

.game-board-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow: hidden;
}

.game-board {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 1;
}

/* ===================================================
   SECTION 10: GAME CARDS
   =================================================== */

.game-card {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.3s;
  transform-style: preserve-3d;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.game-card:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.game-card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card-inner {
  width: 100%;
  height: 100%;
  transition: transform 0.3s ease;
  transform-style: preserve-3d;
  position: relative;
}

.card-front,
.card-back {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  font-size: 24px;
  user-select: none;
}

.card-back {
  background: var(--primary);
  color: #ffffff;
  font-size: 20px;
  font-weight: 700;
}

.card-front {
  background: var(--surface);
  border: 2px solid var(--border);
  transform: rotateY(180deg);
}

.game-card.matched .card-front {
  background: var(--success);
  border-color: var(--success);
  color: #ffffff;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
}

.game-card.mismatched .card-front {
  background: var(--error);
  border-color: var(--error);
  color: #ffffff;
}

/* ===================================================
   SECTION 11: COMBO POPUP
   =================================================== */

.game-combo-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 24px;
  font-weight: 800;
  color: var(--accent);
  pointer-events: none;
  opacity: 0;
  transition: all 0.4s ease;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 50;
}

.game-combo-popup.show {
  opacity: 1;
  transform: translate(-50%, -80%);
}

/* ===================================================
   SECTION 12: RESULT CARD
   =================================================== */

.result-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 90%;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.result-title {
  font-size: 28px;
  margin-bottom: 8px;
  color: var(--accent);
}

.result-score {
  font-size: 48px;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 16px;
  line-height: 1;
}

.result-breakdown {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 12px;
  line-height: 1.6;
}

.result-rewards {
  font-size: 15px;
  margin-bottom: 20px;
  font-weight: 600;
}

.result-card .btn-primary,
.result-card .btn-secondary {
  margin-bottom: 8px;
}

/* ===================================================
   SECTION 13: MODAL
   =================================================== */

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 90%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.modal-card h3 {
  font-size: 20px;
  margin-bottom: 16px;
  text-align: center;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 4px;
  font-weight: 500;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group input:invalid {
  border-color: var(--error);
}

.turnstile-container {
  display: flex;
  justify-content: center;
  margin: 12px 0;
  min-height: 65px;
}

/* ===================================================
   SECTION 14: TABS
   =================================================== */

.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  background: transparent;
  border: none;
  color: var(--text2);
  transition: all 0.15s;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* ===================================================
   SECTION 15: BALANCE & TRANSACTIONS
   =================================================== */

.balance-hero {
  text-align: center;
  padding: 30px 0;
}

.balance-amount {
  font-size: 48px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.balance-label {
  font-size: 14px;
  color: var(--text2);
  margin-top: 4px;
}

.balance-row {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.balance-item {
  flex: 1;
  background: var(--surface);
  padding: 14px;
  border-radius: var(--radius);
  text-align: center;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.balance-item span {
  display: block;
}

.balance-item span:last-child {
  font-size: 18px;
  font-weight: 700;
  margin-top: 4px;
}

.tx-list {
  margin-top: 16px;
}

.tx-item {
  background: var(--surface);
  padding: 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
  font-size: 13px;
  gap: 8px;
}

/* ===================================================
   SECTION 16: REFERRAL
   =================================================== */

.referral-code-section {
  background: var(--surface);
  padding: 20px;
  border-radius: var(--radius);
  text-align: center;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.ref-code {
  display: block;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--primary);
  margin-bottom: 12px;
  user-select: all;
}

.ref-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0;
}

.ref-stats .stat-card {
  padding: 12px;
}

/* ===================================================
   SECTION 17: PROFILE
   =================================================== */

.profile-header {
  text-align: center;
  padding: 20px 0;
}

.profile-header h3 {
  margin-top: 12px;
  font-size: 20px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0;
}

/* ===================================================
   SECTION 18: SETTINGS
   =================================================== */

.settings-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.settings-group input[type="checkbox"] {
  width: 48px;
  height: 28px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 14px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.settings-group input[type="checkbox"]:checked {
  background: var(--primary);
}

.settings-group input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: #ffffff;
  border-radius: var(--radius-full);
  transition: transform 0.2s;
}

.settings-group input[type="checkbox"]:checked::after {
  transform: translateX(20px);
}

.settings-group select {
  padding: 6px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ===================================================
   SECTION 19: TOAST
   =================================================== */

.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #ffffff;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 200;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90%;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-10px);
}

/* ===================================================
   SECTION 20: RESPONSIVE DESIGN
   =================================================== */

@media (min-width: 600px) {
  .game-board {
    max-width: 480px;
  }

  .result-card,
  .modal-card {
    max-width: 420px;
  }

  .quick-actions {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 768px) {
  .game-board {
    max-width: 520px;
  }

  .stats-row {
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
  }

  .play-section {
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
  }
}

@media (min-width: 1024px) {
  .scrollable {
    max-width: 800px;
    margin: 0 auto;
  }
}

/* ===================================================
   SECTION 21: ACCESSIBILITY
   =================================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Focus visible for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ===================================================
   SECTION 22: LOADING STATES
   =================================================== */

.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, transparent 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===================================================
   SECTION 23: UTILITY CLASSES
   =================================================== */

.text-center { text-align: center; }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-warning { color: var(--warning); }
.text-accent { color: var(--accent); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.w-full { width: 100%; }