* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Light theme (default) */
:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --surface-hover: #f0f0f0;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-muted: #666;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --success: #16a34a;
  --error: #dc2626;
  --radius: 10px;
  --shadow: 0 4px 12px rgba(0,0,0,0.1);
  --header-bg: #ffffff;
}

/* Dark theme */
[data-theme="dark"] {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface-hover: #252525;
  --border: #333;
  --text: #f5f5f5;
  --text-muted: #888;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --success: #22c55e;
  --error: #ef4444;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
  --header-bg: #1a1a1a;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* Compact Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.header-divider {
  color: var(--border);
  font-weight: 300;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Search */
.search-box {
  position: relative;
  width: 180px;
}

.search-box input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9999px;
  color: var(--text);
  font-size: 0.875rem;
  transition: border-color 0.2s, box-shadow 0.2s, width 0.2s;
}

.search-box input:focus {
  outline: none;
  border-color: var(--border);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
  width: 220px;
}

[data-theme="dark"] .search-box input:focus {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.search-icon {
  position: absolute;
  left: 0.625rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

/* Sort Buttons - Pill Style */
.sort-buttons {
  display: flex;
  gap: 0.375rem;
  background: var(--surface);
  padding: 0.25rem;
  border-radius: 9999px;
  border: 1px solid var(--border);
}

.sort-btn {
  padding: 0.4rem 0.875rem;
  background: transparent;
  border: none;
  border-radius: 9999px;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sort-btn:hover {
  color: var(--text);
}

.sort-btn.active {
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Theme Toggle */
.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-muted);
}

.theme-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
  transform: rotate(15deg);
}

.theme-btn svg {
  width: 18px;
  height: 18px;
}

.theme-btn .icon-moon { display: none; }
[data-theme="dark"] .theme-btn .icon-sun { display: none; }
[data-theme="dark"] .theme-btn .icon-moon { display: block; }

/* Masonry Gallery */
.gallery {
  column-count: 3;
  column-gap: 1rem;
  padding: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 1000px) {
  .gallery { column-count: 2; }
}

@media (max-width: 600px) {
  .gallery { column-count: 1; max-width: 500px; }

  .header {
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
  }

  .header-left { width: 100%; justify-content: center; }
  .header-right { width: 100%; justify-content: center; }
  .search-box { width: 100%; max-width: 300px; }
  .search-box input:focus { width: 100%; }
}

/* Card */
.card {
  break-inside: avoid;
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1rem;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  background: var(--surface);
  border: 1px solid var(--border);
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}

.card-image {
  position: relative;
  width: 100%;
  display: block;
}

.card-image img {
  display: block;
  width: 100%;
  height: auto;
  transition: transform 0.3s;
}

.card:hover .card-image img {
  transform: scale(1.02);
}

.card-image .placeholder {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e8e8e8 0%, #d0d0d0 100%);
  color: var(--text-muted);
  font-size: 0.75rem;
}

[data-theme="dark"] .card-image .placeholder {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

/* Hover overlay */
.card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.3) 50%, transparent 100%);
  opacity: 0;
  transition: opacity 0.3s;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 1rem;
}

.card:hover .card-overlay {
  opacity: 1;
}

.card-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: #fff;
  margin-bottom: 0.125rem;
  letter-spacing: -0.01em;
}

.card-updated {
  color: rgba(255,255,255,0.6);
  font-size: 0.7rem;
  margin-bottom: 0.625rem;
  font-weight: 400;
}

.card-link {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  background: rgba(255,255,255,0.95);
  color: #1a1a1a;
  text-decoration: none;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  transition: all 0.2s ease;
  align-self: flex-start;
  backdrop-filter: blur(8px);
}

.card-link:hover {
  background: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.card-link svg {
  width: 14px;
  height: 14px;
}

/* Status badge */
.status-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  z-index: 2;
}

.status-badge.ok {
  background: rgba(22, 163, 74, 0.9);
  color: #fff;
}

.status-badge.error {
  background: rgba(220, 38, 38, 0.9);
  color: #fff;
}

.card.hidden {
  display: none;
}

/* Touch devices */
@media (hover: none) {
  .card-overlay {
    opacity: 1;
    background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 50%);
  }
}

/* Footer */
.footer {
  text-align: center;
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  border-top: 1px solid var(--border);
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  animation: fadeIn 0.4s ease-out backwards;
}
