:root {
  color-scheme: dark;
  --bg: #0b1220;
  --bg-elevated: #111c31;
  --bg-card: #15253f;
  --border: rgba(148, 163, 184, 0.2);
  --primary: #38bdf8;
  --primary-soft: rgba(56, 189, 248, 0.1);
  --text: #e2e8f0;
  --text-subtle: #94a3b8;
  --danger: #f87171;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-soft: 0 14px 40px rgba(15, 23, 42, 0.45);
  --transition: 180ms ease;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(
      circle at 10% 10%,
      rgba(56, 189, 248, 0.12),
      transparent 35%
    ),
    radial-gradient(circle at 90% 5%, rgba(168, 85, 247, 0.07), transparent 40%),
    var(--bg);
  color: var(--text);
  line-height: 1.6;
}

body.modal-open {
  overflow: hidden;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  color: #f8fafc;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 1.2rem clamp(1.8rem, 4vw, 3rem);
  background: linear-gradient(
    180deg,
    rgba(15, 23, 42, 0.92) 0%,
    rgba(15, 23, 42, 0.8) 60%,
    transparent 100%
  );
  backdrop-filter: blur(18px);
}

.header-top {
  position: relative;
  max-width: 960px;
  margin-bottom: 0.4rem;
}

.header-top-close {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  border: none;
  background: rgba(148, 163, 184, 0.15);
  border-radius: 999px;
  width: 2rem;
  height: 2rem;
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition);
}

.header-top-close:hover {
  background: rgba(56, 189, 248, 0.35);
}

.header-top-close:active {
  transform: translateY(1px);
}

.tagline {
  margin: 0.8rem 0 0;
  color: var(--text-subtle);
  font-size: 1rem;
}

.control-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  min-width: min(360px, 100%);
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-field:focus-within {
  border-color: rgba(56, 189, 248, 0.6);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.search-icon {
  font-size: 1rem;
  opacity: 0.6;
}

#searchInput {
  flex: 1;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  outline: none;
}

.ghost-btn {
  border: none;
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-subtle);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), color var(--transition),
    transform var(--transition);
}

.ghost-btn:hover {
  background: rgba(148, 163, 184, 0.3);
  color: var(--text);
}

.ghost-btn:active {
  transform: translateY(1px);
}

.clear-filter-btn {
  padding: 0.45rem 0.9rem;
}

#clearSearch {
  display: none;
  align-items: center;
  justify-content: center;
  width: 1.8rem;
  height: 1.8rem;
  font-size: 0.85rem;
}

.result-stats {
  margin-left: auto;
  color: var(--text-subtle);
  font-size: 0.95rem;
}

.tag-filter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
  color: var(--text-subtle);
}

.toggle-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.toggle-btn:hover {
  background: rgba(56, 189, 248, 0.1);
}

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  max-height: 120px;
  overflow-y: auto;
  padding-right: 0.2rem;
  transition: max-height 0.3s ease, opacity 0.3s ease;
}

.tag-filter.collapsed {
  max-height: 0;
  opacity: 0;
}

.tag-filter.expanded {
  max-height: 120px;
  opacity: 1;
}

.tag-button {
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.6);
  color: var(--text-subtle);
  font-size: 0.8rem;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition),
    background var(--transition), color var(--transition);
}

.tag-button:hover {
  transform: translateY(-2px);
  border-color: rgba(56, 189, 248, 0.6);
  color: var(--text);
}

.tag-button.active {
  background: var(--primary-soft);
  border-color: rgba(56, 189, 248, 0.8);
  color: var(--primary);
}

main {
  padding: 0 clamp(1.4rem, 4vw, 3rem) 3rem;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.2rem;
}

