:root {
  --bg-dark: #0F0B1E;
  --surface-dark: #1B1433;
  --surface-variant: #281E48;
  --primary: #9D4EDD;
  --primary-bright: #C77DFF;
  --accent-cyan: #00F5D4;
  --accent-gold: #FFD166;
  --accent-amber: #FFB703;
  --accent-pink: #FF007F;
  --accent-red: #FF2A6D;
  --text-primary: #FFFFFF;
  --text-secondary: #AAA5C4;
}

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

body {
  background-color: var(--bg-dark);
  color: var(--text-primary);
  font-family: 'Outfit', sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow-x: hidden;
}

#app-container {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  background: var(--bg-dark);
  position: relative;
  display: flex;
  flex-direction: column;
}

/* SCREEN MANAGEMENT */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  padding: 16px;
  animation: fadeIn 0.25s ease-out;
}

.screen.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* HERO CARD */
.hero-card {
  background: var(--surface-dark);
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: 24px;
  padding: 24px 20px;
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.hero-card::before {
  content: '';
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  width: 250px;
  height: 250px;
  background: radial-gradient(circle, rgba(157, 78, 221, 0.35) 0%, rgba(0, 245, 212, 0.1) 60%, transparent 100%);
  pointer-events: none;
}

.logo-badge {
  display: inline-flex;
  gap: 6px;
  margin-bottom: 10px;
  padding: 4px 8px;
  cursor: pointer;
}

.logo-badge .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.dot.pink { background: var(--accent-pink); }
.dot.yellow { background: var(--accent-amber); }
.dot.cyan { background: var(--accent-cyan); }
.dot.purple { background: var(--primary); }

.game-title {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 2px;
  margin-bottom: 6px;
  background: linear-gradient(135deg, #FFF 0%, #E0AAFF 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tagline {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 18px;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 14px;
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  width: 100%;
  height: 50px;
  background: var(--primary);
  color: #FFF;
  box-shadow: 0 4px 15px rgba(157, 78, 221, 0.4);
}

.btn-cyan {
  background: var(--accent-cyan);
  color: #000;
  font-weight: 800;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #FFF;
}

.pulse {
  animation: pulseAnim 2s infinite;
}

@keyframes pulseAnim {
  0% { box-shadow: 0 0 0 0 rgba(157, 78, 221, 0.6); }
  70% { box-shadow: 0 0 0 12px rgba(157, 78, 221, 0); }
  100% { box-shadow: 0 0 0 0 rgba(157, 78, 221, 0); }
}

/* NAVIGATION PILLS (Admin Icon REMOVED as requested!) */
.nav-pills {
  display: flex;
  gap: 10px;
  margin: 14px 0 18px 0;
}

.pill {
  flex: 1;
  height: 46px;
  border-radius: 12px;
  background: var(--surface-dark);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #FFF;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.pill-gold {
  border-color: rgba(255, 209, 102, 0.35);
  color: var(--accent-gold);
}

.pill-cyan {
  border-color: rgba(0, 245, 212, 0.35);
  color: var(--accent-cyan);
}

.pill-icon {
  flex: 0 0 46px;
  color: var(--text-secondary);
}

/* STAGE SELECT */
.stage-select-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.stage-select-header h2 {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 1.2px;
  color: var(--accent-cyan);
}

.stage-select-header span {
  font-size: 12px;
  color: var(--text-secondary);
}

.stages-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.stage-card {
  background: var(--surface-dark);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 18px;
  padding: 14px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.stage-card.locked {
  background: #140F24;
  border-color: rgba(255, 255, 255, 0.05);
  cursor: not-allowed;
  opacity: 0.6;
}

.stage-card:not(.locked):hover {
  transform: translateY(-2px);
  border-color: var(--accent-cyan);
}

.stage-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.stage-badge {
  background: var(--primary);
  font-size: 10px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 6px;
}

.stage-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-meta {
  font-size: 11px;
  color: var(--text-secondary);
}

/* GAME HUD */
.game-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #FFF;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.hud-center {
  text-align: center;
}

.stage-tag {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 1px;
  color: var(--accent-cyan);
}

.hud-stats {
  font-size: 12px;
  color: var(--text-secondary);
}

.hud-stats strong {
  color: #FFF;
}

/* 90-SECOND COUNTDOWN TIMER */
.timer-container {
  background: var(--surface-dark);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 8px 12px;
  margin-bottom: 12px;
}

.timer-bar-wrapper {
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}

.timer-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #00F5D4, #FFD166, #FF2A6D);
  transition: width 0.2s linear;
}

.timer-text-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
}

