html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: #E6CCB2;
  background-color: #6B4423;
  font-family: 'Georgia', 'Times New Roman', serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* DYNAMIC THEMATIC BACKGROUND LAYER (plan: Change Scope #3)
   Sits above the Phaser canvas, below the HUD. Carries the phase/site
   background-image set from App.tsx (getSiteBackgroundImage); the canvas
   landscape shows through where the layer's gradients/patterns are
   translucent. Cross-fades smoothly on phase/site changes. */
#app-background {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 5;
  pointer-events: none;
  background-color: #6B4423;
  background-repeat: repeat, no-repeat;
  background-size: auto, cover;
  background-position: center, center;
  transition: background-image 0.8s ease-in-out, opacity 0.6s ease-in-out;
}

#game-container {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
}

#game-container canvas { touch-action: none; }

#hud {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#hud button, #hud a, #hud input,
#hud [role="button"], #hud .interactive {
  pointer-events: auto;
}

/* SCREENS */
.screen {
  pointer-events: auto;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
  overflow-y: auto;
}

/* START SCREEN — translucent so the gebeya.webp panorama layer shows through */
.start-screen {
  background: linear-gradient(180deg, rgba(107,68,35,0.45) 0%, rgba(60,36,18,0.60) 100%);
}
.start-content { text-align: center; max-width: 600px; }
.game-title {
  font-size: clamp(1.8rem, 5vw, 3rem);
  color: #F59E0B;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  margin-bottom: 8px;
  border-bottom: 3px solid #D4A373;
  padding-bottom: 12px;
}
.game-subtitle {
  font-size: clamp(0.9rem, 2vw, 1.2rem);
  color: #E6CCB2;
  margin-bottom: 24px;
}
.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.diff-card {
  background: linear-gradient(135deg, #7F5539, #6B4423);
  border: 2px solid #D4A373;
  border-radius: 8px;
  padding: 14px 10px;
  cursor: pointer;
  transition: all 0.2s;
  color: #E6CCB2;
  font-family: inherit;
}
.diff-card:hover {
  border-color: #F59E0B;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(245,158,11,0.3);
}
.diff-name { display: block; font-size: 1.2rem; font-weight: bold; color: #F59E0B; }
.diff-desc { display: block; font-size: 0.75rem; margin-top: 4px; opacity: 0.8; }
.start-actions { display: flex; gap: 12px; justify-content: center; align-items: center; }

/* BUTTONS */
.btn-primary {
  background: linear-gradient(135deg, #F59E0B, #D97706);
  color: #6B4423;
  border: none;
  border-radius: 8px;
  padding: 14px 28px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  min-height: 56px;
}
.btn-primary:hover { transform: scale(1.05); box-shadow: 0 4px 16px rgba(245,158,11,0.4); }
.btn-secondary {
  background: transparent;
  color: #D4A373;
  border: 2px solid #D4A373;
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  min-height: 48px;
}
.btn-secondary:hover { border-color: #F59E0B; color: #F59E0B; }
.btn-sound {
  background: rgba(212,163,115,0.2);
  border: 2px solid #B08968;
  border-radius: 50%;
  width: 48px; height: 48px;
  font-size: 1.3rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-sound:hover { border-color: #F59E0B; }

/* MODAL */
.modal-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: auto;
}
.modal-content {
  background: linear-gradient(135deg, #7F5539, #6B4423);
  border: 3px solid #D4A373;
  border-radius: 12px;
  padding: 28px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-content h2 { color: #F59E0B; margin-top: 0; }
.modal-content ul { padding-left: 20px; line-height: 1.8; }
.modal-content li { margin-bottom: 8px; }

/* MAP SCREEN — translucent so the continental backdrop layer shows through */
.map-screen {
  background: linear-gradient(180deg, rgba(107,68,35,0.55) 0%, rgba(127,85,57,0.65) 100%);
  justify-content: flex-start;
  padding-top: 12px;
}
.map-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 800px;
  margin-bottom: 12px;
}
.map-header h2 { margin: 0; color: #F59E0B; font-size: 1.3rem; }
.progress-text { color: #D4A373; font-size: 0.9rem; }
.map-scroll {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  overflow-y: auto;
  max-height: 55vh;
  width: 100%;
  max-width: 800px;
  padding: 8px;
}
.map-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 70px;
  max-width: 90px;
  border: 2px solid transparent;
}
.map-node.completed { background: rgba(245,158,11,0.2); border-color: #F59E0B; }
.map-node.active { background: rgba(245,158,11,0.3); border-color: #F59E0B; animation: pulse 1.5s infinite; }
.map-node.locked { opacity: 0.4; cursor: default; }
.node-dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #B08968;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: bold;
  margin-bottom: 4px;
}
.map-node.completed .node-dot { background: #F59E0B; color: #6B4423; }
.map-node.active .node-dot { background: #10B981; color: white; }
.node-name { font-size: 0.6rem; text-align: center; line-height: 1.2; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245,158,11,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(245,158,11,0); }
}
.map-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 800px;
  margin-top: 12px;
  padding: 12px;
  background: rgba(107,68,35,0.8);
  border-radius: 8px;
  border: 1px solid #B08968;
}
.current-site-info { display: flex; flex-direction: column; gap: 2px; }
.current-site-info strong { color: #F59E0B; }
.current-site-info span { font-size: 0.8rem; opacity: 0.8; }

/* LECTURE SCREEN — translucent so the site-specific landscape layer shows through */
.lecture-screen {
  background: linear-gradient(180deg, rgba(107,68,35,0.50) 0%, rgba(127,85,57,0.62) 100%);
}
.lecture-content {
  max-width: 600px;
  width: 100%;
  overflow-y: auto;
  max-height: 90vh;
  padding: 16px;
}
.scholar-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}
.scholar-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #F59E0B, #D97706);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: bold;
  color: #6B4423;
  flex-shrink: 0;
}
.scholar-header h2 { margin: 0; color: #F59E0B; font-size: 1.1rem; }
.scholar-title { margin: 0; font-size: 0.8rem; opacity: 0.7; }
.site-name { color: #D4A373; font-size: 1.3rem; margin-bottom: 4px; }
.site-meta { font-size: 0.8rem; opacity: 0.7; margin-bottom: 16px; color: #B08968; }
.lore-text {
  background: rgba(212,163,115,0.1);
  border-left: 4px solid #F59E0B;
  padding: 16px;
  border-radius: 0 8px 8px 0;
  line-height: 1.7;
  margin-bottom: 20px;
  font-size: 0.95rem;
}
.challenge-btn { margin-bottom: 12px; width: 100%; }

/* CHALLENGE SCREEN — subtle dark overlay for puzzle clarity over the site backdrop */
.challenge-screen {
  background: linear-gradient(180deg, rgba(40,24,12,0.62) 0%, rgba(60,36,18,0.72) 100%);
  justify-content: flex-start;
  padding-top: 8px;
}
.challenge-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 700px;
  padding: 8px 16px;
  background: rgba(0,0,0,0.3);
  border-radius: 8px;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}
.hud-left, .hud-right { display: flex; gap: 12px; align-items: center; }
.hud-site { color: #F59E0B; font-weight: bold; }
.hud-score { color: #D4A373; }
.hud-streak { color: #10B981; font-weight: bold; }
.hud-lives { font-size: 0.9rem; }
.hud-timer { flex: 1; min-width: 120px; text-align: center; }
.timer-bar {
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 4px;
}
.timer-fill {
  height: 100%;
  background: linear-gradient(90deg, #F59E0B, #10B981);
  border-radius: 4px;
  transition: width 1s linear;
}
.timer-text { font-size: 1.1rem; font-weight: bold; color: #E6CCB2; }
.timer-text.urgent { color: #EF4444; animation: blink 0.5s infinite; }
@keyframes blink { 50% { opacity: 0.5; } }

.feedback-banner {
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: bold;
  margin-bottom: 12px;
  animation: slideIn 0.3s ease;
}
.feedback-banner.correct { background: rgba(16,185,129,0.3); border: 2px solid #10B981; color: #10B981; }
.feedback-banner.wrong { background: rgba(239,68,68,0.3); border: 2px solid #EF4444; color: #EF4444; }
@keyframes slideIn { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.challenge-container {
  max-width: 600px;
  width: 100%;
  background: rgba(212,163,115,0.08);
  border: 2px solid #B08968;
  border-radius: 12px;
  padding: 20px;
}
.challenge-title { color: #D4A373; font-size: 1rem; margin-bottom: 12px; text-align: center; }
.challenge-body { text-align: center; }
.challenge-q { font-size: 1rem; margin-bottom: 16px; color: #E6CCB2; }
.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt-btn {
  background: linear-gradient(135deg, #7F5539, #6B4423);
  border: 2px solid #D4A373;
  border-radius: 8px;
  padding: 14px 12px;
  color: #E6CCB2;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
  font-family: inherit;
  min-height: 48px;
}
.opt-btn:hover { border-color: #F59E0B; background: rgba(245,158,11,0.15); }

/* CHRONOLOGICAL */
.chrono-items { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.chrono-btn {
  background: #7F5539;
  border: 2px solid #B08968;
  border-radius: 6px;
  padding: 10px;
  color: #E6CCB2;
  cursor: pointer;
  font-family: inherit;
  min-height: 44px;
}
.chrono-btn.used { opacity: 0.3; cursor: default; }
.order-display { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.order-chip { background: #F59E0B; color: #6B4423; padding: 4px 10px; border-radius: 12px; font-size: 0.8rem; font-weight: bold; }

/* MATCHING */
.match-grid { display: flex; gap: 20px; justify-content: center; }
.match-col { display: flex; flex-direction: column; gap: 8px; }
.match-btn {
  background: #7F5539;
  border: 2px solid #B08968;
  border-radius: 6px;
  padding: 10px 16px;
  color: #E6CCB2;
  cursor: pointer;
  font-family: inherit;
  min-width: 100px;
  min-height: 44px;
}
.match-btn.selected { border-color: #F59E0B; background: rgba(245,158,11,0.2); }
.match-btn.matched { border-color: #10B981; opacity: 0.5; }

/* PATTERN MEMORY */
.simon-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 280px; margin: 0 auto; }
.simon-btn {
  width: 100%; aspect-ratio: 1;
  border-radius: 12px;
  border: 3px solid #B08968;
  font-size: 2rem;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 56px;
}
.simon-0 { background: #D4A373; }
.simon-1 { background: #7F5539; }
.simon-2 { background: #10B981; }
.simon-3 { background: #2563EB; }
.simon-btn.active { transform: scale(1.1); box-shadow: 0 0 20px rgba(245,158,11,0.6); border-color: #F59E0B; }

/* STEP / PATTERN PROGRESS DOTS */
.step-dots { display: flex; gap: 6px; justify-content: center; align-items: center; }
.step-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: rgba(212,163,115,0.3); border: 1px solid #B08968; }
.step-dot.done { background: #F59E0B; border-color: #F59E0B; }
.step-dot.current { background: #E6CCB2; border-color: #F59E0B; }
.pattern-progress { margin-top: 12px; }

/* ENERGY FLOW */
.flow-grid { display: flex; gap: 4px; justify-content: center; margin-bottom: 12px; }
.flow-tile {
  width: 60px; height: 60px;
  background: #7F5539;
  border: 2px solid #D4A373;
  border-radius: 6px;
  font-size: 1.5rem;
  color: #2563EB;
  cursor: pointer;
  transition: transform 0.2s;
}

/* WEIGHT BALANCE */
.balance-display { margin-bottom: 16px; }
.pan { font-size: 2rem; }
.placed-weights { display: flex; gap: 6px; justify-content: center; margin: 8px 0; }
.weight-chip { background: #F59E0B; color: #6B4423; padding: 4px 10px; border-radius: 12px; font-weight: bold; font-size: 0.9rem; }
.total { font-size: 1.1rem; color: #D4A373; }
.weight-buttons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.wt-btn {
  background: #7F5539;
  border: 2px solid #B08968;
  border-radius: 6px;
  padding: 10px 18px;
  color: #E6CCB2;
  font-weight: bold;
  font-family: inherit;
  min-height: 44px;
}
.wt-btn:hover { border-color: #F59E0B; }
.wt-btn.reset { background: rgba(239,68,68,0.2); border-color: #EF4444; }

/* ANOMALY */
.anomaly-grid { display: flex; gap: 12px; justify-content: center; }
.anom-btn {
  width: 70px; height: 70px;
  background: #7F5539;
  border: 2px solid #D4A373;
  border-radius: 10px;
  font-size: 2rem;
  cursor: pointer;
  color: #E6CCB2;
  transition: all 0.2s;
}
.anom-btn:hover { border-color: #F59E0B; transform: scale(1.1); }

/* CIPHER */
.cipher-key { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-bottom: 12px; }
.cipher-pair { background: rgba(212,163,115,0.2); padding: 4px 10px; border-radius: 4px; font-size: 0.9rem; }
.encoded { font-size: 1.8rem; letter-spacing: 8px; color: #F59E0B; margin-bottom: 12px; }
.cipher-input {
  background: rgba(0,0,0,0.3);
  border: 2px solid #B08968;
  border-radius: 6px;
  padding: 10px 16px;
  color: #E6CCB2;
  font-size: 1.2rem;
  text-align: center;
  width: 200px;
  margin-bottom: 12px;
  font-family: inherit;
}
.confirm-btn { width: 150px; }

/* COWRIE */
.cowrie-display { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; font-size: 1.5rem; }
.cowrie-choices { display: flex; gap: 12px; justify-content: center; }

/* GRID SLIDE */
.slide-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; max-width: 240px; margin: 0 auto; }
.slide-btn {
  aspect-ratio: 1;
  background: #7F5539;
  border: 2px solid #B08968;
  border-radius: 6px;
  font-size: 1.5rem;
  font-weight: bold;
  color: #E6CCB2;
  cursor: pointer;
  min-height: 56px;
}
.slide-btn.empty { background: transparent; border-color: transparent; cursor: default; }
.moves { margin-top: 8px; color: #B08968; }

/* CATEGORY SORT */
.cat-items { display: flex; flex-direction: column; gap: 10px; }
.cat-row { display: flex; align-items: center; gap: 12px; }
.cat-label { min-width: 80px; text-align: right; font-weight: bold; color: #D4A373; }
.cat-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.cat-btn {
  background: #7F5539;
  border: 2px solid #B08968;
  border-radius: 6px;
  padding: 8px 12px;
  color: #E6CCB2;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  min-height: 40px;
}
.cat-btn.active { border-color: #F59E0B; background: rgba(245,158,11,0.2); }

/* END SCREENS */
.end-screen { text-align: center; }
/* Desert-sunset trial-failed theme — translucent over the background layer */
.loss-screen { background: linear-gradient(180deg, rgba(50,30,15,0.70) 0%, rgba(120,40,20,0.60) 100%); }
/* Golden coronation theme — translucent over the gebeya.webp panorama */
.win-screen { background: linear-gradient(180deg, rgba(107,68,35,0.55) 0%, rgba(245,158,11,0.20) 100%); }
.end-screen h1 { color: #F59E0B; font-size: clamp(1.5rem, 4vw, 2.5rem); margin-bottom: 8px; }
.end-rank { color: #D4A373; font-size: 1.1rem; margin-bottom: 20px; }
.win-subtitle { color: #10B981; font-size: 1rem; margin-bottom: 20px; }
.end-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat {
  background: rgba(212,163,115,0.1);
  border: 1px solid #B08968;
  border-radius: 8px;
  padding: 12px;
}
.stat span { display: block; font-size: 0.8rem; opacity: 0.7; margin-bottom: 4px; }
.stat strong { display: block; font-size: 1.2rem; color: #F59E0B; }
.win-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* RESPONSIVE */
@media (max-width: 600px) {
  .options-grid { grid-template-columns: 1fr; }
  .match-grid { flex-direction: column; }
  .map-scroll { max-height: 40vh; }
  .map-footer { flex-direction: column; gap: 12px; }
  .challenge-hud { font-size: 0.8rem; }
}