@media (min-width: 1400px) {
  .gallery {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}

@media (max-width: 720px) {
  .app-header {
    position: static;
    padding-top: 1.8rem;
  }

  .control-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .result-stats {
    margin-left: 0;
  }

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

  .card-body {
    padding: 0.7rem 0.8rem 0.9rem;
    gap: 0.5rem;
  }

  .card-title {
    font-size: 0.9rem;
  }

  .tag-chip {
    padding: 0.1rem 0.45rem;
    font-size: 0.65rem;
  }

  .card-meta {
    font-size: 0.7rem;
  }

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

@media (max-width: 480px) {
  .gallery {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.8rem;
  }

  .card-title {
    font-size: 0.85rem;
  }

  .tag-chip {
    padding: 0.1rem 0.4rem;
    font-size: 0.6rem;
  }
}

.prompt-card {
  background: rgba(17, 25, 40, 0.8);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(148, 163, 184, 0.08);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(10px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition), border-color var(--transition);
  cursor: pointer;
}

.prompt-card:hover {
  transform: translateY(-6px);
  border-color: rgba(56, 189, 248, 0.4);
}

.prompt-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: rgba(148, 163, 184, 0.08);
}

.card-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: rgba(148, 163, 184, 0.08);
  color: rgba(148, 163, 184, 0.7);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.card-body {
  padding: 1.1rem 1.1rem 0.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.card-title {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.tag-chip {
  padding: 0.15rem 0.55rem;
  font-size: 0.7rem;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.12);
  color: #bae6fd;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-subtle);
  font-size: 0.75rem;
}

.card-meta span + span::before {
  content: "•";
  margin: 0 0.4rem;
  color: rgba(148, 163, 184, 0.4);
}

.empty-state {
  margin-top: 3rem;
  text-align: center;
  color: var(--text-subtle);
  font-size: 1rem;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 15, 0.72);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1.5rem, 4vw, 3rem);
  z-index: 999;
}

.modal-content {
  position: relative;
  width: min(960px, 100%);
  max-height: 90vh;
  padding: clamp(1.4rem, 2vw, 2.1rem);
  background: radial-gradient(
      circle at top right,
      rgba(56, 189, 248, 0.1),
      transparent 40%
    ),
    rgba(8, 17, 35, 0.98);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: var(--shadow-soft);
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 1.1rem;
  right: 1.1rem;
  border: none;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 999px;
  width: 2.2rem;
  height: 2.2rem;
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  transition: background var(--transition);
}

.modal-close:hover {
  background: rgba(56, 189, 248, 0.7);
}

.modal-header {
  margin-bottom: 1rem;
}

.modal-source {
  margin-top: 0.4rem;
  font-size: 0.9rem;
  color: var(--text-subtle);
}

.modal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.4rem;
}

.modal-tags .tag-chip {
  background: rgba(56, 189, 248, 0.18);
  color: #e0f2fe;
}

.modal-section {
  margin-bottom: 1.6rem;
}

.modal-section h3 {
  margin-bottom: 0.8rem;
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.9rem;
}

.image-grid img {
  width: 70%;
  border-radius: var(--radius-md);
  border: 1px solid rgba(148, 163, 184, 0.18);
  object-fit: cover;
  background: rgba(148, 163, 184, 0.08);
}

.prompt-block {
  position: relative;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.7);
  border-radius: var(--radius-md);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.prompt-block + .prompt-block {
  margin-top: 1rem;
}

.prompt-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
  color: var(--text-subtle);
  font-size: 0.85rem;
}

.copy-btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
  background: rgba(56, 189, 248, 0.12);
  color: #bae6fd;
  cursor: pointer;
  transition: background var(--transition), color var(--transition),
    transform var(--transition);
}

.copy-btn:hover {
  background: rgba(56, 189, 248, 0.25);
  color: #f0f9ff;
  transform: translateY(-1px);
}

pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: "JetBrains Mono", "Fira Code", "SFMono-Regular", ui-monospace,
    SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
    monospace;
  font-size: 0.9rem;
  color: #f8fafc;
}

.note-list {
  padding-left: 1.2rem;
  margin: 0.3rem 0 0;
  color: var(--text-subtle);
}

.description-block {
  color: var(--text-subtle);
  background: rgba(148, 163, 184, 0.08);
  border-radius: var(--radius-md);
  padding: 1rem;
  border: 1px solid rgba(148, 163, 184, 0.14);
}

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.85);
  color: #f8fafc;
  padding: 0.7rem 1.2rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(56, 189, 248, 0.35);
  box-shadow: 0 15px 40px rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(10px);
  font-size: 0.95rem;
  z-index: 1000;
}

.toast.error {
  border-color: rgba(248, 113, 113, 0.65);
  color: #fee2e2;
}