.timer-countdown {
  font-size: 14px;
  font-weight: 900;
  color: var(--accent-gold);
}

.timer-countdown.danger {
  color: var(--accent-red);
  animation: blink 0.5s infinite alternate;
}

@keyframes blink {
  from { opacity: 1; }
  to { opacity: 0.3; }
}

/* CANDY CRUSH MATCH-3 PLAY ARENA */
.play-arena {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 6px 0;
}

.board-container {
  position: relative;
  width: min(92vw, 420px);
  aspect-ratio: 1 / 1;
  background: #140F24;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

/* Secret Artwork behind the Grid with gentle background blur while playing */
.stage-secret-background {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1;
  filter: blur(6px);
  transform: scale(1.05); /* Avoid blur vignette border */
  transition: filter 0.3s;
}

#stage-art-canvas, #stage-art-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* GEM GRID (Candy Crush Style) */
.gem-grid {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 2;
  display: grid;
  padding: 8px;
  gap: 6px;
}

/* GEMS */
.gem-cell {
  position: relative;
  border-radius: 12px;
  background: rgba(20, 15, 36, 0.7);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.3s;
}

.gem-cell.revealed {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.gem-cell.selected {
  outline: 3px solid #FFF;
  box-shadow: 0 0 15px #FFF;
  transform: scale(1.08);
  z-index: 5;
}

.gem-item {
  width: 82%;
  height: 82%;
  border-radius: 50%;
  box-shadow: inset -2px -3px 6px rgba(0,0,0,0.4), inset 2px 3px 6px rgba(255,255,255,0.4), 0 3px 6px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.22s ease-out;
}

/* Lifted effect when dragged or sliding */
.gem-item.lifted {
  transform: translateY(-8px) scale(1.22);
  box-shadow: inset -2px -3px 6px rgba(0,0,0,0.4), inset 2px 3px 6px rgba(255,255,255,0.4), 0 16px 26px rgba(0,0,0,0.65), 0 0 16px rgba(0, 245, 212, 0.85);
  z-index: 10;
}

/* Swapping spin & pulse animation when released/switched with target */
.gem-item.swapping {
  transform: scale(1.18) rotate(360deg);
  box-shadow: inset -2px -3px 6px rgba(0,0,0,0.4), inset 2px 3px 6px rgba(255,255,255,0.4), 0 10px 20px rgba(0, 245, 212, 0.7);
  z-index: 8;
}

/* Switch landing impact bounce */
.gem-item.switched {
  animation: gemSwitchBounce 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes gemSwitchBounce {
  0% { transform: scale(1.2) translateY(-4px); }
  50% { transform: scale(0.9) translateY(2px); }
  100% { transform: scale(1.0) translateY(0); }
}

/* Sparkle icon inside gem */
.gem-item::after {
  content: '';
  width: 30%;
  height: 30%;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  transform: translate(-30%, -30%);
}

/* EXPLOSION FX CANVAS */
.fx-canvas {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 4;
  pointer-events: none;
}

/* PROGRESS & COMBO BAR */
.game-footer {
  margin-top: 10px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.progress-bar-bg {
  height: 10px;
  background: var(--surface-dark);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #9D4EDD, #00F5D4);
  transition: width 0.3s ease-out;
}

.combo-badge {
  text-align: center;
  margin-top: 6px;
  animation: bounce 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.combo-badge span {
  background: var(--accent-gold);
  color: #000;
  font-size: 12px;
  font-weight: 900;
  padding: 3px 12px;
  border-radius: 10px;
  display: inline-block;
}

@keyframes bounce {
  0% { transform: scale(0.6); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* LEADERBOARD & GALLERY */
.screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.screen-header h2 {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 1px;
}

.screen-header .sub {
  font-size: 11px;
  color: var(--text-secondary);
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.leaderboard-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-dark);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 12px 14px;
}

.leaderboard-rank {
  font-size: 16px;
  font-weight: 900;
  width: 32px;
}

.leaderboard-user {
  flex: 1;
}

.leaderboard-name {
  font-weight: 700;
  font-size: 14px;
}

.leaderboard-meta {
  font-size: 11px;
  color: var(--text-secondary);
}

.leaderboard-score {
  font-size: 15px;
  font-weight: 900;
  color: var(--accent-gold);
}

/* ART GALLERY (Pictures STRICTLY hidden if stage is not finished!) */
.info-card {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--surface-dark);
  border: 1px solid rgba(0, 245, 212, 0.3);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 14px;
  font-size: 11px;
  color: var(--text-secondary);
}

.info-card strong {
  color: #FFF;
  display: block;
  font-size: 12px;
  margin-bottom: 2px;
}

.info-card code {
  color: var(--accent-cyan);
}

.gallery-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.gallery-card {
  background: var(--surface-dark);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 14px;
}

.gallery-card.unlocked {
  border-color: rgba(0, 245, 212, 0.3);
}

.gallery-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.gallery-image-frame {
  width: 100%;
  height: 180px;
  border-radius: 14px;
  overflow: hidden;
  background: #140F24;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.gallery-image-frame img, .gallery-image-frame canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.locked-overlay {
  text-align: center;
  padding: 16px;
  color: var(--text-secondary);
}

.locked-overlay svg {
  margin-bottom: 8px;
  opacity: 0.5;
}

.gallery-lore {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 10px 0 12px 0;
  line-height: 1.4;
}

/* MODALS */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.hidden {
  display: none;
}

.modal-card {
  background: var(--surface-dark);
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  border-radius: 24px;
  padding: 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  animation: scaleUp 0.2s ease-out;
}

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

.win-card {
  border-color: var(--accent-cyan);
}

.lose-card {
  border-color: var(--accent-red);
}

.win-crown {
  font-size: 24px;
  color: var(--accent-gold);
  letter-spacing: 4px;
  margin-bottom: 8px;
}

.lose-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.win-score-box {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 12px;
  margin: 14px 0;
  display: flex;
  justify-content: space-around;
  font-size: 13px;
}

.rules-list {
  text-align: left;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 14px 0;
  padding-left: 18px;
}

.rules-list strong {
  color: #FFF;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hidden {
  display: none !important;
}

/* FULLSCREEN ARTWORK POPUP MODAL & ZOOM 2X */
.image-viewer-container {
  position: relative;
  width: min(96vw, 640px);
  max-height: 92vh;
  background: var(--surface-dark);
  border: 1.5px solid var(--accent-cyan);
  border-radius: 24px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.9);
  animation: scaleUp 0.2s ease-out;
}

.btn-viewer-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid var(--accent-cyan);
  color: #FFF;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background 0.2s;
}

.btn-viewer-close:hover {
  background: var(--accent-pink);
}

.viewer-zoom-tip {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-cyan);
  margin-bottom: 12px;
  background: rgba(0, 245, 212, 0.1);
  padding: 4px 14px;
  border-radius: 12px;
}

.viewer-img-wrapper {
  width: 100%;
  max-height: 68vh;
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-in;
  position: relative;
  touch-action: none;
}

.viewer-img-wrapper.zoomed {
  cursor: grab;
}

.viewer-img-wrapper.zoomed:active {
  cursor: grabbing;
}

.viewer-img, .viewer-canvas {
  max-width: 100%;
  max-height: 65vh;
  object-fit: contain; /* Full complete picture shown without cropping */
  border-radius: 14px;
  display: inline-block;
  vertical-align: middle;
  transition: transform 0.15s ease-out;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
}

.viewer-img-wrapper.zoomed .viewer-img,
.viewer-img-wrapper.zoomed .viewer-canvas {
  max-width: 100%;
  max-height: 65vh;
}

.viewer-caption {
  margin-top: 12px;
  font-size: 14px;
  font-weight: 800;
  color: #FFF;
  text-align: center;
}
