/* Base Reset and Styling System */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

:root {
  --bg-color: #0b0c10;
  --panel-bg: rgba(26, 28, 36, 0.65);
  --panel-border: rgba(255, 255, 255, 0.08);
  --primary-color: #7b2cbf;
  --primary-hover: #9d4edd;
  --secondary-color: #240046;
  --secondary-hover: #3c096c;
  --text-color: #f7f7f9;
  --text-muted: #94a3b8;
  --accent-color: #e0aaff;
  --success-color: #10b981;
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  overflow: hidden;
  height: 100vh;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Background Blur Orbs */
.decor-ring {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  z-index: -1;
  opacity: 0.35;
}
.ring-1 {
  width: 50vw;
  height: 50vw;
  background: radial-gradient(circle, var(--primary-color) 0%, transparent 70%);
  top: -10%;
  left: -10%;
}
.ring-2 {
  width: 45vw;
  height: 45vw;
  background: radial-gradient(circle, #3c096c 0%, transparent 70%);
  bottom: -10%;
  right: -10%;
}

/* App Layout Container */
#app-container {
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

/* Glassmorphism Panel Template */
.glass-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
}

/* Splash Screen UI */
#splash-screen {
  width: 90%;
  max-width: 680px;
  padding: 40px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-color: rgba(123, 44, 191, 0.2);
  z-index: 10;
  animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.brand-icon {
  font-size: 2.5rem;
}
.brand h1 {
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 2.8rem;
  background: linear-gradient(135deg, #f7f7f9 30%, var(--accent-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.subtitle {
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1.5;
  margin-top: -8px;
}

/* Drop Zone UI */
#drop-zone {
  border: 2px dashed rgba(123, 44, 191, 0.4);
  border-radius: 16px;
  padding: 36px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: rgba(123, 44, 191, 0.04);
  transition: all 0.3s ease;
  cursor: pointer;
}
#drop-zone.dragover {
  border-color: var(--accent-color);
  background: rgba(123, 44, 191, 0.12);
  transform: scale(1.02);
}
.upload-icon {
  width: 48px;
  height: 48px;
  color: var(--accent-color);
  opacity: 0.85;
}
#drop-zone p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Buttons */
.btn {
  font-family: 'Outfit', sans-serif;
  font-weight: 500;
  border: none;
  border-radius: 10px;
  padding: 10px 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.95rem;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary-color) 0%, #5a189a 100%);
  color: white;
  box-shadow: 0 4px 14px rgba(123, 44, 191, 0.4);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(123, 44, 191, 0.6);
  background: linear-gradient(135deg, var(--primary-hover) 0%, var(--primary-color) 100%);
}
.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  color: var(--text-color);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(1px);
}

/* Sample Images Section */
.samples-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}
.samples-section h3 {
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 500;
}
.samples-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.sample-card {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 16/10;
  cursor: pointer;
  border: 1px solid var(--panel-border);
  transition: all 0.25s ease;
}
.sample-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}
.sample-card span {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
  padding: 8px 12px;
  font-size: 0.8rem;
  color: white;
  font-weight: 500;
  text-align: center;
  opacity: 0.9;
}
.sample-card:hover {
  transform: translateY(-4px) scale(1.03);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
  border-color: rgba(123, 44, 191, 0.5);
}
.sample-card:hover img {
  transform: scale(1.08);
}

/* Difficulty Configurations */
.config-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 12px;
  border-top: 1px solid var(--panel-border);
}
.config-section label {
  font-family: 'Outfit', sans-serif;
  font-weight: 500;
  font-size: 1rem;
}
.difficulty-toggles {
  display: flex;
  gap: 8px;
}
.diff-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-border);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 70px;
  transition: all 0.2s ease;
}
.diff-btn .label {
  font-size: 0.65rem;
  font-weight: 400;
  opacity: 0.7;
}
.diff-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-color);
}
.diff-btn.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--accent-color);
  box-shadow: 0 4px 10px rgba(123, 44, 191, 0.3);
}

