/* ===== Theme & Custom Properties ===== */
:root {
  --md-sys-color-primary: rgb(73, 252, 255);
  --md-sys-color-secondary: rgb(59, 203, 232);
  --md-sys-color-surface: rgb(14, 22, 43);
  --md-sys-color-surface-container: rgb(32, 41, 65);
  --md-sys-color-surface-container-high: rgb(42, 53, 80);
  --md-sys-color-surface-container-highest: rgb(52, 63, 92);
  --md-sys-color-on-surface: rgb(220, 225, 240);
  --md-sys-color-on-surface-variant: rgb(170, 180, 200);
  --md-sys-color-outline: rgb(80, 90, 115);
  --md-sys-color-outline-variant: rgb(55, 65, 90);
  --md-sys-color-on-primary: rgb(0, 30, 30);
  --md-sys-color-error: rgb(255, 100, 100);

  --md-sys-shape-corner-medium: 12px;
  --md-sys-shape-corner-small: 8px;
  --md-sys-shape-corner-extra-small: 4px;

  --card-size: 300px;
  --top-bar-height: 120px;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Roboto', sans-serif;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  min-height: 100vh;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--md-sys-color-surface);
}
::-webkit-scrollbar-thumb {
  background: var(--md-sys-color-outline);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--md-sys-color-on-surface-variant);
}

/* ===== Top App Bar ===== */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--md-sys-color-surface-container);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  padding: 12px 24px;
}

.top-bar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.top-bar-title h1 {
  font-size: 22px;
  font-weight: 500;
  color: var(--md-sys-color-primary);
  letter-spacing: 0.5px;
}

.top-bar-title .subtitle {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  letter-spacing: 0.3px;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.last-updated {
  font-size: 11px;
  color: var(--md-sys-color-on-surface-variant);
  opacity: 0.7;
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* Search Field */
.search-field {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 200px;
  max-width: 320px;
  flex: 1;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 20px;
  pointer-events: none;
}

.search-field input {
  width: 100%;
  padding: 8px 36px 8px 40px;
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  color: var(--md-sys-color-on-surface);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.search-field input:focus {
  border-color: var(--md-sys-color-primary);
}

.search-field input::placeholder {
  color: var(--md-sys-color-on-surface-variant);
  opacity: 0.6;
}

.search-clear {
  position: absolute;
  right: 4px;
}

/* Filter Selects */
.filter-select {
  padding: 8px 28px 8px 12px;
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  color: var(--md-sys-color-on-surface);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23AAB4C8' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color 0.2s;
}

.filter-select:focus {
  border-color: var(--md-sys-color-primary);
}

.filter-select option {
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
}

/* Result Count */
.result-count {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
}

/* Size Control */
.size-control {
  display: flex;
  align-items: center;
  gap: 4px;
}

.size-icon {
  font-size: 18px;
  color: var(--md-sys-color-on-surface-variant);
}

.size-control input[type="range"] {
  width: 80px;
  accent-color: var(--md-sys-color-primary);
  cursor: pointer;
}

/* View Toggle */
.view-toggle {
  display: flex;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  overflow: hidden;
}

.view-toggle .icon-btn {
  border-radius: 0;
  border: none;
}

.view-toggle .icon-btn.active {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

/* ===== Icon Button ===== */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: rgba(73, 252, 255, 0.1);
  color: var(--md-sys-color-primary);
}

.icon-btn .material-icons {
  font-size: 20px;
}

/* ===== States (Loading / Error) ===== */
.state-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  gap: 16px;
  color: var(--md-sys-color-on-surface-variant);
}

.loader {
  width: 40px;
  height: 40px;
  border: 3px solid var(--md-sys-color-outline);
  border-top-color: var(--md-sys-color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.error-icon {
  font-size: 48px;
  color: var(--md-sys-color-error);
}

.btn-filled {
  padding: 10px 24px;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border: none;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s, box-shadow 0.15s;
}

.btn-filled:hover {
  opacity: 0.9;
  box-shadow: 0 2px 8px rgba(73, 252, 255, 0.3);
}

.hidden {
  display: none !important;
}

/* ===== Mod Grid ===== */
.mod-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-size), 1fr));
  gap: 16px;
  padding: 20px 24px 40px;
}

/* ===== Mod Card ===== */
.mod-card {
  position: relative;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-medium);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  border: 1px solid transparent;
}

.mod-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  border-color: var(--md-sys-color-outline-variant);
}

.card-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: var(--md-sys-color-surface-container-high);
  display: block;
}

.card-image-placeholder {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--md-sys-color-surface-container-high);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--md-sys-color-outline);
}

.card-image-placeholder .material-icons {
  font-size: 48px;
}

