/* Catppuccin Mocha */
:root {
  --base: #1e1e2e;
  --mantle: #181825;
  --crust: #11111b;
  --surface0: #313244;
  --surface1: #45475a;
  --surface2: #585b70;
  --overlay0: #6c7086;
  --overlay1: #7f849c;
  --overlay2: #9399b2;
  --subtext0: #a6adc8;
  --subtext1: #bac2de;
  --text: #cdd6f4;
  --lavender: #b4befe;
  --blue: #89b4fa;
  --sapphire: #74c7ec;
  --sky: #89dceb;
  --teal: #94e2d5;
  --green: #a6e3a1;
  --yellow: #f9e2af;
  --peach: #fab387;
  --maroon: #eba0ac;
  --red: #f38ba8;
  --mauve: #cba6f7;
  --pink: #f5c2e7;
  --flamingo: #f2cdcd;
  --rosewater: #f5e0dc;
}

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

html {
  font-size: 16px;
}

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

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header */
header {
  background-color: var(--mantle);
  border-bottom: 1px solid var(--surface0);
  padding: 1.5rem 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text);
}

.controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.controls input,
.controls select {
  background-color: var(--surface0);
  color: var(--text);
  border: 1px solid var(--surface1);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-width: 200px;
}

.controls input:focus,
.controls select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(137, 180, 250, 0.2);
}

.controls input::placeholder {
  color: var(--overlay1);
}

/* Visually hidden */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Breadcrumbs */
#breadcrumbs {
  margin: 1.5rem 0;
  font-size: 0.875rem;
  color: var(--subtext0);
}

#breadcrumbs ol {
  display: flex;
  list-style: none;
  gap: 0.5rem;
  align-items: center;
}

#breadcrumbs li:not(:last-child)::after {
  content: '>';
  margin-left: 0.5rem;
  color: var(--overlay0);
}

#breadcrumbs a {
  color: var(--blue);
  text-decoration: none;
  cursor: pointer;
}

#breadcrumbs a:hover {
  color: var(--lavender);
  text-decoration: underline;
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  padding: 1rem 0 3rem;
}

/* Card */
.card {
  background-color: var(--surface0);
  border: 1px solid var(--surface1);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
}

.card:hover,
.card:focus-within {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  border-color: var(--surface2);
}

.card:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.card-image {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background-color: var(--mantle);
  overflow: hidden;
}

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

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

.card-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background-color: var(--green);
  color: var(--base);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
}

.card-body {
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta {
  font-size: 0.875rem;
  color: var(--subtext0);
}

.card-meta .author {
  color: var(--blue);
}

/* Loading / Error */
.loading,
.error {
  text-align: center;
  padding: 3rem 1rem;
  font-size: 1rem;
  color: var(--subtext0);
}

.error {
  color: var(--red);
}

.hidden {
  display: none !important;
}

/* Modal */
dialog {
  border: none;
  border-radius: 16px;
  background-color: var(--mantle);
  color: var(--text);
  max-width: 900px;
  width: 90vw;
  max-height: 88vh;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
  margin: auto;
}

dialog::backdrop {
  background-color: rgba(17, 17, 27, 0.85);
  backdrop-filter: blur(4px);
}

.modal-content {
  padding: 1.5rem;
  overflow-y: auto;
  max-height: calc(88vh - 3rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--surface2) var(--surface0);
}

.modal-content::-webkit-scrollbar {
  width: 8px;
}

.modal-content::-webkit-scrollbar-track {
  background: var(--surface0);
  border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb {
  background: var(--surface2);
  border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
  background: var(--overlay0);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--surface0);
  border: none;
  color: var(--text);
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  z-index: 2;
}

.modal-close:hover {
  background: var(--surface1);
}

.modal-close:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.modal-header {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.modal-image-wrap {
  flex: 1;
  min-width: 0;
}

.modal-image-wrap img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.modal-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#modal-title {
  font-size: 1.5rem;
  font-weight: 700;
}

#modal-description {
  color: var(--subtext0);
}

#modal-meta {
  font-size: 0.875rem;
  color: var(--subtext1);
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

#modal-bricks {
  background-color: var(--surface0);
  border-radius: 8px;
  padding: 1rem;
}

#modal-bricks summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  padding-left: 1rem;
  position: relative;
}

#modal-bricks summary::before {
  content: '▶';
  position: absolute;
  left: 0;
  font-size: 0.75rem;
  color: var(--subtext0);
  transition: transform 0.2s;
}

#modal-bricks[open] > summary::before {
  content: '▼';
}

.download-icon {
  background: none;
  border: none;
  color: var(--blue);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.2s, color 0.2s;
}

.download-icon:hover {
  color: var(--lavender);
  background-color: var(--surface1);
}

.download-icon:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

#modal-bricks summary:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-radius: 4px;
}

#modal-bricks-table {
  margin-top: 0.75rem;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface2) var(--surface0);
}

#modal-bricks-table::-webkit-scrollbar {
  width: 8px;
}

#modal-bricks-table::-webkit-scrollbar-track {
  background: var(--surface0);
  border-radius: 4px;
}

#modal-bricks-table::-webkit-scrollbar-thumb {
  background: var(--surface2);
  border-radius: 4px;
}

#modal-bricks-table::-webkit-scrollbar-thumb:hover {
  background: var(--overlay0);
}

#modal-bricks-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

#modal-bricks-table th,
#modal-bricks-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--surface1);
}

#modal-bricks-table th {
  position: sticky;
  top: 0;
  background: var(--surface0);
  color: var(--subtext1);
  font-weight: 600;
}

#modal-bricks-table td {
  color: var(--text);
}

#modal-bricks-table tr:hover td {
  background: var(--surface1);
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-block;
  background-color: var(--blue);
  color: var(--base);
  text-decoration: none;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background-color 0.2s, transform 0.2s;
  border: none;
  cursor: pointer;
}

.btn:hover {
  background-color: var(--sapphire);
  transform: translateY(-1px);
}

.btn:focus-visible {
  outline: 2px solid var(--lavender);
  outline-offset: 2px;
}

/* Responsive */
@media (max-width: 640px) {
  header h1 {
    font-size: 1.25rem;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
  }

  .controls input,
  .controls select {
    min-width: 100%;
  }

  dialog {
    width: 95vw;
    max-height: 88vh;
  }

  .modal-content {
    max-height: calc(88vh - 3rem);
  }

  .modal-header {
    flex-direction: column;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .card,
  .card-image img,
  .btn {
    transition: none;
  }
}
