/* ============================================
   Art Gallery - Base Styles
   ============================================
   CSS Variables, Themes, Base Layout, Header, Search
   ============================================ */

/* ===== Fonts ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&family=Playfair+Display:wght@400;700&display=swap');

/* ===== CSS Variables & Theme System ===== */
:root {
  --card-radius: 12px;
  --card-border: rgba(44, 43, 43, 0.247);
  --shadow-soft: 0 10px 30px rgba(2,6,23,0.12);
  --shadow-hover: 0 20px 50px rgba(2,6,23,0.14);
  --focus-outline: 3px solid rgba(255,107,107,0.12);
  --maxw: 1200px;
}

/* Theme Definitions */
:root[data-theme="dark"] {
  --bg-dark: #0b1220;
  --surface: rgba(10,14,20,0.96);
  --muted-panel: rgba(255,255,255,0.02);
  --accent: #ff6b6b;
  --muted: #9fb0c8;
  --text: #e9f1f7;
  --heading: #fff;
}

:root[data-theme="light"] {
  --bg-dark: #f6f6f6;
  --surface: #fff;
  --muted-panel: #fbfbfb;
  --accent: #ff6b6b;
  --muted: #4b5563;
  --text: #0f1720;
  --heading: #0b1220;
}

:root[data-theme="sepia"] {
  --bg-dark: #f2e6d8;
  --surface: #fff6ec;
  --muted-panel: #fbf5ee;
  --accent: #a66a2a;
  --muted: #6a5a4a;
  --text: #251b14;
  --heading: #1b120a;
}

:root[data-theme="high-contrast"] {
  --bg-dark: #000;
  --surface: #000;
  --muted-panel: #000;
  --accent: #00ffff;
  --muted: #fff;
  --text: #fff;
  --heading: #fff;
}

/* ===== Base Styles ===== */
*, *::before, *::after {
  box-sizing: border-box;
}

/* Smooth theme transitions - only on theme-related elements */
:root[data-theme] * {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Skip links for accessibility */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--accent);
  color: white;
  padding: 8px;
  text-decoration: none;
  border-radius: 4px;
  z-index: 1000;
  font-weight: 600;
}

.skip-link:focus {
  top: 6px;
}

/* Screen reader only content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--muted);
  border-top: 4px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

.loading-overlay p {
  color: var(--text);
  font-size: 16px;
  margin: 0;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Error messages */
.error-message {
  position: fixed;
  top: 20px;
  right: 20px;
  max-width: 400px;
  z-index: 1001;
  animation: slideInRight 0.3s ease-out;
}

.error-content {
  background: var(--surface);
  border: 2px solid #ff6b6b;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.error-icon {
  font-size: 32px;
  margin-bottom: 12px;
}

.error-content h3 {
  margin: 0 0 8px 0;
  color: var(--text);
  font-size: 18px;
}

.error-content p {
  margin: 0 0 16px 0;
  color: var(--muted);
  line-height: 1.5;
}

.error-content details {
  margin: 16px 0;
}

.error-content pre {
  background: var(--muted-panel);
  padding: 8px;
  border-radius: 4px;
  font-size: 12px;
  overflow-x: auto;
  margin: 8px 0 0 0;
}

.error-reload-btn {
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
}

.error-reload-btn:hover {
  background: var(--accent);
  opacity: 0.9;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial;
  color: var(--text);
  background-color: var(--bg-dark);
  -webkit-font-smoothing: antialiased;
  padding: 20px 10px;
  min-height: 100vh;
background-image: url("https://www.transparenttextures.com/patterns/xv.png");
  background-repeat: repeat;
  background-attachment: fixed;
  background-size: auto;
}

.container {
  max-width: var(--maxw);
  margin: 12px auto;
  padding: 18px;
  background-color: var(--surface);
  border-radius: 12px;
  border: 6px solid var(--card-border);
  box-shadow: var(--shadow-soft);
  border-style: ridge;
}

/* ===== Header Layout ===== */
header {
  margin-bottom: 24px;
}

.header-top {
  gap: 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

h1 {
  font-family: 'Playfair Display', serif;
  margin: 0;
  font-weight: 700;
  font-size: clamp(36px, 4vw, 28px);
  color: var(--heading);
  line-height: 1.2;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.subtitle {
  color: var(--muted);
  font-size: 15px;
  margin-top: 8px;
  line-height: 1.5;
  text-align: center;
  font-family: Roboto, Arial, sans-serif;
}

/* ===== Artwork Search Section ===== */
.artwork-search-section {
  margin-bottom: 20px;
}

.search-section {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 14px;
  color: var(--muted);
  pointer-events: none;
  width: 18px;
  height: 18px;
  z-index: 1;
  opacity: 0.8;
}

.search {
  padding: 14px 44px 14px 44px;
  border-radius: 20px;
  border: 4px solid rgba(0,0,0,0.15);
  border-style: outset;
  width: 100%;
  background: var(--muted-panel);
  color: var(--text);
  font-size: 15px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* Disable browser's native search input clear button */
.search::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: none;
}

.search-clear {
  position: absolute;
  right: 14px;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  width: 18px;
  height: 18px;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.search-clear:hover {
  opacity: 0.8;
}

.search:not(:placeholder-shown) + .search-clear {
  opacity: 0.6;
}

footer {
  margin-top: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ===== Utility Classes ===== */
.hidden {
  display: none;
}

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 16px;
}



.loading {
  opacity: 0.6;
  pointer-events: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

/* ===== Accessibility ===== */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus-visible,
.custom-select-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.search:focus-visible,
.tag-search:focus-visible {
  outline: none;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 414px) {
  body {
    padding: 10px 6px;
  }
  
  .container {
    padding: 10px;
    border-radius: 8px;
  }
  
  .header-top {
    flex-direction: column;
    gap: 12px;
  }
  
  .artwork-search-section {
    margin-bottom: 12px;
  }
  
  .search-section {
    max-width: 100%;
  }
}

@media (max-width: 375px) {
  .container {
    padding: 8px;
  }
  
  h1 {
    font-size: clamp(18px, 4vw, 24px);
  }
  
  .search {
    font-size: 14px;
    padding: 12px 40px 12px 40px;
  }
}

@media (max-width: 320px) {
  body {
    padding: 8px 4px;
  }
  
  .container {
    padding: 6px;
  }
  
  .search {
    padding: 10px 36px 10px 36px;
  }
}

@media (max-width: 700px) {
  body {
    padding: 12px 8px;
  }
  
  .container {
    padding: 12px;
    border-radius: 10px;
  }
  
  .header-top {
    flex-direction: column;
    gap: 16px;
  }
  
  .artwork-search-section {
    margin-bottom: 16px;
  }
  
  .search-section {
    max-width: 100%;
  }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