.card-body {
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.card-name {
  font-size: 16px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  line-height: 1.3;
}

.card-author {
  font-size: 13px;
  color: var(--md-sys-color-secondary);
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  flex-wrap: wrap;
}

.card-meta-item {
  display: flex;
  align-items: center;
  gap: 3px;
}

.card-meta-item .material-icons {
  font-size: 14px;
}

.card-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chip {
  display: inline-block;
  padding: 2px 10px;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 16px;
  font-size: 11px;
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
}

.card-summary {
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.card-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  background: transparent;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: 16px;
  color: var(--md-sys-color-primary);
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.link-btn:hover {
  background: rgba(73, 252, 255, 0.1);
  border-color: var(--md-sys-color-primary);
}

/* Download FAB — bottom-right of card */
.card-fab {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: background 0.15s, box-shadow 0.15s, transform 0.15s;
  z-index: 2;
}
.card-fab:hover {
  background: rgb(93, 255, 255);
  box-shadow: 0 4px 12px rgba(73, 252, 255, 0.35);
  transform: scale(1.05);
}
.card-fab .material-icons {
  font-size: 20px;
}

/* Row download button */
.row-download-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
  flex-shrink: 0;
}
.row-download-btn:hover {
  background: rgb(93, 255, 255);
}
.row-download-btn .material-icons {
  font-size: 18px;
}

.link-btn .material-icons {
  font-size: 14px;
}

/* ===== List View ===== */
.mod-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 20px 24px 40px;
}

.mod-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto auto;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-small);
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
}

.mod-row:hover {
  background: var(--md-sys-color-surface-container-high);
  border-color: var(--md-sys-color-outline-variant);
}

.row-thumb {
  width: 64px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--md-sys-color-surface-container-high);
  flex-shrink: 0;
}

.row-thumb-placeholder {
  width: 64px;
  height: 40px;
  border-radius: 4px;
  background: var(--md-sys-color-surface-container-high);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--md-sys-color-outline);
  flex-shrink: 0;
}

.row-thumb-placeholder .material-icons {
  font-size: 20px;
}

.row-info {
  min-width: 0;
}

.row-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-author {
  font-size: 12px;
  color: var(--md-sys-color-secondary);
}

.row-version {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
}

.row-date {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
}

.row-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.row-links {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-medium);
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  animation: scaleIn 0.15s ease;
}

@keyframes scaleIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-close {
  position: sticky;
  top: 8px;
  float: right;
  margin: 8px;
  z-index: 10;
  background: var(--md-sys-color-surface-container-high);
}

/* Detail Modal Body */
.detail-gallery {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 8px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.detail-gallery.dragging {
  cursor: grabbing;
  scroll-snap-type: none;
  scroll-behavior: auto;
}

.detail-gallery img {
  max-height: 300px;
  border-radius: var(--md-sys-shape-corner-small);
  object-fit: contain;
  background: var(--md-sys-color-surface);
  flex-shrink: 0;
  cursor: pointer;
  transition: opacity 0.15s;
}

.detail-gallery img:hover {
  opacity: 0.85;
}

/* Image Lightbox */
.lightbox-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: fadeIn 0.15s ease;
}

.lightbox-overlay img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: var(--md-sys-shape-corner-small);
}

.detail-header {
  padding: 16px 24px 0;
}

.detail-name {
  font-size: 24px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  margin-bottom: 4px;
}

.detail-author {
  font-size: 15px;
  color: var(--md-sys-color-secondary);
  margin-bottom: 12px;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 12px;
}

.detail-meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.detail-meta-item .material-icons {
  font-size: 16px;
}

.detail-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.detail-section {
  padding: 0 24px 24px;
}

.detail-images-section {
  padding: 16px 24px;
}

.detail-description {
  font-size: 14px;
  line-height: 1.7;
  color: var(--md-sys-color-on-surface);
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-description a {
  color: var(--md-sys-color-primary);
}

.detail-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 24px 24px;
}

.detail-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  background: rgba(73, 252, 255, 0.1);
  border: 1px solid var(--md-sys-color-primary);
  border-radius: 20px;
  color: var(--md-sys-color-primary);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}

.detail-link-btn:hover {
  background: rgba(73, 252, 255, 0.2);
}

/* Primary download button — detail modal */
.detail-link-btn--primary {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-color: var(--md-sys-color-primary);
}
.detail-link-btn--primary:hover {
  background: rgb(93, 255, 255);
}

.detail-link-btn .material-icons {
  font-size: 18px;
}

/* About Dialog */
.about-dialog {
  max-width: 400px;
  text-align: center;
}

.about-body {
  padding: 40px 32px;
}

.about-body h2 {
  font-size: 28px;
  font-weight: 500;
  color: var(--md-sys-color-primary);
  margin-bottom: 8px;
}

.about-subtitle {
  font-size: 14px;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 16px;
}

.about-credit {
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
  opacity: 0.7;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-right {
    justify-content: space-between;
  }

  .mod-row {
    grid-template-columns: auto 1fr;
    gap: 8px;
  }

  .row-version,
  .row-date,
  .row-categories,
  .row-links {
    display: none;
  }
}

@media (max-width: 600px) {
  .top-bar {
    padding: 10px 12px;
  }

  .mod-grid,
  .mod-list {
    padding: 12px;
  }

  .search-field {
    min-width: 0;
    max-width: none;
  }

  .size-control {
    display: none;
  }

  .modal-content {
    max-height: 95vh;
  }

  .detail-gallery img {
    max-height: 200px;
  }
}
