/* ========================================================
   MiniJoy Arcade - Global Stylesheet (V0.1 MVP)
   Design: Modern, friendly, light pastel with Indigo #4F46E5
   ======================================================== */

:root {
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-light: #EEF2FF;
  --bg-page: #F8FAFC;
  --bg-card: #FFFFFF;
  --text-main: #0F172A;
  --text-sub: #475569;
  --text-muted: #94A3B8;
  --border-light: #E2E8F0;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 40px rgba(15, 23, 42, 0.1);
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", "PingFang SC", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  user-select: none;
}

/* ================= 1. Header Navigation ================= */
header.mj-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-light);
  padding: 14px 24px;
}

.mj-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.mj-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  cursor: pointer;
}

.mj-logo-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #4F46E5, #818CF8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.mj-brand-text {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-main);
}
.mj-brand-text span {
  color: var(--primary);
}

.mj-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mj-search-box {
  position: relative;
  width: 180px;
  transition: width 0.25s ease;
}
@media (min-width: 640px) {
  .mj-search-box { width: 260px; }
}

.mj-search-input {
  width: 100%;
  height: 38px;
  background: #F1F5F9;
  border: 1px solid transparent;
  border-radius: 20px;
  padding: 0 14px 0 36px;
  font-size: 13px;
  outline: none;
  color: var(--text-main);
  transition: all 0.2s ease;
}
.mj-search-input:focus {
  background: #FFFFFF;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.mj-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}

.mj-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--border-light);
  background: #FFFFFF;
  color: var(--text-sub);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.mj-icon-btn:hover {
  background: #F8FAFC;
  color: var(--text-main);
}

/* ================= 2. Home Page Layout ================= */
.mj-home-view {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* Hero Banner */
.mj-hero {
  text-align: center;
  padding: 16px 12px 10px;
}

.mj-hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 12px;
}

.mj-hero-title {
  font-size: 32px;
  font-weight: 900;
  color: var(--text-main);
  letter-spacing: -0.8px;
  margin-bottom: 8px;
}

.mj-hero-sub {
  font-size: 15px;
  color: var(--text-sub);
}

/* Category Filter Chips */
.mj-category-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
}
.mj-category-bar::-webkit-scrollbar { display: none; }

.mj-chip {
  padding: 7px 16px;
  border-radius: 20px;
  background: #FFFFFF;
  border: 1px solid var(--border-light);
  color: var(--text-sub);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.mj-chip:hover {
  background: #F1F5F9;
  color: var(--text-main);
}
.mj-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

/* Games Grid - Mobile First: 2 cards per row on phones! */
.mj-games-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

@media (min-width: 640px) {
  .mj-games-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }
}

@media (min-width: 1024px) {
  .mj-games-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
  }
}

@media (min-width: 1280px) {
  .mj-games-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 24px;
  }
}

/* Game Card */
.mj-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.mj-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  border-color: #CBD5E1;
}

.mj-card-icon {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 38px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.05);
  margin-bottom: 2px;
  transition: transform 0.2s ease;
}

.mj-card:hover .mj-card-icon {
  transform: scale(1.08) rotate(-3deg);
}

.mj-card-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.mj-card-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mj-card-cat {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.mj-card-desc {
  font-size: 11px;
  color: var(--text-sub);
  line-height: 1.4;
  height: 32px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Card Button States */
.mj-card-btn {
  width: 100%;
  padding: 10px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  margin-top: 4px;
}

.mj-card-btn.play {
  background: var(--primary);
  color: #FFFFFF;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
}
.mj-card-btn.play:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.mj-card-btn.coming-soon {
  background: #F1F5F9;
  color: #94A3B8;
  cursor: default;
  pointer-events: none;
  border: 1px dashed #CBD5E1;
}

/* ================= 3. Game Stage & Container ================= */
.mj-game-view {
  display: none;
  flex-direction: column;
  width: 100%;
  min-height: calc(100vh - 67px);
  background: #F1F5F9;
}
.mj-game-view.active {
  display: flex;
}

.mj-game-nav {
  height: 52px;
  padding: 0 20px;
  background: #FFFFFF;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mj-back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #F1F5F9;
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 6px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}
.mj-back-btn:hover { background: #E2E8F0; }

.mj-game-nav-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-main);
}

.mj-game-stage {
  flex: 1;
  max-width: 460px;
  width: 100%;
  margin: 16px auto;
  background: #FFFFFF;
  border-radius: 28px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-light);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

@media (max-width: 500px) {
  .mj-game-stage {
    margin: 0;
    border-radius: 0;
    max-width: 100%;
    min-height: calc(100vh - 52px);
    border: none;
  }
}

/* ================= 4. G01: Tile Match Styles ================= */
.tm-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px;
  gap: 12px;
}

.tm-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tm-stat-pill {
  flex: 1;
  background: #F8FAFC;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tm-stat-label { font-size: 10px; font-weight: 700; color: var(--text-muted); }
.tm-stat-val { font-size: 15px; font-weight: 800; color: var(--text-main); }

.tm-board-container {
  position: relative;
  flex: 1;
  min-height: 380px;
  background: #F8FAFC;
  border-radius: 18px;
  border: 1px solid var(--border-light);
  overflow: hidden;
}

.tm-tile {
  position: absolute;
  width: 48px;
  height: 54px;
  background: #FFFFFF;
  border-radius: 12px;
  box-shadow: 0 4px 0 #CBD5E1, 0 4px 10px rgba(0, 0, 0, 0.08);
  border: 1px solid #E2E8F0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  user-select: none;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.tm-tile.is-active {
  cursor: pointer;
  filter: brightness(1);
}
.tm-tile.is-active:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #CBD5E1, 0 6px 14px rgba(0, 0, 0, 0.12);
}
.tm-tile.is-active:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #CBD5E1;
}

