/* Base Styles */
:root {
  /* Apple-inspired colors */
  --apple-red: #fa233b;
  --apple-blue: #007aff;
  --apple-green: #34c759;
  --apple-orange: #ff9500;
  --apple-gray: #f2f2f7;
  --apple-dark-gray: #1c1c1e;
  --apple-light-gray: #8e8e93;
  --apple-separator: #d1d1d6;
  
  /* Theme variables */
  --background: #ffffff;
  --text-primary: #000000;
  --text-secondary: #8e8e93;
  --card-background: #ffffff;
  --button-background: var(--apple-gray);
  --blur-background: rgba(255, 255, 255, 0.8);
  --shadow-light: rgba(0, 0, 0, 0.1);
  --border-radius: 10px;
  --spacing: 16px;
  
  /* Status colors */
  --error: #ff3b30;
  --success: #34c759;
  --warning: #ff9500;
  --info: #007aff;
  
  /* Transitions */
  --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --background: #000000;
    --text-primary: #ffffff;
    --text-secondary: #8e8e93;
    --card-background: #1c1c1e;
    --button-background: #2c2c2e;
    --apple-separator: #38383a;
    --blur-background: rgba(0, 0, 0, 0.8);
    --shadow-light: rgba(255, 255, 255, 0.1);
  }
}

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

html {
  font-size: 16px;
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', sans-serif;
  background: var(--background);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-bottom: 80px; /* Space for bottom nav */
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: 0.5em;
}

h1 {
  font-size: 2.125rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  background: linear-gradient(135deg, var(--apple-red), #ff6b6b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 {
  font-size: 1.375rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

p {
  margin-bottom: 1em;
}

a {
  color: var(--apple-blue);
  text-decoration: none;
  transition: var(--transition);
}

a:hover {
  text-decoration: underline;
}

/* Layout */
.header {
  background: var(--blur-background);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 0.5px solid var(--apple-separator);
  box-shadow: 0 1px 0 var(--shadow-light);
}

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

.content {
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  padding: 1.5rem;
}

/* Search */
.search-container {
  margin: 1.5rem 0 2rem;
  gap: 8px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

#searchInput {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--apple-separator);
  border-radius: 8px;
  font-size: 16px;
  background: var(--card-background);
  color: var(--text-primary);
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  -webkit-appearance: none;
  appearance: none;
}

#searchInput:focus {
  outline: none;
  border-color: var(--apple-blue);
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.2);
  background: var(--card-background);
}

.filter-chips {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.filter-chips::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  padding: 6px 12px;
  border-radius: 15px;
  background: var(--card-background);
  border: 1px solid var(--apple-separator);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.filter-chip:hover {
  background: var(--button-background);
}

.filter-chip.active {
  background: var(--apple-blue);
  border-color: var(--apple-blue);
  color: white;
}

#search-button {
  padding: 0 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: background 0.2s;
}

#search-button:hover {
  background: var(--primary-dark);
}

/* Results */
#searchResults {
  min-height: 300px;
  position: relative;
  background: transparent;
  border: none;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 20px;
  padding: 16px;
  margin: 0;
  list-style: none;
  cursor: pointer;
}

.result-item {
  background: var(--card-background);
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.2s ease;
  cursor: pointer;
  border: 1px solid var(--apple-separator);
  position: relative;
  padding: 0;
  margin: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.result-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border-color: var(--apple-blue);
}

.result-artwork {
  width: 100%;
  aspect-ratio: 1;
  position: relative;
  background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
  overflow: hidden;
  cursor: pointer;
}

.result-artwork img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.result-item:hover .result-artwork img {
  transform: scale(1.05);
}

.result-info {
  padding: 12px;
  background: transparent;
  cursor: pointer;
}

.result-title {
  font-weight: 600;
  font-size: 14px;
  margin: 0 0 4px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.result-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  cursor: pointer;
}

/* Downloads */
.downloads-list {
  padding: var(--spacing);
  cursor: pointer;
}

.download-item {
  background: var(--surface);
  border-radius: var(--border-radius);
  padding: var(--spacing);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.download-icon {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}

.download-details {
  flex: 1;
  min-width: 0;
}

.download-name {
  font-weight: 500;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-container {
  margin-top: 8px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.3s;
}

.progress-text {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Search Results */
#searchResults {
    padding: 1rem;
}

.result-card {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out;
}

.result-card:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.result-art {
    width: 50px;
    height: 50px;
    border-radius: 4px;
    margin-right: 1rem;
    object-fit: cover;
}

.result-art-placeholder {
    width: 50px;
    height: 50px;
    border-radius: 4px;
    margin-right: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #333;
}

.result-info {
    display: flex;
    flex-direction: column;
}

.result-title {
    font-weight: 500;
    font-size: 1rem;
}

.result-subtitle {
    font-size: 0.85rem;
    color: #aaa;
    margin-top: 2px;
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-danger {
  background: var(--error);
  color: white;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface);
  color: white;
  padding: 12px 24px;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* Connection Status */
.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #666;
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 10px var(--success);
}

/* Loading */
.loading-indicator {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
  color: var(--text-secondary);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  border-top-color: var(--primary);
  animation: spin 1s ease-in-out infinite;
  margin-right: 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 768px) {
  .results-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
  
  .search-container {
    flex-direction: column;
  }
  
  #search-button {
    width: 100%;
    padding: 12px;
  }
}