/* Game Interface Layout */
#game-interface {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.glass-header {
  height: 70px;
  min-height: 70px;
  background: rgba(15, 16, 22, 0.8);
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  z-index: 100;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-puzzle {
  font-size: 1.6rem;
}
.header-logo h2 {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 1.4rem;
  background: linear-gradient(135deg, white 40%, var(--accent-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.controls-group {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Game Main Area */
#game-main {
  flex-grow: 1;
  position: relative;
  overflow: hidden;
  background-color: #0e1017;
  background-image: 
    radial-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 0),
    radial-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 0);
  background-size: 32px 32px;
  background-position: 0 0, 16px 16px;
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Modal and Overlays */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

.modal-content {
  width: 90%;
  max-width: 520px;
  padding: 32px;
  text-align: center;
  border-color: rgba(123, 44, 191, 0.2);
}

.animate-pop {
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Victory Overlay details */
.victory-icon {
  font-size: 4.5rem;
  margin-bottom: 12px;
  animation: bounce 2s infinite alternate;
}
.modal-content h2 {
  font-family: 'Outfit', sans-serif;
  font-size: 2.2rem;
  margin-bottom: 12px;
}
#victory-stats {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin-bottom: 24px;
}
.modal-buttons {
  display: flex;
  gap: 16px;
  justify-content: center;
}

/* Help Modal Grid */
.help-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
  margin-top: 20px;
}
.help-item {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.help-item:last-child {
  border-bottom: none;
}
.help-key {
  font-family: 'Outfit', sans-serif;
  background: rgba(123, 44, 191, 0.15);
  border: 1px solid rgba(123, 44, 191, 0.3);
  color: var(--accent-color);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  min-width: 90px;
  text-align: center;
}
.help-desc {
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

/* Loading Spinner */
.spinner-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(123, 44, 191, 0.2);
  border-top: 4px solid var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.spinner-container p {
  font-family: 'Outfit', sans-serif;
  font-size: 1.1rem;
  font-weight: 500;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes popIn {
  from { transform: scale(0.9) translateY(20px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
@keyframes bounce {
  0% { transform: translateY(0); }
  100% { transform: translateY(-10px); }
}

/* Custom styles for active buttons */
button.btn-secondary.active {
  background: rgba(123, 44, 191, 0.15);
  border-color: rgba(123, 44, 191, 0.4);
  color: var(--accent-color);
}

/* Light Theme Variables */
body.light-theme {
  --bg-color: #f3f4f6;
  --panel-bg: rgba(255, 255, 255, 0.75);
  --panel-border: rgba(0, 0, 0, 0.08);
  --text-color: #1f2937;
  --text-muted: #4b5563;
  --accent-color: #6d28d9;
  --primary-color: #7c3aed;
  --primary-hover: #8b5cf6;
  --secondary-color: #ede9fe;
  --secondary-hover: #ddd6fe;
}
body.light-theme .decor-ring {
  opacity: 0.12;
}

/* Cyberpunk Theme Variables */
body.cyber-theme {
  --bg-color: #0b071a;
  --panel-bg: rgba(18, 12, 38, 0.75);
  --panel-border: rgba(0, 240, 255, 0.15);
  --text-color: #00f0ff;
  --text-muted: #bd93f9;
  --accent-color: #ff007f;
  --primary-color: #bc13fe;
  --primary-hover: #d530ff;
  --secondary-color: #120a2a;
  --secondary-hover: #1e1045;
}
body.cyber-theme .decor-ring {
  background: radial-gradient(circle, #ff007f 0%, transparent 70%);
  opacity: 0.25;
}

/* Responsive adjustments for narrow/short viewports (e.g. website iframes or mobile) */
@media (max-width: 640px) or (max-height: 500px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
  }
  
  #app-container {
    height: auto;
    min-height: 100vh;
    padding: 12px;
    align-items: flex-start;
  }
  
  #splash-screen {
    width: 100%;
    padding: 20px 16px;
    gap: 16px;
    margin-top: 12px;
    margin-bottom: 12px;
  }
  
  .brand h1 {
    font-size: 1.8rem;
  }
  
  .brand-icon {
    font-size: 1.8rem;
  }
  
  .subtitle {
    font-size: 0.9rem;
    margin-top: -4px;
  }
  
  #drop-zone {
    padding: 24px 12px;
    gap: 10px;
  }
  
  #drop-zone p {
    font-size: 0.85rem;
  }
  
  .upload-icon {
    width: 36px;
    height: 36px;
  }
  
  .samples-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  
  .sample-card span {
    font-size: 0.7rem;
    padding: 4px 6px;
  }
  
  .config-section {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
    padding-top: 16px;
  }
  
  .config-section label {
    font-size: 0.9rem;
  }
  
  .difficulty-toggles {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
  }
  
  .diff-btn {
    min-width: 0;
    padding: 6px 4px;
    font-size: 0.85rem;
  }
  
  .diff-btn .label {
    font-size: 0.6rem;
  }
  
  .glass-header h2 {
    font-size: 1.1rem;
  }
  
  .glass-header {
    height: 60px;
    min-height: 60px;
    padding: 0 16px;
  }
  
  .glass-header .btn {
    font-size: 0.85rem;
    padding: 8px 12px;
  }
}

@media (max-width: 520px) {
  .glass-header {
    padding: 0 8px;
  }
  .controls-group {
    gap: 4px;
  }
  .controls-group .btn {
    padding: 8px;
  }
  .controls-group .btn-secondary {
    font-size: 0 !important; /* Hide text */
  }
  .controls-group .btn-secondary .icon {
    font-size: 1.1rem !important; /* Show icon */
    margin: 0 !important;
  }
}