.tm-tile.is-blocked {
  filter: brightness(0.72) grayscale(0.2);
  cursor: not-allowed;
  pointer-events: none;
}

.tm-dock-wrapper {
  background: #EEF2FF;
  border: 2px dashed #C7D2FE;
  border-radius: 18px;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tm-dock-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--primary);
  text-align: center;
  letter-spacing: 0.5px;
}

.tm-dock {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  min-height: 54px;
}

.tm-dock-slot {
  aspect-ratio: 1 / 1.15;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 10px;
  border: 1px solid rgba(199, 210, 254, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tm-dock-tile {
  width: 100%;
  height: 100%;
  background: #FFFFFF;
  border-radius: 10px;
  border: 1px solid #CBD5E1;
  box-shadow: 0 2px 0 #CBD5E1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  animation: popIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popIn {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

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

.tm-tool-btn {
  flex: 1;
  padding: 10px;
  border-radius: 12px;
  background: #FFFFFF;
  border: 1px solid var(--border-light);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}
.tm-tool-btn:hover { background: #F8FAFC; transform: translateY(-1px); }
.tm-tool-btn:active { transform: translateY(1px); }
.tm-tool-btn.danger { color: #EF4444; }

.tm-tool-badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 8px;
}

/* ================= 5. G02: Hidden Treasures Styles ================= */
.ht-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px;
  gap: 12px;
}

.ht-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ht-playfield {
  position: relative;
  flex: 1;
  min-height: 380px;
  background: #FFF1F2;
  border-radius: 18px;
  border: 2px solid #FFE4E6;
  overflow: hidden;
}

.ht-item {
  position: absolute;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: #FFFFFF;
  border: 1px solid #FECDD3;
  box-shadow: 0 4px 12px rgba(244, 63, 94, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.ht-item:hover {
  transform: scale(1.18) !important;
  box-shadow: 0 8px 20px rgba(244, 63, 94, 0.25);
  z-index: 9999 !important;
}

.ht-item.is-highlighted {
  animation: pulseGold 0.8s infinite alternate ease-in-out;
  border: 3px solid #F59E0B;
}

@keyframes pulseGold {
  from { box-shadow: 0 0 10px #F59E0B; }
  to { box-shadow: 0 0 24px #F59E0B; transform: scale(1.15); }
}

/* ================= 6. G03: Word Defense Styles ================= */
.wd-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px;
  gap: 10px;
}

.wd-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.wd-battlefield-wrap {
  position: relative;
  height: 180px;
  background: #1E293B;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
}

canvas#wd-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.wd-castle-base {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(15, 23, 42, 0.85);
  padding: 4px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.wd-castle-label { font-size: 11px; font-weight: 800; color: #94A3B8; }
.wd-castle-bar {
  width: 140px;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}
.wd-castle-fill {
  width: 100%;
  height: 100%;
  background: #10B981;
  transition: width 0.2s ease;
}

.wd-grid-wrapper {
  background: #F8FAFC;
  border: 1px solid var(--border-light);
  border-radius: 18px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wd-grid-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  text-align: center;
}

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

.wd-cell {
  aspect-ratio: 1 / 1;
  background: #FFFFFF;
  border: 2px dashed #CBD5E1;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.wd-cell:hover { border-color: var(--primary); }
.wd-cell.is-selected {
  border-color: #F59E0B;
  background: #FEF3C7;
  transform: scale(0.95);
}

.wd-troop {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  animation: popIn 0.18s ease;
}
.wd-troop-name { font-size: 20px; font-weight: 900; }
.wd-troop-sub { font-size: 10px; font-weight: 800; opacity: 0.9; }

/* ================= 7. G04: Fruit Merge Styles ================= */
.fm-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 14px;
  gap: 10px;
}

.fm-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.fm-next-preview {
  flex: 0 0 76px;
  background: #F8FAFC;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#fm-next-canvas {
  width: 44px;
  height: 44px;
}

.fm-evo-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: #FEF3C7;
  border: 1px solid #FDE68A;
  border-radius: 10px;
  padding: 5px 8px;
  font-size: 13px;
  overflow-x: auto;
  white-space: nowrap;
}

.fm-canvas-box {
  position: relative;
  flex: 1;
  min-height: 420px;
  background: #FFFFFF;
  border-radius: 18px;
  border: 2px solid #E2E8F0;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
}

.fm-danger-bar {
  display: none;
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  background: rgba(239, 68, 68, 0.92);
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  padding: 5px 8px;
  border-radius: 8px;
  z-index: 10;
  animation: pulseRed 0.6s infinite alternate ease-in-out;
}

@keyframes pulseRed {
  from { opacity: 0.8; transform: scale(0.99); }
  to { opacity: 1; transform: scale(1.01); }
}

#fm-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ================= 8. Unified Modal Styles ================= */
.mj-modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.mj-modal-card {
  background: #FFFFFF;
  border-radius: 24px;
  padding: 28px 24px;
  width: 100%;
  max-width: 320px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: zoomIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.mj-modal-title { font-size: 22px; font-weight: 900; color: var(--text-main); margin-bottom: 8px; }
.mj-modal-desc { font-size: 14px; color: var(--text-sub); margin-bottom: 22px; line-height: 1.5; }
.mj-modal-btn {
  width: 100%;
  padding: 13px;
  border-radius: 14px;
  background: var(--primary);
  color: #FFFFFF;
  font-size: 15px;
  font-weight: 800;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
  transition: all 0.15s ease;
}
.mj-modal-btn:hover { background: var(--primary-hover); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes zoomIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Footer */
footer.mj-footer {
  border-top: 1px solid var(--border-light);
  padding: 20px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  background: #FFFFFF;
  margin-top: auto;
}
